| 1 19 20 package org.openharmonise.dav.server.utils; 21 22 import java.io.*; 23 import java.net.*; 24 import java.util.*; 25 import java.util.logging.*; 26 27 import org.openharmonise.commons.dsi.AbstractDataStoreInterface; 28 import org.openharmonise.commons.xml.namespace.NamespaceType; 29 import org.openharmonise.rm.*; 30 import org.openharmonise.rm.config.*; 31 import org.openharmonise.rm.factory.*; 32 import org.openharmonise.rm.metadata.*; 33 import org.openharmonise.rm.resources.*; 34 import org.openharmonise.rm.resources.audit.*; 35 import org.openharmonise.rm.resources.content.*; 36 import org.openharmonise.rm.resources.metadata.properties.*; 37 import org.openharmonise.rm.resources.metadata.values.*; 38 import org.openharmonise.rm.resources.publishing.*; 39 import org.openharmonise.rm.resources.users.*; 40 import org.openharmonise.rm.resources.workflow.properties.*; 41 import org.openharmonise.rm.resources.workflow.values.*; 42 import org.openharmonise.rm.resources.xml.*; 43 import org.openharmonise.rm.security.authorization.*; 44 import org.openharmonise.rm.workflow.WorkflowProfile; 45 46 import com.ibm.webdav.*; 47 48 56 public class HarmoniseNameResolver { 57 58 public static final String PNAME_AUTO_APPROVE_COLLECTIONS = 59 "AUTO_APPROVE_COLLECTIONS"; 60 61 public static final String WEBDAV_ROOT_MARKER = "webdav"; 63 public static final String URL_SEPARATOR = "/"; 64 public static final String UTF_8 = "UTF-8"; 65 private static final String VERSION_SEGMENT = "ver"; 66 67 public static final String RESOURCE_TYPE_VALUE = "value"; 68 public static final String RESOURCE_TYPE_RESOURCE = "resource"; 69 public static final String RESOURCE_TYPE_PROPERTY = "property-resource"; 70 public static final String RESOURCE_TYPE_COLLECTION = "collection"; 71 72 public static final String CONTENT_NAME = "Content"; 73 public static final String WEBSITE_NAME = "Website"; 74 public static final String COMPOSITION_NAME = WEBSITE_NAME + "/Composition"; 75 public static final String METADATA_NAME = "Metadata"; 76 public static final String ARCHIVE_NAME = "Archive"; 77 public static final String ASSETS_NAME = CONTENT_NAME + "/Assets"; 78 public static final String ASSETS_PATH = "/root/assets"; 79 public static final String REPORTS_NAME = "Reports"; 80 public static final String REPORTS_PATH = "/root/reports"; 81 public static final String DOCS_NAME = CONTENT_NAME + "/Documents"; 82 public static final String DOCS_PATH = "/root/documents"; 83 public static final String NEWSLETTER_NAME = "Newsletter"; 84 public static final String NEWSLETTER_PATH = "/root/newsletter"; 85 public static final String PROPERTY_NAME = METADATA_NAME + "/Properties"; 86 public static final String PROPERTY_PATH = "/root/props"; 87 public static final String VALUE_NAME = METADATA_NAME + "/Values"; 88 public static final String VALUE_PATH = "/root/vals"; 89 public static final String WEBPAGES_NAME = 90 WEBSITE_NAME + "/Page Definition"; 91 public static final String WEBPAGES_PATH = "/root"; 92 public static final String O_TEMPLATES_NAME = 93 COMPOSITION_NAME + "/Object Templates"; 94 public static final String O_TEMPLATES_PATH = "/root"; 95 public static final String P_TEMPLATES_NAME = 96 COMPOSITION_NAME + "/Page Templates"; 97 public static final String P_TEMPLATES_PATH = "/root/pages"; 98 public static final String INCLUDES_NAME = COMPOSITION_NAME + "/Includes"; 99 public static final String INCLUDES_PATH = "/root/includes"; 100 public static final String USERS_NAME = "Users"; 101 public static final String USERS_PATH = "/root"; 102 public static final String DISPLAY_NAME = WEBSITE_NAME + "/Display"; 103 public static final String XSLT_NAME = DISPLAY_NAME + "/XSLT"; 104 public static final String XSLT_PATH = "/root"; 105 public static final String SITE_ASSETS_NAME = WEBSITE_NAME + "/Site Assets"; 106 public static final String SITE_ASSETS_PATH = "/root/site assets"; 107 public static final String RBS_PROPS_NAME = "RBS_PROPS"; 108 public static final String RBS_PROPS_PATH = "/root/rbs"; 109 public static final String RBS_VALS_NAME = "RBS_VALS"; 110 public static final String RBS_VALS_PATH = "/root/rbs"; 111 public static final String SYSTEM_PROPS_NAME = "SYSTEM_PROPS"; 112 public static final String SYSTEM_PROPS_PATH = "/root/system"; 113 public static final String WORKFLOW_PROPS_NAME = "WORKFLOW_PROPS"; 114 public static final String WORKFLOW_PROPS_PATH = "/root/workflow"; 115 public static final String WORKFLOW_DEFS_NAME = "WORKFLOW_DEFS"; 116 public static final String WORKFLOW_DEFS_PATH = "/root/workflow_defs"; 117 public static final String WORKFLOW_STAGES_NAME = "WORKFLOW_STAGES"; 118 public static final String WORKFLOW_STAGES_PATH = "/root/workflow_stages"; 119 120 public static final String ROOT_NAME = "root"; 121 public static final String ROOT_PATH = "/root"; 122 123 private static Map URI_2_CLASS_MAPPINGS = new Hashtable(); 124 private static Map CONTENT_HARMONISE_PATH_MAPPINGS = new Hashtable(); 125 private static Map TYPE_MAPPINGS = new Hashtable(); 126 127 private static Map m_liveprop2XML_map = new Hashtable(); 128 private static Map m_rootSections_map = new Hashtable(); 129 private static Map m_histObjects_map = new Hashtable(); 130 private static Map m_rootGroupMappings = new Hashtable(); 131 132 private static Map CLASS_2_RESOURCE_TYPE_MAPPING = new Hashtable(); 133 private static Document m_histDoc = null; 134 private static Section m_histSec = null; 135 private static Asset m_histAsset = null; 136 private static List ROOT_GROUPS = new Vector(); 137 private static Map ROOT_COLLECTION_DESCS = new Hashtable(); 138 private static Map CLASS_2_GROUPOBJECT = new Hashtable(); 139 140 public static final String START_PROP_NAME = "START"; 141 142 145 private static final Logger m_logger = Logger.getLogger(HarmoniseNameResolver.class.getName()); 146 147 public static final String VIRTUAL_RESOURCE_NAME = ".resource"; 148 public static final String VIRTUAL_COLLECTION_NAME = ".collection"; 149 150 static { 151 DAVCollectionDesc content = new DAVCollectionDesc(CONTENT_NAME, true); 153 154 List content_members = new Vector(); 155 content_members.add(DOCS_NAME); 156 content_members.add(ASSETS_NAME); 157 content.addMembers(content_members); 158 159 ROOT_COLLECTION_DESCS.put(CONTENT_NAME, content); 160 161 DAVCollectionDesc website = new DAVCollectionDesc(WEBSITE_NAME, true); 163 164 List website_members = new Vector(); 165 website_members.add(COMPOSITION_NAME); 166 website_members.add(DISPLAY_NAME); 167 website_members.add(SITE_ASSETS_NAME); 168 website_members.add(WEBPAGES_NAME); 169 website.addMembers(website_members); 170 171 ROOT_COLLECTION_DESCS.put(WEBSITE_NAME, website); 172 173 DAVCollectionDesc users = 175 new DAVCollectionDesc( 176 USERS_NAME, 177 USERS_PATH, 178 UserGroup.class.getName()); 179 180 ROOT_COLLECTION_DESCS.put(USERS_NAME, users); 181 182 DAVCollectionDesc newsletter = 184 new DAVCollectionDesc( 185 NEWSLETTER_NAME, 186 NEWSLETTER_PATH, 187 Section.class.getName()); 188 ROOT_COLLECTION_DESCS.put(NEWSLETTER_NAME, newsletter); 189 190 DAVCollectionDesc reports = 192 new DAVCollectionDesc( 193 REPORTS_NAME, 194 REPORTS_PATH, 195 XMLAuditResourceGroup.class.getName()); 196 ROOT_COLLECTION_DESCS.put(REPORTS_NAME, reports); 197 198 DAVCollectionDesc metadata = new DAVCollectionDesc(METADATA_NAME, true); 200 201 List metamembers = new Vector(); 202 metamembers.add(PROPERTY_NAME); 203 metamembers.add(VALUE_NAME); 204 metadata.addMembers(metamembers); 205 ROOT_COLLECTION_DESCS.put(METADATA_NAME, metadata); 206 207 DAVCollectionDesc composition = 209 new DAVCollectionDesc(COMPOSITION_NAME, true); 210 211 List comp_members = new Vector(); 212 213 comp_members.add(O_TEMPLATES_NAME); 214 comp_members.add(P_TEMPLATES_NAME); 215 comp_members.add(INCLUDES_NAME); 216 217 composition.addMembers(comp_members); 218 219 ROOT_COLLECTION_DESCS.put(COMPOSITION_NAME, composition); 220 221 DAVCollectionDesc docs = 223 new DAVCollectionDesc( 224 DOCS_NAME, 225 DOCS_PATH, 226 Section.class.getName()); 227 228 ROOT_COLLECTION_DESCS.put(DOCS_NAME, docs); 229 230 DAVCollectionDesc assets = 232 new DAVCollectionDesc( 233 ASSETS_NAME, 234 ASSETS_PATH, 235 Section.class.getName()); 236 237 ROOT_COLLECTION_DESCS.put(ASSETS_NAME, assets); 238 239 DAVCollectionDesc display = new DAVCollectionDesc(DISPLAY_NAME, true); 241 242 List disp_members = new Vector(); 243 244 disp_members.add(XSLT_NAME); 245 246 display.addMembers(disp_members); 247 248 ROOT_COLLECTION_DESCS.put(DISPLAY_NAME, display); 249 250 DAVCollectionDesc site_assets = 252 new DAVCollectionDesc( 253 SITE_ASSETS_NAME, 254 SITE_ASSETS_PATH, 255 Section.class.getName()); 256 257 ROOT_COLLECTION_DESCS.put(SITE_ASSETS_NAME, site_assets); 258 259 DAVCollectionDesc pages = 261 new DAVCollectionDesc( 262 WEBPAGES_NAME, 263 WEBPAGES_PATH, 264 WebPageGroup.class.getName()); 265 266 ROOT_COLLECTION_DESCS.put(WEBPAGES_NAME, pages); 267 268 DAVCollectionDesc prop = 270 new DAVCollectionDesc( 271 PROPERTY_NAME, 272 PROPERTY_PATH, 273 PropertyGroup.class.getName()); 274 275 ROOT_COLLECTION_DESCS.put(PROPERTY_NAME, prop); 276 277 DAVCollectionDesc vals = 279 new DAVCollectionDesc( 280 VALUE_NAME, 281 VALUE_PATH, 282 ValueGroup.class.getName()); 283 284 ROOT_COLLECTION_DESCS.put(VALUE_NAME, vals); 285 286 DAVCollectionDesc obj_temps = 288 new DAVCollectionDesc( 289 O_TEMPLATES_NAME, 290 O_TEMPLATES_PATH, 291 TemplateGroup.class.getName()); 292 293 ROOT_COLLECTION_DESCS.put(O_TEMPLATES_NAME, obj_temps); 294 295 DAVCollectionDesc page_temps = 297 new DAVCollectionDesc( 298 P_TEMPLATES_NAME, 299 P_TEMPLATES_PATH, 300 XMLResourceGroup.class.getName()); 301 302 ROOT_COLLECTION_DESCS.put(P_TEMPLATES_NAME, page_temps); 303 304 DAVCollectionDesc includes = 306 new DAVCollectionDesc( 307 INCLUDES_NAME, 308 INCLUDES_PATH, 309 XMLResourceGroup.class.getName()); 310 311 ROOT_COLLECTION_DESCS.put(INCLUDES_NAME, includes); 312 313 DAVCollectionDesc xslts = 315 new DAVCollectionDesc( 316 XSLT_NAME, 317 XSLT_PATH, 318 XSLResourceGroup.class.getName()); 319 320 ROOT_COLLECTION_DESCS.put(XSLT_NAME, xslts); 321 322 DAVCollectionDesc rbs_props = 324 new DAVCollectionDesc( 325 RBS_PROPS_NAME, 326 RBS_PROPS_PATH, 327 PropertyGroup.class.getName()); 328 ROOT_COLLECTION_DESCS.put(RBS_PROPS_NAME, rbs_props); 329 330 DAVCollectionDesc rbs_vals = 332 new DAVCollectionDesc( 333 RBS_VALS_NAME, 334 RBS_VALS_PATH, 335 ValueGroup.class.getName()); 336 ROOT_COLLECTION_DESCS.put(RBS_VALS_NAME, rbs_vals); 337 338 DAVCollectionDesc sys_props = 340 new DAVCollectionDesc( 341 SYSTEM_PROPS_NAME, 342 SYSTEM_PROPS_PATH, 343 PropertyGroup.class.getName()); 344 ROOT_COLLECTION_DESCS.put(SYSTEM_PROPS_NAME, sys_props); 345 346 DAVCollectionDesc wrkflw_props = 348 new DAVCollectionDesc( 349 WORKFLOW_PROPS_NAME, 350 WORKFLOW_PROPS_PATH, 351 WorkflowPropertyGroup.class.getName()); 352 ROOT_COLLECTION_DESCS.put(WORKFLOW_PROPS_NAME, wrkflw_props); 353 354 DAVCollectionDesc wrkflw_defs = 356 new DAVCollectionDesc( 357 WORKFLOW_DEFS_NAME, 358 WORKFLOW_DEFS_PATH, 359 WorkflowStageValueGroup.class.getName()); 360 ROOT_COLLECTION_DESCS.put(WORKFLOW_DEFS_NAME, wrkflw_defs); 361 362 DAVCollectionDesc wrkflw_stages = 364 new DAVCollectionDesc( 365 WORKFLOW_STAGES_NAME, 366 WORKFLOW_STAGES_PATH, 367 WorkflowStageValueGroup.class.getName()); 368 ROOT_COLLECTION_DESCS.put(WORKFLOW_STAGES_NAME, wrkflw_stages); 369 370 TYPE_MAPPINGS.put("Document", Document.class.getName()); 371 TYPE_MAPPINGS.put("Asset", Asset.class.getName()); 372 TYPE_MAPPINGS.put("Section", Section.class.getName()); 373 TYPE_MAPPINGS.put("User", User.class.getName()); 374 TYPE_MAPPINGS.put("UserGroup", UserGroup.class.getName()); 375 TYPE_MAPPINGS.put("Value", Value.class.getName()); 376 TYPE_MAPPINGS.put("ValueGroup", ValueGroup.class.getName()); 377 TYPE_MAPPINGS.put("Property", Property.class.getName()); 378 TYPE_MAPPINGS.put("PropertyGroup", PropertyGroup.class.getName()); 379 TYPE_MAPPINGS.put("Template", Template.class.getName()); 380 TYPE_MAPPINGS.put("TemplateGroup", TemplateGroup.class.getName()); 381 TYPE_MAPPINGS.put("WebPage", WebPage.class.getName()); 382 TYPE_MAPPINGS.put("WebPageGroup", WebPageGroup.class.getName()); 383 TYPE_MAPPINGS.put("XSLResourceGroup", XSLResourceGroup.class.getName()); 384 TYPE_MAPPINGS.put("XSLResource", XSLResource.class.getName()); 385 TYPE_MAPPINGS.put("XMLResourceGroup", XMLResourceGroup.class.getName()); 386 TYPE_MAPPINGS.put("XMLResource", XMLResource.class.getName()); 387 TYPE_MAPPINGS.put("XMLAuditResourceGroup", XMLAuditResourceGroup.class.getName()); 388 TYPE_MAPPINGS.put("XMLAuditResource", XMLAuditResource.class.getName()); 389 TYPE_MAPPINGS.put("WorkflowStageValueGroup", WorkflowStageValueGroup.class.getName()); 390 TYPE_MAPPINGS.put("WorkflowStageValue", WorkflowStageValue.class.getName()); 391 TYPE_MAPPINGS.put("WorkflowProperty", WorkflowProperty.class.getName()); 392 TYPE_MAPPINGS.put("WorkflowPropertyGroup", WorkflowProperty.class.getName()); 393 394 ROOT_GROUPS.add(CONTENT_NAME); 395 ROOT_GROUPS.add(WEBSITE_NAME); 396 ROOT_GROUPS.add(USERS_NAME); 397 ROOT_GROUPS.add(NEWSLETTER_NAME); 398 ROOT_GROUPS.add(REPORTS_NAME); 399 ROOT_GROUPS.add(METADATA_NAME); 401 ROOT_GROUPS.add(WORKFLOW_DEFS_NAME); 402 ROOT_GROUPS.add(WORKFLOW_STAGES_NAME); 403 ROOT_GROUPS.add(WORKFLOW_PROPS_NAME); 404 405 CLASS_2_RESOURCE_TYPE_MAPPING.put( 406 Document.class.getName(), 407 RESOURCE_TYPE_RESOURCE); 408 CLASS_2_RESOURCE_TYPE_MAPPING.put( 409 Value.class.getName(), 410 RESOURCE_TYPE_VALUE); 411 CLASS_2_RESOURCE_TYPE_MAPPING.put( 412 Property.class.getName(), 413 RESOURCE_TYPE_RESOURCE); 414 CLASS_2_RESOURCE_TYPE_MAPPING.put( 415 Asset.class.getName(), 416 RESOURCE_TYPE_RESOURCE); 417 CLASS_2_RESOURCE_TYPE_MAPPING.put( 418 User.class.getName(), 419 RESOURCE_TYPE_RESOURCE); 420 CLASS_2_RESOURCE_TYPE_MAPPING.put( 421 Template.class.getName(), 422 RESOURCE_TYPE_RESOURCE); 423 CLASS_2_RESOURCE_TYPE_MAPPING.put( 424 WebPage.class.getName(), 425 RESOURCE_TYPE_RESOURCE); 426 } 427 428 public HarmoniseNameResolver() { 429 } 430 431 436 public static String getRealPath(URL url) throws NameResolverException { 437 438 String sPath = null; 439 try { 440 sPath = URLDecoder.decode(url.getFile(), UTF_8); 441 } catch (UnsupportedEncodingException e) { 442 throw new NameResolverException(e); 443 } 444 445 return getRealPath(sPath); 446 } 447 448 458 public static String getResourceName(URL url) throws UnsupportedEncodingException { 459 String sResourceName = null; 460 461 String sResourcePath = 462 URLDecoder.decode( 463 url.getPath(), 464 HarmoniseNameResolver.UTF_8); 465 466 sResourceName = HarmoniseNameResolver.getLastSegment(sResourcePath); 467 468 return sResourceName; 469 } 470 471 476 public static String getRealPath(String sPath) 477 throws NameResolverException { 478 479 if (m_logger.isLoggable(Level.FINE)) { 480 m_logger.log(Level.FINE,"getRealPath: url file - " + sPath); 481 } 482 483 String pathName = null; 484 int nIndex = sPath.indexOf(WEBDAV_ROOT_MARKER); 485 486 if (nIndex >= 0) { 487 nIndex = sPath.indexOf('/', nIndex + 1); 488 489 if (nIndex >= 0) { 490 pathName = sPath.substring(nIndex + 1); 491 } else { 492 throw new NameResolverException("Invalid URI given - " + sPath); 493 } 494 } else { 495 throw new NameResolverException("Invalid URI given - " + sPath); 496 } 497 498 Iterator iter = ROOT_COLLECTION_DESCS.values().iterator(); 499 boolean bFound = false; 500 501 while (iter.hasNext() == true && bFound == false) { 502 DAVCollectionDesc desc = (DAVCollectionDesc) iter.next(); 503 if (desc.isVirtual() == false) { 504 505 String sColURI = desc.getURI(); 506 507 if (pathName.startsWith(sColURI) == true) { 508 bFound = true; 509 if (pathName.equals(sColURI) == true) { 510 pathName = desc.getHarmonisePath(); 511 } else { 512 513 String sAdd = pathName.substring(sColURI.length() + 1); 514 515 StringBuffer strbuf = new StringBuffer (); 516 517 strbuf.append(desc.getHarmonisePath()); 518 519 if (sAdd != null && sAdd.length() > 0) { 520 strbuf.append(URL_SEPARATOR).append(sAdd); 521 } 522 523 pathName = strbuf.toString(); 524 525 } 526 527 } 528 } 529 } 530 531 if (m_logger.isLoggable(Level.FINE)) { 532 m_logger.log(Level.FINE, "Returning path - " + pathName); 533 } 534 535 return pathName; 536 } 537 538 545 public static String getDAVPath(AbstractChildObject cobj) 546 throws NameResolverException { 547 String sPath = null; 548 549 if(cobj != null) { 550 try { 551 sPath = cobj.getFullPath(); 552 } catch (DataAccessException e) { 553 554 try { 555 throw new NameResolverException( 556 "Problem with " + cobj.getName(), 557 e); 558 } catch (DataAccessException e1) { 559 throw new NameResolverException(e); 560 } 561 } 562 563 sPath = getDAVPath(cobj.getClass(), sPath); 564 } 565 566 567 return sPath; 568 } 569 570 581 public static String getDAVPath(AbstractDataStoreInterface dsi, String harmonisePath) throws NameResolverException { 582 Iterator iter = ROOT_COLLECTION_DESCS.values().iterator(); 583 String sDAVVirtDirName = null; 584 String sDavMapOHRoot = null; 585 boolean bFound = false; 586 587 while (iter.hasNext() && bFound == false) { 588 DAVCollectionDesc desc = (DAVCollectionDesc) iter.next(); 589 590 if(desc.isVirtual() == false && harmonisePath.startsWith(desc.getHarmonisePath())) { 591 String sClass = desc.getHarmoniseClass(); 592 593 try { 594 AbstractChildObject child = (AbstractChildObject) HarmoniseObjectFactory.instantiateHarmoniseObject(dsi,sClass,harmonisePath); 595 596 if(child != null && child.exists() == true) { 597 bFound = true; 598 sDAVVirtDirName = desc.getURI(); 599 sDavMapOHRoot = desc.getHarmonisePath(); 600 } else { 601 AbstractParentObject parent = (AbstractParentObject) HarmoniseObjectFactory.instantiateHarmoniseObject(dsi,sClass,getPathParent(harmonisePath)); 602 603 if(parent != null && parent.exists()) { 604 child = parent.getChildByName(getLastSegment(harmonisePath)); 605 606 if(child != null) { 607 bFound = true; 608 sDAVVirtDirName = desc.getURI(); 609 sDavMapOHRoot = desc.getHarmonisePath(); 610 } 611 } 612 613 } 614 615 } catch (HarmoniseFactoryException e) { 616 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 617 } catch (DataAccessException e) { 618 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 619 } 620 } 621 } 622 String sResult = null; 623 624 if(bFound == true) { 625 StringBuffer sDAVpath = new StringBuffer (); 626 627 sDAVpath.append(URL_SEPARATOR).append(WEBDAV_ROOT_MARKER).append( 628 URL_SEPARATOR); 629 630 if(sDavMapOHRoot == null || sDAVVirtDirName == null) { 631 throw new NameResolverException("Problem getting DAV path from " + sDavMapOHRoot + " and " + sDAVVirtDirName); 632 } 633 sDAVpath.append(harmonisePath.replaceFirst(sDavMapOHRoot, sDAVVirtDirName)); 634 635 if (m_logger.isLoggable(Level.FINE)) { 636 m_logger.log(Level.FINE, 637 "Harmonise path - " + harmonisePath + ", dav path - " + sDAVpath); 638 639 } 640 641 sResult = sDAVpath.toString(); 642 643 } 644 645 return sResult; 646 } 647 648 656 public static String getDAVPath(Class clss, String sHarmonisePath) throws NameResolverException { 657 658 if (m_logger.isLoggable(Level.FINE)) { 659 m_logger.log(Level.FINE, 660 "getDAVPath: class name - " 661 + clss.getName() 662 + " path - " 663 + sHarmonisePath); 664 } 665 666 if (clss.isAssignableFrom(AbstractParentObject.class) == false) { 667 669 String sGroupObjectClassName = (String ) CLASS_2_GROUPOBJECT.get(clss.getName()); 670 671 if(sGroupObjectClassName == null) { 672 673 try { 674 AbstractChildObject child = 675 (AbstractChildObject) clss.newInstance(); 676 677 sGroupObjectClassName = child.getParentObjectClassName(); 678 679 CLASS_2_GROUPOBJECT.put(clss.getName(), sGroupObjectClassName); 680 } catch (InstantiationException e) { 681 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 682 } catch (IllegalAccessException e) { 683 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 684 } 685 } 686 687 try { 688 clss = Class.forName(sGroupObjectClassName); 689 } catch (ClassNotFoundException e) { 690 691 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 692 } 693 } 694 695 Iterator iter = ROOT_COLLECTION_DESCS.values().iterator(); 696 String sDAVVirtDirName = null; 697 String sDavMapOHRoot = null; 698 boolean bFound = false; 699 while (iter.hasNext() && bFound == false) { 700 DAVCollectionDesc desc = (DAVCollectionDesc) iter.next(); 701 702 if (clss.getName().equals(desc.getHarmoniseClass()) 703 && sHarmonisePath.startsWith(desc.getHarmonisePath())) { 704 sDAVVirtDirName = desc.getURI(); 705 sDavMapOHRoot = desc.getHarmonisePath(); 706 bFound = true; 707 } 708 } 709 710 StringBuffer sDAVpath = new StringBuffer (); 711 712 sDAVpath.append(URL_SEPARATOR).append(WEBDAV_ROOT_MARKER).append( 713 URL_SEPARATOR); 714 715 if(sDavMapOHRoot == null || sDAVVirtDirName == null) { 716 throw new NameResolverException("Problem getting DAV path from " + sDavMapOHRoot + " and " + sDAVVirtDirName); 717 } 718 sDAVpath.append(sHarmonisePath.replaceFirst(sDavMapOHRoot, sDAVVirtDirName)); 719 720 if (m_logger.isLoggable(Level.FINE)) { 721 m_logger.log(Level.FINE, 722 "Harmonise path - " + sHarmonisePath + ", dav path - " + sDAVpath); 723 724 } 725 726 return sDAVpath.toString(); 727 } 728 729 736 public static String getVersionPath(AbstractChildObject child) 737 throws NameResolverException { 738 739 int nId = -1; 740 int nKey = -1; 741 try { 742 AbstractChildObject live = 743 (AbstractChildObject) child.getLiveVersion(); 744 if (live != null) { 745 nId = live.getId(); 746 } else { 747 nId = child.getId(); 748 } 749 750 nKey = child.getKey(); 751 } catch (DataAccessException e) { 752 throw new NameResolverException(e); 753 } 754 755 String sClass = child.getClass().getName(); 756 String sType = sClass.substring(sClass.lastIndexOf(".") + 1); 757 758 StringBuffer strbuf = new StringBuffer (); 759 760 strbuf.append(URL_SEPARATOR).append(WEBDAV_ROOT_MARKER).append( 761 URL_SEPARATOR); 762 strbuf.append(sType).append(URL_SEPARATOR); 763 strbuf 764 .append(String.valueOf(nId)) 765 .append(URL_SEPARATOR) 766 .append(VERSION_SEGMENT) 767 .append(URL_SEPARATOR); 768 strbuf.append(String.valueOf(nKey)); 769 770 return strbuf.toString(); 771 } 772 773 780 public static String getFullURL(AbstractChildObject cobj, URL resourceUrl) 781 throws NameResolverException { 782 StringBuffer sURL = new StringBuffer (); 783 784 sURL.append(resourceUrl.getProtocol()); 785 sURL.append("://"); 786 sURL.append(resourceUrl.getHost()); 787 sURL.append(":"); 788 sURL.append(resourceUrl.getPort()); 789 sURL.append(getDAVPath(cobj)); 790 791 return sURL.toString(); 792 } 793 794 802 public static String getUUID(String uri, String user_name) 803 throws NameResolverException { 804 String uuid_base; 805 try { 806 uuid_base = URLDecoder.decode(uri, UTF_8) + user_name; 807 } catch (UnsupportedEncodingException e) { 808 throw new NameResolverException(e); 809 } 810 811 if (m_logger.isLoggable(Level.FINE)) { 812 m_logger.log(Level.FINE, 813 "getUUID: uri - " + uri + ", user - " + user_name); 814 m_logger.log(Level.FINE,"getUUID: UUID - " + uuid_base); 815 } 816 817 return String.valueOf(uuid_base.hashCode()); 818 } 819 820 public static String getTagForLiveProperty(String livepropname) { 821 return (String ) m_liveprop2XML_map.get(livepropname); 822 } 823 824 public static boolean isMappedLiveProperty(String livepropname) { 825 return m_liveprop2XML_map.containsKey(livepropname); 826 } 827 828 public static String getResourceType(String sResourceName) { 829 int nDotIndex = sResourceName.indexOf("."); 830 String sExt = ""; 831 832 if (nDotIndex > 0) { 833 sExt = sResourceName.substring(nDotIndex); 834 } 835 836 return sExt; 837 } 838 839 847 public static boolean isVersionPath(String sPath) { 848 boolean bIsVersion = false; 849 850 int nIndex = 851 sPath.lastIndexOf(URL_SEPARATOR + VERSION_SEGMENT + URL_SEPARATOR); 852 853 if (nIndex > 0) { 854 bIsVersion = true; 855 String sLastSeg = getLastSegment(sPath); 856 857 if (m_logger.isLoggable(Level.FINE)) { 858 m_logger.log(Level.FINE,"Is a number? - " + sLastSeg); 859 } 860 861 try { 862 int nKey = Integer.parseInt(sLastSeg); 863 } catch (NumberFormatException e) { 864 bIsVersion = false; 865 } 866 } 867 868 if (m_logger.isLoggable(Level.FINE)) { 869 m_logger.log(Level.FINE,sPath + " is a version path:" + bIsVersion); 870 } 871 872 return bIsVersion; 873 } 874 875 881 public static boolean isArchiveURL(URL url) { 882 return isArchiveURL(url.getPath()); 883 } 884 885 891 public static boolean isArchiveURL(String sURL) { 892 893 boolean bIsArchive = 894 (sURL 895 .indexOf( 896 URL_SEPARATOR 897 + WEBDAV_ROOT_MARKER 898 + URL_SEPARATOR 899 + ARCHIVE_NAME) 900 >= 0); 901 902 if (m_logger.isLoggable(Level.FINE)) { 903 m_logger.log(Level.FINE, 904 "Checking for archive - " + sURL + " - " + bIsArchive); 905 } 906 907 return bIsArchive; 908 } 909 910 918 public static String getFilePath(URL url) throws NameResolverException { 919 String sResult = null; 920 921 String sName = url.getFile(); 922 sName = sName.substring(sName.lastIndexOf(URL_SEPARATOR) + 1); 923 924 try { 925 StringBuffer sbuf = new StringBuffer (); 926 927 sbuf.append(ConfigSettings.getProperty("UPLOADED_TEMPFILE_DIR")); 928 929 if (sbuf.toString().endsWith(File.separator) == false) { 930 sbuf.append(File.separator); 931 } 932 933 sbuf.append(sName); 934 935 sResult = sbuf.toString(); 936 } catch (ConfigException e) { 937 throw new NameResolverException(e); 938 } 939 return sResult; 940 } 941 942 950 public static AbstractChildObject getObjectFromURL( 951 AbstractDataStoreInterface dsi, 952 URL url) 953 throws NameResolverException { 954 String sPath = null; 955 try { 956 sPath = URLDecoder.decode(url.getFile(), UTF_8); 957 } catch (UnsupportedEncodingException e) { 958 throw new NameResolverException(e); 959 } 960 961 return getObjectFromURL(dsi, sPath); 962 } 963 964 972 public static AbstractChildObject getObjectFromURL( 973 AbstractDataStoreInterface dsi, 974 String sPath) 975 throws NameResolverException { 976 AbstractChildObject child = null; 977 try { 978 sPath = URLDecoder.decode(sPath, UTF_8); 979 } catch (UnsupportedEncodingException e) { 980 throw new NameResolverException(e); 981 } 982 if (isVersionPath(sPath) == true) { 983 child = getObjectFromVersionURL(dsi, sPath); 984 } else if (isArchiveURL(sPath) == true) { 985 child = getArchivedObject(dsi, sPath); 986 } else { 987 child = getObjectFromNonVersionURL(dsi, sPath); 988 } 989 990 return child; 991 } 992 993 1001 public static AbstractChildObject getObjectFromNonVersionURL( 1002 AbstractDataStoreInterface dsi, 1003 String sPath) 1004 throws NameResolverException { 1005 AbstractChildObject child = null; 1006 1007 if (isVersionPath(sPath) == true) { 1008 throw new InvalidPathException("Invalid path"); 1009 } 1010 1011 if (m_logger.isLoggable(Level.FINE)) { 1012 m_logger.log(Level.FINE,"dealing with path - " + sPath); 1013 } 1014 1015 String sParentType = getParentTypeFromURL(sPath); 1016 1017 if (m_logger.isLoggable(Level.FINE)) { 1018 m_logger.log(Level.FINE,"parent type - " + sParentType); 1019 } 1020 1021 if (sParentType != null) { 1022 String ohPath = getRealPath(sPath); 1023 1024 if (m_logger.isLoggable(Level.FINE)) { 1025 m_logger.log(Level.FINE,"real path - " + ohPath); 1026 } 1027 1028 try { 1029 if (ohPath.equals(ROOT_PATH) == true) { 1030 child = 1031 ( 1032 AbstractParentObject) HarmoniseObjectFactory 1033 .instantiatePublishableObject( 1034 dsi, 1035 sParentType, 1036 ohPath); 1037 1038 if (child == null) { 1039 throw new NameResolverException("Didn't find root!"); 1040 } 1041 } else { 1042 String ohParentPath = getPathParent(ohPath); 1043 1044 AbstractParentObject parent = 1045 ( 1046 AbstractParentObject) HarmoniseObjectFactory 1047 .instantiatePublishableObject( 1048 dsi, 1049 sParentType, 1050 ohParentPath); 1051 1052 if(parent != null) { 1053 child = parent.getChildByName(getLastSegment(ohPath)); 1054 } else { 1055 m_logger.logp(Level.INFO, HarmoniseNameResolver.class.getName(), "getObjectFromNonVersionURL", sParentType + " object not found for path " + ohParentPath); 1056 } 1057 } 1058 } catch (HarmoniseFactoryException e) { 1059 throw new NameResolverException(e); 1060 } catch (DataAccessException e) { 1061 throw new NameResolverException(e); 1062 } 1063 } 1064 1065 return child; 1066 } 1067 1068 1076 public static AbstractChildObject getObjectFromVersionURL( 1077 AbstractDataStoreInterface dsi, 1078 String sPath) 1079 throws NameResolverException { 1080 AbstractChildObject child = null; 1081 1082 if (isVersionPath(sPath) == false) { 1083 throw new InvalidPathException("Invalid path"); 1084 } 1085 1086 int nLastSep = sPath.lastIndexOf(URL_SEPARATOR); 1087 1088 if (sPath.endsWith(URL_SEPARATOR)) { 1089 nLastSep = 1090 sPath.substring(0, nLastSep - 1).lastIndexOf(URL_SEPARATOR); 1091 } 1092 1093 int nKey = Integer.parseInt(getLastSegment(sPath)); 1094 1095 int nPostIdSep = 1096 nLastSep - VERSION_SEGMENT.length() - URL_SEPARATOR.length(); 1097 1098 int nPreIdSep = 1099 sPath.substring(0, nPostIdSep).lastIndexOf(URL_SEPARATOR); 1100 1101 String sLiveId = sPath.substring(nPreIdSep + 1, nPostIdSep); 1102 1103 if (m_logger.isLoggable(Level.FINE)) { 1104 m_logger.log(Level.FINE, "looking for live id - " + sLiveId); 1105 } 1106 1107 int nLiveId = Integer.parseInt(sLiveId); 1108 1109 String sType = getTypeFromVersionURL(sPath); 1110 1111 if (m_logger.isLoggable(Level.FINE)) { 1112 m_logger.log(Level.FINE, 1113 "Looking for " 1114 + sType 1115 + " live id = " 1116 + nLiveId 1117 + ", key = " 1118 + nKey); 1119 } 1120 1121 try { 1122 AbstractChildObject liveChild = 1123 (AbstractChildObject) HarmoniseObjectFactory.instantiateHarmoniseObject( 1124 dsi, 1125 sType, 1126 nLiveId); 1127 1128 if(liveChild == null) { 1129 if(m_logger.isLoggable(Level.INFO)) { 1130 m_logger.log(Level.INFO, "Live version in " + sPath + " not found!"); 1131 } 1132 throw new InvalidPathException("Live version in " + sPath + " not found!"); 1133 } 1134 1135 if (liveChild.exists() == true) { 1137 int nLiveKey = liveChild.getKey(); 1138 1139 List versions = null; 1140 1141 if (nLiveKey == nKey) { 1142 child = liveChild; 1143 } else { 1144 1145 if (nLiveKey < nKey) { 1146 versions = liveChild.getPendingVersions(); 1148 } else if (nLiveKey > nKey) { 1149 versions = liveChild.getHistoricalVersions(); 1151 } 1152 1153 child = getChildByKeyFromList(versions, nKey); 1154 1155 if (child == null) { 1156 1159 if (nLiveKey < nKey) { 1160 versions = liveChild.getHistoricalVersions(); 1162 } else if (nLiveKey > nKey) { 1163 versions = liveChild.getPendingVersions(); 1165 } 1166 1167 child = getChildByKeyFromList(versions, nKey); 1168 } 1169 } 1170 } else { 1171 child = 1173 (AbstractChildObject) Class.forName(sType).newInstance(); 1174 child.setId(nLiveId); 1175 child.setHistorical(true); 1176 child.setKey(nKey); 1177 child.setDataStoreInterface(dsi); 1178 } 1179 } catch (HarmoniseFactoryException e) { 1180 throw new NameResolverException(e); 1181 } catch (DataAccessException e) { 1182 throw new NameResolverException(e); 1183 } catch (InstantiationException e) { 1184 throw new NameResolverException(e); 1185 } catch (IllegalAccessException e) { 1186 throw new NameResolverException(e); 1187 } catch (ClassNotFoundException e) { 1188 throw new NameResolverException(e); 1189 } catch (PopulateException e) { 1190 throw new NameResolverException(e); 1191 } 1192 1193 return child; 1194 } 1195 1196 1204 public static AbstractChildObject getArchivedObject( 1205 AbstractDataStoreInterface dsi, 1206 String sPath) 1207 throws NameResolverException { 1208 AbstractChildObject child = null; 1209 1210 if (isArchiveURL(sPath) == false) { 1211 throw new InvalidPathException("Invalid path"); 1212 } 1213 1214 try { 1215 AbstractParentObject parent = null; 1216 String sLivePath = 1217 sPath.replaceAll(URL_SEPARATOR + ARCHIVE_NAME, ""); 1218 1219 String sParentPath = getPathParent(sPath); 1221 1222 String sLiveParentPath = 1223 sParentPath.replaceAll(URL_SEPARATOR + ARCHIVE_NAME, ""); 1224 1225 if (isVirtualCollection(sLiveParentPath) == true) { 1226 if (m_logger.isLoggable(Level.FINE)) { 1228 m_logger.log(Level.FINE, 1229 "looking for virtual parent child - " + sLivePath); 1230 } 1231 1232 if (isVirtualCollection(sLivePath) == false) { 1233 child = getObjectFromURL(dsi, sLivePath); 1234 } 1235 } else { 1236 if (m_logger.isLoggable(Level.FINE)) { 1237 m_logger.log(Level.FINE, 1238 "looking for live parent - " + sLiveParentPath); 1239 } 1240 parent = 1242 (AbstractParentObject) getObjectFromURL(dsi, 1243 sLiveParentPath); 1244 1245 if (parent == null) { 1246 parent = 1248 (AbstractParentObject) getObjectFromURL(dsi, 1249 sParentPath); 1250 } 1251 1252 String sName = getLastSegment(sPath); 1253 1254 child = parent.getArchivedChildByName(sName); 1255 1256 if (child == null) { 1257 child = parent.getChildByName(sName); 1258 1259 if ((child instanceof AbstractParentObject) == false) { 1261 child = null; 1262 } 1263 } 1264 } 1265 1266 } catch (DataAccessException e) { 1267 throw new NameResolverException(e); 1268 } catch (NameResolverException e) { 1269 throw new NameResolverException(e); 1270 } 1271 1272 return child; 1273 } 1274 1275 1282 private static Object getKeyForValue(Object val, Map map) { 1283 Object result = null; 1284 Iterator iter = map.keySet().iterator(); 1285 1286 boolean bFound = false; 1287 1288 while (iter.hasNext() == true && bFound == false) { 1289 Object key = iter.next(); 1290 if (map.get(key).equals(val) == true) { 1291 bFound = true; 1292 result = key; 1293 } 1294 } 1295 1296 return result; 1297 } 1298 1299 1308 public static String getParentTypeFromURL(String sPath) throws NameResolverException { 1309 String sType = null; 1310 1311 try { 1312 sPath = URLDecoder.decode(sPath, UTF_8); 1313 } catch (UnsupportedEncodingException e) { 1314 throw new NameResolverException(e.getLocalizedMessage(), e); 1315 } 1316 1317 DAVCollectionDesc desc = null; 1318 1319 String sSubPath = 1320 sPath.substring( 1321 sPath.indexOf(WEBDAV_ROOT_MARKER) 1322 + WEBDAV_ROOT_MARKER.length() 1323 + 1); 1324 1325 if (m_logger.isLoggable(Level.FINE)) { 1326 m_logger.log(Level.FINE, 1327 "getParentTypeFromURL: sPath - " 1328 + sPath 1329 + ", sSubPath = " 1330 + sSubPath); 1331 } 1332 1333 Iterator iter = ROOT_COLLECTION_DESCS.keySet().iterator(); 1334 1335 boolean bFound = false; 1336 1337 int nKeyLength = 0; 1338 1339 while (iter.hasNext()) { 1340 String sKey = (String ) iter.next(); 1341 1342 if (m_logger.isLoggable(Level.FINER)) { 1343 m_logger.log(Level.FINER,"comparing " + sSubPath + " with " + sKey); 1344 } 1345 1346 if (sSubPath.startsWith(sKey) && sKey.length() > nKeyLength) { 1347 bFound = true; 1348 desc = (DAVCollectionDesc) ROOT_COLLECTION_DESCS.get(sKey); 1349 nKeyLength = sKey.length(); 1350 } 1351 } 1352 1353 if(desc != null){ 1354 sType = desc.getHarmoniseClass(); 1355 } 1356 1357 return sType; 1358 } 1359 1360 1368 public static String getTypeFromVersionURL(String sPath) { 1369 String sType = null; 1370 1371 int nIndex = sPath.indexOf(WEBDAV_ROOT_MARKER); 1372 1373 String sSubPath = 1374 sPath.substring(nIndex + WEBDAV_ROOT_MARKER.length() + 1); 1375 1376 sSubPath = sSubPath.substring(0, sSubPath.indexOf(URL_SEPARATOR)); 1377 1378 Iterator iter = TYPE_MAPPINGS.keySet().iterator(); 1379 1380 boolean bFound = false; 1381 1382 while (iter.hasNext() == true && bFound == false) { 1383 String sKey = (String ) iter.next(); 1384 1385 if (sSubPath.equalsIgnoreCase(sKey) == true) { 1386 bFound = true; 1387 sType = (String ) TYPE_MAPPINGS.get(sKey); 1388 } 1389 } 1390 1391 return sType; 1392 } 1393 1394 1402 public static String getChildTypeFromURL(String sPath) 1403 throws NameResolverException { 1404 String sReturnType = null; 1405 1406 try { 1407 sPath = URLDecoder.decode(sPath, UTF_8); 1408 } catch (UnsupportedEncodingException e) { 1409 throw new NameResolverException(e.getLocalizedMessage(), e); 1410 } 1411 1412 if (sPath.indexOf(ASSETS_NAME) > 0) { 1413 sReturnType = Asset.class.getName(); 1414 } else if ( 1415 sPath.indexOf(DOCS_NAME) > 0 1416 || sPath.indexOf( 1417 WEBDAV_ROOT_MARKER + URL_SEPARATOR + NEWSLETTER_NAME) 1418 > 0) { 1419 sReturnType = Document.class.getName(); 1420 } else { 1421 1423 String sType = getParentTypeFromURL(sPath); 1424 1425 try { 1426 AbstractParentObject parent = 1427 (AbstractParentObject) Class.forName(sType).newInstance(); 1428 1429 List childTypes = parent.getChildClassNames(); 1430 1431 List childNonParentTypes = new Vector(); 1432 1433 Iterator iter = childTypes.iterator(); 1434 1435 while (iter.hasNext()) { 1436 String className = (String ) iter.next(); 1437 1438 if (className.equals(sType) == false) { 1439 sReturnType = className; 1440 } 1441 } 1442 } catch (InstantiationException e) { 1443 throw new NameResolverException(e); 1444 } catch (IllegalAccessException e) { 1445 throw new NameResolverException(e); 1446 } catch (ClassNotFoundException e) { 1447 throw new NameResolverException(e); 1448 } 1449 } 1450 1451 return sReturnType; 1452 } 1453 1454 1460 public static String getPathParent(String sPath) { 1461 String sParent = null; 1462 1463 if (sPath.endsWith(URL_SEPARATOR)) { 1464 sPath = sPath.substring(0, sPath.length() - 1); 1465 } 1466 1467 sParent = sPath.substring(0, sPath.lastIndexOf(URL_SEPARATOR)); 1468 1469 return sParent; 1470 } 1471 1472 1478 public static String getLastSegment(String sPath) { 1479 String sParent = null; 1480 1481 if(sPath != null) { 1482 1483 if (sPath.endsWith(URL_SEPARATOR)) { 1484 sPath = sPath.substring(0, sPath.length() - 1); 1485 } 1486 1487 sParent = 1488 sPath.substring( 1489 sPath.lastIndexOf(URL_SEPARATOR) + 1, 1490 sPath.length()); 1491 } 1492 1493 return sParent; 1494 } 1495 1496 1501 public static List getRootCollections() { 1502 return ROOT_GROUPS; 1503 } 1504 1505 1512 public static boolean isDAVRoot(URL url) { 1513 String sPath = url.getPath(); 1514 1515 return isDAVRoot(sPath); 1516 } 1517 1518 1525 public static boolean isDAVRoot(String sURL) { 1526 String sLastSegment = getLastSegment(sURL); 1527 1528 return sLastSegment.equals(WEBDAV_ROOT_MARKER); 1529 } 1530 1531 1537 public static boolean isArchiveRoot(URL url) { 1538 String sPath = url.getPath(); 1539 1540 return isArchiveRoot(sPath); 1541 } 1542 1543 1549 public static boolean isArchiveRoot(String sPath) { 1550 1551 if (sPath.endsWith(URL_SEPARATOR) == true) { 1552 sPath = sPath.substring(0, sPath.length() - 1); 1553 } 1554 1555 return sPath.endsWith( 1556 WEBDAV_ROOT_MARKER + URL_SEPARATOR + ARCHIVE_NAME); 1557 } 1558 1559 1567 public static boolean isVirtualCollection(URL url) { 1568 1569 String sPath = url.getPath(); 1570 1571 try { 1572 sPath = URLDecoder.decode(sPath, UTF_8); 1573 } catch (UnsupportedEncodingException e) { 1574 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1575 } 1576 1577 return isVirtualCollection(sPath); 1578 } 1579 1580 1587 public static boolean isVirtualResource(URL url) { 1588 1589 String sPath = url.getPath(); 1590 1591 try { 1592 sPath = URLDecoder.decode(sPath, UTF_8); 1593 } catch (UnsupportedEncodingException e) { 1594 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1595 } 1596 1597 return isVirtualResource(sPath); 1598 } 1599 1600 1607 private static boolean isVirtualResource(String path) { 1608 boolean bIsVirtual = false; 1609 1610 1611 String sLastSeg = getLastSegment(path); 1612 1613 if(sLastSeg != null) { 1614 bIsVirtual = sLastSeg.equals(VIRTUAL_RESOURCE_NAME); 1615 } 1616 1617 return bIsVirtual; 1618 } 1619 1620 1628 public static boolean isVirtualCollection(String sPath) { 1629 boolean bIsVirtual = false; 1630 1631 bIsVirtual = isDAVRoot(sPath); 1632 1633 if (bIsVirtual == false) { 1634 bIsVirtual = isArchiveRoot(sPath); 1635 } 1636 1637 if (bIsVirtual == false) { 1638 String sLastSegment = getLastSegment(sPath); 1639 1640 if (m_logger.isLoggable(Level.FINE)) { 1641 m_logger.log(Level.FINE, 1642 "Checking virtual collection - " + sLastSegment); 1643 } 1644 1645 bIsVirtual = sLastSegment.equals(WEBDAV_ROOT_MARKER) 1646 || sLastSegment.equals(VIRTUAL_COLLECTION_NAME); 1647 1648 if (bIsVirtual == false) { 1650 DAVCollectionDesc desc = getCollectionDesc(sPath); 1651 1652 if (desc != null) { 1653 bIsVirtual = desc.isVirtual(); 1654 } 1655 } 1656 1657 if (m_logger.isLoggable(Level.FINE)) { 1658 m_logger.log(Level.FINE, "Is virtual collection - " + bIsVirtual); 1659 } 1660 } 1661 1662 return bIsVirtual; 1663 } 1664 1665 public static List getArchivedVirtualCollectionMemberNames(URL resourceURL) { 1666 List members = null; 1667 1668 String sPath = resourceURL.getPath(); 1669 1670 if (isArchiveURL(sPath) == true) { 1671 sPath = sPath.replaceFirst(URL_SEPARATOR + ARCHIVE_NAME, ""); 1672 1673 members = getVirtualCollectionMemberNames(sPath); 1674 } 1675 1676 return members; 1677 } 1678 1679 public static List getVirtualCollectionMemberNames(URL url) { 1680 return getVirtualCollectionMemberNames(url.getPath()); 1681 } 1682 1683 1689 public static List getVirtualCollectionMemberNames(String sPath) { 1690 1691 try { 1692 sPath = URLDecoder.decode(sPath, UTF_8); 1693 } catch (UnsupportedEncodingException e) { 1694 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1695 } 1696 1697 DAVCollectionDesc desc = getCollectionDesc(sPath); 1698 1699 List members = new ArrayList(); 1700 1701 if (desc != null) { 1702 List fullpaths = desc.getMembers(); 1703 1704 if (fullpaths != null) { 1705 for (Iterator iter = fullpaths.iterator(); iter.hasNext();) { 1706 String sMemberPath = (String ) iter.next(); 1707 members.add(getLastSegment(sMemberPath)); 1708 } 1709 } 1710 } 1711 1712 return members; 1713 } 1714 1715 1723 public static String stripExtension(String sName) { 1724 int nDotIndex = sName.indexOf("."); 1725 if (nDotIndex > 0) { 1726 sName = sName.substring(0, nDotIndex); 1727 } 1728 1729 return sName; 1730 } 1731 1732 1738 public static String getResourceTypeFromClass(String sClassName) 1739 throws NameResolverException { 1740 String sResult = RESOURCE_TYPE_RESOURCE; 1741 1742 Class clss = null; 1743 try { 1744 clss = Class.forName(sClassName); 1745 } catch (ClassNotFoundException e) { 1746 throw new NameResolverException(e.getLocalizedMessage(), e); 1747 } 1748 1749 if (Profile.class.isAssignableFrom(clss) == true) { 1750 sResult = "property"; 1751 } else if (AbstractParentObject.class.isAssignableFrom(clss) == true) { 1752 sResult = RESOURCE_TYPE_COLLECTION; 1753 } else if (CLASS_2_RESOURCE_TYPE_MAPPING.containsKey(sClassName)) { 1754 sResult = (String ) CLASS_2_RESOURCE_TYPE_MAPPING.get(sClassName); 1755 } 1756 1757 return sResult; 1758 } 1759 1760 1768 public static String getClassFromResourceTypeDesc( 1769 String sResourceType, 1770 String sContentType) { 1771 String sClassName = null; 1772 if (sContentType != null && sContentType.length() > 0) { 1773 if (sContentType.startsWith("text") == true) { 1774 sClassName = Document.class.getName(); 1775 } else { 1776 sClassName = Asset.class.getName(); 1777 } 1778 } else { 1779 Iterator iter = CLASS_2_RESOURCE_TYPE_MAPPING.keySet().iterator(); 1780 boolean bFound = false; 1781 while (iter.hasNext() && bFound == false) { 1782 String sTmpName = (String ) iter.next(); 1783 1784 if (CLASS_2_RESOURCE_TYPE_MAPPING 1785 .get(sTmpName) 1786 .equals(sResourceType) 1787 == true) { 1788 sClassName = sTmpName; 1789 bFound = true; 1790 } 1791 } 1792 } 1793 1794 return sClassName; 1795 } 1796 1797 1800 public static String getRootForClass(String sClassname) 1801 throws NameResolverException { 1802 1803 StringBuffer sResult = new StringBuffer (); 1804 1805 sResult.append(URL_SEPARATOR).append(WEBDAV_ROOT_MARKER).append( 1806 URL_SEPARATOR); 1807 1808 try { 1809 AbstractChildObject child = 1810 (AbstractChildObject) Class.forName(sClassname).newInstance(); 1811 1812 String sParentClass = child.getParentObjectClassName(); 1813 1814 boolean bFound = false; 1815 1816 Iterator iter = ROOT_COLLECTION_DESCS.values().iterator(); 1817 1818 while (iter.hasNext() && bFound == false) { 1819 DAVCollectionDesc desc = (DAVCollectionDesc) iter.next(); 1820 1821 if (desc.getHarmoniseClass().equals(sParentClass) == true) { 1822 sResult.append(desc.getURI()).append(URL_SEPARATOR); 1823 bFound = true; 1824 } 1825 } 1826 } catch (InstantiationException e) { 1827 throw new NameResolverException(e.getLocalizedMessage(), e); 1828 } catch (IllegalAccessException e) { 1829 throw new NameResolverException(e.getLocalizedMessage(), e); 1830 } catch (ClassNotFoundException e) { 1831 throw new NameResolverException(e.getLocalizedMessage(), e); 1832 } 1833 1834 return sResult.toString(); 1835 } 1836 1837 1844 private static DAVCollectionDesc getCollectionDesc(String sPath) { 1845 DAVCollectionDesc desc = null; 1846 1847 String sSubPath = 1848 sPath.substring( 1849 sPath.indexOf(WEBDAV_ROOT_MARKER) 1850 + WEBDAV_ROOT_MARKER.length() 1851 + 1); 1852 1853 if (sSubPath.endsWith(URL_SEPARATOR)) { 1854 sSubPath = sSubPath.substring(0, sSubPath.length() - 1); 1855 } 1856 1857 desc = (DAVCollectionDesc) ROOT_COLLECTION_DESCS.get(sSubPath); 1858 1859 return desc; 1860 } 1861 1862 1866 public static boolean isArchivedVirtualCollection(URL resourceURL) { 1867 boolean bIsArchVirt = false; 1868 String sPath = resourceURL.getPath(); 1869 1870 if (isArchiveURL(sPath) == true) { 1871 sPath = sPath.replaceFirst(URL_SEPARATOR + ARCHIVE_NAME, ""); 1872 1873 bIsArchVirt = isVirtualCollection(sPath); 1874 } 1875 1876 return bIsArchVirt; 1877 } 1878 1879 public static boolean hasValidDAVPath(AbstractChildObject child) 1880 throws WebDAVException { 1881 boolean bHasValidDAVpath = false; 1882 1883 if (child != null) { 1884 try { 1885 String sOHPath = child.getPath(); 1886 if(sOHPath != null) { 1887 String sClassname = child.getParentObjectClassName(); 1888 Iterator iter = ROOT_COLLECTION_DESCS.values().iterator(); 1889 1890 while (iter.hasNext() && bHasValidDAVpath == false) { 1891 DAVCollectionDesc desc = (DAVCollectionDesc) iter.next(); 1892 1893 if (desc.isVirtual() == false 1894 && desc.getHarmoniseClass().equals(sClassname) 1895 && sOHPath.startsWith(desc.getHarmonisePath())) { 1896 bHasValidDAVpath = true; 1897 } 1898 } 1899 } 1900 1901 } catch (DataAccessException e) { 1902 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1903 throw new WebDAVException( 1904 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 1905 e.getLocalizedMessage()); 1906 } 1907 1908 } 1909 1910 return bHasValidDAVpath; 1911 } 1912 1913 1921 private static AbstractChildObject getChildByKeyFromList( 1922 List children, 1923 int nKey) 1924 throws DataAccessException { 1925 AbstractChildObject child = null; 1926 Iterator iter = children.iterator(); 1927 1928 while (iter.hasNext() && child == null) { 1929 AbstractChildObject tmpChild = (AbstractChildObject) iter.next(); 1930 1931 if (tmpChild.getKey() == nKey) { 1932 child = tmpChild; 1933 } 1934 1935 } 1936 1937 return child; 1938 } 1939 1940 1946 public static NamespaceType getPropertyNamespace(Property prop) throws DataAccessException { 1947 NamespaceType ns = null; 1948 1949 List rbs_props = AuthorizationValidator.getSecurityProperties(prop.getDataStoreInterface()); 1950 1951 if(rbs_props.contains(prop)) { 1952 ns = NamespaceType.OHRM_RBS; 1953 } else if(prop instanceof WorkflowProperty) { 1954 ns = NamespaceType.OHRM_WORKFLOW; 1955 } else { 1956 ns = NamespaceType.OHRM; 1957 } 1958 1959 return ns; 1960 } 1961 1962 1974 public static Profile getProfileForNamespaceURI(AbstractProfiledObject profObj, String sURI) throws DataAccessException, InvalidProfileException { 1975 Profile nsProf = null; 1976 AbstractDataStoreInterface dsi = profObj.getDataStoreInterface(); 1977 if(sURI.equals(NamespaceType.OHRM_RBS.getURI()) == true) { 1978 1979 nsProf = profObj.getProfile(AuthorityProfile.SECURITY_PROFILE_NAME); 1980 if(nsProf == null) { 1981 nsProf = new AuthorityProfile(dsi); 1982 profObj.addProfile(nsProf); 1983 } 1984 1985 } else if(sURI.equals(NamespaceType.OHRM.getURI()) == true) { 1986 nsProf = profObj.getProfile(); 1987 if(nsProf == null) { 1988 nsProf = new Profile(dsi); 1989 profObj.setProfile(nsProf); 1990 } 1991 } else if(sURI.equals(NamespaceType.OHRM_WORKFLOW.getURI()) == true) { 1992 nsProf = profObj.getProfile(WorkflowProfile.WORKFLOW_PROFILE_NAME); 1993 if(nsProf == null) { 1994 nsProf = new WorkflowProfile(dsi); 1995 profObj.addProfile(nsProf); 1996 } 1997 } 1998 1999 return nsProf; 2000 } 2001 2002 2009 public static boolean isDAVPath(String sPath) { 2010 boolean bIsDAVPath = false; 2011 2012 if(sPath != null) { 2013 bIsDAVPath = sPath.startsWith(URL_SEPARATOR + WEBDAV_ROOT_MARKER); 2014 } 2015 2016 return bIsDAVPath; 2017 } 2018 2019} | Popular Tags |