Search in sources :

Example 71 with SAXBuilder

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);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) SAXBuilder(org.jdom2.input.SAXBuilder) EClass(org.eclipse.emf.ecore.EClass) Element(org.jdom2.Element) Document(org.jdom2.Document) URL(java.net.URL)

Example 72 with SAXBuilder

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));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) FileInputStream(java.io.FileInputStream)

Example 73 with SAXBuilder

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));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) StringReader(java.io.StringReader)

Example 74 with SAXBuilder

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);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 75 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document) IOException(java.io.IOException)

Aggregations

SAXBuilder (org.jdom2.input.SAXBuilder)134 Document (org.jdom2.Document)94 Element (org.jdom2.Element)55 IOException (java.io.IOException)33 JDOMException (org.jdom2.JDOMException)27 File (java.io.File)20 StringReader (java.io.StringReader)20 Test (org.junit.jupiter.api.Test)18 InputStream (java.io.InputStream)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 URL (java.net.URL)9 XMLOutputter (org.jdom2.output.XMLOutputter)8 Modification (com.thoughtworks.go.domain.materials.Modification)7 List (java.util.List)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputSource (org.xml.sax.InputSource)6 ParseException (java.text.ParseException)5 MCRPath (org.mycore.datamodel.niofs.MCRPath)5 BufferedInputStream (java.io.BufferedInputStream)4