use of org.jdom.input.SAXBuilder in project beast-mcmc by beast-dev.
the class AbstractPolygon2D method readKMLFile.
public static List<AbstractPolygon2D> readKMLFile(String fileName) {
List<AbstractPolygon2D> polygons = new ArrayList<AbstractPolygon2D>();
try {
SAXBuilder builder = new SAXBuilder();
builder.setValidation(false);
builder.setIgnoringElementContentWhitespace(true);
Document doc = builder.build(new File(fileName));
Element root = doc.getRootElement();
if (!root.getName().equalsIgnoreCase("KML"))
throw new RuntimeException("Not a KML file");
readKMLElement(root, polygons);
} catch (IOException e) {
e.printStackTrace();
} catch (JDOMException e) {
e.printStackTrace();
}
return polygons;
}
use of org.jdom.input.SAXBuilder in project cas by apereo.
the class AbstractSamlObjectBuilder method constructDocumentFromXml.
/**
* Construct document from xml string.
*
* @param xmlString the xml string
* @return the document
*/
public static Document constructDocumentFromXml(final String xmlString) {
try {
final SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return builder.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
} catch (final Exception e) {
return null;
}
}
use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class XmlUtil method readXML.
public static Document readXML(File file) throws RuntimeException {
SAXBuilder builder = new SAXBuilder(false);
Document sDoc = null;
GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
builder.setErrorHandler(errorHandler);
try {
sDoc = builder.build(file);
// 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.input.SAXBuilder in project vcell by virtualcell.
the class XmlUtil method readXML.
// useful for the translators.
public static Document readXML(Reader reader, String schemaLocation, String parserClass, String schemaLocationPropName) throws RuntimeException {
SAXBuilder builder = null;
Document sDoc = null;
GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
try {
if (schemaLocation != null && schemaLocation.length() > 0) {
// ignores the parserClass, since xerces is the only validating parser we have
builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature("http://xml.org/sax/features/validation", true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setErrorHandler(errorHandler);
builder.setProperty(schemaLocationPropName, schemaLocation);
} else {
// ignore schemaLocationPropName
if (parserClass == null) {
// not necessarily 'xerces'
builder = new SAXBuilder(false);
} else {
builder = new SAXBuilder(parserClass, false);
}
builder.setErrorHandler(errorHandler);
}
sDoc = builder.build(reader);
// ----- 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.input.SAXBuilder in project vcell by virtualcell.
the class SBMLUtils method readXML.
public static Element readXML(Reader reader) throws IOException, SbmlException {
try {
SAXBuilder builder = new SAXBuilder(false);
Document sDoc = builder.build(reader);
Element root = sDoc.getRootElement();
return root;
} catch (JDOMException e) {
e.printStackTrace(System.out);
throw new SbmlException(e.getMessage());
}
}
Aggregations