From 8f3b7e2d6841c1e962e513fc1bcf41032289d9fe Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 30 Sep 2014 13:48:55 +0000 Subject: [PATCH] - removed old, not working FactoriesSetup class - Added own implementations of TransformerFactory etc which act as a wrapper for the configured implementations. At the moment this is only used for TransformerFactory because using it for SAXParserFactory and maybe for DocumentBuilderFactory causes crazy errors. - Moved the Reindexer utilitity from ccm-ldn-search to ccm-ldn-util. It is useful for rebuilding the index and has no dependencies to other parts of ccm-ldn-search. Also ccm-ldn-search will be removed in near future. git-svn-id: https://svn.libreccm.org/ccm/trunk@2894 8810af33-2d31-482b-a856-94f89814c4df --- .../src/com/arsdigita/core/Initializer.java | 3 - .../web/CCMApplicationContextListener.java | 4 - .../xml/CCMDocumentBuilderFactory.java | 93 +++++++++++ .../arsdigita/xml/CCMSAXParserFactory.java | 89 ++++++++++ .../arsdigita/xml/CCMTransformerFactory.java | 135 +++++++++++++++ .../src/com/arsdigita/xml/FactoriesSetup.java | 134 --------------- ccm-core/src/com/arsdigita/xml/XMLConfig.java | 154 ++++++------------ .../arsdigita/london/util/cmd/Reindexer.java | 114 +++++++++++++ ccm-sci-bundle/application.xml | 1 - 9 files changed, 484 insertions(+), 243 deletions(-) create mode 100644 ccm-core/src/com/arsdigita/xml/CCMDocumentBuilderFactory.java create mode 100644 ccm-core/src/com/arsdigita/xml/CCMSAXParserFactory.java create mode 100644 ccm-core/src/com/arsdigita/xml/CCMTransformerFactory.java delete mode 100755 ccm-core/src/com/arsdigita/xml/FactoriesSetup.java create mode 100755 ccm-ldn-util/src/com/arsdigita/london/util/cmd/Reindexer.java diff --git a/ccm-core/src/com/arsdigita/core/Initializer.java b/ccm-core/src/com/arsdigita/core/Initializer.java index b9bd1d6b3..a7525ade9 100755 --- a/ccm-core/src/com/arsdigita/core/Initializer.java +++ b/ccm-core/src/com/arsdigita/core/Initializer.java @@ -50,7 +50,6 @@ import com.arsdigita.web.ApplicationType; import com.arsdigita.web.Host; import com.arsdigita.webdevsupport.WebDevSupport; import com.arsdigita.workflow.simple.TaskComment; -import com.arsdigita.xml.FactoriesSetup; import org.apache.log4j.Logger; @@ -103,8 +102,6 @@ public class Initializer extends CompoundInitializer { s_log.debug("Running core init(DomainInitEvent) ..."); - FactoriesSetup.setupFactories(); - e.getFactory().registerInstantiator (Host.BASE_DATA_OBJECT_TYPE, new DomainObjectInstantiator() { diff --git a/ccm-core/src/com/arsdigita/web/CCMApplicationContextListener.java b/ccm-core/src/com/arsdigita/web/CCMApplicationContextListener.java index 818edb241..aad56f89d 100644 --- a/ccm-core/src/com/arsdigita/web/CCMApplicationContextListener.java +++ b/ccm-core/src/com/arsdigita/web/CCMApplicationContextListener.java @@ -23,7 +23,6 @@ import com.arsdigita.runtime.ContextCloseEvent; import com.arsdigita.runtime.ContextInitEvent; import com.arsdigita.runtime.Runtime; // import com.arsdigita.util.ResourceManager; -import com.arsdigita.xml.FactoriesSetup; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; @@ -114,9 +113,6 @@ public class CCMApplicationContextListener implements ServletContextListener { CCMResourceManager.setBaseDirectory(m_appBase); s_log.info("BaseDir set to: " + m_appBase); - // Setup the XML factory configuration - FactoriesSetup.setupFactories(); - // Central startup procedure, initialize the database and // domain coupling machinary // Runtime runtime = new Runtime(); diff --git a/ccm-core/src/com/arsdigita/xml/CCMDocumentBuilderFactory.java b/ccm-core/src/com/arsdigita/xml/CCMDocumentBuilderFactory.java new file mode 100644 index 000000000..458526c58 --- /dev/null +++ b/ccm-core/src/com/arsdigita/xml/CCMDocumentBuilderFactory.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2014 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.xml; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.apache.log4j.Logger; + +/** + * This class acts as a facade for the {@link DocumentBuilderFactory} implementation configured + * in {@link XMLConfig}. The current API in the Java Standard API does not allow to configure + * the implementation of {@link DocumentBuilderFactory} to use at runtime. + * Therefore we are setting this facade as implementation to + * use via {@code META-INF/services/javax.parsers.DocumentBuilderFactory}. This class + * uses {@link DocumentBuilderFactory#newInstance(java.lang.String, java.lang.ClassLoader)} to + * create an instance of the configured {@link DocumentBuilderFactory} implementation and delegates + * all calls to it. + * + * Note: For yet unknown reasons setting this class as DocumentBuilderFactory causes crazy errors. + * Has the be investigated. In the meantime this class is not used. + * + * @author Jens Pelzetter + */ +public class CCMDocumentBuilderFactory extends DocumentBuilderFactory { + + private static final Logger LOGGER = Logger.getLogger(CCMDocumentBuilderFactory.class); + private final DocumentBuilderFactory factory; + + public CCMDocumentBuilderFactory() { + super(); + + final XMLConfig config = XMLConfig.getConfig(); + final String classname = config.getDOMBuilderFactoryClassname(); + + if (classname == null || classname.isEmpty()) { + //To make this class errorprone we check for null and empty string. Normally this + //is not possible, but to be sure, we check the classname provided by XMLConfig and + //fallback to the default value if the string is null or empty. + LOGGER.warn("DOMBuilderFactory classname provided by XMLConfig is null or empty. " + + "This indicates a invalid configuration. Check your configuration! " + + "Falling back to default."); + factory = DocumentBuilderFactory.newInstance( + config.getDefaultDOMBuilderFactoryClassname(), null); + } else { + factory = DocumentBuilderFactory.newInstance(classname, null); + } + } + + @Override + public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + return factory.newDocumentBuilder(); + } + + @Override + public void setAttribute(final String name, + final Object value) throws IllegalArgumentException { + factory.setAttribute(name, value); + } + + @Override + public Object getAttribute(final String name) throws IllegalArgumentException { + return factory.getAttribute(name); + } + + @Override + public void setFeature(final String name, + final boolean value) throws ParserConfigurationException { + factory.setFeature(name, value); + } + + @Override + public boolean getFeature(final String name) throws ParserConfigurationException { + return factory.getFeature(name); + } + +} diff --git a/ccm-core/src/com/arsdigita/xml/CCMSAXParserFactory.java b/ccm-core/src/com/arsdigita/xml/CCMSAXParserFactory.java new file mode 100644 index 000000000..9b1c2941b --- /dev/null +++ b/ccm-core/src/com/arsdigita/xml/CCMSAXParserFactory.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.xml; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.apache.log4j.Logger; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; + +/** + * This class acts as a facade for the {@link SAXParserFactory} implementation configured + * in {@link XMLConfig}. The current API in the Java Standard API does not allow to configure + * the implementation of {@link SAXParserFactory} to use at runtime. + * Therefore we are setting this facade as implementation to + * use via {@code META-INF/services/javax.xml.transform.SAXParserFactory}. This class + * uses {@link SAXParserFactory#newInstance(java.lang.String, java.lang.ClassLoader)} to + * create an instance of the configured {@link SAXParserFactory} implementation and delegates + * all calls to it. + * + * Note: For yet unknown reasons setting this class as SAXBuilderFactory causes crazy errors. + * Has the be investigated. In the meantime this class is not used. + * + * @author Jens Pelzetter + */ +public class CCMSAXParserFactory extends SAXParserFactory { + + private static final Logger LOGGER = Logger.getLogger(CCMSAXParserFactory.class); + private final SAXParserFactory factory; + + public CCMSAXParserFactory() { + super(); + + final XMLConfig config = XMLConfig.getConfig(); + final String classname = config.getSAXParserFactoryClassname(); + + if (classname == null || classname.isEmpty()) { + //To make this class errorprone we check for null and empty string. Normally this + //is not possible, but to be sure, we check the classname provided by XMLConfig and + //fallback to the default value if the string is null or empty. + LOGGER.warn("SAXParserFactory classname provided by XMLConfig is null or empty. " + + "This indicates a invalid configuration. Check your configuration! " + + "Falling back to default."); + factory = SAXParserFactory.newInstance( + config.getDefaultSAXParserFactoryClassname(), null); + } else { + factory = SAXParserFactory.newInstance(classname, null); + } + } + + @Override + public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { + return factory.newSAXParser(); + } + + @Override + public void setFeature(final String name, final boolean value) + throws ParserConfigurationException, + SAXNotRecognizedException, + SAXNotSupportedException { + factory.setFeature(name, value); + } + + @Override + public boolean getFeature(final String name) throws ParserConfigurationException, + SAXNotRecognizedException, + SAXNotSupportedException { + return factory.getFeature(name); + } + +} diff --git a/ccm-core/src/com/arsdigita/xml/CCMTransformerFactory.java b/ccm-core/src/com/arsdigita/xml/CCMTransformerFactory.java new file mode 100644 index 000000000..50c7215a1 --- /dev/null +++ b/ccm-core/src/com/arsdigita/xml/CCMTransformerFactory.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2014 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.xml; + +import javax.xml.transform.ErrorListener; +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import org.apache.log4j.Logger; + +/** + * This class acts as a facade for the {@link TransformerFactory} implementation configured + * in {@link XMLConfig}. The current API in the Java Standard API does not allow to configure + * the implementation of {@link TransformerFactory} to use at runtime. + * Therefore we are setting this facade as implementation to + * use via {@code META-INF/services/javax.xml.transform.TransformerFactory}. This class + * uses {@link TransformerFactory#newInstance(java.lang.String, java.lang.ClassLoader)} to + * create an instance of the configured {@link TransformerFactory} implementation and delegates + * all calls to it. + * + * @author Jens Pelzetter + */ +public class CCMTransformerFactory extends TransformerFactory { + + private static final Logger LOGGER = Logger.getLogger(CCMTransformerFactory.class); + private final TransformerFactory factory; + + public CCMTransformerFactory() { + super(); + + //Get an XMLConfig instance + final XMLConfig config = XMLConfig.getConfig(); + //Get the classname + final String classname = config.getXSLTransformerFactoryClassname(); + + if (classname == null || classname.isEmpty()) { + //To make this class errorprone we check for null and empty string. Normally this + //is not possible, but to be sure, we check the classname provided by XMLConfig and + //fallback to the default value if the string is null or empty. + LOGGER.warn("XSLTransformerFactory classname provided by XMLConfig is null or empty. " + + "This indicates a invalid configuration. Check your configuration! " + + "Falling back to default."); + factory = TransformerFactory.newInstance( + config.getDefaultXSLTransformerFactoryClassname(), null); + } else { + factory = TransformerFactory.newInstance(classname, null); + } + } + + @Override + public Transformer newTransformer(final Source source) + throws TransformerConfigurationException { + return factory.newTransformer(source); + } + + @Override + public Transformer newTransformer() throws TransformerConfigurationException { + return factory.newTransformer(); + } + + @Override + public Templates newTemplates(final Source source) throws TransformerConfigurationException { + return factory.newTemplates(source); + } + + @Override + public Source getAssociatedStylesheet(final Source source, + final String media, + final String title, + final String charset) + throws TransformerConfigurationException { + return factory.getAssociatedStylesheet(source, media, title, charset); + } + + @Override + public void setURIResolver(final URIResolver resolver) { + factory.setURIResolver(resolver); + } + + @Override + public URIResolver getURIResolver() { + return factory.getURIResolver(); + } + + @Override + public void setFeature(final String name, + final boolean value) throws TransformerConfigurationException { + factory.setFeature(name, value); + } + + @Override + public boolean getFeature(final String name) { + return factory.getFeature(name); + } + + @Override + public void setAttribute(final String name, final Object value) { + factory.setAttribute(name, value); + } + + @Override + public Object getAttribute(final String name) { + return factory.getAttribute(name); + } + + @Override + public void setErrorListener(final ErrorListener listener) { + factory.setErrorListener(listener); + } + + @Override + public ErrorListener getErrorListener() { + return factory.getErrorListener(); + } + +} diff --git a/ccm-core/src/com/arsdigita/xml/FactoriesSetup.java b/ccm-core/src/com/arsdigita/xml/FactoriesSetup.java deleted file mode 100755 index de6c552f6..000000000 --- a/ccm-core/src/com/arsdigita/xml/FactoriesSetup.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.xml; - -import org.apache.log4j.Logger; - -/** - * Utility class to configure the FactoriesSetup parsers using Sun's javax.xml - * specified classes and methods (in the javax.xml..... packages) and should be - * invokes as early as possible in the CCM startup process. - * - * Parsers rsp. transformers are created using a factory class. There are 2 - * methods available: - * - * Static method newinstance() - * searches the configuration following 4 steps: - * 1. Use the javax.xml.parsers.[name]Factory system property - * 2. Use properties file "lib/jaxp.properties" in the JRE directory - * 3. Use the Services API, which will look in a file - * META-INF/services/javax.xml.parsers.[name]Factory - * in jars available to the runtime. - * 4. Platform default [name]Factory instance - * - * Static method newInstance(String factoryClassName, ClassLoader classLoader) - * Currently not used by CCM code. Refactoring requirred. - * C.f. - * http://www.docjar.com/html/api/javax/xml/parsers/DocumentBuilderFactory.java.html - * - * Previously CCM used to place the desired parser class names as runtime - * parameters (-D...) into the Tomcat startup script. This method requires a - * custom Tomcat configuration and constrains all other applications running in - * the servlet container to use the same configuration. - * - * The preferred method is the second option of newinstance, but - * requires to dig deeper into the CCM code. - * - * As an intermediate solution the implementation to use is stored in - * the configuration registry, read at startup and set as system.properties. - * - * Called once by c.ad.core.Initializer at startup and - * CCMApplicationContextListener. - * - * modified by - * @author pboy - */ - - -// ///////////////////////////////////////////////////////////////////////////// -// -// NOTE: The ServiceProviderInterface as implementet by the JaxP factory -// class newInstance() follow a specific search order as explained above. -// The META-INF directory MUST be found via ContextClasspathLoader, i.e. must -// be located in WEB-INF/classes/META-INF or in a jar-file at WEB-INF/lib (or -// in one of the locations searched by common class loader which is not useful) -// Therefore is is not possible to switch a factory implementation after -// deployment at runtime or webapp startup, because both locations are not meant -// to be changed after deployment of an application. -// The alternative instantiation using newInstance(ImplementationClass, -// LoaderClass) is no replacement, because developers may use newInstance() -// anyway and probably get an unintended implementation. -// -// Therefore we must engage a quick'nd dirty way to achieve the goal and mess -// around with the WEB-INF/classes directory, until a better solution will be -// available. -// -// ///////////////////////////////////////////////////////////////////////////// - - - -public class FactoriesSetup { - - private static final Logger s_log = Logger.getLogger - (FactoriesSetup.class); - - /* ************ public getter / setter section ************ */ - - /** - * Actually configures the factory classes to use. It calls an internal - * method which modifies the system.property. - */ - public static void setupFactories() { - // setupFactory("javax.xml.parsers.DocumentBuilderFactory", - // XMLConfig.getConfig().getDOMBuilderFactoryClassname()); - // setupFactory("javax.xml.parsers.SAXParserFactory", - // XMLConfig.getConfig().getSAXParserFactoryClassname()); - // setupFactory("javax.xml.transform.TransformerFactory", - // XMLConfig.getConfig().getXSLTransformerFactoryClassname()); - } - - /* ************ internal worker methods section ************ */ - - /** - * Actually configures the factories to use by setting the system.properties - * - * ToDo: Use an alternative Factory constructor of javax.xml. ... (e.g. - * DocumentBuilderFactory) which directly accepts a classname and a - * class loader, so we do not depend on a system wide configuration. - * - * @param name the system property name to set according to the javax.xml spec. - * @param impl the value of the class name of the factory to use - */ - static void setupFactory(String name, - String impl) { - if (impl != null) { - if (s_log.isInfoEnabled()) { - s_log.info("Setting " + name + " to " + impl); - } - // System.setProperty(name, - // impl); - } else { - if (s_log.isInfoEnabled()) { - s_log.info("Leaving " + name + " as " + - System.getProperty(name)); - } - } - } - -} diff --git a/ccm-core/src/com/arsdigita/xml/XMLConfig.java b/ccm-core/src/com/arsdigita/xml/XMLConfig.java index f7f2c63d3..d633796e0 100755 --- a/ccm-core/src/com/arsdigita/xml/XMLConfig.java +++ b/ccm-core/src/com/arsdigita/xml/XMLConfig.java @@ -24,7 +24,6 @@ import com.arsdigita.util.parameter.BooleanParameter; import com.arsdigita.util.parameter.StringParameter; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.TransformerFactory; import org.apache.log4j.Logger; @@ -66,45 +65,36 @@ public final class XMLConfig extends AbstractConfig { } // supported XSL transformer implementations - private static final String RESIN - = "com.caucho.xsl.Xsl"; - private static final String SAXON - = "com.icl.saxon.TransformerFactoryImpl"; - private static final String SAXON_HE - = "net.sf.saxon.TransformerFactoryImpl"; - private static final String XALAN - = "org.apache.xalan.processor.TransformerFactoryImpl"; - private static final String XSLTC - = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; + private static final String RESIN = "com.caucho.xsl.Xsl"; + private static final String SAXON = "com.icl.saxon.TransformerFactoryImpl"; + private static final String SAXON_HE = "net.sf.saxon.TransformerFactoryImpl"; + private static final String XALAN = "org.apache.xalan.processor.TransformerFactoryImpl"; + private static final String XSLTC = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; // supported documentBuilder implementations - private static final String DOM_XERCES - = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; - private static final String DOM_RESIN - = "com.caucho.xml.parsers.XmlDocumentBuilderFactory"; + private static final String DOM_XERCES = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; + private static final String DOM_RESIN = "com.caucho.xml.parsers.XmlDocumentBuilderFactory"; // supported SAX parser implementations - private static final String SAX_XERCES - = "org.apache.xerces.jaxp.SAXParserFactoryImpl"; - private static final String SAX_RESIN - = "com.caucho.xml.parsers.XmlSAXParserFactory"; + private static final String SAX_XERCES = "org.apache.xerces.jaxp.SAXParserFactoryImpl"; + private static final String SAX_RESIN = "com.caucho.xml.parsers.XmlSAXParserFactory"; private final Parameter m_xfmr = new StringParameter( - "waf.xml.xsl_transformer", - Parameter.REQUIRED, "saxon"); + "waf.xml.xsl_transformer", + Parameter.REQUIRED, "saxon"); private final Parameter m_builder = new StringParameter( - "waf.xml.dom_builder", - Parameter.REQUIRED, "xerces"); + "waf.xml.dom_builder", + Parameter.REQUIRED, "xerces"); private final Parameter m_parser = new StringParameter( - "waf.xml.sax_parser", - Parameter.REQUIRED, "xerces"); + "waf.xml.sax_parser", + Parameter.REQUIRED, "xerces"); private final Parameter m_activateFullTimeFormatter = new BooleanParameter( - "waf.xml.activate_full_date_formatter", - Parameter.OPTIONAL, false); + "waf.xml.activate_full_date_formatter", + Parameter.OPTIONAL, false); /** - * Constructs an empty XMLConfig object following the singelton pattern. + * Constructs an empty XMLConfig object following the singleton pattern. * * They are meant as a singleton pattern (with private constructor), but it does not work with * the associated classes AbstractConfig and ConfigRegistry because they can currently not deal @@ -133,7 +123,7 @@ public final class XMLConfig extends AbstractConfig { */ public String getXSLTransformerFactoryClassname() { - String key = (String) get(m_xfmr); + final String key = (String) get(m_xfmr); // Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc if (key.equalsIgnoreCase("xsltc")) { @@ -146,88 +136,60 @@ public final class XMLConfig extends AbstractConfig { return SAXON_HE; } else { // return defaultValue - return SAXON; + return getDefaultXSLTransformerFactoryClassname(); } } - + /** - * Returns a new XSL Transformer factory using the configured class. - * - * 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 + * Returns the class name of the default {@link TransformerFactory}. This method encapsulates + * the default value so that is easy to change. The method is only for use by the + * classes in the {@code com.arsdigita.xml} package, therefore the method is {@code protected}. + * + * @return */ - public TransformerFactory newXSLTransformerFactoryInstance() { - - // Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc - // returns full qualified classname - final String classname = getXSLTransformerFactoryClassname(); - - if (classname == null || classname.isEmpty()) { - //return plattform default - s_log. - warn("XSLTransformerFactory classname is null or empty. Check your configuration."); - return TransformerFactory.newInstance(); - } else { - // return configured class - return TransformerFactory.newInstance(classname, null); - } + protected String getDefaultXSLTransformerFactoryClassname() { + return SAXON; } /** * Returns the Document Builder factory class name to use * * The method assures that the return value is a valid class name. + * + * Not used at the moment. * * @return String Document Builder factory class name */ public String getDOMBuilderFactoryClassname() { - String key = (String) get(m_builder); + final String key = (String) get(m_builder); // Defined values: xerces (default)|resin if (key.equalsIgnoreCase("resin")) { return DOM_RESIN; } else { - return DOM_XERCES; + return getDefaultDOMBuilderFactoryClassname(); } } - + /** - * 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 + * Returns the class name of the default {@link DocumentBuilderFactory}. + * This method encapsulates the default value so that is easy to change. The method is only for + * use by the classes in the {@code com.arsdigita.xml} package, therefore the method is + * {@code protected}. + * + * @return */ - 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); - } - + protected String getDefaultDOMBuilderFactoryClassname() { + return DOM_XERCES; } /** * Returns the Sax Parser factory class name to use. * * The method assures that the return value is a valid class name. + * + * Not used at the moment. * * @return String Sax Parser factory class name */ @@ -239,31 +201,20 @@ public final class XMLConfig extends AbstractConfig { if (key.equalsIgnoreCase("resin")) { return SAX_RESIN; } else { - return SAX_XERCES; + return getDefaultSAXParserFactoryClassname(); } } /** - * 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 + * Returns the class name of the default {@link SAXParserFactory}. + * This method encapsulates the default value so that is easy to change. The method is only for + * use by the classes in the {@code com.arsdigita.xml} package, therefore the method is + * {@code protected}. + * + * @return */ - 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); - } - + protected String getDefaultSAXParserFactoryClassname() { + return SAX_XERCES; } /** @@ -283,4 +234,5 @@ public final class XMLConfig extends AbstractConfig { public void setActivateFullTimeFormatter(final boolean activateFullTimeFormatter) { set(m_activateFullTimeFormatter, activateFullTimeFormatter); } + } diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/Reindexer.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/Reindexer.java new file mode 100755 index 000000000..c4aa99e43 --- /dev/null +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/Reindexer.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package com.arsdigita.london.util.cmd; + +import com.arsdigita.domain.DomainObject; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.util.cmd.Program; +import com.arsdigita.london.util.Transaction; + +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.OID; + +import com.arsdigita.cms.ContentPage; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; + +import org.apache.log4j.Logger; + +import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; + + +public class Reindexer extends Program { + private static final Logger s_log = Logger.getLogger( Reindexer.class ); + + public Reindexer() { + super("Reindexer", + "1.0.0", + ""); + + getOptions().addOption + (OptionBuilder + .hasArg(true) + .withLongOpt("object-type") + .withDescription("Restrict to objects a type") + .create('t')); + getOptions().addOption + (OptionBuilder + .hasArg(true) + .withLongOpt("filter-query") + .withDescription("Name of a query for filtering objects") + .create('f')); + getOptions().addOption + (OptionBuilder + .hasArg(false) + .withLongOpt("ignore-errors") + .withDescription("Ignore any errors") + .create('i')); + } + + public void doRun(CommandLine cmdLine) { + final boolean ignoreErrors = cmdLine.hasOption("i"); + String baseType = cmdLine.getOptionValue("t"); + if (baseType == null) { + baseType = ContentPage.BASE_DATA_OBJECT_TYPE; + } + + String filter = cmdLine.getOptionValue("f"); + DataCollection objects = SessionManager.getSession().retrieve(baseType); + if (filter != null) { + objects.addInSubqueryFilter("id", filter); + } + + List toProcess = new ArrayList(); + while (objects.next()) { + toProcess.add(objects.getDataObject().getOID()); + } + + Iterator it = toProcess.iterator(); + int i = 1; + while (it.hasNext()) { + final OID oid = (OID)it.next(); + + s_log.info("Processing " + i++ + " of " + toProcess.size() + " " + oid); + Transaction txn = new Transaction() { + public void doRun() { + DomainObject obj = DomainObjectFactory.newInstance(oid); + obj.save(); + } + }; + try { + txn.run(); + } catch (Throwable ex) { + s_log.error("Cannot reindex " + oid, ex); + if (!ignoreErrors) { + return; + } + } + } + } + + public static void main(String[] args) { + new Reindexer().run(args); + } +} diff --git a/ccm-sci-bundle/application.xml b/ccm-sci-bundle/application.xml index c0d929103..df716437e 100644 --- a/ccm-sci-bundle/application.xml +++ b/ccm-sci-bundle/application.xml @@ -11,7 +11,6 @@ -