From 111934301b336e545e605ac540ec703b198795ac Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 25 Oct 2017 18:06:38 +0000 Subject: [PATCH] CCM NG: Reverted some changes from revision r5078 git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5083 8810af33-2d31-482b-a856-94f89814c4df --- .../dispatcher/BaseDispatcherServlet.java | 5 +- .../com/arsdigita/templating/XSLTemplate.java | 8 +- .../ui/admin/SystemInformationTab.java | 92 ++++---- .../main/java/com/arsdigita/xml/Document.java | 203 +++++++++--------- .../main/java/com/arsdigita/xml/Element.java | 171 ++++++++------- .../src/main/java/com/arsdigita/xml/XML.java | 7 +- .../ui/admin/sysinfo/SysInfoController.java | 60 +++--- 7 files changed, 289 insertions(+), 257 deletions(-) diff --git a/ccm-core/src/main/java/com/arsdigita/dispatcher/BaseDispatcherServlet.java b/ccm-core/src/main/java/com/arsdigita/dispatcher/BaseDispatcherServlet.java index 5ea982dd9..4d84008b0 100755 --- a/ccm-core/src/main/java/com/arsdigita/dispatcher/BaseDispatcherServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/dispatcher/BaseDispatcherServlet.java @@ -155,7 +155,8 @@ public abstract class BaseDispatcherServlet extends HttpServlet File file = new File(getServletContext().getRealPath( "/WEB-INF/web.xml")); // all we care about is the welcome-file-list element - SAXParserFactory spf = SAXParserFactory.class.getDeclaredConstructor().newInstance(); + SAXParserFactory spf = SAXParserFactory + .newInstance(); spf.setValidating(false); SAXParser parser = spf.newSAXParser(); parser.parse(file, new WebXMLReader()); @@ -165,8 +166,6 @@ public abstract class BaseDispatcherServlet extends HttpServlet LOGGER.error("error in init", pce); } catch (IOException ioe) { LOGGER.error("error in init", ioe); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - LOGGER.error(e); } // default to index.jsp, index.html if (m_welcomeFiles.isEmpty()) { diff --git a/ccm-core/src/main/java/com/arsdigita/templating/XSLTemplate.java b/ccm-core/src/main/java/com/arsdigita/templating/XSLTemplate.java index 6cd20c8ad..c2655d79f 100755 --- a/ccm-core/src/main/java/com/arsdigita/templating/XSLTemplate.java +++ b/ccm-core/src/main/java/com/arsdigita/templating/XSLTemplate.java @@ -98,7 +98,8 @@ public final class XSLTemplate { try { LOGGER.debug("Getting new templates object"); - final TransformerFactory factory = TransformerFactory.class.getDeclaredConstructor().newInstance(); + final TransformerFactory factory = TransformerFactory + .newInstance(); factory.setURIResolver(resolver); factory.setErrorListener(listener); @@ -110,10 +111,7 @@ public final class XSLTemplate { throw new WrappedTransformerException(ex); } catch (TransformerException 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 // recursively(!) (i.e. scanning each style sheet whose URL has been diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/SystemInformationTab.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/SystemInformationTab.java index d088fe8b9..bbc10ba9f 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/SystemInformationTab.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/SystemInformationTab.java @@ -51,14 +51,18 @@ public class SystemInformationTab extends LayoutPanel { final SegmentedPanel panel = new SegmentedPanel(); - panel.addSegment(new Label(GlobalizationUtil.globalize("ui.admin.sysinfo.appinfo")), - new PropertySheet(new CCMSysInfoPropertySheetModelBuilder())); + panel.addSegment(new Label(GlobalizationUtil.globalize( + "ui.admin.sysinfo.appinfo")), + new PropertySheet( + new CCMSysInfoPropertySheetModelBuilder())); panel.addSegment(new Label(GlobalizationUtil.globalize( "ui.admin.sysinfo.java_system_properties")), - new PropertySheet(new JavaSystemPropertiesSheetModelBuilder())); - - panel.addSegment(new Label(GlobalizationUtil.globalize("ui.admin.sysinfo.xml_config")), + new PropertySheet( + new JavaSystemPropertiesSheetModelBuilder())); + + panel.addSegment(new Label(GlobalizationUtil.globalize( + "ui.admin.sysinfo.xml_config")), new PropertySheet(new XMLConfigSheetModelBuilder())); setRight(panel); @@ -73,7 +77,8 @@ public class SystemInformationTab extends LayoutPanel { } @Override - public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) { + public PropertySheetModel makeModel(final PropertySheet sheet, + final PageState state) { return new CCMSysInfoPropertySheetModel(); } @@ -130,7 +135,8 @@ public class SystemInformationTab extends LayoutPanel { } @Override - public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) { + public PropertySheetModel makeModel(final PropertySheet sheet, + final PageState state) { return new JavaSystemPropertiesSheetModel(); } @@ -182,7 +188,8 @@ public class SystemInformationTab extends LayoutPanel { } @Override - public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) { + public PropertySheetModel makeModel(final PropertySheet sheet, + final PageState state) { return new XMLConfigSheetModel(); } @@ -232,18 +239,23 @@ public class SystemInformationTab extends LayoutPanel { public GlobalizedMessage getGlobalizedLabel() { switch (currentIndex) { 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: - return GlobalizationUtil.globalize("ui.admin.sysinfo.xml_transformer"); + return GlobalizationUtil.globalize( + "ui.admin.sysinfo.xml_transformer"); case DOCUMENT_BUILDER_FACTORY_INDEX: return GlobalizationUtil.globalize( "ui.admin.sysinfo.xml_document_builder_factory"); 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: - return GlobalizationUtil.globalize("ui.admin.sysinfo.sax_parser_factory"); + return GlobalizationUtil.globalize( + "ui.admin.sysinfo.sax_parser_factory"); case SAX_PARSER_INDEX: - return GlobalizationUtil.globalize("ui.admin.sysinfo.sax_parser"); + return GlobalizationUtil.globalize( + "ui.admin.sysinfo.sax_parser"); default: return GlobalizationUtil.globalize("unknown"); } @@ -253,42 +265,48 @@ public class SystemInformationTab extends LayoutPanel { public String getValue() { switch (currentIndex) { case TRANSFORMER_FACTORY_INDEX: - try { - return TransformerFactory.class.getDeclaredConstructor().newInstance().getClass().getName(); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } + return TransformerFactory + .newInstance() + .getClass() + .getName(); case TRANSFORMER_INDEX: try { - return TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer().getClass().getName(); - } catch(TransformerConfigurationException ex) { + return TransformerFactory + .newInstance() + .newTransformer() + .getClass() + .getName(); + } catch (TransformerConfigurationException ex) { return "???"; - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { } case DOCUMENT_BUILDER_FACTORY_INDEX: - try { - return DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().getClass().getName(); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } - case DOCUMENT_BUILDER_INDEX: - try{ - return DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().newDocumentBuilder().getClass() + return DocumentBuilderFactory.newInstance().getClass() .getName(); - } catch(ParserConfigurationException ex) { + case DOCUMENT_BUILDER_INDEX: + try { + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .getClass() + .getName(); + } catch (ParserConfigurationException ex) { return "???"; - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { } case SAX_PARSER_FACTORY_INDEX: - try { - return SAXParserFactory.class.getDeclaredConstructor().newInstance().getClass().getName(); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } + return SAXParserFactory + .newInstance() + .getClass() + .getName(); case SAX_PARSER_INDEX: try { - return SAXParserFactory.class.getDeclaredConstructor().newInstance().newSAXParser().getClass().getName(); - } catch(ParserConfigurationException | SAXException ex) { + return SAXParserFactory + .newInstance() + .newSAXParser() + .getClass() + .getName(); + } catch (ParserConfigurationException | SAXException ex) { return "???"; - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } + } default: return ""; } diff --git a/ccm-core/src/main/java/com/arsdigita/xml/Document.java b/ccm-core/src/main/java/com/arsdigita/xml/Document.java index 214521fd3..7532e591c 100644 --- a/ccm-core/src/main/java/com/arsdigita/xml/Document.java +++ b/ccm-core/src/main/java/com/arsdigita/xml/Document.java @@ -41,31 +41,30 @@ import java.lang.reflect.InvocationTargetException; * org.jdom.Document using org.w3c.dom.Document. * * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * pboy (Jan. 09) - * Class uses "DocumentBuilderFactory.class.getDeclaredConstructor().newInstance()" to setup the parser - * (according to the javax.xml specification). This is a simple and + * pboy (Jan. 09) Class uses "DocumentBuilderFactory.newInstance()" to setup the + * parser (according to the javax.xml specification). This is a simple and * straightforward, but rather thumb method. It requires a JVM wide acceptable - * configuration (using a system.property or a static JRE configuration file) and - * contrains all programms in a JVM (e.g. multiple CCM running in a container) - * to use the same configuration. + * configuration (using a system.property or a static JRE configuration file) + * and contrains all programms in a JVM (e.g. multiple CCM running in a + * container) to use the same configuration. * * Other methods are available but we have to dig deeper into the CCM code. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * - * @author Patrick McNeill + * @author Patrick McNeill * @since ACS 4.5a * @version $Id$ */ public class Document { - private static final Logger LOGGER = - LogManager.getLogger(Document.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(Document.class + .getName()); /** - * this is the identity XSL stylesheet. We need to provide the - * identity transform as XSL explicitly because the default - * transformer (newTransformer()) strips XML namespace attributes. - * Also, this XSLT will strip the debugging info - * from the XML document if present. + * this is the identity XSL stylesheet. We need to provide the identity + * transform as XSL explicitly because the default transformer + * (newTransformer()) strips XML namespace attributes. Also, this XSLT will + * strip the debugging info from the XML document if + * present. */ // XXX For some reason JD.XSLT doesn't copy xmlns: attributes // to the output doc with @@ -84,31 +83,29 @@ public class Document { */ // Explicitly create elements & attributes to avoid namespace // problems - private final static String identityXSL = - "\n" - + "\n" - + "\n" - + " \n" - + "\n" - + "\n" - + " \n" - + "\n" - + "\n" - + " \n" - + "\n" - + "\n" - + "\n" - + ""; + private final static String identityXSL = "\n" + + "\n" + + "\n" + + " \n" + + "\n" + + "\n" + + " \n" + + "\n" + + "\n" + + " \n" + + "\n" + + "\n" + + "\n" + + ""; /** - * A single DocumentBuilderFactory to use for - * creating Documents. + * A single DocumentBuilderFactory to use for creating + * Documents. */ protected static DocumentBuilderFactory s_builder = null; /** - * A single DocumentBuilder to use for - * creating Documents. + * A single DocumentBuilder to use for creating Documents. */ protected static ThreadLocal s_db = null; @@ -117,25 +114,27 @@ public class Document { // instead to achieve independence from a JVM wide configuration. // Requires additional modifications in c.ad.util.xml.XML static { - try { - LOGGER.debug("Static initalizer starting..."); - s_builder = DocumentBuilderFactory.class.getDeclaredConstructor().newInstance(); - s_builder.setNamespaceAware(true); - s_db = new ThreadLocal() { +// try { + LOGGER.debug("Static initalizer starting..."); + s_builder = DocumentBuilderFactory.newInstance(); + s_builder.setNamespaceAware(true); + s_db = new ThreadLocal() { - @Override - public Object initialValue() { - try { - return s_builder.newDocumentBuilder(); - } catch (ParserConfigurationException pce) { - return null; - } + @Override + public Object initialValue() { + try { + return s_builder.newDocumentBuilder(); + } catch (ParserConfigurationException pce) { + return null; } - }; - LOGGER.debug("Static initalized finished."); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - LOGGER.error(e); - } + } + + }; + LOGGER.debug("Static initalized finished."); +// } +// catch ( e) { +// LOGGER.error(e); +// } } /* Used to build the DOM Documents that this class wraps */ @@ -146,14 +145,14 @@ public class Document { /** * Creates a new Document class with no root element. - * + * * @throws javax.xml.parsers.ParserConfigurationException */ public Document() throws ParserConfigurationException { DocumentBuilder db = (DocumentBuilder) s_db.get(); if (db == null) { throw new ParserConfigurationException( - "Unable to create a DocumentBuilder"); + "Unable to create a DocumentBuilder"); } m_document = db.newDocument(); } @@ -173,13 +172,14 @@ public class Document { * Creates a new Document class with the given root element. * * @param rootNode the element to use as the root node + * * @throws javax.xml.parsers.ParserConfigurationException */ public Document(Element rootNode) throws ParserConfigurationException { DocumentBuilder db = (DocumentBuilder) s_db.get(); if (db == null) { throw new ParserConfigurationException( - "Unable to create a DocumentBuilder"); + "Unable to create a DocumentBuilder"); } m_document = db.newDocument(); @@ -188,30 +188,31 @@ public class Document { } /** - * Creates a document from the passed in string that should - * be properly formatted XML - * + * Creates a document from the passed in string that should be properly + * formatted XML + * * @param xmlString + * * @throws javax.xml.parsers.ParserConfigurationException * @throws org.xml.sax.SAXException */ public Document(String xmlString) - throws ParserConfigurationException, org.xml.sax.SAXException { + throws ParserConfigurationException, org.xml.sax.SAXException { this(new org.xml.sax.InputSource(new java.io.StringReader(xmlString))); } public Document(byte[] xmlBytes) - throws ParserConfigurationException, org.xml.sax.SAXException { + throws ParserConfigurationException, org.xml.sax.SAXException { this(new org.xml.sax.InputSource(new java.io.ByteArrayInputStream( - xmlBytes))); + xmlBytes))); } private Document(org.xml.sax.InputSource inputSource) - throws ParserConfigurationException, org.xml.sax.SAXException { + throws ParserConfigurationException, org.xml.sax.SAXException { DocumentBuilder db = (DocumentBuilder) s_db.get(); if (db == null) { throw new ParserConfigurationException( - "Unable to create a DocumentBuilder"); + "Unable to create a DocumentBuilder"); } org.w3c.dom.Document domDoc; @@ -227,6 +228,7 @@ public class Document { * Sets the root element. * * @param rootNode the element to use as the root node + * * @return this document. */ public Document setRootElement(Element rootNode) { @@ -237,14 +239,15 @@ public class Document { } /** - * Creates a new element and sets it as the root. - * Equivalent to + * Creates a new element and sets it as the root. Equivalent to *
      * Element root = new Element("name", NS);
      * doc.setRootElement(root);
      * 
