public Document parse(InputStream in) throws SAXException, IOException { LSInput input = ls.createLSInput(); input.setByteStream(in); try { return parser.parse(input); } catch (LSException e) { Throwable e2 = e.getCause(); if (e2 instanceof IOException) throw (IOException) e2; else throw e; } }
public Document parse(InputStream in, String systemId) throws SAXException, IOException { LSInput input = ls.createLSInput(); input.setByteStream(in); input.setSystemId(systemId); try { return parser.parse(input); } catch (LSException e) { Throwable e2 = e.getCause(); if (e2 instanceof IOException) throw (IOException) e2; else throw e; } }
public Document parse(String systemId) throws SAXException, IOException { try { return parser.parseURI(systemId); } catch (LSException e) { Throwable e2 = e.getCause(); if (e2 instanceof IOException) throw (IOException) e2; else throw e; } }
protected void serializeDOM_LS(Element elt, OutputStream out, boolean pretty) throws LSException { DOMImplementationLS impl = (DOMImplementationLS)XMLImplFinder.getDOMImplementation(); // init and configure serializer LSSerializer serializer = impl.createLSSerializer(); DOMConfiguration config = serializer.getDomConfig(); config.setParameter("format-pretty-print", pretty); // wrap output stream LSOutput output = impl.createLSOutput(); output.setByteStream(out); // launch serialization serializer.write(elt, output); }
/** * Creates an LSException. On J2SE 1.4 and above the cause for the exception will be set. */ public static LSException createLSException(short code, Throwable cause) { LSException lse = new LSException(code, cause != null ? cause.getMessage() : null); if (cause != null && ThrowableMethods.fgThrowableMethodsAvailable) { try { ThrowableMethods.fgThrowableInitCauseMethod.invoke(lse, new Object [] {cause}); } // Something went wrong. There's not much we can do about it. catch (Exception e) {} } return lse; }
public Document parse(LSInput input) throws DOMException, LSException { if (async) { return doParse(input); } else { synchronized (this) { return doParse(input); } } }
public Document parseURI(String uri) throws DOMException, LSException { LSInput input = new DomLSInput(); input.setSystemId(uri); return parse(input); }
public boolean writeToURI(Node node, String uri) throws LSException { LSOutput output = new DomLSOutput(); output.setSystemId(uri); return write(node, output); }
public String writeToString(Node node) throws DOMException, LSException { Writer writer = new StringWriter(); LSOutput output = new DomLSOutput(); output.setCharacterStream(writer); write(node, output); return writer.toString(); }
/** * Creates an LSException. On J2SE 1.4 and above the cause for the exception will be set. */ private static LSException createLSException(short code, Throwable cause) { LSException lse = new LSException(code, cause != null ? cause.getMessage() : null); if (cause != null && ThrowableMethods.fgThrowableMethodsAvailable) { try { ThrowableMethods.fgThrowableInitCauseMethod.invoke(lse, new Object [] {cause}); } // Something went wrong. There's not much we can do about it. catch (Exception e) {} } return lse; }
private static String serializeTransformElement(Element xformEl) throws DOMException, LSException { Document document = xformEl.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); // serializer.getDomConfig().setParameter("namespaces", true); // serializer.getDomConfig().setParameter("namespace-declarations", true); serializer.getDomConfig().setParameter("canonical-form", false); serializer.getDomConfig().setParameter("xml-declaration", false); String str = serializer.writeToString(xformEl); return str; }
/** * Parse an XML document from a location identified by an URI reference. * If the URI contains a fragment identifier (see section 4.1 in ), the * behavior is not defined by this specification. * */ public Document parseURI (String uri) throws LSException { //If DOMParser insstance is already busy parsing another document when this // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec if ( fBusy ) { String msg = DOMMessageFormatter.formatMessage ( DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR",null); throw new DOMException ( DOMException.INVALID_STATE_ERR,msg); } XMLInputSource source = new XMLInputSource (null, uri, null); try { currentThread = Thread.currentThread(); fBusy = true; parse (source); fBusy = false; if (abortNow && currentThread.isInterrupted()) { //reset interrupt state abortNow = false; Thread.interrupted(); } } catch (Exception e){ fBusy = false; if (abortNow && currentThread.isInterrupted()) { Thread.interrupted(); } if (abortNow) { abortNow = false; restoreHandlers(); return null; } // Consume this exception if the user // issued an interrupt or an abort. if (e != Abort.INSTANCE) { if (!(e instanceof XMLParseException) && fErrorHandler != null) { DOMErrorImpl error = new DOMErrorImpl (); error.fException = e; error.fMessage = e.getMessage (); error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; fErrorHandler.getErrorHandler ().handleError (error); } if (DEBUG) { e.printStackTrace (); } throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace(); } } Document doc = getDocument(); dropDocumentReferences(); return doc; }
/** * Parse an XML document from a resource identified by an * <code>LSInput</code>. * */ public Document parse (LSInput is) throws LSException { // need to wrap the LSInput with an XMLInputSource XMLInputSource xmlInputSource = dom2xmlInputSource (is); if ( fBusy ) { String msg = DOMMessageFormatter.formatMessage ( DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR",null); throw new DOMException ( DOMException.INVALID_STATE_ERR,msg); } try { currentThread = Thread.currentThread(); fBusy = true; parse (xmlInputSource); fBusy = false; if (abortNow && currentThread.isInterrupted()) { //reset interrupt state abortNow = false; Thread.interrupted(); } } catch (Exception e) { fBusy = false; if (abortNow && currentThread.isInterrupted()) { Thread.interrupted(); } if (abortNow) { abortNow = false; restoreHandlers(); return null; } // Consume this exception if the user // issued an interrupt or an abort. if (e != Abort.INSTANCE) { if (!(e instanceof XMLParseException) && fErrorHandler != null) { DOMErrorImpl error = new DOMErrorImpl (); error.fException = e; error.fMessage = e.getMessage (); error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; fErrorHandler.getErrorHandler().handleError (error); } if (DEBUG) { e.printStackTrace (); } throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace(); } } Document doc = getDocument(); dropDocumentReferences(); return doc; }
/** * Parse an XML document from a location identified by an URI reference. * If the URI contains a fragment identifier (see section 4.1 in ), the * behavior is not defined by this specification. * */ public Document parseURI (String uri) throws LSException { //If DOMParser insstance is already busy parsing another document when this // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec if ( fBusy ) { String msg = DOMMessageFormatter.formatMessage ( DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR",null); throw new DOMException ( DOMException.INVALID_STATE_ERR,msg); } XMLInputSource source = new XMLInputSource (null, uri, null, false); try { currentThread = Thread.currentThread(); fBusy = true; parse (source); fBusy = false; if (abortNow && currentThread.isInterrupted()) { //reset interrupt state abortNow = false; Thread.interrupted(); } } catch (Exception e){ fBusy = false; if (abortNow && currentThread.isInterrupted()) { Thread.interrupted(); } if (abortNow) { abortNow = false; restoreHandlers(); return null; } // Consume this exception if the user // issued an interrupt or an abort. if (e != Abort.INSTANCE) { if (!(e instanceof XMLParseException) && fErrorHandler != null) { DOMErrorImpl error = new DOMErrorImpl (); error.fException = e; error.fMessage = e.getMessage (); error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; fErrorHandler.getErrorHandler ().handleError (error); } if (DEBUG) { e.printStackTrace (); } throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace(); } } Document doc = getDocument(); dropDocumentReferences(); return doc; }