1 23 24 package org.apache.slide.webdav.util; 25 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 import java.util.Set ; 31 import java.util.StringTokenizer ; 32 33 import org.apache.slide.common.Domain; 34 import org.apache.slide.common.NamespaceAccessToken; 35 import org.apache.slide.common.ServiceAccessException; 36 import org.apache.slide.common.SlideToken; 37 import org.apache.slide.content.Content; 38 import org.apache.slide.content.NodeProperty; 39 import org.apache.slide.content.NodeRevisionDescriptor; 40 import org.apache.slide.content.NodeRevisionDescriptors; 41 import org.apache.slide.content.NodeRevisionNumber; 42 import org.apache.slide.content.RevisionAlreadyExistException; 43 import org.apache.slide.content.RevisionDescriptorNotFoundException; 44 import org.apache.slide.content.RevisionNotFoundException; 45 import org.apache.slide.content.NodeProperty.NamespaceCache; 46 import org.apache.slide.event.VetoException; 47 import org.apache.slide.lock.ObjectLockedException; 48 import org.apache.slide.security.AccessDeniedException; 49 import org.apache.slide.structure.LinkedObjectNotFoundException; 50 import org.apache.slide.structure.ObjectAlreadyExistsException; 51 import org.apache.slide.structure.ObjectNotFoundException; 52 import org.apache.slide.structure.Structure; 53 import org.apache.slide.structure.SubjectNode; 54 55 56 59 public class UriHandler implements DeltavConstants, AclConstants, DaslConstants { 60 61 65 protected static boolean useHistoryCollectionHack = false; 66 67 71 public static void setGloballyUseHistoryCollectionHack(boolean useHistoryCollectionHack) { 72 UriHandler.useHistoryCollectionHack = useHistoryCollectionHack; 75 } 76 77 80 public static UriHandler getUriHandler( String resourcePath ) { 81 return new UriHandler( resourcePath ); 82 } 83 84 87 public static UriHandler 88 getUriHandler( NodeRevisionDescriptors nrds, NodeRevisionDescriptor nrd ) { 89 90 StringBuffer b = new StringBuffer (); 91 String uri = nrds.getUri(); 92 UriHandler uriHandler = UriHandler.getUriHandler( uri ); 93 if ( ! uriHandler.isHistoryUri() ) { 94 b.append( uri ); 96 } 97 else { 98 if( (NodeRevisionNumber.HIDDEN_0_0).equals(nrd.getRevisionNumber()) ) { 99 b.append( uri ); 101 } 102 else { 103 b.append( uri ); 105 if( !uri.endsWith("/") ) { 106 b.append( "/" ); 107 } 108 b.append( nrd.getRevisionNumber().toString() ); 109 } 110 } 111 return new UriHandler( b.toString() ); 112 } 113 114 120 public static UriHandler 121 createNextHistoryUri( SlideToken sToken, NamespaceAccessToken nsaToken, UriHandler uh ) 122 throws ObjectNotFoundException, AccessDeniedException, ObjectLockedException, 123 LinkedObjectNotFoundException, ServiceAccessException, 124 RevisionDescriptorNotFoundException, RevisionNotFoundException, VetoException { 125 126 UriHandler result = null; 127 String nsName = nsaToken.getName(); 128 UriHandler hpathHandler = 129 HistoryPathHandler.getResolvedHistoryPathHandler( nsName, uh ); 130 Content content = nsaToken.getContentHelper(); 131 String hpath = hpathHandler.toString(); 132 133 Structure structure = nsaToken.getStructureHelper(); 134 String uniqueUri = structure.generateUniqueUri(sToken, hpath); 135 136 if (uniqueUri != null) { 137 if (UriHandler.useHistoryCollectionHack) { 138 String nextHnStr = uniqueUri.substring(uniqueUri.lastIndexOf('/') + 1); 140 long nextHnLong = Long.parseLong(nextHnStr) + 10; 143 nextHnStr = String.valueOf(nextHnLong); 144 145 StringBuffer pathBuffer = new StringBuffer (hpath); 147 for (int i = 0; i < nextHnStr.length() - 1; i++) { 148 pathBuffer.append('/'); 149 pathBuffer.append(nextHnStr.charAt(i)); 150 String dir = pathBuffer.toString(); 153 try { 154 structure.retrieve(sToken, dir); 155 } catch (ObjectNotFoundException onfe) { 156 try { 157 structure.create(sToken, new SubjectNode(), dir); 158 content.create(sToken, dir, new NodeRevisionDescriptor(0), null); 159 } catch (ObjectAlreadyExistsException oae) { 160 Domain.warn("Object " + dir + " already exists."); 161 } catch (RevisionAlreadyExistException rae) { 162 Domain.warn("Revision " + dir + " already exists."); 163 } 164 } 165 } 166 167 pathBuffer.append("/h").append(nextHnStr.charAt(nextHnStr.length() - 1)); 169 String fullPath = pathBuffer.toString(); 170 171 return new UriHandler(fullPath); 172 173 } else { 174 return new UriHandler(uniqueUri); 175 } 176 } else { 177 178 NodeRevisionDescriptors hpathNrds = content.retrieve(sToken, hpath); 179 NodeRevisionDescriptor hpathNrd = content.retrieve(sToken, hpathNrds); 180 NodeProperty nextHnProp = hpathNrd.getProperty(I_NEXT_HISTORY_NAME, NamespaceCache.SLIDE_URI); 181 182 if (UriHandler.useHistoryCollectionHack) { 183 184 if (nextHnProp == null || nextHnProp.getValue() == null) { 185 nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, "10", NamespaceCache.SLIDE_URI); 188 nextHnProp.setKind(NodeProperty.Kind.PROTECTED); 189 hpathNrd.setProperty(nextHnProp); 190 } 191 192 String nextHnStr = (String ) nextHnProp.getValue(); 193 long nextHnLong = Long.parseLong(nextHnStr); 194 195 if (nextHnLong % 10 == 0) { 196 long dirNum = nextHnLong / 10; 198 char dirChar[] = Long.toString(dirNum).toCharArray(); 199 StringBuffer buf = new StringBuffer (); 200 for (int i = 0; i < dirChar.length - 1; i++) { 201 buf.append(dirChar[i]); 202 buf.append('/'); 203 } 204 buf.append(dirChar[dirChar.length - 1]); 205 String dirPath = hpath + "/" + buf.toString(); 206 207 try { 208 structure.create(sToken, new SubjectNode(), dirPath); 209 content.create(sToken, dirPath, new NodeRevisionDescriptor(0), null); 213 } catch (ObjectAlreadyExistsException oae) { 214 Domain.warn("Object " + dirPath + " already exists."); 215 } catch (RevisionAlreadyExistException rae) { 216 Domain.warn("Revision " + dirPath + " already exists."); 217 } 218 } 219 220 StringBuffer buf = new StringBuffer (); 221 char nextHnChar[] = nextHnStr.toCharArray(); 222 for (int i = 0; i < nextHnChar.length - 1; i++) { 223 buf.append(nextHnChar[i]); 224 buf.append('/'); 225 } 226 buf.append('h'); 227 buf.append(nextHnChar[nextHnChar.length - 1]); 228 229 result = new UriHandler(hpath + "/" + buf.toString()); 230 231 nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, String.valueOf(nextHnLong + 1), 232 NamespaceCache.SLIDE_URI); 233 hpathNrd.setProperty(nextHnProp); 234 235 } else { 236 237 if (nextHnProp == null) { 238 nextHnProp = hpathNrd.getProperty(I_NEXT_HISTORY_NAME); 241 if (nextHnProp != null) { 242 hpathNrd.removeProperty(nextHnProp); 243 nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, nextHnProp.getValue(), 244 NamespaceCache.SLIDE_URI); 245 nextHnProp.setKind(NodeProperty.Kind.PROTECTED); 246 hpathNrd.setProperty(nextHnProp); 247 } 248 } 249 if (nextHnProp == null || nextHnProp.getValue() == null) { 250 nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, I_INITIAL_HISTORY_NAME, NamespaceCache.SLIDE_URI); 251 nextHnProp.setKind(NodeProperty.Kind.PROTECTED); 252 hpathNrd.setProperty(nextHnProp); 253 } 254 255 String nextHnStr = (String ) nextHnProp.getValue(); 256 result = new UriHandler(hpath + "/" + nextHnStr); 257 258 long nextHnLong = Long.parseLong(nextHnStr); 259 nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, String.valueOf(nextHnLong + 1), 260 NamespaceCache.SLIDE_URI); 261 hpathNrd.setProperty(nextHnProp); 262 263 } 264 content.store(sToken, hpath, hpathNrd, null); return result; 266 } 267 } 268 269 270 276 public static UriHandler 277 createNextWorkingresourceUri( SlideToken sToken, NamespaceAccessToken nsaToken, UriHandler uh ) 278 throws ObjectNotFoundException, AccessDeniedException, ObjectLockedException, 279 LinkedObjectNotFoundException, ServiceAccessException, 280 RevisionDescriptorNotFoundException, RevisionNotFoundException, VetoException { 281 282 UriHandler result = null; 283 String nsName = nsaToken.getName(); 284 UriHandler wrpathHandler = 285 WorkingresourcePathHandler.getResolvedWorkingresourcePathHandler( nsName, uh ); 286 Content content = nsaToken.getContentHelper(); 287 String wrpath = wrpathHandler.toString(); 288 289 Structure structure = nsaToken.getStructureHelper(); 290 String uniqueUri = structure.generateUniqueUri(sToken, wrpath); 291 292 if (uniqueUri != null) { 293 result = new UriHandler(uniqueUri); 294 } else { 295 NodeRevisionDescriptors wrpathNrds = 296 content.retrieve( sToken, wrpath ); 297 298 NodeRevisionDescriptor wrpathNrd = 299 content.retrieve( sToken, wrpathNrds ); 300 301 NodeProperty nextWrnProp = wrpathNrd.getProperty(I_NEXT_WORKINGRESOURCE_NAME, 302 NamespaceCache.SLIDE_URI); 303 if (nextWrnProp == null) { 304 nextWrnProp = wrpathNrd.getProperty( I_NEXT_WORKINGRESOURCE_NAME ); 307 if (nextWrnProp != null) { 308 wrpathNrd.removeProperty(nextWrnProp); 309 nextWrnProp = new NodeProperty(I_NEXT_WORKINGRESOURCE_NAME, 310 nextWrnProp.getValue(), 311 NamespaceCache.SLIDE_URI); 312 nextWrnProp.setKind( NodeProperty.Kind.PROTECTED ); 313 wrpathNrd.setProperty( nextWrnProp ); 314 } 315 } 316 317 if( nextWrnProp == null || nextWrnProp.getValue() == null ) { 318 nextWrnProp = 319 new NodeProperty(I_NEXT_WORKINGRESOURCE_NAME, 320 I_INITIAL_WORKINGRESOURCE_NAME, 321 NamespaceCache.SLIDE_URI ); 322 nextWrnProp.setKind( NodeProperty.Kind.PROTECTED ); 323 wrpathNrd.setProperty( nextWrnProp ); 324 } 325 326 String nextWrnStr = (String )nextWrnProp.getValue(); 327 result = new UriHandler( wrpath+"/"+nextWrnStr ); 328 329 long nextWrnLong = Long.parseLong( nextWrnStr ); 330 nextWrnProp = new NodeProperty(I_NEXT_WORKINGRESOURCE_NAME, 331 String.valueOf(nextWrnLong + 1), 332 NamespaceCache.SLIDE_URI ); 333 wrpathNrd.setProperty( nextWrnProp ); 334 335 content.store( sToken, wrpath, wrpathNrd, null ); } 337 return result; 338 } 339 340 344 public static UriHandler 345 createVersionUri( UriHandler vhrUri, String version ) { 346 return new UriHandler( vhrUri, version ); 347 } 348 349 352 protected static Map registeredStores = new HashMap (); 353 protected static Set allScopes = new HashSet (); 354 protected static Set allStoreNames = new HashSet (); 355 356 359 public static void notifyStoreCreated( String namespaceName, String scope, String storeName ) { 360 Map storesInNamespace = (Map )registeredStores.get( namespaceName ); 361 if( storesInNamespace == null ) { 362 storesInNamespace = new HashMap (); 363 registeredStores.put( namespaceName, storesInNamespace ); 364 } 365 UriHandler scopeUh = new UriHandler(scope); 366 storesInNamespace.put( scopeUh, storeName ); 367 allScopes.add( scopeUh ); 368 allStoreNames.add( storeName ); 369 } 370 371 374 protected static UriHandler bestMatchingScope( String namespaceName, UriHandler uh ) { 375 UriHandler result = null; 376 Map storesInNamespace = (Map )registeredStores.get( namespaceName ); 377 Iterator i = storesInNamespace.keySet().iterator(); 378 int matchSize = 0; 379 while( i.hasNext() ) { 380 UriHandler scopeUh = (UriHandler)i.next(); 381 if( scopeUh.isAncestorOf(uh) && scopeUh.length() > matchSize ) { 382 matchSize = scopeUh.length(); 383 result = scopeUh; 384 } 385 } 386 return result; 387 } 388 389 private String uri; 390 private String [] uriTokens = null; 391 392 393 396 protected UriHandler( String uri ) { 397 this.uri = uri; 398 399 StringTokenizer t = new StringTokenizer ( uri, "/" ); 400 int n = t.countTokens(); 401 this.uriTokens = new String [n]; 402 for( int i = 0; i < n; i++ ) 403 uriTokens[i] = t.nextToken(); 404 } 405 406 409 protected UriHandler( String [] uriTokens, int number ) { 410 String [] t = new String [number]; 411 for( int i = 0; i < number; i++ ) 412 t[i] = uriTokens[i]; 413 this.uriTokens = t; 414 } 415 416 419 protected UriHandler( UriHandler vhrUri, String versionName ) { 420 int n = vhrUri.length(); 421 this.uriTokens = new String [n + 1]; 422 for( int i = 0; i < n; i++ ) 423 uriTokens[i] = vhrUri.getUriTokens()[i]; 424 uriTokens[n] = versionName; 425 } 426 427 430 public String getUri() { 431 if( uri == null ) 432 uri = toString(); 433 return uri; 434 } 435 436 439 public String getName() { 440 if( uriTokens.length == 0 ) 441 return null; 442 return uriTokens[uriTokens.length - 1]; 443 } 444 445 448 public UriHandler getParentUriHandler() { 449 if( uriTokens.length == 0 ) 450 return null; 451 return new UriHandler( uriTokens, uriTokens.length - 1 ); 452 } 453 454 458 public boolean isAncestorOf( UriHandler uh ) { 459 if( uriTokens.length > uh.length() ) 460 return false; 461 for( int i = 0; i < uriTokens.length; i++ ) 462 if( !uriTokens[i].equals(uh.getUriTokens()[i]) ) 463 return false; 464 return true; 465 } 466 467 470 public String [] getUriTokens() { 471 return uriTokens; 472 } 473 474 477 public boolean isRootUri() { 478 return (uriTokens.length == 0); 479 } 480 481 484 public boolean isHistoryPathUri() { 485 HistoryPathHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler(); 486 return hpathHandler.isHistoryPathUri( this ); 487 } 488 489 492 public boolean isHistoryUri() { 493 HistoryPathHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler(); 494 495 if (UriHandler.useHistoryCollectionHack) { 496 if (hpathHandler.isAncestorOf(this)) { 497 String [] hpathTokens = hpathHandler.getUriTokens(); 498 if (uriTokens.length < hpathTokens.length + 1) { 499 return false; 500 } 501 String h = uriTokens[uriTokens.length - 1]; 502 return (h.charAt(0) == 'h'); 503 } else { 504 return false; 505 } 506 } else { 507 String [] hpathTokens = hpathHandler.getUriTokens(); 508 509 if ((hpathTokens.length + 1) == uriTokens.length) { 510 if (hpathHandler.isHistoryPathUri(getParentUriHandler())) { 511 try { 512 Integer.parseInt(uriTokens[uriTokens.length - 1]); 513 return true; 514 } catch (NumberFormatException x) { 515 } 516 ; 517 } 518 } 519 return false; 520 } 521 } 522 523 526 public boolean isVersionUri() { 527 HistoryPathHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler(); 528 529 if (UriHandler.useHistoryCollectionHack) { 530 533 534 if (hpathHandler.isAncestorOf(this)) { 535 String [] hpathTokens = hpathHandler.getUriTokens(); 536 if (uriTokens.length < hpathTokens.length + 2) { 537 return false; 538 } 539 String h = uriTokens[uriTokens.length - 2]; 540 return (h.charAt(0) == 'h'); 541 } else { 542 return false; 543 } 544 } else { 545 546 String [] hpathTokens = hpathHandler.getUriTokens(); 547 548 if ((hpathTokens.length + 2) == uriTokens.length) { 549 if (getParentUriHandler().isHistoryUri()) 550 return true; 551 } 552 return false; 553 } 554 } 555 556 559 public boolean isWorkspacePathUri() { 560 WorkspacePathHandler wspathHandler = WorkspacePathHandler.getWorkspacePathHandler(); 561 return wspathHandler.isWorkspacePathUri( this ); 562 } 563 564 567 public boolean isWorkspaceUri() { 568 WorkspacePathHandler wspathHandler = WorkspacePathHandler.getWorkspacePathHandler(); 569 String [] wspathTokens = wspathHandler.getUriTokens(); 570 571 if( (wspathTokens.length + 1) == uriTokens.length ) { 572 if( wspathHandler.isWorkspacePathUri(getParentUriHandler()) ) { 573 return true; 574 } 575 } 576 return false; 577 } 578 579 582 public boolean isResourceInWorkspaceUri() { 583 WorkspacePathHandler wspathHandler = WorkspacePathHandler.getWorkspacePathHandler(); 584 String [] wspathTokens = wspathHandler.getUriTokens(); 585 586 if( (wspathTokens.length + 1) < uriTokens.length ) { 587 UriHandler p = new UriHandler( uriTokens, wspathTokens.length + 1 ); 588 if( p.isWorkspaceUri() ) { 589 return true; 590 } 591 } 592 return false; 593 } 594 595 598 public boolean isWorkingresourcePathUri() { 599 WorkingresourcePathHandler wrpathHandler = WorkingresourcePathHandler.getWorkingresourcePathHandler(); 600 return wrpathHandler.isWorkingresourcePathUri( this ); 601 } 602 603 606 public boolean isWorkingresourceUri() { 607 WorkingresourcePathHandler wrpathHandler = WorkingresourcePathHandler.getWorkingresourcePathHandler(); 608 String [] wrpathTokens = wrpathHandler.getUriTokens(); 609 610 if( (wrpathTokens.length + 1) == uriTokens.length ) { 611 if( wrpathHandler.isWorkingresourcePathUri(getParentUriHandler()) ) { 612 try { 613 Integer.parseInt( uriTokens[uriTokens.length - 1] ); 614 return true; 615 } 616 catch( NumberFormatException x ) {}; 617 } 618 } 619 return false; } 620 621 625 public String getWorkspaceName() { 626 UriHandler wspathHandler = WorkspacePathHandler.getWorkspacePathHandler(); 627 String [] wspathTokens = wspathHandler.getUriTokens(); 628 629 if( !isWorkspaceUri() ) 630 throw new IllegalStateException ( 631 "URI "+uri+" is not a workspace URI" ); 632 633 return uriTokens[wspathTokens.length]; 634 } 635 636 640 public String getHistoryName() { 641 UriHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler(); 642 String [] hpathTokens = hpathHandler.getUriTokens(); 643 644 if (UriHandler.useHistoryCollectionHack) { 645 if (isHistoryUri()) { 646 return getName(); 647 } else if (isVersionUri()) { 648 return uriTokens[uriTokens.length - 2]; 649 } else { 650 throw new IllegalStateException ("URI " + toString() + " is neither history nor version URI"); 651 } 652 } else { 653 if (!isHistoryUri() && !isVersionUri()) 654 throw new IllegalStateException ("URI " + uri + " is neither history nor version URI"); 655 656 return uriTokens[hpathTokens.length]; 657 } 658 } 659 660 665 public String getVersionName() { 666 if (!isVersionUri()) 667 throw new IllegalStateException ("URI " + uri + " is not a version URI"); 668 669 if (UriHandler.useHistoryCollectionHack) { 670 return getName(); 671 } else { 672 UriHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler(); 673 String [] hpathTokens = hpathHandler.getUriTokens(); 674 675 return uriTokens[hpathTokens.length + 1]; 676 } 677 } 678 679 684 public String getAssociatedHistoryUri() { 685 if( !isVersionUri() ) 686 throw new IllegalStateException ( 687 "URI "+uri+" is not a version URI" ); 688 689 StringBuffer b = new StringBuffer (); 690 for( int i = 0; i < (uriTokens.length - 1); i++ ) { 691 b.append( "/" ); 692 b.append( uriTokens[i] ); 693 } 694 return b.toString(); 695 } 696 697 703 public String getAssociatedWorkspaceUri() { 704 if( !isWorkspaceUri() && !isResourceInWorkspaceUri() ) 705 return null; 706 707 UriHandler wspathHandler = WorkspacePathHandler.getWorkspacePathHandler(); 708 String [] wspathTokens = wspathHandler.getUriTokens(); 709 StringBuffer b = new StringBuffer (); 710 for( int i = 0; i < (wspathTokens.length + 1); i++ ) { 711 b.append( "/" ); 712 b.append( uriTokens[i] ); 713 } 714 return b.toString(); 715 } 716 717 728 public String getAssociatedBaseStoreName( String namespaceName ) { 729 String result = ""; 730 731 if( isHistoryPathUri() || isHistoryUri() || isVersionUri() ) { 732 if( HistoryPathHandler.parameterized ) { 733 result = extractStoreName( HistoryPathHandler.historyPathHandler ); 734 } 735 else { 736 Domain.info( "Cannot determine base store name for URI "+this ); 737 } 738 } 739 else if( isWorkspacePathUri() || isWorkspaceUri() || isResourceInWorkspaceUri() ) { 740 if( WorkspacePathHandler.parameterized ) { 741 result = extractStoreName( WorkspacePathHandler.workspacePathHandler ); 742 } 743 else { 744 Domain.info( "Cannot determine base store name for URI "+this ); 745 } 746 } 747 else if( isWorkingresourcePathUri() || isWorkingresourceUri() ) { 748 if( WorkingresourcePathHandler.parameterized ) { 749 result = extractStoreName( WorkingresourcePathHandler.workingresourcePathHandler ); 750 } 751 else { 752 Domain.info( "Cannot determine base store name for URI "+this ); 753 } 754 } 755 else { 756 UriHandler scopeUh = bestMatchingScope( namespaceName, this ); 757 Map storesInNamespace = (Map )registeredStores.get( namespaceName ); 758 result = (String )storesInNamespace.get( scopeUh ); 759 } 760 return result; 761 } 762 763 766 private String extractStoreName( UriHandler pUh ) { 767 String result = ""; 768 String [] pTokens = pUh.getUriTokens(); 769 int ptIndex = -1; 770 for( int i = 0; i < pTokens.length; i++ ) { 771 if( pTokens[i].indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0 ) { 772 ptIndex = i; 773 break; 774 } 775 } 776 if( ptIndex >= 0 ) { 777 result = extractStoreName( pTokens[ptIndex], uriTokens[ptIndex] ); 778 } 779 return result; 780 } 781 782 785 private String extractStoreName( String prmStr, String srcStr ) { 786 String tail = null; 787 int start = prmStr.indexOf( I_STORE_PLACE_HOLDER_IN_PATH ); 788 int endP = start + I_STORE_PLACE_HOLDER_IN_PATH.length(); 789 int endS = -1; 790 791 if( endP < prmStr.length() ) { 792 tail = prmStr.substring( endP ); 793 endS = srcStr.lastIndexOf( tail ); 794 } 795 else 796 endS = srcStr.length(); 797 798 return srcStr.substring( start, endS ); 799 } 800 801 809 public boolean isRestrictedUri() { 810 if( isRootUri() ) 811 return true; 812 if( isVersionUri() ) 813 return true; 814 if( isHistoryUri() ) 815 return true; 816 if( isHistoryPathUri() ) 817 return true; 818 if( isWorkspaceUri() ) 819 return true; 820 if( isWorkspacePathUri() ) 821 return true; 822 if( isWorkingresourceUri() ) 823 return true; 824 if( isWorkingresourcePathUri() ) 825 return true; 826 827 UriHandler p = getParentUriHandler(); 828 if( p != null ) { 829 if( p.isRootUri() ) 830 return true; 831 if( p.isHistoryPathUri() ) 832 return true; 833 if( p.isWorkingresourcePathUri() ) 834 return true; 835 } 836 return false; 837 } 838 839 842 public boolean equals( Object o ) { 843 if( !(o instanceof UriHandler) ) 844 return false; 845 String [] oTokens = ((UriHandler)o).getUriTokens(); 846 if( oTokens.length != uriTokens.length ) 847 return false; 848 for( int i = 0; i < uriTokens.length; i++ ) 849 if( !oTokens[i].equals(uriTokens[i]) ) 850 return false; 851 return true; 852 } 853 854 857 public int hashCode() { 858 return uriTokens.length; 859 } 860 861 864 public int length() { 865 return uriTokens.length; 866 } 867 868 871 public String toString() { 872 StringBuffer b = new StringBuffer (); 873 if( uriTokens.length == 0 ) 874 b.append("/"); 875 else 876 for( int i = 0; i < uriTokens.length; i++ ) 877 b.append("/").append( uriTokens[i] ); 878 return b.toString(); 879 } 880 } 881 882 | Popular Tags |