- 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
master
jensp 2014-09-30 13:48:55 +00:00
parent 4d3aa1fca9
commit 8f3b7e2d68
9 changed files with 484 additions and 243 deletions

View File

@ -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() {

View File

@ -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();

View File

@ -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 <jens@jp-digital.de>
*/
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);
}
}

View File

@ -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 <jens@jp-digital.de>
*/
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);
}
}

View File

@ -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 <jens@jp-digital.de>
*/
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();
}
}

View File

@ -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 <code>javax.xml.parsers.[name]Factory</code> system property
* 2. Use properties file "lib/jaxp.properties" in the JRE directory
* 3. Use the Services API, which will look in a file
* <code>META-INF/services/javax.xml.parsers.[name]Factory</code>
* in jars available to the runtime.
* 4. Platform default <code>[name]Factory</code> 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 <code>newinstance</code>, but
* requires to dig deeper into the CCM code.
*
* As an <em>intermediate</em> 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));
}
}
}
}

View File

@ -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,35 +136,19 @@ 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.
* 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}.
*
* 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
*/
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;
}
/**
@ -182,46 +156,32 @@ public final class XMLConfig extends AbstractConfig {
*
* 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.
* 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}.
*
* 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
* @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;
}
/**
@ -229,6 +189,8 @@ public final class XMLConfig extends AbstractConfig {
*
* The method assures that the return value is a valid class name.
*
* Not used at the moment.
*
* @return String Sax Parser factory class name
*/
public String getSAXParserFactoryClassname() {
@ -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.
* 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}.
*
* 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
* @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);
}
}

View File

@ -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);
}
}

View File

@ -11,7 +11,6 @@
<ccm:requires name="ccm-navigation" version="6.6.0" relation="ge"/>
<ccm:requires name="ccm-portalworkspace" version="6.6.1" relation="ge"/>
<ccm:requires name="ccm-subsite" version="6.6.0" relation="ge"/>
<ccm:requires name="ccm-ldn-search" version="6.6.0" relation="ge"/>
<ccm:requires name="ccm-ldn-terms" version="6.6.0" relation="ge"/>
</ccm:dependencies>