moved parts of XML parsing into shared library
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 8 Jul 2013 18:49:55 +0000 (21:49 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 8 Jul 2013 18:49:55 +0000 (21:49 +0300)
.settings/org.eclipse.m2e.core.prefs
src/main/java/eu/svjatoslav/inspector/xml/xsd/Main.java
src/main/java/eu/svjatoslav/inspector/xml/xsd/XSD.java
src/main/java/eu/svjatoslav/inspector/xml/xsd/XmlElement.java [deleted file]

index ff7698f..f897a7f 100644 (file)
@@ -1,4 +1,4 @@
 activeProfiles=
 eclipse.preferences.version=1
-resolveWorkspaceProjects=false
+resolveWorkspaceProjects=true
 version=1
index d0093f4..41e7de6 100644 (file)
@@ -1,14 +1,20 @@
 package eu.svjatoslav.inspector.xml.xsd;
 
-import java.io.FileNotFoundException;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
 
 public class Main {
 
-       public static void main(final String[] args) throws FileNotFoundException {
+       public static void main(final String[] args) throws SAXException,
+                       IOException, ParserConfigurationException {
 
                final XSD xsd = new XSD();
 
-               xsd.parse("/home/n0/Desktop/MeterSchema.xsd");
+               xsd.parse(new FileInputStream("/home/n0/Desktop/MeterSchema.xsd"));
 
                System.out.println(xsd);
 
index 3d5ff45..2b60bf4 100644 (file)
@@ -1,19 +1,17 @@
 package eu.svjatoslav.inspector.xml.xsd;
 
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
+import eu.svjatoslav.commons.data.xml.XmlElement;
+import eu.svjatoslav.commons.data.xml.XmlHelper;
+
 public class XSD {
 
        private static final String XMLNS_PREFIX = "xmlns:";
@@ -30,44 +28,16 @@ public class XSD {
                        }
        }
 
-       public void parse(final InputStream inputStream) {
-
-               final DocumentBuilderFactory builderFactory = DocumentBuilderFactory
-                               .newInstance();
-
-               DocumentBuilder builder = null;
-               try {
-                       builder = builderFactory.newDocumentBuilder();
-               } catch (final ParserConfigurationException e) {
-                       e.printStackTrace();
-               }
-
-               Document document;
-               try {
-                       document = builder.parse(inputStream);
-               } catch (final SAXException e) {
-                       e.printStackTrace();
-                       return;
-               } catch (final IOException e) {
-                       e.printStackTrace();
-                       return;
-               }
+       public void parse(final InputStream inputStream) throws SAXException,
+                       IOException, ParserConfigurationException {
 
-               final XmlElement xsdSchema = new XmlElement(
-                               document.getDocumentElement());
+               final XmlElement xsdSchema = XmlHelper.parseXml(inputStream);
 
                detectNamespaces(xsdSchema);
 
                System.out.println(xsdSchema.toString());
        }
 
-       public void parse(final String filePath) throws FileNotFoundException {
-
-               final FileInputStream inputStream = new FileInputStream(filePath);
-
-               parse(inputStream);
-       }
-
        @Override
        public String toString() {
                final StringBuffer result = new StringBuffer();
diff --git a/src/main/java/eu/svjatoslav/inspector/xml/xsd/XmlElement.java b/src/main/java/eu/svjatoslav/inspector/xml/xsd/XmlElement.java
deleted file mode 100644 (file)
index 6863fd4..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-package eu.svjatoslav.inspector.xml.xsd;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-public class XmlElement {
-
-       Element element;
-
-       public XmlElement(final Element element) {
-               this.element = element;
-       }
-
-       public List<String> getAttributeNames() {
-               final ArrayList<String> result = new ArrayList<String>();
-
-               final NamedNodeMap attributes = element.getAttributes();
-
-               for (int i = 0; i < attributes.getLength(); i++) {
-                       final Node node = attributes.item(i);
-
-                       result.add(node.getNodeName());
-               }
-
-               return result;
-       }
-
-       public String getAttributeValue(final String attributeName) {
-               return element.getAttribute(attributeName);
-       }
-
-       @Override
-       public String toString() {
-               final StringBuffer result = new StringBuffer();
-
-               result.append("node name: " + element.getNodeName() + "\n");
-
-               final NamedNodeMap attributes = element.getAttributes();
-
-               for (int i = 0; i < attributes.getLength(); i++) {
-                       final Node node = attributes.item(i);
-
-                       result.append("    " + node.getNodeName() + "\n");
-               }
-
-               return result.toString();
-       }
-
-}