/** * 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); }
DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler);
@SuppressWarnings("unchecked") @Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { String str = getString(0, arguments); if (CommonUtils.notEmpty(str)) { if (uninitialized) { try { DocumentBuilderFactory dbf = NodeModel.getDocumentBuilderFactory(); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false); dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); uninitialized = false; } catch (ParserConfigurationException e) { } } InputSource is = new InputSource(new StringReader(str)); try { return NodeModel.parse(is); } catch (SAXException | IOException | ParserConfigurationException e) { return null; } } return null; }
@SuppressWarnings("unchecked") @Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { String str = getString(0, arguments); if (CommonUtils.notEmpty(str)) { if (uninitialized) { try { DocumentBuilderFactory dbf = NodeModel.getDocumentBuilderFactory(); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false); dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); uninitialized = false; } catch (ParserConfigurationException e) { } } InputSource is = new InputSource(new StringReader(str)); try { return NodeModel.parse(is); } catch (SAXException | IOException | ParserConfigurationException e) { return null; } } return null; }
/** * Create a NodeModel from an XML file. * @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(File f, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); if (errorHandler != null) builder.setErrorHandler(errorHandler); Document doc = builder.parse(f); if (removeComments) { removeComments(doc); } if (removePIs) { removePIs(doc); } mergeAdjacentText(doc); return wrap(doc); }
/** * 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); }
DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler);
DocumentBuilder builder = getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler);