/** * Removes all comments and processing instruction, and unites adjacent text nodes (here CDATA counts as text as * well). This is similar to applying {@link #removeComments(Node)}, {@link #removePIs(Node)}, and finally * {@link #mergeAdjacentText(Node)}, but it does all that somewhat faster. */ static public void simplify(Node parent) { simplify(parent, new StringBuilder(0)); }
simplify(child, collectorTextChildBuff); } else { int type = child.getNodeType();
/** * Same as {@link #parse(InputSource, boolean, boolean)}, but loads from a {@link File}; don't miss the security * warnings documented there. */ static public NodeModel parse(File f, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler); Document doc = builder.parse(f); if (removeComments && removePIs) { simplify(doc); } else { if (removeComments) { removeComments(doc); } if (removePIs) { removePIs(doc); } mergeAdjacentText(doc); } return wrap(doc); }
simplify(doc); } else { if (removeComments) {
/** * Removes all comments and processing instruction, and unites adjacent text nodes (here CDATA counts as text as * well). This is similar to applying {@link #removeComments(Node)}, {@link #removePIs(Node)}, and finally * {@link #mergeAdjacentText(Node)}, but it does all that somewhat faster. */ static public void simplify(Node parent) { simplify(parent, new StringBuilder(0)); }
/** * Removes all comments and processing instruction, and unites adjacent text nodes (here CDATA counts as text as * well). This is similar to applying {@link #removeComments(Node)}, {@link #removePIs(Node)}, and finally * {@link #mergeAdjacentText(Node)}, but it does all that somewhat faster. */ static public void simplify(Node parent) { simplify(parent, new StringBuilder(0)); }
/** * Loads the node model for merging xml. * * @param inputStream The input stream of the xml. * @return The node model. */ protected NodeModel loadMergeXmlModel(InputStream inputStream) throws EnunciateException { try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(false); //no namespace for the merging... Document doc = builderFactory.newDocumentBuilder().parse(inputStream); NodeModel.simplify(doc); return NodeModel.wrap(doc.getDocumentElement()); } catch (Exception e) { throw new EnunciateException("Error parsing web.xml file for merging", e); } }
private NodeModel loadNodeModel(File xml) throws EnunciateException { Document doc; try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(false); builderFactory.setValidating(false); DocumentBuilder builder = builderFactory.newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { //we don't want to validate or parse external dtds... return new InputSource(new StringReader("")); } }); doc = builder.parse(new FileInputStream(xml)); } catch (Exception e) { throw new EnunciateException("Error parsing " + xml, e); } NodeModel.simplify(doc); return NodeModel.wrap(doc.getDocumentElement()); }
Node child = children.item(i); if (child.hasChildNodes()) { simplify(child); prevTextChild = null; i++;
simplify(child, collectorTextChildBuff); } else { int type = child.getNodeType();
simplify(child, collectorTextChildBuff); } else { int type = child.getNodeType();
/** * Create a NodeModel from a SAX input source. Adjacent text nodes will be merged (and CDATA sections * are considered as text nodes). * @param removeComments whether to remove all comment nodes * (recursively) from the tree before processing * @param removePIs whether to remove all processing instruction nodes * (recursively from the tree before processing */ static public NodeModel parse(InputSource is, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); if (errorHandler != null) builder.setErrorHandler(errorHandler); Document doc = builder.parse(is); if (removeComments && removePIs) { simplify(doc); } else { if (removeComments) { removeComments(doc); } if (removePIs) { removePIs(doc); } mergeAdjacentText(doc); } return wrap(doc); }
/** * Same as {@link #parse(InputSource, boolean, boolean)}, but loads from a {@link File}; don't miss the security * warnings documented there. */ static public NodeModel parse(File f, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler); Document doc = builder.parse(f); if (removeComments && removePIs) { simplify(doc); } else { if (removeComments) { removeComments(doc); } if (removePIs) { removePIs(doc); } mergeAdjacentText(doc); } return wrap(doc); }
/** * Same as {@link #parse(InputSource, boolean, boolean)}, but loads from a {@link File}; don't miss the security * warnings documented there. */ static public NodeModel parse(File f, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler); Document doc = builder.parse(f); if (removeComments && removePIs) { simplify(doc); } else { if (removeComments) { removeComments(doc); } if (removePIs) { removePIs(doc); } mergeAdjacentText(doc); } return wrap(doc); }
simplify(doc); } else { if (removeComments) {
simplify(doc); } else { if (removeComments) {