pnever      2002/07/17 05:24:52

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        UriHandler.java HistoryPathHandler.java
                        WorkingresourcePathHandler.java
                        WorkspacePathHandler.java
  Log:
  Fixed problem with parameterized history, workingresource and workspace paths.
  
  Revision  Changes    Path
  1.20      +88 -3     
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/UriHandler.java
  
  Index: UriHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/UriHandler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- UriHandler.java   11 Jul 2002 14:57:08 -0000      1.19
  +++ UriHandler.java   17 Jul 2002 12:24:51 -0000      1.20
  @@ -65,6 +65,7 @@
   
   import java.util.*;
   
  +import org.apache.slide.common.Domain;
   import org.apache.slide.common.SlideToken;
   import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.ServiceAccessException;
  @@ -561,6 +562,90 @@
               b.append( uriTokens[i] );
           }
           return b.toString();
  +    }
  +    
  +    /**
  +     * Returns the associated <b>base</b> store name.
  +     * Examples (assume historyPath is parameterized: /history/${store}):
  +     *   uri=/history/mycoll/1       --->  result=mycoll  // history URI
  +     *   uri=/history/files/1/1.17   --->  result=files   // version URI
  +     *   uri=/files/foo/bar.xml      --->  result=files   // best matching scope
  +     * If the URI is e.g. a version URI but historyPath is not parameterized, no 
associated
  +     * base store can be determined.
  +     *
  +     * @return the associated base store name.
  +     */
  +    public String getAssociatedBaseStoreName( String namespaceName ) {
  +        String result = "";
  +        
  +        if( isHistoryPathUri() || isHistoryUri() || isVersionUri() ) {
  +            if( HistoryPathHandler.parameterized ) {
  +                result = extractStoreName( HistoryPathHandler.historyPathHandler );
  +            }
  +            else {
  +                Domain.info( "Cannot determine base store name for URI "+this );
  +            }
  +        }
  +        else if( isWorkspacePathUri() || isWorkspaceUri() || 
isResourceInWorkspaceUri() ) {
  +            if( WorkspacePathHandler.parameterized ) {
  +                result = extractStoreName( 
WorkspacePathHandler.workspacePathHandler );
  +            }
  +            else {
  +                Domain.info( "Cannot determine base store name for URI "+this );
  +            }
  +        }
  +        else if( isWorkingresourcePathUri() || isWorkingresourceUri() ) {
  +            if( WorkingresourcePathHandler.parameterized ) {
  +                result = extractStoreName( 
WorkingresourcePathHandler.workingresourcePathHandler );
  +            }
  +            else {
  +                Domain.info( "Cannot determine base store name for URI "+this );
  +            }
  +        }
  +        else {
  +            UriHandler scopeUh = bestMatchingScope( namespaceName, this );
  +            Map storesInNamespace = (Map)registeredStores.get( namespaceName );
  +            result = (String)storesInNamespace.get( scopeUh );
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Extract the store name from a parameterized path.
  +     */
  +    private String extractStoreName( UriHandler pUh ) {
  +        String result = "";
  +        String[] pTokens = pUh.getUriTokens();
  +        int ptIndex = -1;
  +        for( int i = 0; i < pTokens.length; i++ ) {
  +            if( pTokens[i].indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0 ) {
  +                ptIndex = i;
  +                break;
  +            }
  +        }
  +        if( ptIndex >= 0 ) {
  +            result = extractStoreName( pTokens[ptIndex], uriTokens[ptIndex] );
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Extract the store name from a parameterized path.
  +     */
  +    private String extractStoreName( String prmStr, String srcStr ) {
  +        String tail = null;
  +        int start = prmStr.indexOf( I_STORE_PLACE_HOLDER_IN_PATH );
  +        int endP = start + I_STORE_PLACE_HOLDER_IN_PATH.length();
  +        int endS = -1;
  +        
  +        if( endP < prmStr.length() ) {
  +            tail = prmStr.substring( endP );
  +            endS = srcStr.lastIndexOf( tail );
  +        }
  +        else
  +            endS = srcStr.length();
  +        
  +        return srcStr.substring( start, endS );
       }
       
       /**
  
  
  
  1.9       +31 -10    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/HistoryPathHandler.java
  
  Index: HistoryPathHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/HistoryPathHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HistoryPathHandler.java   20 Jun 2002 11:31:36 -0000      1.8
  +++ HistoryPathHandler.java   17 Jul 2002 12:24:51 -0000      1.9
  @@ -75,6 +75,9 @@
       
       static HistoryPathHandler historyPathHandler = new HistoryPathHandler( 
HISTORY_PATH );
           
  +    static boolean parameterized = 
(HISTORY_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0);
  +
  +    
       /**
        * Factory method.
        */
  @@ -86,16 +89,18 @@
        * Get a resolved UriHandler for this HistoryPathHandler.
        */
       public static UriHandler getResolvedHistoryPathHandler( String namespaceName, 
UriHandler uh ) {
  -        UriHandler scopeUh = bestMatchingScope( namespaceName, uh );
  -        Map storesInNamespace = (Map)registeredStores.get( namespaceName );
  -        String storeName = (String)storesInNamespace.get( scopeUh );
  -        return getResolvedHistoryPathHandler( storeName );
  +        if( parameterized ) {
  +            return getResolvedHistoryPathHandler( 
uh.getAssociatedBaseStoreName(namespaceName) );
  +        }
  +        else
  +            return historyPathHandler;
       }
       
       /**
        * Get a resolved UriHandler for this HistoryPathHandler.
        */
       public static UriHandler getResolvedHistoryPathHandler( String storeName ) {
  +        if( parameterized ) {
           StringBuffer b;
           String rp = historyPathHandler.toString();
           int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH );
  @@ -109,6 +114,9 @@
           }
           return new UriHandler(rp);
       }
  +        else
  +            return historyPathHandler;
  +    }
       
       /**
        * Factory method.
  @@ -119,15 +127,12 @@
       
       
       private Set resolvedHistoryPaths = null;
  -    private boolean parameterized = false;
       
       /**
        * Protected constructor
        */
       protected HistoryPathHandler( String uri ) {
           super( uri );
  -        parameterized =
  -            (HISTORY_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0);
       }
       
       /**
  @@ -144,6 +149,22 @@
               resolve();
           
           return resolvedHistoryPaths.contains( uh );
  +    }
  +    
  +    /**
  +     * Return the resolved history paths
  +     */
  +    public List getResolvedHistoryPaths() {
  +        List result;
  +        if( parameterized ) {
  +            resolve();
  +            result = new ArrayList( resolvedHistoryPaths );
  +        }
  +        else {
  +            result = new ArrayList();
  +            result.add( HISTORY_PATH );
  +        }
  +        return result;
       }
       
       /**
  
  
  
  1.8       +31 -12    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WorkingresourcePathHandler.java
  
  Index: WorkingresourcePathHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WorkingresourcePathHandler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WorkingresourcePathHandler.java   20 Jun 2002 11:31:36 -0000      1.7
  +++ WorkingresourcePathHandler.java   17 Jul 2002 12:24:51 -0000      1.8
  @@ -73,9 +73,11 @@
       final static String WORKINGRESOURCE_PATH =
           Domain.getParameter( I_WORKINGRESOURCEPATH, I_WORKINGRESOURCEPATH_DEFAULT );
       
  -    final static WorkingresourcePathHandler workingresourcePathHandler =
  +    static WorkingresourcePathHandler workingresourcePathHandler =
           new WorkingresourcePathHandler( WORKINGRESOURCE_PATH );
       
  +    static boolean parameterized = 
(WORKINGRESOURCE_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0);
  +    
       
       /**
        * Factory method.
  @@ -88,16 +90,18 @@
        * Get a resolved UriHandler for this WorkingresourcePathHandler.
        */
       public static UriHandler getResolvedWorkingresourcePathHandler( String 
namespaceName, UriHandler uh ) {
  -        UriHandler scopeUh = bestMatchingScope( namespaceName, uh );
  -        Map storesInNamespace = (Map)registeredStores.get( namespaceName );
  -        String storeName = (String)storesInNamespace.get( scopeUh );
  -        return getResolvedWorkingresourcePathHandler( storeName );
  +        if( parameterized ) {
  +            return getResolvedWorkingresourcePathHandler( 
uh.getAssociatedBaseStoreName(namespaceName) );
  +        }
  +        else
  +            return workingresourcePathHandler;
       }
       
       /**
        * Get a resolved UriHandler for this WorkingresourcePathHandler.
        */
       public static UriHandler getResolvedWorkingresourcePathHandler( String 
storeName ) {
  +        if( parameterized ) {
           StringBuffer b;
           String rp = workingresourcePathHandler.toString();
           int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH );
  @@ -111,6 +115,9 @@
           }
           return new UriHandler(rp);
           }
  +        else
  +            return workingresourcePathHandler;
  +        }
       
       /**
        * Factory method.
  @@ -121,15 +128,12 @@
       
       
       private Set resolvedWorkingresourcePaths = null;
  -    private boolean parameterized = false;
       
       /**
        * Protected constructor
        */
       protected WorkingresourcePathHandler( String uri ) {
           super( uri );
  -        parameterized =
  -            (WORKINGRESOURCE_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0);
       }
       
       /**
  @@ -149,6 +153,22 @@
   }
   
       /**
  +     * Return the resolved workingresource paths
  +     */
  +    public List getResolvedWorkingresourcePaths() {
  +        List result;
  +        if( parameterized ) {
  +            resolve();
  +            result = new ArrayList( resolvedWorkingresourcePaths );
  +        }
  +        else {
  +            result = new ArrayList();
  +            result.add( WORKINGRESOURCE_PATH );
  +        }
  +        return result;
  +    }
  +
  +    /**
        * Resolve this workingresource path handler
        */
       private void resolve() {
  @@ -162,5 +182,4 @@
           }
   }
   }
  -
   
  
  
  
  1.7       +31 -11    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WorkspacePathHandler.java
  
  Index: WorkspacePathHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WorkspacePathHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WorkspacePathHandler.java 20 Jun 2002 11:31:36 -0000      1.6
  +++ WorkspacePathHandler.java 17 Jul 2002 12:24:51 -0000      1.7
  @@ -73,9 +73,11 @@
       final static String WORKSPACE_PATH =
           Domain.getParameter( I_WORKSPACEPATH, I_WORKSPACEPATH_DEFAULT );
   
  -    final static WorkspacePathHandler workspacePathHandler =
  +    static WorkspacePathHandler workspacePathHandler =
           new WorkspacePathHandler( WORKSPACE_PATH );
   
  +    static boolean parameterized = 
(WORKSPACE_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0);
  +
       
       /**
        * Factory method.
  @@ -88,16 +90,18 @@
        * Get a resolved UriHandler for this WorkspacePathHandler.
        */
       public static UriHandler getResolvedWorkspacePathHandler( String namespaceName, 
UriHandler uh ) {
  -        UriHandler scopeUh = bestMatchingScope( namespaceName, uh );
  -        Map storesInNamespace = (Map)registeredStores.get( namespaceName );
  -        String storeName = (String)storesInNamespace.get( scopeUh );
  -        return getResolvedWorkspacePathHandler( storeName );
  +        if( parameterized ) {
  +            return getResolvedWorkspacePathHandler( 
uh.getAssociatedBaseStoreName(namespaceName) );
  +        }
  +        else
  +            return workspacePathHandler;
       }
       
       /**
        * Get a resolved UriHandler for this WorkspacePathHandler.
        */
       public static UriHandler getResolvedWorkspacePathHandler( String storeName ) {
  +        if( parameterized ) {
           StringBuffer b;
           String rp = workspacePathHandler.toString();
           int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH );
  @@ -111,6 +115,9 @@
           }
           return new UriHandler(rp);
       }
  +        else
  +            return workspacePathHandler;
  +    }
       
       /**
        * Factory method.
  @@ -121,15 +128,12 @@
       
       
       private Set resolvedWorkspacePaths = null;
  -    private boolean parameterized = false;
       
       /**
        * Protected constructor
        */
       protected WorkspacePathHandler( String uri ) {
           super( uri );
  -        parameterized =
  -            (WORKSPACE_PATH.indexOf(I_STORE_PLACE_HOLDER_IN_PATH) >= 0);
       }
       
       /**
  @@ -146,6 +150,22 @@
               resolve();
   
           return resolvedWorkspacePaths.contains( uh );
  +    }
  +    
  +    /**
  +     * Return the resolved workspace paths
  +     */
  +    public List getResolvedWorkspacePaths() {
  +        List result;
  +        if( parameterized ) {
  +            resolve();
  +            result = new ArrayList( resolvedWorkspacePaths );
  +        }
  +        else {
  +            result = new ArrayList();
  +            result.add( WORKSPACE_PATH );
  +        }
  +        return result;
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to