|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xml.internal.serializer; |
|
|
|
import java.util.Properties; |
|
import javax.xml.transform.OutputKeys; |
|
import jdk.xml.internal.SecuritySupport; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public final class OutputPropertiesFactory |
|
{ |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final String |
|
S_BUILTIN_EXTENSIONS_URL = "http://xml.apache.org/xalan"; |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final String |
|
S_BUILTIN_OLD_EXTENSIONS_URL = "http://xml.apache.org/xslt"; |
|
|
|
//************************************************************ |
|
//* PUBLIC CONSTANTS |
|
//************************************************************ |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String S_BUILTIN_EXTENSIONS_UNIVERSAL = |
|
"{" + S_BUILTIN_EXTENSIONS_URL + "}"; |
|
|
|
// Some special Xalan keys. |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String S_KEY_INDENT_AMOUNT = |
|
S_BUILTIN_EXTENSIONS_UNIVERSAL + "indent-amount"; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String S_KEY_LINE_SEPARATOR = |
|
S_BUILTIN_EXTENSIONS_UNIVERSAL + "line-separator"; |
|
|
|
/** This non-standard property key is used to set the name of the fully qualified |
|
* Java class that implements the ContentHandler interface. |
|
* Fully qualified name of class with a default constructor that |
|
* implements the ContentHandler interface, where the result tree events |
|
* will be sent to. |
|
*/ |
|
|
|
public static final String S_KEY_CONTENT_HANDLER = |
|
S_BUILTIN_EXTENSIONS_UNIVERSAL + "content-handler"; |
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String S_KEY_ENTITIES = |
|
S_BUILTIN_EXTENSIONS_UNIVERSAL + "entities"; |
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String S_USE_URL_ESCAPING = |
|
S_BUILTIN_EXTENSIONS_UNIVERSAL + "use-url-escaping"; |
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String S_OMIT_META_TAG = |
|
S_BUILTIN_EXTENSIONS_UNIVERSAL + "omit-meta-tag"; |
|
|
|
|
|
|
|
*/ |
|
public static final String S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL = |
|
"{" + S_BUILTIN_OLD_EXTENSIONS_URL + "}"; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final int S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL_LEN = |
|
S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL.length(); |
|
|
|
|
|
//************************************************************ |
|
//* PRIVATE CONSTANTS |
|
//************************************************************ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static final String[] PROP_XML = { |
|
"method", |
|
"version", |
|
"encoding", |
|
"indent", |
|
"omit-xml-declaration", |
|
"standalone", |
|
"media-type", |
|
"{http://xml.apache.org/xalan}indent-amount", |
|
"{http://xml.apache.org/xalan}content-handler", |
|
"{http://xml.apache.org/xalan}entities" |
|
}; |
|
|
|
private static final String[] PROP_XML_VALUE = { |
|
"xml", |
|
"1.0", |
|
"UTF-8", |
|
"no", |
|
"no", |
|
"no", |
|
"text/xml", |
|
"0", |
|
"com.sun.org.apache.xml.internal.serializer.ToXMLStream", |
|
"com/sun/org/apache/xml/internal/serializer/XMLEntities" |
|
}; |
|
|
|
private static final String[] PROP_HTML = { |
|
"method", |
|
"indent", |
|
"media-type", |
|
"version", |
|
"{http://xml.apache.org/xalan}indent-amount", |
|
"{http://xml.apache.org/xalan}content-handler", |
|
"{http://xml.apache.org/xalan}entities", |
|
"{http://xml.apache.org/xalan}use-url-escaping", |
|
"{http://xml.apache.org/xalan}omit-meta-tag" |
|
}; |
|
|
|
private static final String[] PROP_HTML_VALUE = { |
|
"html", |
|
"yes", |
|
"text/html", |
|
"4.0", |
|
"4", |
|
"com.sun.org.apache.xml.internal.serializer.ToHTMLStream", |
|
"com/sun/org/apache/xml/internal/serializer/HTMLEntities", |
|
"yes", |
|
"no" |
|
}; |
|
|
|
private static final String[] PROP_TEXT = { |
|
"method", |
|
"media-type", |
|
"{http://xml.apache.org/xalan}content-handler" |
|
}; |
|
|
|
private static final String[] PROP_TEXT_VALUE = { |
|
"text", |
|
"text/plain", |
|
"com.sun.org.apache.xml.internal.serializer.ToTextStream" |
|
}; |
|
|
|
private static final String[] PROP_UNKNOWN = { |
|
"method", |
|
"version", |
|
"encoding", |
|
"indent", |
|
"omit-xml-declaration", |
|
"standalone", |
|
"media-type", |
|
"{http://xml.apache.org/xalan}indent-amount", |
|
"{http://xml.apache.org/xalan}content-handler" |
|
}; |
|
|
|
private static final String[] PROP_UNKNOWN_VALUE = { |
|
"xml", |
|
"1.0", |
|
"UTF-8", |
|
"no", |
|
"no", |
|
"no", |
|
"text/xml", |
|
"0", |
|
"com.sun.org.apache.xml.internal.serializer.ToUnknownStream", |
|
}; |
|
|
|
//************************************************************ |
|
//* PRIVATE STATIC FIELDS |
|
//************************************************************ |
|
|
|
|
|
private static Properties m_xml_properties = null; |
|
|
|
|
|
private static Properties m_html_properties = null; |
|
|
|
|
|
private static Properties m_text_properties = null; |
|
|
|
|
|
private static Properties m_unknown_properties = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public final Properties getDefaultMethodProperties(String method) |
|
{ |
|
Properties defaultProperties = null; |
|
|
|
if (null == m_xml_properties) { |
|
m_xml_properties = initProperties(PROP_XML, PROP_XML_VALUE, null); |
|
} |
|
|
|
|
|
switch (method) { |
|
case Method.XML: |
|
defaultProperties = m_xml_properties; |
|
break; |
|
case Method.HTML: |
|
if (null == m_html_properties) { |
|
m_html_properties = initProperties( |
|
PROP_HTML, PROP_HTML_VALUE, m_xml_properties); |
|
} |
|
defaultProperties = m_html_properties; |
|
break; |
|
case Method.TEXT: |
|
if (null == m_text_properties) { |
|
m_text_properties = initProperties( |
|
PROP_TEXT, PROP_TEXT_VALUE, m_xml_properties); |
|
|
|
if (null == m_text_properties.getProperty(OutputKeys.ENCODING)) |
|
{ |
|
String mimeEncoding = Encodings.getMimeEncoding(null); |
|
m_text_properties.put(OutputKeys.ENCODING, mimeEncoding); |
|
} |
|
} |
|
defaultProperties = m_text_properties; |
|
break; |
|
case com.sun.org.apache.xml.internal.serializer.Method.UNKNOWN: |
|
if (null == m_unknown_properties) { |
|
m_unknown_properties = initProperties( |
|
PROP_UNKNOWN, PROP_UNKNOWN_VALUE, m_xml_properties); |
|
} |
|
defaultProperties = m_unknown_properties; |
|
break; |
|
default: |
|
defaultProperties = m_xml_properties; |
|
break; |
|
} |
|
|
|
// wrap these cached defaultProperties in a new Property object just so |
|
|
|
return new Properties(defaultProperties); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static private Properties initProperties(String[] keys, String[] values, Properties defaults) |
|
{ |
|
Properties props = new Properties(defaults); |
|
|
|
for (int i = 0; i < keys.length; i++) { |
|
|
|
String sys = SecuritySupport.getSystemProperty(keys[i]); |
|
props.put(keys[i], (sys == null) ? values[i] : sys); |
|
} |
|
|
|
return props; |
|
} |
|
} |