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 463298 2006-10-12 16:10:32Z henning $
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 * @throws Exception
52 */
53 public void initialize( RuntimeServices rs ) throws Exception;
54
55 /**
56 * Gets the named resource. Returned class type corresponds to specified type
57 * (i.e. <code>Template</code> to <code>RESOURCE_TEMPLATE</code>).
58 *
59 * @param resourceName The name of the resource to retrieve.
60 * @param resourceType The type of resource (<code>RESOURCE_TEMPLATE</code>,
61 * <code>RESOURCE_CONTENT</code>, etc.).
62 * @param encoding The character encoding to use.
63 * @return Resource with the template parsed and ready.
64 * @throws ResourceNotFoundException if template not found
65 * from any available source.
66 * @throws ParseErrorException if template cannot be parsed due
67 * to syntax (or other) error.
68 * @throws Exception if a problem in parse
69 */
70 public Resource getResource(String resourceName, int resourceType, String encoding )
71 throws ResourceNotFoundException, ParseErrorException, Exception;
72
73 /**
74 * Determines is a template exists, and returns name of the loader that
75 * provides it. This is a slightly less hokey way to support
76 * the Velocity.templateExists() utility method, which was broken
77 * when per-template encoding was introduced. We can revisit this.
78 *
79 * @param resourceName Name of template or content resource
80 * @return class name of loader than can provide it
81 */
82 public String getLoaderNameForResource(String resourceName );
83
84 }
85
86