KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > util > WorkspacePathHandler


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WorkspacePathHandler.java,v 1.10 2004/02/11 11:30:35 ozeigermann Exp $
3  * $Revision: 1.10 $
4  * $Date: 2004/02/11 11:30:35 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.util;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Set JavaDoc;
31
32 import org.apache.slide.common.Domain;
33
34 public class WorkspacePathHandler extends UriHandler {
35     
36     final static String JavaDoc 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     /**
46      * Factory method.
47      */

48     public static WorkspacePathHandler getWorkspacePathHandler() {
49         return workspacePathHandler;
50         }
51     
52     /**
53      * Get a resolved UriHandler for this WorkspacePathHandler.
54      */

55     public static UriHandler getResolvedWorkspacePathHandler( String JavaDoc namespaceName, UriHandler uh ) {
56         if( parameterized ) {
57             return getResolvedWorkspacePathHandler( uh.getAssociatedBaseStoreName(namespaceName) );
58         }
59         else
60             return workspacePathHandler;
61     }
62     
63     /**
64      * Get a resolved UriHandler for this WorkspacePathHandler.
65      */

66     public static UriHandler getResolvedWorkspacePathHandler( String JavaDoc storeName ) {
67         if( parameterized ) {
68         StringBuffer JavaDoc b;
69         String JavaDoc rp = workspacePathHandler.toString();
70         int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH );
71         if( k >= 0 ) {
72             b = new StringBuffer JavaDoc( 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     /**
86      * Factory method.
87      */

88     public static String JavaDoc getWorkspacePath() {
89         return WORKSPACE_PATH;
90     }
91     
92     
93     private Set JavaDoc resolvedWorkspacePaths = null;
94     
95     /**
96      * Protected constructor
97      */

98     protected WorkspacePathHandler( String JavaDoc uri ) {
99         super( uri );
100     }
101     
102     /**
103      * Return true if the specified URI is a valid workspace path URI
104      */

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     /**
119      * Return the resolved workspace paths
120      */

121     public List JavaDoc getResolvedWorkspacePaths() {
122         return getResolvedWorkspacePaths( null );
123     }
124     
125     /**
126      * Return the resolved workspace paths
127      */

128     public List JavaDoc getResolvedWorkspacePaths( String JavaDoc storeName ) {
129         List JavaDoc result;
130         if( parameterized ) {
131             if( storeName != null ) {
132                 result = new ArrayList JavaDoc();
133                 result.add( getResolvedWorkspacePathHandler(storeName) );
134             }
135             else {
136                 resolve();
137                 result = new ArrayList JavaDoc( resolvedWorkspacePaths );
138             }
139         }
140         else {
141             result = new ArrayList JavaDoc();
142             result.add( WORKSPACE_PATH );
143         }
144         return result;
145     }
146
147     /**
148      * Resolve this workspace path handler
149      */

150     private void resolve() {
151         resolvedWorkspacePaths = new HashSet JavaDoc();
152         Iterator JavaDoc i = allStoreNames.iterator();
153         while( i.hasNext() ) {
154             String JavaDoc storeName = (String JavaDoc)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