KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WorkingresourcePathHandler.java,v 1.11 2004/02/11 11:30:35 ozeigermann Exp $
3  * $Revision: 1.11 $
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 WorkingresourcePathHandler extends UriHandler {
35     
36     final static String JavaDoc 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     /**
45      * Factory method.
46      */

47     public static WorkingresourcePathHandler getWorkingresourcePathHandler() {
48         return workingresourcePathHandler;
49         }
50     
51     /**
52      * Get a resolved UriHandler for this WorkingresourcePathHandler.
53      * @param namespaceName the namespace name
54      * @param uh an URI required to determine the associated base store;
55      * usually the URI of the version resource being checked out.
56      */

57     public static UriHandler getResolvedWorkingresourcePathHandler( String JavaDoc namespaceName, UriHandler uh ) {
58         if( parameterized ) {
59             // requires URI to determine associated base store; usually URI of version being checked-out.
60
// NOTE: if the workingresource path is parameterized but the history path is not ... we have trouble :-(
61
return getResolvedWorkingresourcePathHandler( uh.getAssociatedBaseStoreName(namespaceName) );
62         }
63         else
64             return workingresourcePathHandler;
65     }
66     
67     /**
68      * Get a resolved UriHandler for this WorkingresourcePathHandler.
69      */

70     public static UriHandler getResolvedWorkingresourcePathHandler( String JavaDoc storeName ) {
71         if( parameterized ) {
72         StringBuffer JavaDoc b;
73         String JavaDoc rp = workingresourcePathHandler.toString();
74         int k = rp.indexOf( I_STORE_PLACE_HOLDER_IN_PATH );
75         if( k >= 0 ) {
76             b = new StringBuffer JavaDoc( 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     /**
90      * Factory method.
91      */

92     public static String JavaDoc getWorkingresourcePath() {
93         return WORKINGRESOURCE_PATH;
94     }
95     
96     
97     private Set JavaDoc resolvedWorkingresourcePaths = null;
98     
99     /**
100      * Protected constructor
101      */

102     protected WorkingresourcePathHandler( String JavaDoc uri ) {
103         super( uri );
104     }
105     
106     /**
107      * Return true if the specified URI is a valid workingresource path URI
108      */

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     /**
123      * Return the resolved workingresource paths
124      */

125     public List JavaDoc getResolvedWorkingresourcePaths() {
126         List JavaDoc result;
127         if( parameterized ) {
128             resolve();
129             result = new ArrayList JavaDoc( resolvedWorkingresourcePaths );
130         }
131         else {
132             result = new ArrayList JavaDoc();
133             result.add( WORKINGRESOURCE_PATH );
134         }
135         return result;
136     }
137
138     /**
139      * Resolve this workingresource path handler
140      */

141     private void resolve() {
142         resolvedWorkingresourcePaths = new HashSet JavaDoc();
143         Iterator JavaDoc i = allStoreNames.iterator();
144         while( i.hasNext() ) {
145             String JavaDoc storeName = (String JavaDoc)i.next();
146             UriHandler rpuh = getResolvedWorkingresourcePathHandler( storeName );
147             if( allScopes.contains(rpuh) )
148                 resolvedWorkingresourcePaths.add( rpuh );
149         }
150 }
151 }
152
153
Popular Tags