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;
}
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;
}
}
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;
}
}
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;
}
}
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());
}
}
Aggregations