CCM NG: Reverted some changes from revision r5078

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5083 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2017-10-25 18:06:38 +00:00
parent 8209244a33
commit d5c7c63a8c
7 changed files with 289 additions and 257 deletions

View File

@ -155,7 +155,8 @@ public abstract class BaseDispatcherServlet extends HttpServlet
File file = new File(getServletContext().getRealPath( File file = new File(getServletContext().getRealPath(
"/WEB-INF/web.xml")); "/WEB-INF/web.xml"));
// all we care about is the welcome-file-list element // all we care about is the welcome-file-list element
SAXParserFactory spf = SAXParserFactory.class.getDeclaredConstructor().newInstance(); SAXParserFactory spf = SAXParserFactory
.newInstance();
spf.setValidating(false); spf.setValidating(false);
SAXParser parser = spf.newSAXParser(); SAXParser parser = spf.newSAXParser();
parser.parse(file, new WebXMLReader()); parser.parse(file, new WebXMLReader());
@ -165,8 +166,6 @@ public abstract class BaseDispatcherServlet extends HttpServlet
LOGGER.error("error in init", pce); LOGGER.error("error in init", pce);
} catch (IOException ioe) { } catch (IOException ioe) {
LOGGER.error("error in init", ioe); LOGGER.error("error in init", ioe);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
} }
// default to index.jsp, index.html // default to index.jsp, index.html
if (m_welcomeFiles.isEmpty()) { if (m_welcomeFiles.isEmpty()) {

View File

@ -98,7 +98,8 @@ public final class XSLTemplate {
try { try {
LOGGER.debug("Getting new templates object"); LOGGER.debug("Getting new templates object");
final TransformerFactory factory = TransformerFactory.class.getDeclaredConstructor().newInstance(); final TransformerFactory factory = TransformerFactory
.newInstance();
factory.setURIResolver(resolver); factory.setURIResolver(resolver);
factory.setErrorListener(listener); factory.setErrorListener(listener);
@ -110,9 +111,6 @@ public final class XSLTemplate {
throw new WrappedTransformerException(ex); throw new WrappedTransformerException(ex);
} catch (TransformerException ex) { } catch (TransformerException ex) {
throw new WrappedTransformerException(ex); throw new WrappedTransformerException(ex);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
throw new RuntimeException(e);
} }
// List contains each include/import URL found in the style sheet // List contains each include/import URL found in the style sheet

View File

@ -51,14 +51,18 @@ public class SystemInformationTab extends LayoutPanel {
final SegmentedPanel panel = new SegmentedPanel(); final SegmentedPanel panel = new SegmentedPanel();
panel.addSegment(new Label(GlobalizationUtil.globalize("ui.admin.sysinfo.appinfo")), panel.addSegment(new Label(GlobalizationUtil.globalize(
new PropertySheet(new CCMSysInfoPropertySheetModelBuilder())); "ui.admin.sysinfo.appinfo")),
new PropertySheet(
new CCMSysInfoPropertySheetModelBuilder()));
panel.addSegment(new Label(GlobalizationUtil.globalize( panel.addSegment(new Label(GlobalizationUtil.globalize(
"ui.admin.sysinfo.java_system_properties")), "ui.admin.sysinfo.java_system_properties")),
new PropertySheet(new JavaSystemPropertiesSheetModelBuilder())); new PropertySheet(
new JavaSystemPropertiesSheetModelBuilder()));
panel.addSegment(new Label(GlobalizationUtil.globalize("ui.admin.sysinfo.xml_config")), panel.addSegment(new Label(GlobalizationUtil.globalize(
"ui.admin.sysinfo.xml_config")),
new PropertySheet(new XMLConfigSheetModelBuilder())); new PropertySheet(new XMLConfigSheetModelBuilder()));
setRight(panel); setRight(panel);
@ -73,7 +77,8 @@ public class SystemInformationTab extends LayoutPanel {
} }
@Override @Override
public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) { public PropertySheetModel makeModel(final PropertySheet sheet,
final PageState state) {
return new CCMSysInfoPropertySheetModel(); return new CCMSysInfoPropertySheetModel();
} }
@ -130,7 +135,8 @@ public class SystemInformationTab extends LayoutPanel {
} }
@Override @Override
public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) { public PropertySheetModel makeModel(final PropertySheet sheet,
final PageState state) {
return new JavaSystemPropertiesSheetModel(); return new JavaSystemPropertiesSheetModel();
} }
@ -182,7 +188,8 @@ public class SystemInformationTab extends LayoutPanel {
} }
@Override @Override
public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) { public PropertySheetModel makeModel(final PropertySheet sheet,
final PageState state) {
return new XMLConfigSheetModel(); return new XMLConfigSheetModel();
} }
@ -232,18 +239,23 @@ public class SystemInformationTab extends LayoutPanel {
public GlobalizedMessage getGlobalizedLabel() { public GlobalizedMessage getGlobalizedLabel() {
switch (currentIndex) { switch (currentIndex) {
case TRANSFORMER_FACTORY_INDEX: case TRANSFORMER_FACTORY_INDEX:
return GlobalizationUtil.globalize("ui.admin.sysinfo.xml_transformer_factory"); return GlobalizationUtil.globalize(
"ui.admin.sysinfo.xml_transformer_factory");
case TRANSFORMER_INDEX: case TRANSFORMER_INDEX:
return GlobalizationUtil.globalize("ui.admin.sysinfo.xml_transformer"); return GlobalizationUtil.globalize(
"ui.admin.sysinfo.xml_transformer");
case DOCUMENT_BUILDER_FACTORY_INDEX: case DOCUMENT_BUILDER_FACTORY_INDEX:
return GlobalizationUtil.globalize( return GlobalizationUtil.globalize(
"ui.admin.sysinfo.xml_document_builder_factory"); "ui.admin.sysinfo.xml_document_builder_factory");
case DOCUMENT_BUILDER_INDEX: case DOCUMENT_BUILDER_INDEX:
return GlobalizationUtil.globalize("ui.admin.sysinfo.xml_document_builder"); return GlobalizationUtil.globalize(
"ui.admin.sysinfo.xml_document_builder");
case SAX_PARSER_FACTORY_INDEX: case SAX_PARSER_FACTORY_INDEX:
return GlobalizationUtil.globalize("ui.admin.sysinfo.sax_parser_factory"); return GlobalizationUtil.globalize(
"ui.admin.sysinfo.sax_parser_factory");
case SAX_PARSER_INDEX: case SAX_PARSER_INDEX:
return GlobalizationUtil.globalize("ui.admin.sysinfo.sax_parser"); return GlobalizationUtil.globalize(
"ui.admin.sysinfo.sax_parser");
default: default:
return GlobalizationUtil.globalize("unknown"); return GlobalizationUtil.globalize("unknown");
} }
@ -253,41 +265,47 @@ public class SystemInformationTab extends LayoutPanel {
public String getValue() { public String getValue() {
switch (currentIndex) { switch (currentIndex) {
case TRANSFORMER_FACTORY_INDEX: case TRANSFORMER_FACTORY_INDEX:
try { return TransformerFactory
return TransformerFactory.class.getDeclaredConstructor().newInstance().getClass().getName(); .newInstance()
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { .getClass()
} .getName();
case TRANSFORMER_INDEX: case TRANSFORMER_INDEX:
try { try {
return TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer().getClass().getName(); return TransformerFactory
.newInstance()
.newTransformer()
.getClass()
.getName();
} catch (TransformerConfigurationException ex) { } catch (TransformerConfigurationException ex) {
return "???"; return "???";
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
} }
case DOCUMENT_BUILDER_FACTORY_INDEX: case DOCUMENT_BUILDER_FACTORY_INDEX:
try { return DocumentBuilderFactory.newInstance().getClass()
return DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().getClass().getName(); .getName();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
case DOCUMENT_BUILDER_INDEX: case DOCUMENT_BUILDER_INDEX:
try { try {
return DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().newDocumentBuilder().getClass() return DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.getClass()
.getName(); .getName();
} catch (ParserConfigurationException ex) { } catch (ParserConfigurationException ex) {
return "???"; return "???";
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
} }
case SAX_PARSER_FACTORY_INDEX: case SAX_PARSER_FACTORY_INDEX:
try { return SAXParserFactory
return SAXParserFactory.class.getDeclaredConstructor().newInstance().getClass().getName(); .newInstance()
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { .getClass()
} .getName();
case SAX_PARSER_INDEX: case SAX_PARSER_INDEX:
try { try {
return SAXParserFactory.class.getDeclaredConstructor().newInstance().newSAXParser().getClass().getName(); return SAXParserFactory
.newInstance()
.newSAXParser()
.getClass()
.getName();
} catch (ParserConfigurationException | SAXException ex) { } catch (ParserConfigurationException | SAXException ex) {
return "???"; return "???";
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
} }
default: default:
return ""; return "";

View File

@ -41,13 +41,12 @@ import java.lang.reflect.InvocationTargetException;
* <code>org.jdom.Document</code> using <code>org.w3c.dom.Document</code>. * <code>org.jdom.Document</code> using <code>org.w3c.dom.Document</code>.
* *
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* pboy (Jan. 09) * pboy (Jan. 09) Class uses "DocumentBuilderFactory.newInstance()" to setup the
* Class uses "DocumentBuilderFactory.class.getDeclaredConstructor().newInstance()" to setup the parser * parser (according to the javax.xml specification). This is a simple and
* (according to the javax.xml specification). This is a simple and
* straightforward, but rather thumb method. It requires a JVM wide acceptable * straightforward, but rather thumb method. It requires a JVM wide acceptable
* configuration (using a system.property or a static JRE configuration file) and * configuration (using a system.property or a static JRE configuration file)
* contrains all programms in a JVM (e.g. multiple CCM running in a container) * and contrains all programms in a JVM (e.g. multiple CCM running in a
* to use the same configuration. * container) to use the same configuration.
* *
* Other methods are available but we have to dig deeper into the CCM code. * Other methods are available but we have to dig deeper into the CCM code.
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -58,14 +57,14 @@ import java.lang.reflect.InvocationTargetException;
*/ */
public class Document { public class Document {
private static final Logger LOGGER = private static final Logger LOGGER = LogManager.getLogger(Document.class
LogManager.getLogger(Document.class.getName()); .getName());
/** /**
* this is the identity XSL stylesheet. We need to provide the * this is the identity XSL stylesheet. We need to provide the identity
* identity transform as XSL explicitly because the default * transform as XSL explicitly because the default transformer
* transformer (newTransformer()) strips XML namespace attributes. * (newTransformer()) strips XML namespace attributes. Also, this XSLT will
* Also, this XSLT will strip the <bebop:structure> debugging info * strip the <bebop:structure> debugging info from the XML document if
* from the XML document if present. * present.
*/ */
// XXX For some reason JD.XSLT doesn't copy xmlns: attributes // XXX For some reason JD.XSLT doesn't copy xmlns: attributes
// to the output doc with <xsl:copy> // to the output doc with <xsl:copy>
@ -84,8 +83,7 @@ public class Document {
*/ */
// Explicitly create elements & attributes to avoid namespace // Explicitly create elements & attributes to avoid namespace
// problems // problems
private final static String identityXSL = private final static String identityXSL = "<xsl:stylesheet version=\"2.0\""
"<xsl:stylesheet version=\"2.0\""
+ " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" + " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
+ "<xsl:output method=\"xml\"/>\n" + "<xsl:output method=\"xml\"/>\n"
+ "<xsl:template match=\"text()|comment()|processing-instruction()\">\n" + "<xsl:template match=\"text()|comment()|processing-instruction()\">\n"
@ -102,13 +100,12 @@ public class Document {
+ "</xsl:template>\n" + "</xsl:template>\n"
+ "</xsl:stylesheet>"; + "</xsl:stylesheet>";
/** /**
* A single <code>DocumentBuilderFactory</code> to use for * A single <code>DocumentBuilderFactory</code> to use for creating
* creating Documents. * Documents.
*/ */
protected static DocumentBuilderFactory s_builder = null; protected static DocumentBuilderFactory s_builder = null;
/** /**
* A single <code>DocumentBuilder</code> to use for * A single <code>DocumentBuilder</code> to use for creating Documents.
* creating Documents.
*/ */
protected static ThreadLocal s_db = null; protected static ThreadLocal s_db = null;
@ -117,9 +114,9 @@ public class Document {
// instead to achieve independence from a JVM wide configuration. // instead to achieve independence from a JVM wide configuration.
// Requires additional modifications in c.ad.util.xml.XML // Requires additional modifications in c.ad.util.xml.XML
static { static {
try { // try {
LOGGER.debug("Static initalizer starting..."); LOGGER.debug("Static initalizer starting...");
s_builder = DocumentBuilderFactory.class.getDeclaredConstructor().newInstance(); s_builder = DocumentBuilderFactory.newInstance();
s_builder.setNamespaceAware(true); s_builder.setNamespaceAware(true);
s_db = new ThreadLocal() { s_db = new ThreadLocal() {
@ -131,11 +128,13 @@ public class Document {
return null; return null;
} }
} }
}; };
LOGGER.debug("Static initalized finished."); LOGGER.debug("Static initalized finished.");
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { // }
LOGGER.error(e); // catch ( e) {
} // LOGGER.error(e);
// }
} }
/* Used to build the DOM Documents that this class wraps */ /* Used to build the DOM Documents that this class wraps */
@ -173,6 +172,7 @@ public class Document {
* Creates a new Document class with the given root element. * Creates a new Document class with the given root element.
* *
* @param rootNode the element to use as the root node * @param rootNode the element to use as the root node
*
* @throws javax.xml.parsers.ParserConfigurationException * @throws javax.xml.parsers.ParserConfigurationException
*/ */
public Document(Element rootNode) throws ParserConfigurationException { public Document(Element rootNode) throws ParserConfigurationException {
@ -188,10 +188,11 @@ public class Document {
} }
/** /**
* Creates a document from the passed in string that should * Creates a document from the passed in string that should be properly
* be properly formatted XML * formatted XML
* *
* @param xmlString * @param xmlString
*
* @throws javax.xml.parsers.ParserConfigurationException * @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.SAXException * @throws org.xml.sax.SAXException
*/ */
@ -227,6 +228,7 @@ public class Document {
* Sets the root element. * Sets the root element.
* *
* @param rootNode the element to use as the root node * @param rootNode the element to use as the root node
*
* @return this document. * @return this document.
*/ */
public Document setRootElement(Element rootNode) { public Document setRootElement(Element rootNode) {
@ -237,14 +239,15 @@ public class Document {
} }
/** /**
* Creates a new element and sets it as the root. * Creates a new element and sets it as the root. Equivalent to
* Equivalent to
* <pre> * <pre>
* Element root = new Element("name", NS); * Element root = new Element("name", NS);
* doc.setRootElement(root); * doc.setRootElement(root);
* </pre> * </pre>
*
* @param elt the element name * @param elt the element name
* @param ns the element's namespace URI * @param ns the element's namespace URI
*
* @return The newly created root element. * @return The newly created root element.
*/ */
public Element createRootElement(String elt, String ns) { public Element createRootElement(String elt, String ns) {
@ -256,13 +259,14 @@ public class Document {
} }
/** /**
* Creates a new element and sets it as the root. * Creates a new element and sets it as the root. Equivalent to
* Equivalent to
* <pre> * <pre>
* Element root = new Element("name", NS); * Element root = new Element("name", NS);
* doc.setRootElement(root); * doc.setRootElement(root);
* </pre> * </pre>
*
* @param elt the element name * @param elt the element name
*
* @return The newly created root element. * @return The newly created root element.
*/ */
public Element createRootElement(String elt) { public Element createRootElement(String elt) {
@ -274,8 +278,9 @@ public class Document {
} }
/** /**
* Returns the root element for the document. This is the top-level * Returns the root element for the document. This is the top-level element
* element (the "HTML" element in an HTML document). * (the "HTML" element in an HTML document).
*
* @return the document's root element. * @return the document's root element.
*/ */
public Element getRootElement() { public Element getRootElement() {
@ -285,10 +290,10 @@ public class Document {
} }
/** /**
* Not a part of <code>org.jdom.Document</code>, this function returns * Not a part of <code>org.jdom.Document</code>, this function returns the
* the internal DOM representation of this document. This method should * internal DOM representation of this document. This method should only be
* only be used when passing the DOM to the translator. It will require * used when passing the DOM to the translator. It will require changes once
* changes once JDOM replaces this class. * JDOM replaces this class.
* *
* @return this document. * @return this document.
*/ */
@ -297,16 +302,16 @@ public class Document {
} }
/** /**
* General toString() method for org.w3c.domDocument. * General toString() method for org.w3c.domDocument. Not really related to
* Not really related to xml.Document, but needed here. * xml.Document, but needed here. Converts an XML in-memory DOM to String
* Converts an XML in-memory DOM to String representation, using * representation, using an XSLT identity transformation.
* an XSLT identity transformation. *
* @param document the <code>org.w3c.dom.Document</code> object to convert
* to a String representation
* @param indent if <code>true</code>, try to indent elements according to
* normal XML/SGML indentation conventions (may only work
* with certain XSLT engines)
* *
* @param document the <code>org.w3c.dom.Document</code> object
* to convert to a String representation
* @param indent if <code>true</code>, try to indent elements according to normal
* XML/SGML indentation conventions (may only work with certain
* XSLT engines)
* @return a String representation of <code>document</code>. * @return a String representation of <code>document</code>.
*/ */
public static String toString(org.w3c.dom.Document document, public static String toString(org.w3c.dom.Document document,
@ -314,10 +319,11 @@ public class Document {
Transformer identity; Transformer identity;
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
try { try {
StreamSource identitySource = StreamSource identitySource = new StreamSource(new StringReader(
new StreamSource(new StringReader(identityXSL)); identityXSL));
identity = TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer( identity = TransformerFactory
identitySource); .newInstance()
.newTransformer(identitySource);
identity.setOutputProperty("method", "xml"); identity.setOutputProperty("method", "xml");
identity.setOutputProperty("indent", (indent ? "yes" : "no")); identity.setOutputProperty("indent", (indent ? "yes" : "no"));
identity.setOutputProperty("encoding", "UTF-8"); identity.setOutputProperty("encoding", "UTF-8");
@ -325,9 +331,6 @@ public class Document {
} catch (javax.xml.transform.TransformerException e) { } catch (javax.xml.transform.TransformerException e) {
LOGGER.error("error in toString", e); LOGGER.error("error in toString", e);
return document.toString(); return document.toString();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
return null; // This shouldn't be possible
} }
try { try {
@ -338,9 +341,12 @@ public class Document {
} }
} }
/** Convenience wrapper for static toString(Document, boolean), /**
* without additional indenting. * Convenience wrapper for static toString(Document, boolean), without
* additional indenting.
*
* @param document the <code>org.w3c.dom.Document</code> to output * @param document the <code>org.w3c.dom.Document</code> to output
*
* @return a String representation of <code>document</code>. * @return a String representation of <code>document</code>.
*/ */
public static String toString(org.w3c.dom.Document document) { public static String toString(org.w3c.dom.Document document) {
@ -349,20 +355,25 @@ public class Document {
/** /**
* Generates an XML text representation of this document. * Generates an XML text representation of this document.
*
* @param indent if <code>true</code>, try to indent XML elements according * @param indent if <code>true</code>, try to indent XML elements according
* to XML/SGML convention * to XML/SGML convention
*
* @return a String representation of <code>this</code>. * @return a String representation of <code>this</code>.
*/ */
public String toString(boolean indent) { public String toString(boolean indent) {
return toString(m_document, indent); return toString(m_document, indent);
} }
/** Generates an XML text representation of this document, /**
* without additional indenting. * Generates an XML text representation of this document, without additional
* indenting.
*
* @return a String representation of <code>this</code>. * @return a String representation of <code>this</code>.
*/ */
@Override @Override
public String toString() { public String toString() {
return toString(m_document, false); return toString(m_document, false);
} }
} }

View File

@ -35,19 +35,20 @@ import java.util.List;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Attr; import org.w3c.dom.Attr;
/** /**
* A wrapper class that implements some functionality of * A wrapper class that implements some functionality of
* <code>org.jdom.Element</code> using <code>org.w3c.dom.Element</code>. * <code>org.jdom.Element</code> using <code>org.w3c.dom.Element</code>.
* *
* @author Patrick McNeill * @author Patrick McNeill
* @since ACS 4.5a * @since ACS 4.5a
* @version $Revision$ $Date$ * @version $Revision$ $Date: 2017-10-25 15:26:01 +0200 (Mi, 25 Okt 2017)
* $
* @version $Id$ * @version $Id$
*/ */
public class Element { public class Element {
private static final Logger LOGGER = LogManager.getLogger(Element.class.getName()); private static final Logger LOGGER = LogManager.getLogger(Element.class
.getName());
protected org.w3c.dom.Element m_element; protected org.w3c.dom.Element m_element;
/* DOM element that is being wrapped */ /* DOM element that is being wrapped */
/** /**
@ -56,11 +57,12 @@ public class Element {
private org.w3c.dom.Document m_doc; private org.w3c.dom.Document m_doc;
private static ThreadLocal s_localDocument = new ThreadLocal() { private static ThreadLocal s_localDocument = new ThreadLocal() {
@Override @Override
public Object initialValue() { public Object initialValue() {
try { try {
DocumentBuilderFactory builder = DocumentBuilderFactory builder = DocumentBuilderFactory
DocumentBuilderFactory.class.getDeclaredConstructor().newInstance(); .newInstance();
builder.setNamespaceAware(true); builder.setNamespaceAware(true);
return builder.newDocumentBuilder().newDocument(); return builder.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
@ -68,9 +70,6 @@ public class Element {
throw new UncheckedWrapperException( throw new UncheckedWrapperException(
"INTERNAL: Could not create thread local DOM document.", "INTERNAL: Could not create thread local DOM document.",
e); e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
return null; // This shouldn't be possible
} }
} }
@ -92,7 +91,6 @@ public class Element {
// .getOwnerDocument().importNode(element.m_element, // .getOwnerDocument().importNode(element.m_element,
// true); // true);
// } // }
public void syncDocs() { public void syncDocs() {
if (m_doc == null) { if (m_doc == null) {
m_doc = (org.w3c.dom.Document) s_localDocument.get(); m_doc = (org.w3c.dom.Document) s_localDocument.get();
@ -104,9 +102,9 @@ public class Element {
} }
/** /**
* Protected constructor to set up factories, etc. Does not actually * Protected constructor to set up factories, etc. Does not actually create
* create a new element. Used if we are programatically setting the * a new element. Used if we are programatically setting the m_element field
* m_element field later. * later.
*/ */
protected Element() { protected Element() {
} }
@ -139,16 +137,17 @@ public class Element {
} }
/** /**
* Creates a new element and adds it as a child to this * Creates a new element and adds it as a child to this element.
* element. <code>elt.newChildElement("newElt")</code> is * <code>elt.newChildElement("newElt")</code> is equivalent to
* equivalent to
* <pre> * <pre>
* Element newElt = new Element("newElt"); * Element newElt = new Element("newElt");
* elt.addChild(newElt); * elt.addChild(newElt);
* </pre> * </pre>
* *
* @param name the name of the element * @param name the name of the element
*
* @return the created child element. * @return the created child element.
*
* @pre m_element != null * @pre m_element != null
*/ */
public Element newChildElement(String name) { public Element newChildElement(String name) {
@ -165,10 +164,9 @@ public class Element {
} }
/** /**
* Creates a new element. Adds it as a child to this element * Creates a new element. Adds it as a child to this element element and
* element and assigns it to the namespace defined at <code>uri</code>. * assigns it to the namespace defined at <code>uri</code>.
* <code>elt.newChildElement("newElt", namespace)</code> is * <code>elt.newChildElement("newElt", namespace)</code> is equivalent to
* equivalent to
* <pre> * <pre>
* Element newElt = new Element("newElt", namespace); * Element newElt = new Element("newElt", namespace);
* elt.addChild(newElt); * elt.addChild(newElt);
@ -176,7 +174,9 @@ public class Element {
* *
* @param name the name of the Element * @param name the name of the Element
* @param uri the URI for the namespace definition * @param uri the URI for the namespace definition
*
* @return the created child element. * @return the created child element.
*
* @pre m_element != null * @pre m_element != null
*/ */
public Element newChildElement(String name, String uri) { public Element newChildElement(String name, String uri) {
@ -194,10 +194,10 @@ public class Element {
} }
/** /**
* Copies the passed in element and all of its children to a new * Copies the passed in element and all of its children to a new Element.
* Element.
* *
* @param copyFrom * @param copyFrom
*
* @return * @return
*/ */
public Element newChildElement(Element copyFrom) { public Element newChildElement(Element copyFrom) {
@ -208,18 +208,20 @@ public class Element {
} }
Element copyTo = new Element(); Element copyTo = new Element();
copyTo.m_element = m_doc.createElementNS(copyFrom.m_element.getNamespaceURI(), copyFrom.getName()); copyTo.m_element = m_doc.createElementNS(copyFrom.m_element
.getNamespaceURI(), copyFrom.getName());
this.m_element.appendChild(copyTo.m_element); this.m_element.appendChild(copyTo.m_element);
newChildElementHelper(copyFrom, copyTo); newChildElementHelper(copyFrom, copyTo);
return copyTo; return copyTo;
} }
/** /**
* Copies the passed in element and all of its children to a new * Copies the passed in element and all of its children to a new Element
* Element using the passed-in name. * using the passed-in name.
* *
* @param name * @param name
* @param copyFrom * @param copyFrom
*
* @return * @return
*/ */
public Element newChildElement(String name, Element copyFrom) { public Element newChildElement(String name, Element copyFrom) {
@ -235,12 +237,13 @@ public class Element {
} }
/** /**
* Copies the passed in element and all of its children to a new * Copies the passed in element and all of its children to a new Element
* Element using the passed-in name. * using the passed-in name.
* *
* @param name * @param name
* @param uri * @param uri
* @param copyFrom * @param copyFrom
*
* @return * @return
*/ */
public Element newChildElement(String name, String uri, Element copyFrom) { public Element newChildElement(String name, String uri, Element copyFrom) {
@ -258,7 +261,6 @@ public class Element {
private void newChildElementHelper(Element copyFrom, Element copyTo) { private void newChildElementHelper(Element copyFrom, Element copyTo) {
copyTo.setText(copyFrom.getText()); copyTo.setText(copyFrom.getText());
NamedNodeMap nnm = copyFrom.m_element.getAttributes(); NamedNodeMap nnm = copyFrom.m_element.getAttributes();
if (nnm != null) { if (nnm != null) {
@ -282,6 +284,7 @@ public class Element {
* *
* @param name the name of the attribute * @param name the name of the attribute
* @param value the value of the attribute * @param value the value of the attribute
*
* @return this element. * @return this element.
*/ */
public Element addAttribute(String name, String value) { public Element addAttribute(String name, String value) {
@ -307,6 +310,7 @@ public class Element {
* Adds a child element to this element. * Adds a child element to this element.
* *
* @param newContent the new child element * @param newContent the new child element
*
* @return this element. * @return this element.
*/ */
public Element addContent(Element newContent) { public Element addContent(Element newContent) {
@ -319,11 +323,11 @@ public class Element {
} }
/** /**
* Sets the text value of the current element (the part between the * Sets the text value of the current element (the part between the tags).
* tags). If the passed in text is null then it is converted to * If the passed in text is null then it is converted to the empty string.
* the empty string.
* *
* @param text the text to include * @param text the text to include
*
* @return this element. * @return this element.
*/ */
public Element setText(String text) { public Element setText(String text) {
@ -334,16 +338,16 @@ public class Element {
// is to throw the NPE which causes other problems // is to throw the NPE which causes other problems
text = ""; text = "";
} }
org.w3c.dom.Text textElem = org.w3c.dom.Text textElem = m_element.getOwnerDocument().createTextNode(
m_element.getOwnerDocument().createTextNode(text); text);
m_element.appendChild(textElem); m_element.appendChild(textElem);
return this; return this;
} }
/** /**
* Returns the concatenation of all the text in all child nodes * Returns the concatenation of all the text in all child nodes of the
* of the current element. * current element.
* *
* @return * @return
*/ */
@ -370,8 +374,8 @@ public class Element {
cdata = ""; cdata = "";
} }
org.w3c.dom.CDATASection cdataSection = org.w3c.dom.CDATASection cdataSection = m_element.getOwnerDocument()
m_element.getOwnerDocument().createCDATASection(cdata); .createCDATASection(cdata);
m_element.appendChild(cdataSection); m_element.appendChild(cdataSection);
@ -399,15 +403,15 @@ public class Element {
} }
/** /**
* Returns a <code>List</code> of all the child elements nested * Returns a <code>List</code> of all the child elements nested directly
* directly (one level deep) within this element, as <code>Element</code> * (one level deep) within this element, as <code>Element</code> objects. If
* objects. If this target element has no nested elements, an empty * this target element has no nested elements, an empty <code>List</code> is
* <code>List</code> is returned. The returned list is "live", so * returned. The returned list is "live", so changes to it affect the
* changes to it affect the element's actual contents. * element's actual contents.
* <p> * <p>
* *
* This performs no recursion, so elements nested two levels deep would * This performs no recursion, so elements nested two levels deep would have
* have to be obtained with: * to be obtained with:
* <pre> * <pre>
* Iterator itr = currentElement.getChildren().iterator(); * Iterator itr = currentElement.getChildren().iterator();
* while (itr.hasNext()) { * while (itr.hasNext()) {
@ -416,6 +420,7 @@ public class Element {
* // Do something with these children * // Do something with these children
* } * }
* </pre> * </pre>
*
* @return list of child <code>Element</code> objects for this element. * @return list of child <code>Element</code> objects for this element.
*/ */
public java.util.List getChildren() { public java.util.List getChildren() {
@ -434,8 +439,7 @@ public class Element {
public java.util.Map getAttributes() { public java.util.Map getAttributes() {
// Retrieve the attributes of the DOM Element // Retrieve the attributes of the DOM Element
org.w3c.dom.NamedNodeMap attributeNodeMap = org.w3c.dom.NamedNodeMap attributeNodeMap = m_element.getAttributes();
m_element.getAttributes();
// Create the HashMap that we will return the attributes // Create the HashMap that we will return the attributes
// in // in
@ -457,10 +461,11 @@ public class Element {
/** /**
* Retrieves an attribute value by name. * Retrieves an attribute value by name.
*
* @param name The name of the attribute to retrieve * @param name The name of the attribute to retrieve
* @return The Attr value as a string, *
* or the empty string if that attribute does not have a specified * @return The Attr value as a string, or the empty string if that attribute
* or default value. * does not have a specified or default value.
*/ */
public String getAttribute(String name) { public String getAttribute(String name) {
return m_element.getAttribute(name); return m_element.getAttribute(name);
@ -475,9 +480,8 @@ public class Element {
} }
/** /**
* Functions to allow this class to interact appropriately with the * Functions to allow this class to interact appropriately with the Document
* Document class (for example, allows nodes to be moved around, * class (for example, allows nodes to be moved around, and so on).
* and so on).
* *
* @return the internal DOM Element. * @return the internal DOM Element.
*/ */
@ -486,9 +490,9 @@ public class Element {
} }
/** /**
* Imports the internal node into another document. * Imports the internal node into another document. This could also be done
* This could also be done with a combination of getInternalElement * with a combination of getInternalElement and a setInternalElement
* and a setInternalElement function. * function.
* *
* @param doc the org.w3c.dom.Document to import into * @param doc the org.w3c.dom.Document to import into
*/ */
@ -504,14 +508,13 @@ public class Element {
} }
/** /**
* Workaround for bug in some versions of Xerces. * Workaround for bug in some versions of Xerces. For some reason,
* For some reason, importNode doesn't also copy attribute * importNode doesn't also copy attribute values unless you call getValue()
* values unless you call getValue() on them first. This may * on them first. This may be fixed in a later version of Xerces. In the
* be fixed in a later version of Xerces. In the meantime, * meantime, calling visitAllAttributes(node) before importNode should help.
* calling visitAllAttributes(node) before importNode should
* help.
* *
* @param node the org.w3c.dom.Node about to be imported * @param node the org.w3c.dom.Node about to be imported
*
* @deprecated with no replacement, 1 May 2003 * @deprecated with no replacement, 1 May 2003
*/ */
public static void visitAllAttributes(org.w3c.dom.Node node) { public static void visitAllAttributes(org.w3c.dom.Node node) {
@ -531,9 +534,10 @@ public class Element {
} }
/** /**
* retrieve an unordered list of strings relating to node tree including * retrieve an unordered list of strings relating to node tree including and
* and below the current element. Strings include element names, attribute names, * below the current element. Strings include element names, attribute
* attribute values, text and CData sections * names, attribute values, text and CData sections
*
* @return * @return
*/ */
private List getXMLFragments() { private List getXMLFragments() {
@ -559,9 +563,10 @@ public class Element {
} }
/** /**
* retrieve a string that is an ordered concatenation of all information describing * retrieve a string that is an ordered concatenation of all information
* this node and its subnodes, suitable as the basis of a hashCode or equals * describing this node and its subnodes, suitable as the basis of a
* implementation. * hashCode or equals implementation.
*
* @return * @return
*/ */
protected String getXMLHashString() { protected String getXMLHashString() {

View File

@ -204,7 +204,8 @@ public class XML {
// configuration (affecting all CCM instances which may run in a // configuration (affecting all CCM instances which may run in a
// container). // container).
// Requires additional modifications in c.ad.util.xml.XML // Requires additional modifications in c.ad.util.xml.XML
SAXParserFactory spf = SAXParserFactory.class.getDeclaredConstructor().newInstance(); SAXParserFactory spf = SAXParserFactory
.newInstance();
spf.setFeature("http://xml.org/sax/features/namespaces", true); spf.setFeature("http://xml.org/sax/features/namespaces", true);
SAXParser parser = spf.newSAXParser(); SAXParser parser = spf.newSAXParser();
parser.parse(source, handler); parser.parse(source, handler);
@ -219,8 +220,6 @@ public class XML {
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedWrapperException("error parsing stream", e); throw new UncheckedWrapperException("error parsing stream", e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
} }
} }

View File

@ -80,54 +80,56 @@ public class SysInfoController {
final ResourceBundle texts = ResourceBundle.getBundle( final ResourceBundle texts = ResourceBundle.getBundle(
"com.arsdigita.ui.admin.AdminResources"); "com.arsdigita.ui.admin.AdminResources");
try {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer_factory"), texts.getString("ui.admin.sysinfo.xml_transformer_factory"),
TransformerFactory.class.getDeclaredConstructor().newInstance().getClass().getName())); TransformerFactory
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { .newInstance()
} .getClass()
.getName()));
try { try {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer"), texts.getString("ui.admin.sysinfo.xml_transformer"),
TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer().getClass() TransformerFactory.newInstance()
.newTransformer()
.getClass()
.getName())); .getName()));
} catch (TransformerConfigurationException ex) { } catch (TransformerConfigurationException ex) {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer"), "???")); texts.getString("ui.admin.sysinfo.xml_transformer"), "???"));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
try {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder_factory"), texts.getString("ui.admin.sysinfo.xml_document_builder_factory"),
DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().getClass().getName())); DocumentBuilderFactory.newInstance().getClass().getName()));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
} }
try { try {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder"), texts.getString("ui.admin.sysinfo.xml_document_builder"),
DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().newDocumentBuilder() DocumentBuilderFactory
.getClass().getName())); .newInstance()
.newDocumentBuilder()
.getClass()
.getName()));
} catch (ParserConfigurationException ex) { } catch (ParserConfigurationException ex) {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder"), texts.getString("ui.admin.sysinfo.xml_document_builder"),
"???")); "???"));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
} }
try {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser_factory"), texts.getString("ui.admin.sysinfo.sax_parser_factory"),
SAXParserFactory.class.getDeclaredConstructor().newInstance().getClass().getName())); SAXParserFactory
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { .newInstance()
} .getClass()
.getName()));
try { try {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser"), texts.getString("ui.admin.sysinfo.sax_parser"),
SAXParserFactory.class.getDeclaredConstructor().newInstance().newSAXParser().getClass() SAXParserFactory
.newInstance()
.newSAXParser()
.getClass()
.getName())); .getName()));
} catch (ParserConfigurationException | SAXException ex) { } catch (ParserConfigurationException | SAXException ex) {
xmlProps.add(new SysInfoProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser"), "???")); texts.getString("ui.admin.sysinfo.sax_parser"), "???"));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
} }
return xmlProps; return xmlProps;