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.component.html.util;
20  
21  import javax.faces.context.FacesContext;
22  
23  import org.apache.myfaces.renderkit.html.util.ResourceHandler;
24  
25  /**
26   * Class whose instances represent a virtual resource which will be collected by
27   * the StreamingResourceHandler.
28   * 
29   * @author Mario Ivankovits
30   */
31  public class StreamingResourceHandler implements ResourceHandler
32  {
33      private final String _resource;
34  
35      /**
36       * Constructor.
37       * 
38       * @param resourceName is the name of a file that can be found in dir
39       *  "resource/{resourceName} relative to the location of the specified
40       *  component class in the classpath.
41       */
42      public StreamingResourceHandler(String resourceName)
43      {
44          _resource = resourceName;
45      }
46      
47      /**
48       * Return a Class object which can decode the url generated by this
49       * class in the getResourceUri method and use that info to locate
50       * the resource data represented by this object.
51       * 
52       * @see org.apache.myfaces.shared.renderkit.html.util.ResourceHandler#getResourceLoaderClass()
53       */
54      public Class getResourceLoaderClass()
55      {
56          return StreamingResourceLoader.class;
57      }
58  
59      /**
60       * Return a URL that the browser can later submit to retrieve the resource
61       * handled by this instance.
62       * <p>
63       * The emitted URL is of form:
64       * <pre>
65       *   {partial.class.name}/{resourceName}
66       * </pre>
67       * where partial.class.name is the name of the base class specified in the
68       * constructor, and resourceName is the resource specified in the constructor.
69       * 
70       * @see org.apache.myfaces.shared.renderkit.html.util.ResourceHandler#getResourceUri(javax.faces.context.FacesContext)
71       */
72      public String getResourceUri(FacesContext context)
73      {
74          return _resource;
75      }
76  }