public void fatalError(SAXParseException e) throws SAXException { throw new SAXException(new ParserException(e)); }
public void error(SAXParseException e) throws SAXException { throw new SAXException(new ParserException(e)); }
public void parse(InputSource source) throws ParserException { try { xr.parse(source); } catch (Exception ex) { throw new ParserException(ex); } }
protected ParserException unwrapException(Exception ex) { // Another historic moment in Java XML API design! if (ex.getCause() != null && ex.getCause() instanceof ParserException) { return (ParserException)ex.getCause(); } return new ParserException(ex); }
public D parse(File file, boolean validate) throws ParserException { if (file == null) throw new IllegalArgumentException("Can't parse null file"); try { return parse(file.toURI().toURL(), validate); } catch (Exception ex) { throw new ParserException("Parsing file failed: " + file, ex); } }
public String print(Source source, int indent, boolean standalone) throws ParserException { try { Transformer transformer = createTransformer("xml", indent, standalone); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); StringWriter out = new StringWriter(); transformer.transform(source, new StreamResult(out)); out.flush(); return out.toString(); } catch (Exception e) { throw new ParserException(e); } }
public D parse(URL url, boolean validate) throws ParserException { if (url == null) throw new IllegalArgumentException("Can't parse null URL"); try { return parse(url.openStream(), validate); } catch (Exception ex) { throw new ParserException("Parsing URL failed: " + url, ex); } }
public Transformer createTransformer(String method, int indent, boolean standalone) throws ParserException { try { TransformerFactory transFactory = TransformerFactory.newInstance(); if (indent > 0) { try { transFactory.setAttribute("indent-number", indent); } catch (IllegalArgumentException ex) { // Fuck you, Apache morons. } } Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, standalone ? "no" : "yes"); // JDK 7 bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7150637 if (standalone) { try { transformer.setOutputProperty("http://www.oracle.com/xml/is-standalone", "yes"); } catch (IllegalArgumentException e) { // Expected on older versions } } transformer.setOutputProperty(OutputKeys.INDENT, indent > 0 ? "yes" : "no"); if (indent > 0) transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent)); transformer.setOutputProperty(OutputKeys.METHOD, method); return transformer; } catch (Exception ex) { throw new ParserException(ex); } }
public CHILD getRequiredChild(String name) throws ParserException { CHILD[] children = getChildren(name); if (children.length != 1) { throw new ParserException("Required single child element of '" + getElementName() + "' not found: " + name); } return children[0]; }
throw new ParserException(ex);
throw new ParserException(ex);