View Javadoc

1   package org.apache.velocity.runtime.resource;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import org.apache.velocity.runtime.RuntimeServices;
23  
24  import org.apache.velocity.exception.ResourceNotFoundException;
25  import org.apache.velocity.exception.ParseErrorException;
26  
27  /**
28   * Class to manage the text resource for the Velocity
29   * Runtime.
30   *
31   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
32   * @author <a href="mailto:paulo.gaspar@krankikom.de">Paulo Gaspar</a>
33   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
34   * @version $Id: ResourceManager.java 898050 2010-01-11 20:15:31Z nbubna $
35   */
36  public interface ResourceManager
37  {
38      /**
39       * A template resources.
40       */
41      public static final int RESOURCE_TEMPLATE = 1;
42  
43      /**
44       * A static content resource.
45       */
46      public static final int RESOURCE_CONTENT = 2;
47  
48      /**
49       * Initialize the ResourceManager.
50       * @param rs
51       */
52      public void initialize( RuntimeServices rs );
53  
54      /**
55       * Gets the named resource.  Returned class type corresponds to specified type
56       * (i.e. <code>Template</code> to <code>RESOURCE_TEMPLATE</code>).
57       *
58       * @param resourceName The name of the resource to retrieve.
59       * @param resourceType The type of resource (<code>RESOURCE_TEMPLATE</code>,
60       *                     <code>RESOURCE_CONTENT</code>, etc.).
61       * @param encoding  The character encoding to use.
62       * @return Resource with the template parsed and ready.
63       * @throws ResourceNotFoundException if template not found
64       *          from any available source.
65       * @throws ParseErrorException if template cannot be parsed due
66       *          to syntax (or other) error.
67       */
68      public Resource getResource(String resourceName, int resourceType, String encoding )
69          throws ResourceNotFoundException, ParseErrorException;
70  
71      /**
72       *  Determines is a template exists, and returns name of the loader that
73       *  provides it.  This is a slightly less hokey way to support
74       *  the Velocity.templateExists() utility method, which was broken
75       *  when per-template encoding was introduced.  We can revisit this.
76       *
77       *  @param resourceName Name of template or content resource
78       *  @return class name of loader than can provide it
79       */
80      public String getLoaderNameForResource(String resourceName );
81  
82  }
83  
84