1 23 24 package org.apache.slide.webdav.util; 25 26 import java.util.ArrayList ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Set ; 31 32 import org.apache.slide.common.Domain; 33 34 public class WorkingresourcePathHandler extends UriHandler { 35 36 final static String WORKINGRESOURCE_PATH = 37 Domain.getParameter( I_WORKINGRESOURCEPATH, I_WORKINGRESOURCEPATH_DEFAULT ); 38 39 static WorkingresourcePathHandler workingresourcePathHandler = 40 new WorkingresourcePathHandler( WORKINGRESOURCE_PATH ); 41 42 static boolean parameterized = (WORKINGRESOURCE_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0); 43 44 47 public static WorkingresourcePathHandler getWorkingresourcePathHandler() { 48 return workingresourcePathHandler; 49 } 50 51 57 public static UriHandler getResolvedWorkingresourcePathHandler( String namespaceName, UriHandler uh ) { 58 if( parameterized ) { 59 return getResolvedWorkingresourcePathHandler( uh.getAssociatedBaseStoreName(namespaceName) ); 62 } 63 else 64 return workingresourcePathHandler; 65 } 66 67 70 public static UriHandler getResolvedWorkingresourcePathHandler( String storeName ) { 71 if( parameterized ) { 72 StringBuffer b; 73 String rp = workingresourcePathHandler.toString(); 74 int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH ); 75 if( k >= 0 ) { 76 b = new StringBuffer ( rp ); 77 while( k >= 0 ) { 78 b.replace( k, k + I_STORE_PLACE_HOLDER_IN_PATH.length(), storeName ); 79 k = b.toString().indexOf(I_STORE_PLACE_HOLDER_IN_PATH); 80 } 81 rp = b.toString(); 82 } 83 return new UriHandler(rp); 84 } 85 else 86 return workingresourcePathHandler; 87 } 88 89 92 public static String getWorkingresourcePath() { 93 return WORKINGRESOURCE_PATH; 94 } 95 96 97 private Set resolvedWorkingresourcePaths = null; 98 99 102 protected WorkingresourcePathHandler( String uri ) { 103 super( uri ); 104 } 105 106 109 public boolean isWorkingresourcePathUri( UriHandler uh ) { 110 if( !parameterized ) 111 return equals( uh ); 112 113 if( !Domain.namespacesAreInitialized() ) 114 return false; 115 116 if( resolvedWorkingresourcePaths == null ) 117 resolve(); 118 119 return resolvedWorkingresourcePaths.contains( uh ); 120 } 121 122 125 public List getResolvedWorkingresourcePaths() { 126 List result; 127 if( parameterized ) { 128 resolve(); 129 result = new ArrayList ( resolvedWorkingresourcePaths ); 130 } 131 else { 132 result = new ArrayList (); 133 result.add( WORKINGRESOURCE_PATH ); 134 } 135 return result; 136 } 137 138 141 private void resolve() { 142 resolvedWorkingresourcePaths = new HashSet (); 143 Iterator i = allStoreNames.iterator(); 144 while( i.hasNext() ) { 145 String storeName = (String )i.next(); 146 UriHandler rpuh = getResolvedWorkingresourcePathHandler( storeName ); 147 if( allScopes.contains(rpuh) ) 148 resolvedWorkingresourcePaths.add( rpuh ); 149 } 150 } 151 } 152 153 | Popular Tags |