use of org.jdom2.input.SAXBuilder in project archi by archimatetool.
the class ViewpointManager method loadDefaultViewpointsFile.
/**
* Load viewpoints from XML file
*/
void loadDefaultViewpointsFile() throws IOException, JDOMException {
// Load localised file from bundle
// $NON-NLS-1$
URL url = FileLocator.find(Platform.getBundle(BUNDLE_ID), new Path("$nl$/" + VIEWPOINTS_FILE));
url = FileLocator.resolve(url);
Document doc = new SAXBuilder().build(url);
Element rootElement = doc.getRootElement();
for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) {
// $NON-NLS-1$
// $NON-NLS-1$
String id = xmlViewpoint.getAttributeValue("id");
if (id == null || "".equals(id)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank id for viewpoint");
continue;
}
// $NON-NLS-1$
Element xmlName = xmlViewpoint.getChild("name");
if (xmlName == null) {
// $NON-NLS-1$
System.err.println("No name element for viewpoint");
continue;
}
String name = xmlName.getText();
if (name == null || "".equals(name)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank name for viewpoint");
continue;
}
Viewpoint vp = new Viewpoint(id, name);
for (Element xmlConcept : xmlViewpoint.getChildren("concept")) {
// $NON-NLS-1$
String conceptName = xmlConcept.getText();
if (conceptName == null || "".equals(conceptName)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank concept name for viewpoint");
continue;
}
if (ELEMENTS_MAP.containsKey(conceptName)) {
addCollection(vp, conceptName);
} else {
EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName);
if (eClass != null) {
addConcept(vp, eClass);
} else {
// $NON-NLS-1$
System.err.println("Couldn't get eClass: " + conceptName);
}
}
}
VIEWPOINTS.put(id, vp);
}
}
use of org.jdom2.input.SAXBuilder in project archi by archimatetool.
the class JDOMUtils method readXMLFile.
/**
* Reads and returns a JDOM Document from file without Schema Validation
* @param file The XML File
* @return The JDOM Document or null if not found
* @throws JDOMException
* @throws IOException
*/
public static Document readXMLFile(File file) throws IOException, JDOMException {
SAXBuilder builder = new SAXBuilder();
setFeatures(builder);
// This allows UNC mapped locations to load
return builder.build(new FileInputStream(file));
}
use of org.jdom2.input.SAXBuilder in project archi by archimatetool.
the class JDOMUtils method readXMLString.
/**
* Reads and returns a JDOM Document from String without Schema Validation
* @param xmlString
* @return
* @throws JDOMException
* @throws IOException
*/
public static Document readXMLString(String xmlString) throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
setFeatures(builder);
return builder.build(new StringReader(xmlString));
}
use of org.jdom2.input.SAXBuilder in project k-9 by k9mail.
the class SettingsExporterTest method parseXML.
private Document parseXML(byte[] xml) throws Exception {
SAXBuilder builder = new SAXBuilder();
InputStream stream = new ByteArrayInputStream(xml);
return builder.build(stream);
}
use of org.jdom2.input.SAXBuilder in project pcgen by PCGen.
the class Initiative method loadINIT.
/**
* Perform initial loading
* @param initFile
* @param comp
*/
public void loadINIT(File initFile, PCGenMessageHandler comp) {
try {
SAXBuilder builder = new SAXBuilder();
Document character = builder.build(initFile);
loadFromDocument(character, comp);
} catch (Exception e) {
JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(this), "File load error: " + initFile.getName());
Logging.errorPrint("File Load Error" + initFile.getName());
Logging.errorPrint(e.getMessage(), e);
}
}
Aggregations