View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.shared.resource;
20  
21  import javax.faces.application.ResourceHandler;
22  import javax.faces.context.FacesContext;
23  
24  /**
25   * A utility class to isolate a ResourceHandler implementation from its
26   * underlying implementation
27   */
28  public abstract class ResourceHandlerSupport
29  {
30  
31      /**
32       * Calculate the resource base path.
33       * 
34       * It should extract a string like:
35       * 
36       * ResourceHandler.RESOURCE_IDENTIFIER + '/' + getResourceName()
37       * 
38       * For example:
39       * 
40       * /javax.faces.resource/image.jpg
41       * 
42       * This is used on ResourceHandler.handleResourceRequest()
43       * 
44       */
45      public abstract String calculateResourceBasePath(FacesContext facesContext);
46  
47      /**
48       * Return an array of resource loaders used to find resources.
49       * The order of ResourceLoaders define its precedence. 
50       * 
51       * @return
52       */
53      public abstract ResourceLoader[] getResourceLoaders();
54  
55      /**
56       * Return an array of resource loaders used to find resources 
57       * associated with a contract. The order of ContractResourceLoaders 
58       * define its precedence. 
59       * 
60       * @since 2.2
61       * @return 
62       */
63      public abstract ContractResourceLoader[] getContractResourceLoaders();
64  
65      /**
66       * Return an array of resource loaders used to find resources
67       * that can be located using ResourceHandler.createViewResource().
68       * The order of ResourceLoaders define its precedence. 
69       * 
70       * @since 2.2
71       * @return 
72       */
73      public abstract ResourceLoader[] getViewResourceLoaders();
74      
75      /**
76       * Check if the mapping used is done using extensions (.xhtml, .jsf)
77       * or if it is not (/faces/*)
78       * @return
79       */
80      public abstract boolean isExtensionMapping();
81      
82      /**
83       * Get the mapping used as prefix(/faces) or sufix(.jsf)
84       * 
85       * @return
86       */
87      public abstract String getMapping();
88      
89      /**
90       * Return the time when the app started. This is useful to set the
91       * "Last-Modified" header in some specific cases.
92       * 
93       * @return
94       */
95      public abstract long getStartupTime();
96      
97      /**
98       * Return the time that should be set on "Expires" header in a resource.
99       * 
100      * @return
101      */
102     public abstract long getMaxTimeExpires();
103     
104     public String getResourceIdentifier()
105     {
106         return ResourceHandler.RESOURCE_IDENTIFIER;
107     }
108 }