Search in sources :

Example 71 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project intellij-community by JetBrains.

the class ValidateXmlActionHandler method createParser.

protected SAXParser createParser() throws SAXException, ParserConfigurationException {
    if (!needsDtdChecking() && !needsSchemaChecking() && !myForceChecking) {
        return null;
    }
    SAXParserFactory factory = new SAXParserFactoryImpl();
    boolean schemaChecking = false;
    if (hasDtdDeclaration()) {
        factory.setValidating(true);
    }
    if (needsSchemaChecking()) {
        factory.setValidating(true);
        factory.setNamespaceAware(true);
        //jdk 1.5 API
        try {
            factory.setXIncludeAware(true);
        } catch (NoSuchMethodError ignore) {
        }
        schemaChecking = true;
    }
    try {
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    } catch (Exception ignore) {
    }
    SAXParser parser = factory.newSAXParser();
    parser.setProperty(ENTITY_RESOLVER_PROPERTY_NAME, myXmlResourceResolver);
    try {
        parser.getXMLReader().setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    } catch (Exception ignore) {
    }
    if (schemaChecking) {
        // when dtd checking schema refs could not be validated @see http://marc.theaimsgroup.com/?l=xerces-j-user&m=112504202423704&w=2
        XMLGrammarPool grammarPool = getGrammarPool(myFile, myForceChecking);
        configureEntityManager(myFile, parser);
        parser.getXMLReader().setProperty(GRAMMAR_FEATURE_ID, grammarPool);
    }
    try {
        if (schemaChecking) {
            parser.setProperty(JAXPConstants.JAXP_SCHEMA_LANGUAGE, JAXPConstants.W3C_XML_SCHEMA);
            parser.getXMLReader().setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
            if (Boolean.TRUE.equals(Boolean.getBoolean(XmlResourceResolver.HONOUR_ALL_SCHEMA_LOCATIONS_PROPERTY_KEY))) {
                parser.getXMLReader().setFeature("http://apache.org/xml/features/honour-all-schemaLocations", true);
            }
            parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", Boolean.TRUE);
            parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/warn-on-duplicate-attdef", Boolean.TRUE);
        }
        parser.getXMLReader().setFeature("http://apache.org/xml/features/warn-on-duplicate-entitydef", Boolean.TRUE);
        parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/unparsed-entity-checking", Boolean.FALSE);
    } catch (SAXNotRecognizedException ex) {
        // it is possible to continue work with configured parser
        LOG.info("Xml parser installation seems screwed", ex);
    }
    return parser;
}
Also used : XMLGrammarPool(org.apache.xerces.xni.grammars.XMLGrammarPool) SAXParserFactoryImpl(org.apache.xerces.jaxp.SAXParserFactoryImpl) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 72 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getPolicyMap.

public static String getPolicyMap(String name) {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        Element get = doc.createElement("nf:get");
        doc.getDocumentElement().appendChild(get);
        Element filter = doc.createElement("nf:filter");
        filter.setAttribute("type", "subtree");
        get.appendChild(filter);
        // Create the show port-profile name <profile-name> command.
        Element show = doc.createElement("show");
        filter.appendChild(show);
        Element policyMap = doc.createElement("policy-map");
        show.appendChild(policyMap);
        Element nameNode = doc.createElement("name");
        nameNode.setTextContent(name);
        policyMap.appendChild(nameNode);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 73 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getUpdatePortProfile.

public static String getUpdatePortProfile(String name, SwitchPortMode mode, List<Pair<VsmCommand.OperationType, String>> params) {
    try {
        // Create the document and root element.
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        // Edit configuration command.
        Element editConfig = doc.createElement("nf:edit-config");
        doc.getDocumentElement().appendChild(editConfig);
        // Command to get into exec configure mode.
        Element target = doc.createElement("nf:target");
        Element running = doc.createElement("nf:running");
        target.appendChild(running);
        editConfig.appendChild(target);
        // Command to update the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(configPortProfileDetails(doc, name, mode, params));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating update port profile message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating update port profile message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 74 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getDeletePolicyMap.

public static String getDeletePolicyMap(String name) {
    try {
        // Create the document and root element.
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        // Edit configuration command.
        Element editConfig = doc.createElement("nf:edit-config");
        doc.getDocumentElement().appendChild(editConfig);
        // Command to get into exec configure mode.
        Element target = doc.createElement("nf:target");
        Element running = doc.createElement("nf:running");
        target.appendChild(running);
        editConfig.appendChild(target);
        // Command to create the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(deletePolicyMapDetails(doc, name));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating delete policy map message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating delete policy map message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 75 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project CloudStack-archive by CloudStack-extras.

the class VsmResponse method initialize.

protected void initialize() {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        docFactory.setNamespaceAware(true);
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        _docResponse = docBuilder.parse(new InputSource(new StringReader(_xmlResponse)));
        if (_docResponse != null) {
            parse(_docResponse.getDocumentElement());
        }
    } catch (ParserConfigurationException e) {
        s_logger.error("Error parsing the response : " + e.toString());
    } catch (SAXException e) {
        s_logger.error("Error parsing the response : " + e.toString());
    } catch (IOException e) {
        s_logger.error("Error parsing the response : " + e.toString());
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1353 SAXException (org.xml.sax.SAXException)975 IOException (java.io.IOException)891 Document (org.w3c.dom.Document)710 DocumentBuilder (javax.xml.parsers.DocumentBuilder)631 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)569 Element (org.w3c.dom.Element)372 InputSource (org.xml.sax.InputSource)246 NodeList (org.w3c.dom.NodeList)226 Node (org.w3c.dom.Node)210 SAXParser (javax.xml.parsers.SAXParser)175 TransformerException (javax.xml.transform.TransformerException)163 File (java.io.File)162 InputStream (java.io.InputStream)158 SAXParserFactory (javax.xml.parsers.SAXParserFactory)137 ByteArrayInputStream (java.io.ByteArrayInputStream)129 StringReader (java.io.StringReader)117 ArrayList (java.util.ArrayList)115 DOMSource (javax.xml.transform.dom.DOMSource)109 StreamResult (javax.xml.transform.stream.StreamResult)93