diff --git a/themoviedbapi/src/com/moviejukebox/themoviedb/tools/DOMHelper.java b/themoviedbapi/src/com/moviejukebox/themoviedb/tools/DOMHelper.java index 521943db6..c87de81c4 100644 --- a/themoviedbapi/src/com/moviejukebox/themoviedb/tools/DOMHelper.java +++ b/themoviedbapi/src/com/moviejukebox/themoviedb/tools/DOMHelper.java @@ -10,14 +10,11 @@ * For any reuse or distribution, you must make clear to others the * license terms of this work. */ - package com.moviejukebox.themoviedb.tools; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -35,6 +32,7 @@ import org.xml.sax.SAXException; * */ public class DOMHelper { + /** * Gets the string value of the tag element name passed * @param element @@ -43,7 +41,7 @@ public class DOMHelper { */ public static String getValueFromElement(Element element, String tagName) { String returnValue = ""; - + try { NodeList elementNodeList = element.getElementsByTagName(tagName); Element tagElement = (Element) elementNodeList.item(0); @@ -52,7 +50,7 @@ public class DOMHelper { } catch (Exception ignore) { return returnValue; } - + return returnValue; } @@ -60,22 +58,27 @@ public class DOMHelper { * Get a DOM document from the supplied URL * @param url * @return - * @throws MalformedURLException * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ - public static Document getEventDocFromUrl(String url) - throws MalformedURLException, IOException, ParserConfigurationException, SAXException, UnsupportedEncodingException { - //InputStream in = (new URL(url)).openStream(); - String webPage = WebBrowser.request(url); - InputStream in = new ByteArrayInputStream(webPage.getBytes("UTF-8")); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(in); - - doc.getDocumentElement().normalize(); + public static Document getEventDocFromUrl(String url) + throws IOException, ParserConfigurationException, SAXException { + Document doc = null; + InputStream in = null; + try { + String webPage = WebBrowser.request(url); + in = new ByteArrayInputStream(webPage.getBytes("UTF-8")); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + doc = db.parse(in); + doc.getDocumentElement().normalize(); + } finally { + if (in != null) { + in.close(); + } + } return doc; } }