*
addElement(HtmlTag.DIV, "id", "div1", "style", "font: 10pt * sans-serif;")- * + * * @param tag is the HtmlTag name for the {@code ElementW} node * @param attributes is a sequence of attribute name and value * @return the newly added {@code ElementW} node @@ -87,7 +86,7 @@ public ElementW addElement(HtmlTag tag, String... attributes) { * Adds a new {@code ElementW} node with the given name to this element and * returns the new node. Adds an attribute to the new node for each name and * value in attributes. - * + * *
*
addElement("div", "id", "div1", "style", "font: 10pt * sans-serif;")@@ -140,7 +139,7 @@ public ElementW addAttribute(String name, String value) { /** * Appends the value to the class attribute of this {@code ElementW} creating a * new attribute if one doesn't already exist - * + * * @param value is the value of the class attribute to append or set * @return this {@code ElementW} */ @@ -257,16 +256,6 @@ public ElementW elementById(String idValue) { return null; } - @Deprecated - public ElementW addDiv(String div_class) { - return addElement(HtmlTag.DIV, "class", div_class); - } - - @Deprecated - public ElementW addDiv(String div_class, String text) { - return addDiv(div_class).addText(text); - } - /** * Creates a deep copy of this element. The new element is detached from its * parent, and getParent() on the clone will return null. diff --git a/src/main/java/com/mays/util/html/HtmlPage.java b/src/main/java/com/mays/util/html/HtmlPage.java index 8b61d42..c28117e 100644 --- a/src/main/java/com/mays/util/html/HtmlPage.java +++ b/src/main/java/com/mays/util/html/HtmlPage.java @@ -1,10 +1,12 @@ package com.mays.util.html; +import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; import java.nio.file.Paths; import org.dom4j.Document; +import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.SAXReader; @@ -29,13 +31,13 @@ public HtmlPage(String name, String stylesheet, String script) { element = addBody(stylesheet, script); } - public HtmlPage(Path path) throws Exception { + public HtmlPage(Path path) throws DocumentException { SAXReader reader = new SAXReader(); document = reader.read(path.toString()); element = new ElementW(document.getRootElement()); } - public HtmlPage(InputStream stream) throws Exception { + public HtmlPage(InputStream stream) throws DocumentException { SAXReader reader = new SAXReader(); document = reader.read(stream); element = new ElementW(document.getRootElement()); @@ -86,7 +88,7 @@ private ElementW addBody(String stylesheet, String script) { return new ElementW(html.addElement("body")); } - public void write(String outdir) throws Exception { + public void write(String outdir) throws IOException { HtmlUtil.write(document, Paths.get(outdir, name + ".html")); } diff --git a/src/main/java/com/mays/util/html/HtmlUtil.java b/src/main/java/com/mays/util/html/HtmlUtil.java index a1ece4a..adcf756 100644 --- a/src/main/java/com/mays/util/html/HtmlUtil.java +++ b/src/main/java/com/mays/util/html/HtmlUtil.java @@ -11,6 +11,9 @@ public class HtmlUtil { + private HtmlUtil() { + } + public static void write(Document document, Path file) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); @@ -20,7 +23,7 @@ public static void write(Document document, Path file) throws IOException { writer.write(document); writer.close(); } - + public static String write(Document document) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); diff --git a/src/main/java/com/mays/util/xml/XmlResourceResolver.java b/src/main/java/com/mays/util/xml/XmlResourceResolver.java index f1d0085..1c74a56 100644 --- a/src/main/java/com/mays/util/xml/XmlResourceResolver.java +++ b/src/main/java/com/mays/util/xml/XmlResourceResolver.java @@ -3,6 +3,7 @@ import java.io.InputStream; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.MissingResourceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,10 +23,10 @@ public XmlResourceResolver(String basePath) { @Override public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { Path path = Paths.get(basePath, systemId); - logger.info("Resolve resource: " + path.toString()); + logger.info("Resolve resource: " + path); InputStream resource = this.getClass().getClassLoader().getResourceAsStream(path.toString()); if (resource == null) - throw new RuntimeException("Could not find the specified xsd file: " + basePath + " " + systemId); + throw new MissingResourceException("Could not find the specified xsd file", basePath, systemId); return new XmlLSInputImpl(publicId, systemId, baseURI, resource, "UTF-8"); } diff --git a/src/main/java/com/mays/util/xml/XmlUtil.java b/src/main/java/com/mays/util/xml/XmlUtil.java index 81a70fe..f92c3d7 100644 --- a/src/main/java/com/mays/util/xml/XmlUtil.java +++ b/src/main/java/com/mays/util/xml/XmlUtil.java @@ -24,11 +24,13 @@ import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; -@SuppressWarnings("unused") public class XmlUtil { private static final Logger logger = LoggerFactory.getLogger(XmlUtil.class); + private XmlUtil() { + } + public static void write(Document document, Path file) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); @@ -37,31 +39,29 @@ public static void write(Document document, Path file) throws IOException { writer.close(); } - // TODO // https://stackoverflow.com/questions/55571046/eclipse-is-confused-by-imports-accessible-from-more-than-one-module -// public static void validate(String file, String xsd, String schema_dir) -// throws ParserConfigurationException, SAXException, IOException { -// XmlUtil.validate(new FileInputStream(file), xsd, schema_dir); -// } -// -// public static void validate(InputStream in, String xsd, String schema_dir) -// throws ParserConfigurationException, SAXException, IOException { -// // See javax.xml.validation -// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); -// dbf.setNamespaceAware(true); -// DocumentBuilder parser = dbf.newDocumentBuilder(); -// org.w3c.dom.Document document = parser.parse(in); -// SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); -// factory.setResourceResolver(new XmlResourceResolver(schema_dir)); -// ArrayList