List of usage examples for javax.xml.parsers DocumentBuilderFactory setValidating
public void setValidating(boolean validating)
From source file:edu.internet2.middleware.shibboleth.common.config.SpringDocumentLoader.java
/** {@inheritDoc} */ public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); factory.setCoalescing(true);/*from ww w . j a v a2s . c om*/ factory.setIgnoringComments(true); factory.setNamespaceAware(true); factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new LoggingErrorHandler(log)); builder.setEntityResolver(new ClasspathResolver()); return builder.parse(inputSource); }
From source file:net.sf.commons.ssh.directory.Directory.java
private Document getDocument(String resource) throws ParserConfigurationException, SAXException, IOException { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setCoalescing(true); documentBuilderFactory.setIgnoringComments(true); documentBuilderFactory.setNamespaceAware(false); documentBuilderFactory.setValidating(false); final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.parse(Directory.class.getResource(resource).toString()); }
From source file:com.castlemock.web.mock.soap.model.project.service.CreateSoapPortsService.java
/** * The method creates ports based on provided definitions. * @param files Definitions used to create new ports. * @param generateResponse Boolean value for if a default response should be generated for each new operation * @return List of ports generated from the provided definitions. * @throws WSDLException Throws an WSDLException if WSDL parsing failed. *///from w w w . j a v a 2 s.c o m private List<SoapPortDto> createPorts(final List<File> files, final boolean generateResponse) throws WSDLException { try { final List<SoapPortDto> soapPorts = new ArrayList<>(); final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(false); documentBuilderFactory.setNamespaceAware(true); for (File file : files) { final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); final Document document = documentBuilder.parse(file); document.getDocumentElement().normalize(); final List<SoapPortDto> fileSoapPorts = getSoapPorts(document, generateResponse); soapPorts.addAll(fileSoapPorts); } return soapPorts; } catch (Exception e) { throw new IllegalArgumentException("Unable parse WSDL file", e); } }
From source file:com.connexta.arbitro.finder.impl.FileBasedPolicyFinderModule.java
/** * Private helper that tries to load the given file-based policy, and * returns null if any error occurs.// w ww . j a v a2 s .c om * * @param policyFile file path to policy * @param finder policy finder * @return <code>AbstractPolicy</code> */ private AbstractPolicy loadPolicy(String policyFile, PolicyFinder finder) { AbstractPolicy policy = null; InputStream stream = null; try { // create the factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setNamespaceAware(true); factory.setValidating(false); // create a builder based on the factory & try to load the policy DocumentBuilder db = factory.newDocumentBuilder(); stream = new FileInputStream(policyFile); Document doc = db.parse(stream); // handle the policy, if it's a known type Element root = doc.getDocumentElement(); String name = DOMHelper.getLocalName(root); if (name.equals("Policy")) { policy = Policy.getInstance(root); } else if (name.equals("PolicySet")) { policy = PolicySet.getInstance(root, finder); } } catch (Exception e) { // just only logs log.error("Fail to load policy : " + policyFile, e); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { log.error("Error while closing input stream"); } } } if (policy != null) { policies.put(policy.getId(), policy); } return policy; }
From source file:com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser.java
private DocumentBuilder newDocumentBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);/* w w w . j av a2 s . co m*/ dbf.setValidating(false); try { return dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
From source file:org.fcrepo.auth.xacml.FedoraPolicyFinderModule.java
/** * Creates a new policy or policy set object from the given policy node * * @param policyBinary/*ww w . j a va 2 s. c om*/ * @return */ private AbstractPolicy loadPolicy(final FedoraBinary policyBinary) { String policyName = "unparsed"; try { // create the factory final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setNamespaceAware(true); factory.setValidating(false); final DocumentBuilder db = factory.newDocumentBuilder(); // Parse the policy content final Document doc = db.parse(policyBinary.getContent()); // handle the policy, if it's a known type final Element root = doc.getDocumentElement(); final String name = root.getTagName(); policyName = PolicyUtil.getID(doc); if (name.equals("Policy")) { return Policy.getInstance(root); } else if (name.equals("PolicySet")) { return PolicySet.getInstance(root, finder); } else { // this isn't a root type that we know how to handle throw new Exception("Unknown root document type: " + name); } } catch (final Exception e) { LOGGER.error("Unable to parse policy from {}", policyName, e); } // a default fall-through in the case of an error return null; }
From source file:se.vgregion.incidentreport.pivotaltracker.impl.PivotalTrackerServiceImpl.java
protected List<TyckTillProjectData> getProjectData(InputStream xml) throws Exception { List<TyckTillProjectData> result = new ArrayList<TyckTillProjectData>(); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setValidating(false); docBuilderFactory.setNamespaceAware(false); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(xml); xml.close();// www .java 2 s .c o m NodeList projectNodes = doc.getElementsByTagName("project"); // System.out.println("antal projekt=" + projectNodes.getLength()); for (int s = 0; s < projectNodes.getLength(); s++) { Node projectNode = projectNodes.item(s); NodeList projectChildNodes = projectNode.getChildNodes(); TyckTillProjectData data = new TyckTillProjectData(); for (int i = 0; i < projectChildNodes.getLength(); i++) { Node projectAttributeNode = projectChildNodes.item(i); String nodeName = projectAttributeNode.getNodeName(); String nodeValue = projectAttributeNode.getTextContent(); short nodeType = projectAttributeNode.getNodeType(); if (nodeType == 1) { // System.out.println("node:" + nodeName + "=" + nodeValue); if ("id".equals(nodeName)) { data.setId(nodeValue); } else if ("name".equals(nodeName)) { data.setName(nodeValue); } else if ("memberships".equals(nodeName)) { NodeList mNodes = projectAttributeNode.getChildNodes(); for (int k = 0; k < mNodes.getLength(); k++) { Node mNode = mNodes.item(k);// membership NodeList mNodes2 = mNode.getChildNodes(); for (int m = 0; m < mNodes2.getLength(); m++) { Node maNode = mNodes2.item(m);// membership if (maNode.getNodeType() == 1) { if ("person".equals(maNode.getNodeName())) { data.addMember(maNode.getTextContent()); } else { // System.out.println(" fgfgf=" + // maNode.getNodeName()); } } } } } } } result.add(data); } return result; }
From source file:com.mediaworx.xmlutils.XmlHelper.java
/** * Creates and returns a document builder that is configured with the following options: * <ul>/* w ww.ja v a2s .c o m*/ * <li>don't validate</li> * <li>ignore comments</li> * <li>ignore content whitespace</li> * <li>convert CDATA nodes to text nodes</li> * <li>don't perform namespace processing</li> * <li>ignore DTDs</li> * </ul> * @return the DocumentBuilder * @throws ParserConfigurationException if for some reason the DocumentBuilder used to parse the XML can't be * initialized */ private DocumentBuilder getNonValidatingDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(false); documentBuilderFactory.setIgnoringComments(true); documentBuilderFactory.setIgnoringElementContentWhitespace(true); documentBuilderFactory.setCoalescing(true); documentBuilderFactory.setFeature("http://xml.org/sax/features/namespaces", false); documentBuilderFactory.setFeature("http://xml.org/sax/features/validation", false); documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); return documentBuilderFactory.newDocumentBuilder(); }
From source file:gov.va.ds4p.ds4pmobileportal.ui.eHealthExchange.java
private static Document loadDocument(String xmlString) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true);/* w w w. j ava 2 s . c o m*/ DocumentBuilder db = dbf.newDocumentBuilder(); InputSource source = new InputSource(new StringReader(xmlString)); Document doc = db.parse(source); return doc; }