package edu.brown.cs.student.term.parsing; import org.w3c.dom.Document; import org.xml.sax.SAXException; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.time.Instant; public class UrlXmlParser extends XmlParser{ public UrlXmlParser() { 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) { try { System.err.println("LOG: To make class for url: " + pathToXml + " in parse() of " + getClass()); URL url = new URL(pathToXml); System.err.println("LOG: To establish urlConnection in parse() of " + getClass()); URLConnection conn = url.openConnection(); conn.addRequestProperty("User-Agent", "Chrome"); System.err.println("LOG: Calling builder.parse() for url: " + pathToXml + " in " + getClass()); return builder.parse(conn.getInputStream()); } catch (SAXException e) { System.err.println("INTERNAL: SAX " + getClass() + " : " + e.getClass()); } catch (IOException e) { e.printStackTrace(); System.err.println("INTERNAL: IO " + getClass() + " : " + e.getClass()); } return null; } }