Added methods for creating instances of TransformerFactory, DocumentBuilder and SAXParser using the newInstance(String classname, ClassLoader loader) methods of these classes.
git-svn-id: https://svn.libreccm.org/ccm/trunk@2892 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
64b928f46e
commit
19e8d52464
|
|
@ -22,6 +22,8 @@ import com.arsdigita.runtime.AbstractConfig;
|
||||||
import com.arsdigita.util.parameter.Parameter;
|
import com.arsdigita.util.parameter.Parameter;
|
||||||
import com.arsdigita.util.parameter.BooleanParameter;
|
import com.arsdigita.util.parameter.BooleanParameter;
|
||||||
import com.arsdigita.util.parameter.StringParameter;
|
import com.arsdigita.util.parameter.StringParameter;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
@ -29,22 +31,23 @@ import org.apache.log4j.Logger;
|
||||||
/**
|
/**
|
||||||
* Stores the configuration record for the XML functionality.
|
* Stores the configuration record for the XML functionality.
|
||||||
*
|
*
|
||||||
* Most important: Configuration of the XML factories:
|
* Most important: Configuration of the XML factories: - Document Builder - Sax Parser - XSL
|
||||||
* - Document Builder
|
* Transformer
|
||||||
* - Sax Parser
|
|
||||||
* - XSL Transformer
|
|
||||||
*
|
*
|
||||||
* @version $Id: XMLConfig.java 1393 2006-11-28 09:12:32Z sskracic $
|
* @version $Id: XMLConfig.java 1393 2006-11-28 09:12:32Z sskracic $
|
||||||
*/
|
*/
|
||||||
public final class XMLConfig extends AbstractConfig {
|
public final class XMLConfig extends AbstractConfig {
|
||||||
|
|
||||||
/** Internal logger instance to faciliate debugging. Enable logging output
|
/**
|
||||||
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
|
* Internal logger instance to faciliate debugging. Enable logging output by editing
|
||||||
* and set com.arsdigita.xml.XMLConfig=DEBUG by uncommenting
|
* /WEB-INF/conf/log4j.properties int hte runtime environment and set
|
||||||
* or adding the line. */
|
* com.arsdigita.xml.XMLConfig=DEBUG by uncommenting or adding the line.
|
||||||
|
*/
|
||||||
private static final Logger s_log = Logger.getLogger(XMLConfig.class);
|
private static final Logger s_log = Logger.getLogger(XMLConfig.class);
|
||||||
|
|
||||||
/** Private instance of this class to be returned after initialization. */
|
/**
|
||||||
|
* Private instance of this class to be returned after initialization.
|
||||||
|
*/
|
||||||
private static XMLConfig s_config;
|
private static XMLConfig s_config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -62,31 +65,29 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
return s_config;
|
return s_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// supported XSL transformer implementations
|
// supported XSL transformer implementations
|
||||||
private static final String RESIN =
|
private static final String RESIN
|
||||||
"com.caucho.xsl.Xsl";
|
= "com.caucho.xsl.Xsl";
|
||||||
private static final String SAXON =
|
private static final String SAXON
|
||||||
"com.icl.saxon.TransformerFactoryImpl";
|
= "com.icl.saxon.TransformerFactoryImpl";
|
||||||
private static final String SAXON_HE =
|
private static final String SAXON_HE
|
||||||
"net.sf.saxon.TransformerFactoryImpl";
|
= "net.sf.saxon.TransformerFactoryImpl";
|
||||||
private static final String XALAN =
|
private static final String XALAN
|
||||||
"org.apache.xalan.processor.TransformerFactoryImpl";
|
= "org.apache.xalan.processor.TransformerFactoryImpl";
|
||||||
private static final String XSLTC =
|
private static final String XSLTC
|
||||||
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
|
= "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
|
||||||
|
|
||||||
// supported documentBuilder implementations
|
// supported documentBuilder implementations
|
||||||
private static final String DOM_XERCES =
|
private static final String DOM_XERCES
|
||||||
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl";
|
= "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl";
|
||||||
private static final String DOM_RESIN =
|
private static final String DOM_RESIN
|
||||||
"com.caucho.xml.parsers.XmlDocumentBuilderFactory";
|
= "com.caucho.xml.parsers.XmlDocumentBuilderFactory";
|
||||||
|
|
||||||
// supported SAX parser implementations
|
// supported SAX parser implementations
|
||||||
private static final String SAX_XERCES =
|
private static final String SAX_XERCES
|
||||||
"org.apache.xerces.jaxp.SAXParserFactoryImpl";
|
= "org.apache.xerces.jaxp.SAXParserFactoryImpl";
|
||||||
private static final String SAX_RESIN =
|
private static final String SAX_RESIN
|
||||||
"com.caucho.xml.parsers.XmlSAXParserFactory";
|
= "com.caucho.xml.parsers.XmlSAXParserFactory";
|
||||||
|
|
||||||
|
|
||||||
private final Parameter m_xfmr = new StringParameter(
|
private final Parameter m_xfmr = new StringParameter(
|
||||||
"waf.xml.xsl_transformer",
|
"waf.xml.xsl_transformer",
|
||||||
|
|
@ -105,13 +106,15 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
/**
|
/**
|
||||||
* Constructs an empty XMLConfig object following the singelton pattern.
|
* Constructs an empty XMLConfig object following the singelton pattern.
|
||||||
*
|
*
|
||||||
* They are meant as a singelton pattern (with private constructor), but
|
* They are meant as a singleton pattern (with private constructor), but it does not work with
|
||||||
* it does not work with the associated classes AbstractConfig and
|
* the associated classes AbstractConfig and ConfigRegistry because they can currently not deal
|
||||||
* ConfigRegistry because they can currently not deal with a private constructor
|
* with a private constructor
|
||||||
*/
|
*/
|
||||||
// private XMLConfig() {
|
// private XMLConfig() {
|
||||||
public XMLConfig() {
|
public XMLConfig() {
|
||||||
|
|
||||||
|
super();
|
||||||
|
|
||||||
register(m_xfmr);
|
register(m_xfmr);
|
||||||
register(m_builder);
|
register(m_builder);
|
||||||
register(m_parser);
|
register(m_parser);
|
||||||
|
|
@ -121,7 +124,6 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************ public getter / setter section ************ */
|
/* ************ public getter / setter section ************ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the XSL Transformer factory class name to use.
|
* Returns the XSL Transformer factory class name to use.
|
||||||
*
|
*
|
||||||
|
|
@ -129,18 +131,18 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
*
|
*
|
||||||
* @return String XSL Transformer factory class name
|
* @return String XSL Transformer factory class name
|
||||||
*/
|
*/
|
||||||
public final String getXSLTransformerFactoryClassname() {
|
public String getXSLTransformerFactoryClassname() {
|
||||||
|
|
||||||
String m_key = (String) get(m_xfmr);
|
String key = (String) get(m_xfmr);
|
||||||
|
|
||||||
// Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc
|
// Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc
|
||||||
if (m_key.toLowerCase().equals("xsltc")) {
|
if (key.equalsIgnoreCase("xsltc")) {
|
||||||
return XSLTC;
|
return XSLTC;
|
||||||
} else if (m_key.toLowerCase().equals("xalan")) {
|
} else if (key.equalsIgnoreCase("xalan")) {
|
||||||
return XALAN;
|
return XALAN;
|
||||||
} else if (m_key.toLowerCase().equals("resin")) {
|
} else if (key.equalsIgnoreCase("resin")) {
|
||||||
return RESIN;
|
return RESIN;
|
||||||
} else if (m_key.toLowerCase().equals("saxonhe")) {
|
} else if (key.equalsIgnoreCase("saxonhe")) {
|
||||||
return SAXON_HE;
|
return SAXON_HE;
|
||||||
} else {
|
} else {
|
||||||
// return defaultValue
|
// return defaultValue
|
||||||
|
|
@ -149,27 +151,30 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the XSL Transformer factory class name to use.
|
* Returns a new XSL Transformer factory using the configured class.
|
||||||
*
|
*
|
||||||
* The method assures that the return value is a valid class name.
|
* If the class name returned by {@link #getXSLTransformerFactoryClassname()} is {@code null} or
|
||||||
|
* empty {@link TransformerFactory#newInstance()} is used, otherwise
|
||||||
|
* {@link TransformerFactory#newInstance(java.lang.String, java.lang.ClassLoader)} to return the
|
||||||
|
* configured TransformerFactory
|
||||||
*
|
*
|
||||||
* @return String XSL Transformer factory class name
|
* @return String XSL Transformer factory class name
|
||||||
*/
|
*/
|
||||||
public final TransformerFactory getnewXSLTransformerFactoryInstance() {
|
public TransformerFactory newXSLTransformerFactoryInstance() {
|
||||||
|
|
||||||
// Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc
|
// Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc
|
||||||
// returns full qualified classname
|
// returns full qualified classname
|
||||||
String classname = getXSLTransformerFactoryClassname();
|
final String classname = getXSLTransformerFactoryClassname();
|
||||||
|
|
||||||
if (classname.isEmpty()) {
|
if (classname == null || classname.isEmpty()) {
|
||||||
//return plattform default
|
//return plattform default
|
||||||
|
s_log.
|
||||||
|
warn("XSLTransformerFactory classname is null or empty. Check your configuration.");
|
||||||
return TransformerFactory.newInstance();
|
return TransformerFactory.newInstance();
|
||||||
} else {
|
} else {
|
||||||
// return configured class
|
// return configured class
|
||||||
return TransformerFactory.newInstance( classname,
|
return TransformerFactory.newInstance(classname, null);
|
||||||
null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -179,18 +184,46 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
*
|
*
|
||||||
* @return String Document Builder factory class name
|
* @return String Document Builder factory class name
|
||||||
*/
|
*/
|
||||||
public final String getDOMBuilderFactoryClassname() {
|
public String getDOMBuilderFactoryClassname() {
|
||||||
|
|
||||||
String m_key = (String) get(m_builder);
|
String key = (String) get(m_builder);
|
||||||
|
|
||||||
// Defined values: xerces (default)|resin
|
// Defined values: xerces (default)|resin
|
||||||
if (m_key.toLowerCase().equals("resin")) {
|
if (key.equalsIgnoreCase("resin")) {
|
||||||
return DOM_RESIN;
|
return DOM_RESIN;
|
||||||
} else {
|
} else {
|
||||||
return DOM_XERCES;
|
return DOM_XERCES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new DocumentBuilder factory using the configured class.
|
||||||
|
*
|
||||||
|
* If the class name returned by {@link #getDOMBuilderFactoryClassname() ()} is {@code null} or
|
||||||
|
* empty {@link DocumentBuilderFactory#newInstance()} is used, otherwise
|
||||||
|
* {@link DocumentBuilderFactory#newInstance(java.lang.String, java.lang.ClassLoader)} to return
|
||||||
|
* the configured TransformerFactory
|
||||||
|
*
|
||||||
|
* @return String XSL Transformer factory class name
|
||||||
|
*/
|
||||||
|
public DocumentBuilderFactory newDocumentBuilderFactoryInstance() {
|
||||||
|
|
||||||
|
// Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc
|
||||||
|
// returns full qualified classname
|
||||||
|
final String classname = getDOMBuilderFactoryClassname();
|
||||||
|
|
||||||
|
if (classname == null || classname.isEmpty()) {
|
||||||
|
//return plattform default
|
||||||
|
s_log.warn(
|
||||||
|
"DocumentBuilderFactory classname is null or empty. Check your configuration.");
|
||||||
|
return DocumentBuilderFactory.newInstance();
|
||||||
|
} else {
|
||||||
|
// return configured class
|
||||||
|
return DocumentBuilderFactory.newInstance(classname, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Sax Parser factory class name to use.
|
* Returns the Sax Parser factory class name to use.
|
||||||
*
|
*
|
||||||
|
|
@ -198,32 +231,56 @@ public final class XMLConfig extends AbstractConfig {
|
||||||
*
|
*
|
||||||
* @return String Sax Parser factory class name
|
* @return String Sax Parser factory class name
|
||||||
*/
|
*/
|
||||||
public final String getSAXParserFactoryClassname() {
|
public String getSAXParserFactoryClassname() {
|
||||||
|
|
||||||
String m_key = (String) get(m_parser);
|
final String key = (String) get(m_parser);
|
||||||
|
|
||||||
// Defined values: xerces (default)|resin
|
// Defined values: xerces (default)|resin
|
||||||
if (m_key.toLowerCase().equals("resin")) {
|
if (key.equalsIgnoreCase("resin")) {
|
||||||
return SAX_RESIN;
|
return SAX_RESIN;
|
||||||
} else {
|
} else {
|
||||||
return SAX_XERCES;
|
return SAX_XERCES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new SAXParser factory using the configured class.
|
||||||
|
*
|
||||||
|
* If the class name returned by {@link #getSAXParserFactoryClassname() ()} is {@code null} or
|
||||||
|
* empty {@link SAXParserFactory#newInstance()} is used, otherwise
|
||||||
|
* {@link SAXParserFactory#newInstance(java.lang.String, java.lang.ClassLoader)} to return the
|
||||||
|
* configured TransformerFactory
|
||||||
|
*
|
||||||
|
* @return String XSL Transformer factory class name
|
||||||
|
*/
|
||||||
|
public SAXParserFactory newSAXParserFactoryInstance() {
|
||||||
|
|
||||||
|
final String classname = getSAXParserFactoryClassname();
|
||||||
|
|
||||||
|
if (classname == null || classname.isEmpty()) {
|
||||||
|
s_log.warn("SAXParserFactory classname is null or empty. Check your configuration.");
|
||||||
|
return SAXParserFactory.newInstance();
|
||||||
|
} else {
|
||||||
|
return SAXParserFactory.newInstance(classname, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the activateFullTimeFormatter flag.
|
* Returns the activateFullTimeFormatter flag.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean getActivateFullTimeFormatter() {
|
public boolean getActivateFullTimeFormatter() {
|
||||||
return ((Boolean) get(m_activateFullTimeFormatter)).booleanValue();
|
return (Boolean) get(m_activateFullTimeFormatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the activateFullTimeFormatter flag.
|
* Sets the activateFullTimeFormatter flag.
|
||||||
|
*
|
||||||
* @param activateFullTimeFormatter
|
* @param activateFullTimeFormatter
|
||||||
*/
|
*/
|
||||||
public void setActivateFullTimeFormatter(boolean activateFullTimeFormatter) {
|
public void setActivateFullTimeFormatter(final boolean activateFullTimeFormatter) {
|
||||||
set(m_activateFullTimeFormatter, new Boolean(activateFullTimeFormatter));
|
set(m_activateFullTimeFormatter, activateFullTimeFormatter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue