aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/edu/brown/cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/edu/brown/cs')
-rw-r--r--src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java38
-rw-r--r--src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java2
-rw-r--r--src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java37
3 files changed, 77 insertions, 0 deletions
diff --git a/src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java b/src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java
new file mode 100644
index 0000000..27c3988
--- /dev/null
+++ b/src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java
@@ -0,0 +1,38 @@
+package edu.brown.cs.student.term.parsing;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+
+public class LocalXmlParser extends XmlParser {
+ public LocalXmlParser() {
+ super();
+ }
+
+ /**
+ * Method used to parse the xml file.
+ *
+ * @param pathToXml The path to the xml text file.
+ * @return The tree structure parsed as an xml doc.
+ */
+ @Override
+ public Document parse(String pathToXml) {
+ // TODO: change to online hosted file option
+ // Creating the file reference.
+ System.err.println("LOG: To make file reference for " + pathToXml + " in " + getClass());
+ File file = new File(pathToXml);
+
+ // Parsing the file.
+ try {
+ System.err.println("LOG: Calling builder.parse() in " + getClass());
+ return builder.parse(file);
+ } catch (SAXException e) {
+ System.err.println("INTERNAL: SAX " + getClass() + " : " + e.getClass());
+ } catch (IOException e) {
+ System.err.println("INTERNAL: IO " + getClass() + " : " + e.getClass());
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java b/src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java
new file mode 100644
index 0000000..adad835
--- /dev/null
+++ b/src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java
@@ -0,0 +1,2 @@
+package edu.brown.cs.student.term.parsing;public class UrlXmlParser {
+}
diff --git a/src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java b/src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java
new file mode 100644
index 0000000..d8182d6
--- /dev/null
+++ b/src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java
@@ -0,0 +1,37 @@
+package edu.brown.cs.student.term.parsing;
+
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+public abstract class XmlParser {
+ protected DocumentBuilder builder = null;
+
+ /**
+ * This constructor crates and saves the builder that turns the xml text into a tree stricture.
+ */
+ protected XmlParser() {
+ // Builds the immutable factory
+ System.err.println("LOG: Constructor of " + getClass() + ". To make XML parser factory.");
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(true);
+ factory.setIgnoringElementContentWhitespace(true);
+
+ // Creates the builder from the factory
+ try {
+ System.err.println("LOG: To make documentBuilder in " + getClass());
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ System.err.println("INTERNAL: " + getClass() + " : " + e.getClass());
+ }
+ }
+
+ /**
+ * Method used to parse the xml file.
+ * @param pathToXml The path to the xml text file.
+ * @return The tree structure parsed as an xml doc.
+ */
+ public abstract Document parse(String pathToXml);
+}