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 WorkspacePathHandler extends UriHandler { 35 36 final static String WORKSPACE_PATH = 37 Domain.getParameter( I_WORKSPACEPATH, I_WORKSPACEPATH_DEFAULT ); 38 39 static WorkspacePathHandler workspacePathHandler = 40 new WorkspacePathHandler( WORKSPACE_PATH ); 41 42 static boolean parameterized = (WORKSPACE_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0); 43 44 45 48 public static WorkspacePathHandler getWorkspacePathHandler() { 49 return workspacePathHandler; 50 } 51 52 55 public static UriHandler getResolvedWorkspacePathHandler( String namespaceName, UriHandler uh ) { 56 if( parameterized ) { 57 return getResolvedWorkspacePathHandler( uh.getAssociatedBaseStoreName(namespaceName) ); 58 } 59 else 60 return workspacePathHandler; 61 } 62 63 66 public static UriHandler getResolvedWorkspacePathHandler( String storeName ) { 67 if( parameterized ) { 68 StringBuffer b; 69 String rp = workspacePathHandler.toString(); 70 int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH ); 71 if( k >= 0 ) { 72 b = new StringBuffer ( rp ); 73 while( k >= 0 ) { 74 b.replace( k, k + I_STORE_PLACE_HOLDER_IN_PATH.length(), storeName ); 75 k = b.toString().indexOf(I_STORE_PLACE_HOLDER_IN_PATH); 76 } 77 rp = b.toString(); 78 } 79 return new UriHandler(rp); 80 } 81 else 82 return workspacePathHandler; 83 } 84 85 88 public static String getWorkspacePath() { 89 return WORKSPACE_PATH; 90 } 91 92 93 private Set resolvedWorkspacePaths = null; 94 95 98 protected WorkspacePathHandler( String uri ) { 99 super( uri ); 100 } 101 102 105 public boolean isWorkspacePathUri( UriHandler uh ) { 106 if( !parameterized ) 107 return equals( uh ); 108 109 if( !Domain.namespacesAreInitialized() ) 110 return false; 111 112 if( resolvedWorkspacePaths == null ) 113 resolve(); 114 115 return resolvedWorkspacePaths.contains( uh ); 116 } 117 118 121 public List getResolvedWorkspacePaths() { 122 return getResolvedWorkspacePaths( null ); 123 } 124 125 128 public List getResolvedWorkspacePaths( String storeName ) { 129 List result; 130 if( parameterized ) { 131 if( storeName != null ) { 132 result = new ArrayList (); 133 result.add( getResolvedWorkspacePathHandler(storeName) ); 134 } 135 else { 136 resolve(); 137 result = new ArrayList ( resolvedWorkspacePaths ); 138 } 139 } 140 else { 141 result = new ArrayList (); 142 result.add( WORKSPACE_PATH ); 143 } 144 return result; 145 } 146 147 150 private void resolve() { 151 resolvedWorkspacePaths = new HashSet (); 152 Iterator i = allStoreNames.iterator(); 153 while( i.hasNext() ) { 154 String storeName = (String )i.next(); 155 UriHandler rpuh = getResolvedWorkspacePathHandler( storeName ); 156 if( allScopes.contains(rpuh) ) 157 resolvedWorkspacePaths.add( rpuh ); 158 } 159 } 160 } 161 162 163 164 165 | Popular Tags |