1 package org.apache.velocity.runtime.directive;
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.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 /**
36 * Decides the encoding used during input processing of this
37 * directive.
38 *
39 * Get the resource, and assume that we use the encoding of the
40 * current template the 'current resource' can be
41 * <code>null</code> if we are processing a stream....
42 *
43 * @param context The context to derive the default input encoding
44 * from.
45 * @return The encoding to use when processing this directive.
46 */
47 protected String getInputEncoding(InternalContextAdapter context)
48 {
49 Resource current = context.getCurrentResource();
50 if (current != null)
51 {
52 return current.getEncoding();
53 }
54 else
55 {
56 return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
57 }
58 }
59 }