/** * Same as {@link #parse(InputSource, boolean, boolean) parse(is, true, true)}; don't miss the security warnings * documented there. */ static public NodeModel parse(InputSource is) throws SAXException, IOException, ParserConfigurationException { return parse(is, true, true); }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(source, true, true)}, but loads from a {@link File}; * don't miss the security warnings documented there. */ static public NodeModel parse(File f) throws SAXException, IOException, ParserConfigurationException { return parse(f, true, true); }
/** * Performs the transformation. */ void transform() throws Exception { String templateName = ftlFile.getName(); Template template = cfg.getTemplate(templateName, locale); NodeModel rootNode = NodeModel.parse(inputFile); OutputStream outputStream = System.out; if (outputFile != null) { outputStream = new FileOutputStream(outputFile); } Writer outputWriter = new OutputStreamWriter(outputStream, encoding); try { template.process(null, outputWriter, null, rootNode); } finally { if (outputFile != null) outputWriter.close(); } }
@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; }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(is, true, true)}; don't miss the security warnings * documented there. */ static public NodeModel parse(InputSource is) throws SAXException, IOException, ParserConfigurationException { return parse(is, true, true); }
/** * Create a NodeModel from an XML file. By default, * all comments and processing instruction nodes are * stripped from the tree. */ static public NodeModel parse(File f) throws SAXException, IOException, ParserConfigurationException { return parse(f, true, true); }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(is, true, true)}; don't miss the security warnings * documented there. */ static public NodeModel parse(InputSource is) throws SAXException, IOException, ParserConfigurationException { return parse(is, true, true); }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(source, true, true)}, but loads from a {@link File}; * don't miss the security warnings documented there. */ static public NodeModel parse(File f) throws SAXException, IOException, ParserConfigurationException { return parse(f, true, true); }
/** * Create a NodeModel from an XML input source. By default, * all comments and processing instruction nodes are * stripped from the tree. */ static public NodeModel parse(InputSource is) throws SAXException, IOException, ParserConfigurationException { return parse(is, true, true); }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(source, true, true)}, but loads from a {@link File}; * don't miss the security warnings documented there. */ static public NodeModel parse(File f) throws SAXException, IOException, ParserConfigurationException { return parse(f, true, true); }
public static NodeModel loadXML(InputStream input) { if (input == null) { return null; } try { final InputSource source = new InputSource(input); return NodeModel.parse(source); } catch (Exception e) { e.printStackTrace(); // TODO: log return null; } }
public NodeModel getXmlNodeModel() { NodeModel nodeModel = null; try { nodeModel = NodeModel.parse(new InputSource(new StringReader(getXml()))); } catch (Throwable err) { logger.error(err); } return nodeModel; }
public NodeModel getXmlNodeModel() { NodeModel nodeModel = null; try { nodeModel = NodeModel.parse(new InputSource(new StringReader(getXml()))); } catch (Throwable err) { logger.error(err); } return nodeModel; }
/** * Performs the transformation. */ void transform() throws Exception { String templateName = ftlFile.getName(); Template template = cfg.getTemplate(templateName, locale); NodeModel rootNode = NodeModel.parse(inputFile); OutputStream outputStream = System.out; if (outputFile != null) { outputStream = new FileOutputStream(outputFile); } Writer outputWriter = new OutputStreamWriter(outputStream, encoding); try { template.process(null, outputWriter, null, rootNode); } finally { if (outputFile != null) outputWriter.close(); } }
/** * Performs the transformation. */ void transform() throws Exception { String templateName = ftlFile.getName(); Template template = cfg.getTemplate(templateName, locale); NodeModel rootNode = NodeModel.parse(inputFile); OutputStream outputStream = System.out; if (outputFile != null) { outputStream = new FileOutputStream(outputFile); } Writer outputWriter = new OutputStreamWriter(outputStream, encoding); try { template.process(null, outputWriter, null, rootNode); } finally { if (outputFile != null) outputWriter.close(); } }
/** * Performs the transformation. */ void transform() throws Exception { String templateName = ftlFile.getName(); Template template = cfg.getTemplate(templateName, locale); NodeModel rootNode = NodeModel.parse(inputFile); OutputStream outputStream = System.out; if (outputFile != null) { outputStream = new FileOutputStream(outputFile); } Writer outputWriter = new OutputStreamWriter(outputStream, encoding); try { template.process(null, outputWriter, null, rootNode); } finally { if (outputFile != null) outputWriter.close(); } }
/** * @return FreeMarker NodeModel for the XML content of this node, or null if no parsable XML found */ public NodeModel getXmlNodeModel() { try { return NodeModel.parse(new InputSource(new StringReader(getContent()))); } catch (Throwable err) { if (logger.isDebugEnabled()) logger.debug(err.getMessage(), err); return null; } }
/** * @return FreeMarker NodeModel for the XML content of this node, or null if no parsable XML found */ public NodeModel getXmlNodeModel() { try { return NodeModel.parse(new InputSource(new StringReader(getContent()))); } catch (Throwable err) { if (logger.isDebugEnabled()) logger.debug(err.getMessage(), err); return null; } }
/** * Converts an xml string to a freemarker node model * * @param xml String * * @return freemarker node model */ @ScriptMethod ( help="Converts an xml string to a freemarker node model", output="Freemarker node model" ) public NodeModel parseXMLNodeModel(@ScriptParameter(help="Input XML string") String xml) { try { return NodeModel.parse(new InputSource(new StringReader(xml))); } catch (Throwable err) { err.printStackTrace(); return null; } }