+ * * @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. */ public Element createRootElement(String elt, String ns) { @@ -256,13 +259,14 @@ public class Document { } /** - * Creates a new element and sets it as the root. - * Equivalent to + * Creates a new element and sets it as the root. Equivalent to *
      * Element root = new Element("name", NS);
      * doc.setRootElement(root);
      * 
+ * * @param elt the element name + * * @return The newly created root element. */ public Element createRootElement(String elt) { @@ -274,8 +278,9 @@ public class Document { } /** - * Returns the root element for the document. This is the top-level - * element (the "HTML" element in an HTML document). + * Returns the root element for the document. This is the top-level element + * (the "HTML" element in an HTML document). + * * @return the document's root element. */ public Element getRootElement() { @@ -285,10 +290,10 @@ public class Document { } /** - * Not a part of org.jdom.Document, this function returns - * the internal DOM representation of this document. This method should - * only be used when passing the DOM to the translator. It will require - * changes once JDOM replaces this class. + * Not a part of org.jdom.Document, this function returns the + * internal DOM representation of this document. This method should only be + * used when passing the DOM to the translator. It will require changes once + * JDOM replaces this class. * * @return this document. */ @@ -297,16 +302,16 @@ public class Document { } /** - * General toString() method for org.w3c.domDocument. - * Not really related to xml.Document, but needed here. - * Converts an XML in-memory DOM to String representation, using - * an XSLT identity transformation. + * General toString() method for org.w3c.domDocument. Not really related to + * xml.Document, but needed here. Converts an XML in-memory DOM to String + * representation, using an XSLT identity transformation. + * + * @param document the org.w3c.dom.Document object to convert + * to a String representation + * @param indent if true, try to indent elements according to + * normal XML/SGML indentation conventions (may only work + * with certain XSLT engines) * - * @param document the org.w3c.dom.Document object - * to convert to a String representation - * @param indent if true, try to indent elements according to normal - * XML/SGML indentation conventions (may only work with certain - * XSLT engines) * @return a String representation of document. */ public static String toString(org.w3c.dom.Document document, @@ -314,10 +319,11 @@ public class Document { Transformer identity; ByteArrayOutputStream os = new ByteArrayOutputStream(); try { - StreamSource identitySource = - new StreamSource(new StringReader(identityXSL)); - identity = TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer( - identitySource); + StreamSource identitySource = new StreamSource(new StringReader( + identityXSL)); + identity = TransformerFactory + .newInstance() + .newTransformer(identitySource); identity.setOutputProperty("method", "xml"); identity.setOutputProperty("indent", (indent ? "yes" : "no")); identity.setOutputProperty("encoding", "UTF-8"); @@ -325,10 +331,7 @@ public class Document { } catch (javax.xml.transform.TransformerException e) { LOGGER.error("error in toString", e); return document.toString(); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - LOGGER.error(e); - return null; // This shouldn't be possible - } + } try { return os.toString("UTF-8"); @@ -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 org.w3c.dom.Document to output + * * @return a String representation of 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. + * * @param indent if true, try to indent XML elements according - * to XML/SGML convention + * to XML/SGML convention + * * @return a String representation of this. */ public String toString(boolean 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 this. */ @Override public String toString() { return toString(m_document, false); } + } diff --git a/ccm-core/src/main/java/com/arsdigita/xml/Element.java b/ccm-core/src/main/java/com/arsdigita/xml/Element.java index 8c04368be..50d4d737e 100644 --- a/ccm-core/src/main/java/com/arsdigita/xml/Element.java +++ b/ccm-core/src/main/java/com/arsdigita/xml/Element.java @@ -35,19 +35,20 @@ import java.util.List; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Attr; - /** * A wrapper class that implements some functionality of * org.jdom.Element using org.w3c.dom.Element. * - * @author Patrick McNeill + * @author Patrick McNeill * @since ACS 4.5a - * @version $Revision$ $Date$ + * @version $Revision$ $Date: 2017-10-25 15:26:01 +0200 (Mi, 25 Okt 2017) + * $ * @version $Id$ */ 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; /* DOM element that is being wrapped */ /** @@ -56,21 +57,19 @@ public class Element { private org.w3c.dom.Document m_doc; private static ThreadLocal s_localDocument = new ThreadLocal() { + @Override public Object initialValue() { try { - DocumentBuilderFactory builder = - DocumentBuilderFactory.class.getDeclaredConstructor().newInstance(); + DocumentBuilderFactory builder = DocumentBuilderFactory + .newInstance(); builder.setNamespaceAware(true); return builder.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { LOGGER.error(e); throw new UncheckedWrapperException( - "INTERNAL: Could not create thread local DOM document.", - e); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - LOGGER.error(e); - return null; // This shouldn't be possible + "INTERNAL: Could not create thread local DOM document.", + e); } } @@ -92,7 +91,6 @@ public class Element { // .getOwnerDocument().importNode(element.m_element, // true); // } - public void syncDocs() { if (m_doc == null) { 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 - * create a new element. Used if we are programatically setting the - * m_element field later. + * Protected constructor to set up factories, etc. Does not actually create + * a new element. Used if we are programatically setting the m_element field + * later. */ protected Element() { } @@ -125,11 +123,11 @@ public class Element { /** * Creates a new element with the given name, and assigns it to the - * namespace defined at uri. The namespace prefix is + * namespace defined at uri. The namespace prefix is * automatically determined. * * @param name the name of the element - * @param uri the URI for the namespace definition + * @param uri the URI for the namespace definition */ public Element(String name, String uri) { Assert.exists(name, String.class); @@ -139,16 +137,17 @@ public class Element { } /** - * Creates a new element and adds it as a child to this - * element. elt.newChildElement("newElt") is - * equivalent to + * Creates a new element and adds it as a child to this element. + * elt.newChildElement("newElt") is equivalent to *
      * Element newElt = new Element("newElt");
      * elt.addChild(newElt);
      * 
* * @param name the name of the element + * * @return the created child element. + * * @pre m_element != null */ public Element newChildElement(String name) { @@ -165,18 +164,19 @@ public class Element { } /** - * Creates a new element. Adds it as a child to this element - * element and assigns it to the namespace defined at uri. - * elt.newChildElement("newElt", namespace) is - * equivalent to + * Creates a new element. Adds it as a child to this element element and + * assigns it to the namespace defined at uri. + * elt.newChildElement("newElt", namespace) is equivalent to *
      * Element newElt = new Element("newElt", namespace);
      * elt.addChild(newElt);
      * 
* * @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. + * * @pre m_element != null */ public Element newChildElement(String name, String uri) { @@ -194,11 +194,11 @@ public class Element { } /** - * Copies the passed in element and all of its children to a new - * Element. - * + * Copies the passed in element and all of its children to a new Element. + * * @param copyFrom - * @return + * + * @return */ public Element newChildElement(Element copyFrom) { Assert.exists(copyFrom, Element.class); @@ -208,19 +208,21 @@ public class 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); newChildElementHelper(copyFrom, copyTo); return copyTo; } /** - * Copies the passed in element and all of its children to a new - * Element using the passed-in name. - * + * Copies the passed in element and all of its children to a new Element + * using the passed-in name. + * * @param name * @param copyFrom - * @return + * + * @return */ public Element newChildElement(String name, Element copyFrom) { if (m_doc == null) { @@ -235,13 +237,14 @@ public class Element { } /** - * Copies the passed in element and all of its children to a new - * Element using the passed-in name. - * + * Copies the passed in element and all of its children to a new Element + * using the passed-in name. + * * @param name * @param uri * @param copyFrom - * @return + * + * @return */ public Element newChildElement(String name, String uri, Element copyFrom) { if (m_doc == null) { @@ -258,7 +261,6 @@ public class Element { private void newChildElementHelper(Element copyFrom, Element copyTo) { copyTo.setText(copyFrom.getText()); - NamedNodeMap nnm = copyFrom.m_element.getAttributes(); if (nnm != null) { @@ -280,8 +282,9 @@ public class Element { /** * Adds an attribute to the element. * - * @param name the name of the attribute + * @param name the name of the attribute * @param value the value of the attribute + * * @return this element. */ public Element addAttribute(String name, String value) { @@ -307,6 +310,7 @@ public class Element { * Adds a child element to this element. * * @param newContent the new child element + * * @return this element. */ public Element addContent(Element newContent) { @@ -319,11 +323,11 @@ public class Element { } /** - * Sets the text value of the current element (the part between the - * tags). If the passed in text is null then it is converted to - * the empty string. + * Sets the text value of the current element (the part between the tags). + * If the passed in text is null then it is converted to the empty string. * * @param text the text to include + * * @return this element. */ public Element setText(String text) { @@ -334,18 +338,18 @@ public class Element { // is to throw the NPE which causes other problems text = ""; } - org.w3c.dom.Text textElem = - m_element.getOwnerDocument().createTextNode(text); + org.w3c.dom.Text textElem = m_element.getOwnerDocument().createTextNode( + text); m_element.appendChild(textElem); return this; } /** - * Returns the concatenation of all the text in all child nodes - * of the current element. - * - * @return + * Returns the concatenation of all the text in all child nodes of the + * current element. + * + * @return */ public String getText() { StringBuilder result = new StringBuilder(); @@ -370,8 +374,8 @@ public class Element { cdata = ""; } - org.w3c.dom.CDATASection cdataSection = - m_element.getOwnerDocument().createCDATASection(cdata); + org.w3c.dom.CDATASection cdataSection = m_element.getOwnerDocument() + .createCDATASection(cdata); m_element.appendChild(cdataSection); @@ -399,15 +403,15 @@ public class Element { } /** - * Returns a List of all the child elements nested - * directly (one level deep) within this element, as Element - * objects. If this target element has no nested elements, an empty - * List is returned. The returned list is "live", so - * changes to it affect the element's actual contents. + * Returns a List of all the child elements nested directly + * (one level deep) within this element, as Element objects. If + * this target element has no nested elements, an empty List is + * returned. The returned list is "live", so changes to it affect the + * element's actual contents. *

* - * This performs no recursion, so elements nested two levels deep would - * have to be obtained with: + * This performs no recursion, so elements nested two levels deep would have + * to be obtained with: *

      * Iterator itr = currentElement.getChildren().iterator();
      * while (itr.hasNext()) {
@@ -416,6 +420,7 @@ public class Element {
      *      // Do something with these children
      *    }
      * 
+ * * @return list of child Element objects for this element. */ public java.util.List getChildren() { @@ -434,8 +439,7 @@ public class Element { public java.util.Map getAttributes() { // Retrieve the attributes of the DOM Element - org.w3c.dom.NamedNodeMap attributeNodeMap = - m_element.getAttributes(); + org.w3c.dom.NamedNodeMap attributeNodeMap = m_element.getAttributes(); // Create the HashMap that we will return the attributes // in @@ -457,10 +461,11 @@ public class Element { /** * Retrieves an attribute value by name. + * * @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 - * or default value. + * + * @return The Attr value as a string, or the empty string if that attribute + * does not have a specified or default value. */ public String getAttribute(String name) { return m_element.getAttribute(name); @@ -475,9 +480,8 @@ public class Element { } /** - * Functions to allow this class to interact appropriately with the - * Document class (for example, allows nodes to be moved around, - * and so on). + * Functions to allow this class to interact appropriately with the Document + * class (for example, allows nodes to be moved around, and so on). * * @return the internal DOM Element. */ @@ -486,9 +490,9 @@ public class Element { } /** - * Imports the internal node into another document. - * This could also be done with a combination of getInternalElement - * and a setInternalElement function. + * Imports the internal node into another document. This could also be done + * with a combination of getInternalElement and a setInternalElement + * function. * * @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. - * For some reason, importNode doesn't also copy attribute - * values unless you call getValue() on them first. This may - * be fixed in a later version of Xerces. In the meantime, - * calling visitAllAttributes(node) before importNode should - * help. + * Workaround for bug in some versions of Xerces. For some reason, + * importNode doesn't also copy attribute values unless you call getValue() + * on them first. This may be fixed in a later version of Xerces. In the + * meantime, calling visitAllAttributes(node) before importNode should help. * * @param node the org.w3c.dom.Node about to be imported + * * @deprecated with no replacement, 1 May 2003 */ 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 - * and below the current element. Strings include element names, attribute names, - * attribute values, text and CData sections + * retrieve an unordered list of strings relating to node tree including and + * below the current element. Strings include element names, attribute + * names, attribute values, text and CData sections + * * @return */ private List getXMLFragments() { @@ -559,9 +563,10 @@ public class Element { } /** - * retrieve a string that is an ordered concatenation of all information describing - * this node and its subnodes, suitable as the basis of a hashCode or equals - * implementation. + * retrieve a string that is an ordered concatenation of all information + * describing this node and its subnodes, suitable as the basis of a + * hashCode or equals implementation. + * * @return */ protected String getXMLHashString() { @@ -585,7 +590,7 @@ public class Element { Date start = new Date(); String hashString = getXMLHashString(); LOGGER.debug( - "hashCode: getXMLString took " + "hashCode: getXMLString took " + (new Date().getTime() - start.getTime()) + " millisecs"); @@ -607,7 +612,7 @@ public class Element { String thisXML = getXMLHashString(); String otherXML = otherElement.getXMLHashString(); LOGGER.debug( - "Equals: getXMLString twice took " + "Equals: getXMLString twice took " + (new Date().getTime() - start.getTime()) + " millisecs"); return thisXML.equals(otherXML); diff --git a/ccm-core/src/main/java/com/arsdigita/xml/XML.java b/ccm-core/src/main/java/com/arsdigita/xml/XML.java index cf93eebb9..3d1f4735c 100644 --- a/ccm-core/src/main/java/com/arsdigita/xml/XML.java +++ b/ccm-core/src/main/java/com/arsdigita/xml/XML.java @@ -204,7 +204,8 @@ public class XML { // configuration (affecting all CCM instances which may run in a // container). // 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); SAXParser parser = spf.newSAXParser(); parser.parse(source, handler); @@ -219,9 +220,7 @@ public class XML { } } catch (IOException e) { throw new UncheckedWrapperException("error parsing stream", e); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - LOGGER.error(e); - } + } } /** diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/sysinfo/SysInfoController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/sysinfo/SysInfoController.java index c1c4c29ad..8f832e7cc 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/sysinfo/SysInfoController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/sysinfo/SysInfoController.java @@ -62,7 +62,7 @@ public class SysInfoController { final List sysInfo = new ArrayList<>(); properties.stringPropertyNames().forEach(propName -> sysInfo.add( new SysInfoProperty(propName, - properties.getProperty(propName)))); + properties.getProperty(propName)))); return sysInfo; } @@ -71,7 +71,7 @@ public class SysInfoController { final List javaSysProps = new ArrayList<>(); systemProperties.stringPropertyNames().forEach(propName -> javaSysProps .add(new SysInfoProperty(propName, systemProperties.getProperty( - propName)))); + propName)))); return javaSysProps; } @@ -80,56 +80,58 @@ public class SysInfoController { final ResourceBundle texts = ResourceBundle.getBundle( "com.arsdigita.ui.admin.AdminResources"); - try { - xmlProps.add(new SysInfoProperty( - texts.getString("ui.admin.sysinfo.xml_transformer_factory"), - TransformerFactory.class.getDeclaredConstructor().newInstance().getClass().getName())); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } + xmlProps.add(new SysInfoProperty( + texts.getString("ui.admin.sysinfo.xml_transformer_factory"), + TransformerFactory + .newInstance() + .getClass() + .getName())); try { xmlProps.add(new SysInfoProperty( texts.getString("ui.admin.sysinfo.xml_transformer"), - TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer().getClass() - .getName())); + TransformerFactory.newInstance() + .newTransformer() + .getClass() + .getName())); } catch (TransformerConfigurationException ex) { xmlProps.add(new SysInfoProperty( texts.getString("ui.admin.sysinfo.xml_transformer"), "???")); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } - try { xmlProps.add(new SysInfoProperty( - texts.getString("ui.admin.sysinfo.xml_document_builder_factory"), - DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().getClass().getName())); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { + texts.getString("ui.admin.sysinfo.xml_document_builder_factory"), + DocumentBuilderFactory.newInstance().getClass().getName())); } try { xmlProps.add(new SysInfoProperty( texts.getString("ui.admin.sysinfo.xml_document_builder"), - DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().newDocumentBuilder() - .getClass().getName())); + DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .getClass() + .getName())); } catch (ParserConfigurationException ex) { xmlProps.add(new SysInfoProperty( texts.getString("ui.admin.sysinfo.xml_document_builder"), "???")); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { - } - try { - xmlProps.add(new SysInfoProperty( - texts.getString("ui.admin.sysinfo.sax_parser_factory"), - SAXParserFactory.class.getDeclaredConstructor().newInstance().getClass().getName())); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { } + xmlProps.add(new SysInfoProperty( + texts.getString("ui.admin.sysinfo.sax_parser_factory"), + SAXParserFactory + .newInstance() + .getClass() + .getName())); try { xmlProps.add(new SysInfoProperty( texts.getString("ui.admin.sysinfo.sax_parser"), - SAXParserFactory.class.getDeclaredConstructor().newInstance().newSAXParser().getClass() - .getName())); + SAXParserFactory + .newInstance() + .newSAXParser() + .getClass() + .getName())); } catch (ParserConfigurationException | SAXException ex) { xmlProps.add(new SysInfoProperty( texts.getString("ui.admin.sysinfo.sax_parser"), "???")); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { } - + return xmlProps; }