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