KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > cache > URLKeyUtil


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.lenya.ac.cache;
19
20 import java.io.IOException JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22
23 import org.apache.excalibur.source.Source;
24 import org.apache.excalibur.source.SourceResolver;
25
26 /**
27  * Utility class to generate String cache keys from webapp URLs.
28  * @version $Id: URLKeyUtil.java 43238 2004-08-16 16:06:14Z andreas $
29  */

30 public final class URLKeyUtil {
31
32     /**
33      * Ctor.
34      */

35     private URLKeyUtil() {
36     }
37
38     /**
39      * Generates a cache key for a context and a webapp URL.
40      * @param resolver The resolver of the context.
41      * @param webappUrl The webapp Url.
42      * @return A String.
43      * @throws MalformedURLException when something went wrong.
44      * @throws IOException when something went wrong.
45      */

46     public static String JavaDoc generateKey(SourceResolver resolver, String JavaDoc webappUrl)
47         throws MalformedURLException JavaDoc, IOException JavaDoc {
48         Source source = null;
49         String JavaDoc key;
50         try {
51             source = resolver.resolveURI("context:///");
52             key = source.getURI() + "_" + webappUrl;
53         }
54         finally {
55             if (source != null) {
56                 resolver.release(source);
57             }
58         }
59         return key;
60     }
61
62 }
63
Popular Tags