use of org.jdom.JDOMException in project vcell by virtualcell.
the class XmlUtil method readXML.
public static Document readXML(InputStream inputStream) throws RuntimeException {
SAXBuilder builder = new SAXBuilder(false);
Document sDoc = null;
GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
builder.setErrorHandler(errorHandler);
try {
sDoc = builder.build(inputStream);
// Element root = null;
// root = sDoc.getRootElement();
// flush/replace previous error log with every read.
String errorHandlerLog = errorHandler.getErrorLog();
if (errorHandlerLog.length() > 0) {
System.out.println(errorHandlerLog);
XmlUtil.errorLog = errorHandlerLog;
} else {
XmlUtil.errorLog = "";
}
} catch (JDOMException e) {
e.printStackTrace();
throw new RuntimeException("source document is not well-formed\n" + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unable to read source document\n" + e.getMessage());
}
return sDoc;
}
use of org.jdom.JDOMException in project che by eclipse.
the class EffectivePomWriter method addMavenNamespace.
/**
* method from org.apache.maven.plugins.help.AbstractEffectiveMojo
* Add a Pom/Settings namespaces to the effective XML content.
*
* @param effectiveXml not null the effective POM or Settings
* @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
* @return the content of the root element, i.e. <project/> or <settings/> with the Maven namespace or
* the original <code>effective</code> if an error occurred.
* @see #POM_XSD_URL
* @see #SETTINGS_XSD_URL
*/
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(effectiveXml));
Element rootElement = document.getRootElement();
// added namespaces
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
}
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(document.getRootElement(), w);
return w.toString();
} catch (JDOMException e) {
return effectiveXml;
} catch (IOException e) {
return effectiveXml;
}
}
use of org.jdom.JDOMException in project voldemort by voldemort.
the class RestUtils method parseSerializerDefinition.
private static SerializerDefinition parseSerializerDefinition(String serializerInfoXml, String elementName) {
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(new StringReader(serializerInfoXml));
Element root = doc.getRootElement();
Element serializerElement = root.getChild(elementName);
return StoreDefinitionsMapper.readSerializer(serializerElement);
} catch (JDOMException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
use of org.jdom.JDOMException in project voldemort by voldemort.
the class ClusterMapper method readCluster.
@SuppressWarnings("unchecked")
public Cluster readCluster(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder(false);
Document doc = builder.build(input);
if (verifySchema) {
Validator validator = this.schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if (!root.getName().equals(CLUSTER_ELMT))
throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
String name = root.getChildText(CLUSTER_NAME_ELMT);
List<Zone> zones = new ArrayList<Zone>();
for (Element node : (List<Element>) root.getChildren(ZONE_ELMT)) zones.add(readZone(node));
List<Node> servers = new ArrayList<Node>();
for (Element node : (List<Element>) root.getChildren(SERVER_ELMT)) servers.add(readServer(node));
return new Cluster(name, servers, zones);
} catch (JDOMException e) {
throw new MappingException(e);
} catch (SAXException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
use of org.jdom.JDOMException in project voldemort by voldemort.
the class StoreDefinitionsMapper method readStore.
public static StoreDefinition readStore(Reader input) {
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(input);
Element root = doc.getRootElement();
return readStore(root);
} catch (JDOMException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
Aggregations