1 | package org.apache.velocity.runtime.directive; |
2 | |
3 | /* |
4 | * Copyright 2000-2001,2004 The Apache Software Foundation. |
5 | * |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * 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, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | */ |
18 | |
19 | import org.apache.velocity.context.InternalContextAdapter; |
20 | import org.apache.velocity.runtime.RuntimeConstants; |
21 | import org.apache.velocity.runtime.resource.Resource; |
22 | |
23 | /** |
24 | * Base class for directives which do input operations |
25 | * (e.g. <code>#include()</code>, <code>#parse()</code>, etc.). |
26 | * |
27 | * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> |
28 | * @since 1.4 |
29 | */ |
30 | public abstract class InputBase extends Directive |
31 | { |
32 | /** |
33 | * Decides the encoding used during input processing of this |
34 | * directive. |
35 | * |
36 | * Get the resource, and assume that we use the encoding of the |
37 | * current template the 'current resource' can be |
38 | * <code>null</code> if we are processing a stream.... |
39 | * |
40 | * @param context The context to derive the default input encoding |
41 | * from. |
42 | * @return The encoding to use when processing this directive. |
43 | */ |
44 | protected String getInputEncoding(InternalContextAdapter context) |
45 | { |
46 | Resource current = context.getCurrentResource(); |
47 | if (current != null) |
48 | { |
49 | return current.getEncoding(); |
50 | } |
51 | else |
52 | { |
53 | return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING); |
54 | } |
55 | } |
56 | } |