List of usage examples for javax.xml.parsers DocumentBuilderFactory setValidating
public void setValidating(boolean validating)
From source file:com.ikon.util.FormUtils.java
/** * Parse params.xml definitions//from w ww.jav a2s. c o m * * @return A List parameter elements. */ public static List<FormElement> parseReportParameters(InputStream is) throws ParseException { log.debug("parseReportParameters({})", is); List<FormElement> params = new ArrayList<FormElement>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); if (is != null) { Document doc = db.parse(is); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("report-parameters"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { NodeList nlField = nForm.getChildNodes(); params = parseField(nlField); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage(), e); } catch (SAXException e) { throw new ParseException(e.getMessage(), e); } catch (IOException e) { throw new ParseException(e.getMessage(), e); } log.debug("parseReportParameters: {}", params); return params; }
From source file:com.ikon.util.FormUtils.java
/** * Parse form.xml definitions/*from w w w.j a v a 2s .c o m*/ * * @return A Map with all the forms and its form elements. */ public static Map<String, List<FormElement>> parseWorkflowForms(InputStream is) throws ParseException { log.debug("parseWorkflowForms({})", is); Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); if (is != null) { Document doc = db.parse(is); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("workflow-form"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { String taskName = nForm.getAttributes().getNamedItem("task").getNodeValue(); NodeList nlField = nForm.getChildNodes(); List<FormElement> fe = parseField(nlField); forms.put(taskName, fe); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage(), e); } catch (SAXException e) { throw new ParseException(e.getMessage(), e); } catch (IOException e) { throw new ParseException(e.getMessage(), e); } log.debug("parseWorkflowForms: {}", forms); return forms; }
From source file:DOMImport.java
public void inandout(String infile1, String infile2, String outfile) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true); dbf.setNamespaceAware(true);// ww w. j ava2s .co m dbf.setIgnoringElementContentWhitespace(true); Document doc1 = null; Document doc2 = null; try { DocumentBuilder builder = dbf.newDocumentBuilder(); builder.setErrorHandler(new MyErrorHandler()); InputSource is1 = new InputSource(infile1); doc1 = builder.parse(is1); InputSource is2 = new InputSource(infile2); doc2 = builder.parse(is2); importName(doc1, doc2); FileOutputStream fos = new FileOutputStream(outfile); TreeToXML ttxml = new TreeToXML(); ttxml.write(fos, doc2); fos.close(); } catch (SAXException e) { System.exit(1); } catch (ParserConfigurationException e) { System.err.println(e); System.exit(1); } catch (IOException e) { System.err.println(e); System.exit(1); } }
From source file:org.npr.api.Client.java
public Node execute() throws ClientProtocolException, IOException, SAXException, ParserConfigurationException { InputStream data = download(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(false);/*from w w w .j a v a 2 s . c o m*/ if (data != null) { Document document = dbf.newDocumentBuilder().parse(data); return document.getDocumentElement(); } return null; }
From source file:com.ikon.util.FormUtils.java
/** * Parse PropertyGroups.xml definitions/*from w w w . java2s .co m*/ * * @return A Map with all the forms and its form elements. */ public static synchronized Map<PropertyGroup, List<FormElement>> parsePropertyGroupsForms(String pgForm) throws IOException, ParseException { log.debug("parsePropertyGroupsForms({})", pgForm); if (pGroups == null) { pGroups = new HashMap<PropertyGroup, List<FormElement>>(); FileInputStream fis = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); fis = new FileInputStream(pgForm); if (fis != null) { Document doc = db.parse(fis); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("property-group"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { PropertyGroup pg = new PropertyGroup(); Node item = nForm.getAttributes().getNamedItem("label"); if (item != null) pg.setLabel(item.getNodeValue()); item = nForm.getAttributes().getNamedItem("name"); if (item != null) pg.setName(item.getNodeValue()); item = nForm.getAttributes().getNamedItem("visible"); if (item != null) pg.setVisible(Boolean.valueOf(item.getNodeValue())); item = nForm.getAttributes().getNamedItem("readonly"); if (item != null) pg.setReadonly(Boolean.valueOf(item.getNodeValue())); NodeList nlField = nForm.getChildNodes(); List<FormElement> fe = parseField(nlField); pGroups.put(pg, fe); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage()); } catch (SAXException e) { throw new ParseException(e.getMessage()); } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(fis); } } log.debug("parsePropertyGroupsForms: {}", pGroups); return clonedPropertyGroups(); }
From source file:com.openkm.util.FormUtils.java
/** * Parse params.xml definitions/*from w w w . j a v a 2 s . c om*/ * * @return A List parameter elements. */ public static List<FormElement> parseReportParameters(InputStream is) throws ParseException { log.debug("parseReportParameters({})", is); long begin = System.currentTimeMillis(); List<FormElement> params = new ArrayList<FormElement>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); if (is != null) { Document doc = db.parse(is); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("report-parameters"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { NodeList nlField = nForm.getChildNodes(); params = parseField(nlField); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage(), e); } catch (SAXException e) { throw new ParseException(e.getMessage(), e); } catch (IOException e) { throw new ParseException(e.getMessage(), e); } log.trace("parseReportParameters.Time: {}", System.currentTimeMillis() - begin); log.debug("parseReportParameters: {}", params); return params; }
From source file:com.openkm.util.FormUtils.java
/** * Parse form.xml definitions//from w w w . j av a2 s . c om * * @return A Map with all the forms and its form elements. */ public static Map<String, List<FormElement>> parseWorkflowForms(InputStream is) throws ParseException { log.debug("parseWorkflowForms({})", is); long begin = System.currentTimeMillis(); Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); if (is != null) { Document doc = db.parse(is); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("workflow-form"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { String taskName = nForm.getAttributes().getNamedItem("task").getNodeValue(); NodeList nlField = nForm.getChildNodes(); List<FormElement> fe = parseField(nlField); forms.put(taskName, fe); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage(), e); } catch (SAXException e) { throw new ParseException(e.getMessage(), e); } catch (IOException e) { throw new ParseException(e.getMessage(), e); } log.trace("parseWorkflowForms.Time: {}", System.currentTimeMillis() - begin); log.debug("parseWorkflowForms: {}", forms); return forms; }
From source file:com.openkm.util.FormUtils.java
/** * Parse PropertyGroups.xml definitions// ww w . j a v a 2 s. c om * * @param pgDefFile Path to file where is the Property Groups definition. * @return A Map with all the forms and its form elements. */ public static synchronized Map<PropertyGroup, List<FormElement>> parsePropertyGroupsForms(String pgDefFile) throws IOException, ParseException { log.debug("parsePropertyGroupsForms({})", pgDefFile); if (pGroups == null) { long begin = System.currentTimeMillis(); pGroups = new HashMap<PropertyGroup, List<FormElement>>(); FileInputStream fis = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); fis = new FileInputStream(pgDefFile); if (fis != null) { Document doc = db.parse(fis); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("property-group"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { PropertyGroup pg = new PropertyGroup(); Node item = nForm.getAttributes().getNamedItem("label"); if (item != null) pg.setLabel(item.getNodeValue()); item = nForm.getAttributes().getNamedItem("name"); if (item != null) pg.setName(item.getNodeValue()); item = nForm.getAttributes().getNamedItem("visible"); if (item != null) pg.setVisible(Boolean.valueOf(item.getNodeValue())); item = nForm.getAttributes().getNamedItem("readonly"); if (item != null) pg.setReadonly(Boolean.valueOf(item.getNodeValue())); NodeList nlField = nForm.getChildNodes(); List<FormElement> fe = parseField(nlField); pGroups.put(pg, fe); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage()); } catch (SAXException e) { throw new ParseException(e.getMessage()); } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(fis); } log.trace("parsePropertyGroupsForms.Time: {}", System.currentTimeMillis() - begin); } log.debug("parsePropertyGroupsForms: {}", pGroups); return clonedPropertyGroups(); }
From source file:com.jaxio.celerio.output.XmlCodeFormatter.java
private Document parseXmlFile(String in) { try {//from ww w. j a v a2 s . com DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setExpandEntityReferences(false); // prevent dtd download... // http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references dbf.setFeature("http://xml.org/sax/features/namespaces", false); dbf.setFeature("http://xml.org/sax/features/validation", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder db = dbf.newDocumentBuilder(); // // prevent dtd download... // db.setEntityResolver(new EntityResolver() { // @Override // public InputSource resolveEntity(String publicId, String systemId) // throws SAXException, IOException { // return new InputSource(new StringReader("")); // } // }); // InputSource is = new InputSource(new StringReader(in)); return db.parse(is); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:it.unibas.spicy.persistence.xml.DAOXmlUtility.java
public org.w3c.dom.Document buildNewDOM() throws DAOException { org.w3c.dom.Document document = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); try {/*from w w w. j a v a 2 s. co m*/ DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException pce) { logger.error(pce); throw new DAOException(pce.getMessage()); } catch (DOMException doe) { logger.error(doe); throw new DAOException(doe.getMessage()); } return document; }