KickJava   Java API By Example, From Geeks To Geeks.

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


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

47     public static HistoryPathHandler getHistoryPathHandler() {
48         return historyPathHandler;
49     }
50     
51     /**
52      * Get a resolved UriHandler for this HistoryPathHandler.
53      */

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

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

87     public static String JavaDoc getHistoryPath() {
88         return HISTORY_PATH;
89     }
90     
91     
92     private Set JavaDoc resolvedHistoryPaths = null;
93     
94     /**
95      * Protected constructor
96      */

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

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     /**
118      * Return the resolved history paths
119      */

120     public List JavaDoc getResolvedHistoryPaths() {
121         return getResolvedHistoryPaths( null );
122     }
123     
124     /**
125      * Return the resolved history paths
126      */

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

149     private void resolve() {
150         resolvedHistoryPaths = new HashSet JavaDoc();
151         Iterator JavaDoc i = allStoreNames.iterator();
152         while( i.hasNext() ) {
153             String JavaDoc storeName = (String JavaDoc)i.next();
154             UriHandler rpuh = getResolvedHistoryPathHandler( storeName );
155             if( allScopes.contains(rpuh) )
156                 resolvedHistoryPaths.add( rpuh );
157         }
158     }
159 }
160
161
162
Popular Tags