01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.jasper.xmlparser;
18:
19: import java.io.IOException;
20: import java.util.jar.JarFile;
21:
22: import org.apache.jasper.JasperException;
23: import org.apache.jasper.JspCompilationContext;
24: import org.apache.jasper.compiler.ErrorDispatcher;
25:
26: public class XMLEncodingDetector {
27:
28: /**
29: * Autodetects the encoding of the XML document supplied by the given
30: * input stream.
31: *
32: * Encoding autodetection is done according to the XML 1.0 specification,
33: * Appendix F.1: Detection Without External Encoding Information.
34: *
35: * @param err The error dispatcher
36: *
37: * @return Two-element array, where the first element (of type
38: * java.lang.String) contains the name of the autodetected encoding, and
39: * the second element (of type java.lang.Boolean) specifies whether the
40: * encoding was specified by the encoding attribute of an XML declaration
41: * (prolog).
42: */
43: public static Object[] getEncoding(String fname, JarFile jarFile,
44: JspCompilationContext ctxt, ErrorDispatcher err)
45: throws IOException, JasperException {
46: XMLEncodingDetector detector = null;
47: try {
48: Class.forName("org.apache.xerces.util.SymbolTable");
49: Class detectorClass = Class
50: .forName("org.apache.jasper.xmlparser.XercesEncodingDetector");
51: detector = (XMLEncodingDetector) detectorClass
52: .newInstance();
53: } catch (Exception ex) {
54: detector = new XMLEncodingDetector();
55: }
56: return detector.getEncodingMethod(fname, jarFile, ctxt, err);
57: }
58:
59: public Object[] getEncodingMethod(String fname, JarFile jarFile,
60: JspCompilationContext ctxt, ErrorDispatcher err)
61: throws IOException, JasperException {
62: Object result[] = new Object[] { "UTF8", new Boolean(false) };
63: return result;
64: }
65: }
|