KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > IResourceLocation


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

15 package org.apache.tapestry;
16
17 import java.net.URL JavaDoc;
18 import java.util.Locale JavaDoc;
19
20 /**
21  * Describes the location of a resource, such as a specification
22  * or template. Resources may be located within the classpath,
23  * or within the Web context root or somewhere else entirely.
24  *
25  * <p>
26  * Resources may be either base or localized. A localized
27  * version of a base resource may be obtained
28  * via {@link #getLocalization(Locale)}.
29  *
30  * <p>
31  * Resource locations are used as Map keys, they must
32  * implement {@link java.lang.Object#hashCode()} and
33  * {@link java.lang.Object#equals(java.lang.Object)}
34  * properly.
35  *
36  * <p>
37  * Resource locations are valid even if the corresponding
38  * resource <i>doesn't exist</i>. To verify if a localization
39  * actually exists, use {@link #getResourceURL()}, which returns
40  * null if the resource doesn't exist. {@link #getLocalization(Locale)}
41  * returns only real resource locations, where the resource exists.
42  *
43  * <p>
44  * Folders must be represented with a trailing slash.
45  *
46  * @author Howard Lewis Ship
47  * @since 3.0
48  *
49  **/

50
51 public interface IResourceLocation
52 {
53     /**
54      * Returns a URL for the resource.
55      *
56      * @return the URL for the resource if it exists, or null if it does not
57      *
58      **/

59     
60     public URL JavaDoc getResourceURL();
61     
62     /**
63      * Returns the file name portion of the resource location.
64      *
65      **/

66     
67     public String JavaDoc getName();
68     
69     /**
70      * Returns a localized version of this resource (or this resource, if no
71      * appropriate localization is found). Should only be invoked
72      * on a base resource.
73      *
74      * @param locale to localize for, or null for no localization.
75      * @return a localized version of this resource, of null if the resource
76      * itself does not exist.
77      *
78      **/

79     
80     public IResourceLocation getLocalization(Locale JavaDoc locale);
81     
82     /**
83      * Returns at a relative location to this resource.
84      * The new resource may or may not exist; this can be determined
85      * via {@link #getResourceURL()}.
86      *
87      * @param name name of new resource, possibly as a relative path, or
88      * as an absolute path (starting with a slash).
89      *
90      **/

91     
92     public IResourceLocation getRelativeLocation(String JavaDoc name);
93     
94     /**
95      * Returns the path that represents the resource. This should
96      * only be used when the type of resource is known.
97      *
98      **/

99     
100     public String JavaDoc getPath();
101
102     /**
103      * Returns the locale for which this resource has been localized
104      * or null if the resource has not been localized. This should
105      * only be used when the type of resource is known.
106      *
107      * This locale is the same or more general than the locale for which localization
108      * was requested. For example, if the requested locale was en_US, but only the file
109      * Home_en was found, this locale returned would be en.
110      **/

111     
112     public Locale JavaDoc getLocale();
113 }
114
Popular Tags