01: package org.apache.velocity.runtime.directive;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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.context.InternalContextAdapter;
23: import org.apache.velocity.runtime.RuntimeConstants;
24: import org.apache.velocity.runtime.resource.Resource;
25:
26: /**
27: * Base class for directives which do input operations
28: * (e.g. <code>#include()</code>, <code>#parse()</code>, etc.).
29: *
30: * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
31: * @since 1.4
32: */
33: public abstract class InputBase extends Directive {
34: /**
35: * Decides the encoding used during input processing of this
36: * directive.
37: *
38: * Get the resource, and assume that we use the encoding of the
39: * current template the 'current resource' can be
40: * <code>null</code> if we are processing a stream....
41: *
42: * @param context The context to derive the default input encoding
43: * from.
44: * @return The encoding to use when processing this directive.
45: */
46: protected String getInputEncoding(InternalContextAdapter context) {
47: Resource current = context.getCurrentResource();
48: if (current != null) {
49: return current.getEncoding();
50: } else {
51: return (String) rsvc
52: .getProperty(RuntimeConstants.INPUT_ENCODING);
53: }
54: }
55: }
|