use of javax.xml.parsers.ParserConfigurationException in project CloudStack-archive by CloudStack-extras.
the class VsmResponse method printResponse.
// Helper routine to check for the response received.
protected void printResponse() {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DOMImplementationLS ls = (DOMImplementationLS) docBuilder.getDOMImplementation();
LSSerializer lss = ls.createLSSerializer();
System.out.println(lss.writeToString(_docResponse));
} catch (ParserConfigurationException e) {
s_logger.error("Error parsing the repsonse : " + e.toString());
}
}
use of javax.xml.parsers.ParserConfigurationException in project CloudStack-archive by CloudStack-extras.
the class LibvirtStoragePoolXMLParser method parseStoragePoolXML.
public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) {
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(poolXML));
Document doc = builder.parse(is);
Element rootElement = doc.getDocumentElement();
String type = rootElement.getAttribute("type");
String uuid = getTagValue("uuid", rootElement);
String poolName = getTagValue("name", rootElement);
Element source = (Element) rootElement.getElementsByTagName("source").item(0);
String host = getAttrValue("host", "name", source);
String path = getAttrValue("dir", "path", source);
Element target = (Element) rootElement.getElementsByTagName("target").item(0);
String targetPath = getTagValue("path", target);
return new LibvirtStoragePoolDef(LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()), poolName, uuid, host, path, targetPath);
} catch (ParserConfigurationException e) {
s_logger.debug(e.toString());
} catch (SAXException e) {
s_logger.debug(e.toString());
} catch (IOException e) {
s_logger.debug(e.toString());
}
return null;
}
use of javax.xml.parsers.ParserConfigurationException in project zxing by zxing.
the class HtmlAssetTranslator method translateOneFile.
private static void translateOneFile(String language, Path targetHtmlDir, Path sourceFile, String translationTextTranslated) throws IOException {
Path destFile = targetHtmlDir.resolve(sourceFile.getFileName());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(sourceFile.toFile());
} catch (ParserConfigurationException pce) {
throw new IllegalStateException(pce);
} catch (SAXException sae) {
throw new IOException(sae);
}
Element rootElement = document.getDocumentElement();
rootElement.normalize();
Queue<Node> nodes = new LinkedList<>();
nodes.add(rootElement);
while (!nodes.isEmpty()) {
Node node = nodes.poll();
if (shouldTranslate(node)) {
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
nodes.add(children.item(i));
}
}
if (node.getNodeType() == Node.TEXT_NODE) {
String text = node.getTextContent();
if (!text.trim().isEmpty()) {
text = StringsResourceTranslator.translateString(text, language);
node.setTextContent(' ' + text + ' ');
}
}
}
Node translateText = document.createTextNode(translationTextTranslated);
Node paragraph = document.createElement("p");
paragraph.appendChild(translateText);
Node body = rootElement.getElementsByTagName("body").item(0);
body.appendChild(paragraph);
DOMImplementationRegistry registry;
try {
registry = DOMImplementationRegistry.newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
String fileAsString = writer.writeToString(document);
// Replace default XML header with HTML DOCTYPE
fileAsString = fileAsString.replaceAll("<\\?xml[^>]+>", "<!DOCTYPE HTML>");
Files.write(destFile, Collections.singleton(fileAsString), StandardCharsets.UTF_8);
}
use of javax.xml.parsers.ParserConfigurationException in project ACS by ACS-Community.
the class ScriptFilter method getFileMenuSaveStatusButton.
/**
* This method initializes FileMenuSaveStatusButton
* @return javax.swing.JMenuItem
*/
private JMenuItem getFileMenuSaveStatusButton() {
if (FileMenuSaveStatusButton == null) {
FileMenuSaveStatusButton = new JMenuItem();
FileMenuSaveStatusButton.setText("Save GUI status");
FileMenuSaveStatusButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showSaveDialog(cl.utfsm.samplingSystemUI.SamplingSystemGUI.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
String file = chooser.getSelectedFile().getAbsolutePath();
if (file.endsWith(".ssgst")) {
writeStatusFile(file);
} else {
writeStatusFile(file + ".ssgst");
}
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (TransformerException e1) {
e1.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
});
}
return FileMenuSaveStatusButton;
}
use of javax.xml.parsers.ParserConfigurationException in project midpoint by Evolveum.
the class XPathHolder method toElement.
public Element toElement(String elementNamespace, String localElementName) {
// TODO: is this efficient?
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder loader = factory.newDocumentBuilder();
return toElement(elementNamespace, localElementName, loader.newDocument());
} catch (ParserConfigurationException ex) {
throw new AssertionError("Error on creating XML document " + ex.getMessage());
}
}
Aggregations