List of usage examples for org.xml.sax SAXParseException printStackTrace
public void printStackTrace()
From source file:Main.java
public static Document createDomDocument(String fileName) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = null;/*from w w w.jav a2 s. co m*/ try { File file = new File(fileName); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(file); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:Main.java
/** * * @param fileName/* w w w. j a v a 2 s . c o m*/ * @return */ // public static Document createDomDocument(String fileName) { public static Document createDomDocument(URI fileName) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = null; try { // File file = new File(fileName); java.io.InputStream is = fileName.toURL().openStream(); DocumentBuilder builder = factory.newDocumentBuilder(); // document = builder.parse(file); document = builder.parse(is); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:Main.java
/** * //w ww . j ava 2 s . com * <B>Purpose:</B> Coverts an XML File to an XML Document Object * * @param file * @return * @throws CoreException * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ public static Document fileToXml(File file) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); InputStream inputStream = new FileInputStream(file); org.w3c.dom.Document doc = null; try { doc = documentBuilderFactory.newDocumentBuilder().parse(inputStream); } catch (SAXParseException e) { e.printStackTrace(); } return doc; }
From source file:Main.java
/** * //from w w w . j a v a 2 s . c o m * <B>Purpose:</B> Coverts an XML File to an XML Document Object * * @param file * @return * @throws CoreException * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ public static Document fileToXml(InputStream in) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); org.w3c.dom.Document doc = null; try { doc = documentBuilderFactory.newDocumentBuilder().parse(in); } catch (SAXParseException e) { e.printStackTrace(); } return doc; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates DOM Document object from XML string * * @param xmlString//w w w. ja v a 2 s . c o m * @return xml document * @throws Exception */ public static Document createXMLDocumentFromString(String xmlString) throws Exception { Document document = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); InputStream is = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); document = builder.parse(is); } catch (SAXParseException spe) { Locator2Impl locator = new Locator2Impl(); spe.printStackTrace(); throw new SAXParseException("", locator); } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:Main.java
public void warning(SAXParseException exception) throws SAXException { exception.printStackTrace(); }
From source file:Main.java
public void error(SAXParseException exception) throws SAXException { exception.printStackTrace(); }
From source file:Main.java
public void fatalError(SAXParseException exception) throws SAXException { exception.printStackTrace(); }
From source file:com.pontecultural.flashcards.ReadSpreadsheet.java
public void run() { try {//w w w . j a v a 2s . c o m // This class is used to upload a zip file via // the web (ie,fileData). To test it, the file is // give to it directly via odsFile. One of // which must be defined. assertFalse(odsFile == null && fileData == null); XMLReader reader = null; final String ZIP_CONTENT = "content.xml"; // Open office files are zipped. // Walk through it and find "content.xml" ZipInputStream zin = null; try { if (fileData != null) { zin = new ZipInputStream(new BufferedInputStream(fileData.getInputStream())); } else { zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(odsFile))); } ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { if (entry.getName().equals(ZIP_CONTENT)) { break; } } SAXParserFactory spf = SAXParserFactory.newInstance(); //spf.setValidating(validate); SAXParser parser = spf.newSAXParser(); reader = parser.getXMLReader(); // reader.setErrorHandler(new MyErrorHandler()); reader.setContentHandler(this); // reader.parse(new InputSource(zf.getInputStream(entry))); reader.parse(new InputSource(zin)); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (zin != null) zin.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:de.suse.swamp.core.util.BugzillaTools.java
private synchronized void xmlToData(String url) throws Exception { HttpState initialState = new HttpState(); String authUsername = swamp.getProperty("BUGZILLA_AUTH_USERNAME"); String authPassword = swamp.getProperty("BUGZILLA_AUTH_PWD"); if (authUsername != null && authUsername.length() != 0) { Credentials defaultcreds = new UsernamePasswordCredentials(authUsername, authPassword); initialState.setCredentials(AuthScope.ANY, defaultcreds); } else {/*from w w w . ja v a 2s .c om*/ Cookie[] cookies = getCookies(); for (int i = 0; i < cookies.length; i++) { initialState.addCookie(cookies[i]); Logger.DEBUG("Added Cookie: " + cookies[i].getName() + "=" + cookies[i].getValue(), log); } } HttpClient httpclient = new HttpClient(); httpclient.setState(initialState); HttpMethod httpget = new GetMethod(url); try { httpclient.executeMethod(httpget); } catch (Exception e) { throw new Exception("Could not get URL " + url); } String content = httpget.getResponseBodyAsString(); char[] chars = content.toCharArray(); // removing illegal characters from bugzilla output. for (int i = 0; i < chars.length; i++) { if (chars[i] < 32 && chars[i] != 9 && chars[i] != 10 && chars[i] != 13) { Logger.DEBUG("Removing illegal character: '" + chars[i] + "' on position " + i, log); chars[i] = ' '; } } Logger.DEBUG(String.valueOf(chars), log); CharArrayReader reader = new CharArrayReader(chars); XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); parser.setFeature("http://xml.org/sax/features/validation", false); // disable parsing of external dtd parser.setFeature("http://xml.org/sax/features/external-general-entities", false); parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false); parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); parser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); // get XML File BugzillaReader handler = new BugzillaReader(); parser.setContentHandler(handler); InputSource source = new InputSource(); source.setCharacterStream(reader); source.setEncoding("utf-8"); try { parser.parse(source); } catch (SAXParseException spe) { spe.printStackTrace(); throw spe; } httpget.releaseConnection(); if (errormsg != null) { throw new Exception(errormsg); } }