Search in sources :

Example 41 with Element

use of org.omegat.filters3.Element in project archi by archimatetool.

the class ViewpointManager method loadDefaultViewpointsFile.

/**
 * Load viewpoints from XML file
 */
void loadDefaultViewpointsFile() throws IOException, JDOMException {
    URL url = Platform.getBundle(BUNDLE_ID).getEntry(VIEWPOINTS_FILE);
    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 : SAXBuilder(org.jdom2.input.SAXBuilder) EClass(org.eclipse.emf.ecore.EClass) Element(org.jdom2.Element) Document(org.jdom2.Document) URL(java.net.URL)

Example 42 with Element

use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.

the class ServiceCatalogBuilder method build.

/**
 * Parses xml file to ServiceCatalog with Jdom
 *
 * @param xmlFile
 *            The instance of xml file
 * @return instance of ServiceCatalog
 */
public static ServiceCatalog build(final File xmlFile) {
    String fileName = xmlFile.getName().trim().toLowerCase();
    // remove suffix
    if (fileName.endsWith(Constants.XML_FILE_SUFFIX)) {
        fileName = fileName.substring(0, fileName.length() - Constants.XML_FILE_SUFFIX.length() - 1);
    } else {
        throw new IllegalArgumentException("API file is not xml format: " + fileName);
    }
    // filter name
    int separatorIndex = fileName.indexOf(Constants.NAME_STRING_SEPARATOR);
    if (separatorIndex == -1) {
        throw new IllegalArgumentException("API file name should split with " + Constants.NAME_STRING_SEPARATOR + " actually: " + fileName);
    }
    String serviceName = fileName.substring(0, separatorIndex);
    String version = fileName.substring(separatorIndex + 1, fileName.length());
    Document document;
    try {
        document = new SAXBuilder().build(xmlFile);
    } catch (Exception ex) {
        throw new IllegalArgumentException("Invalid XML file:\n " + xmlFile.getAbsolutePath(), ex);
    }
    if (document == null) {
        return null;
    }
    // Navigates to resource tag, it's a little tricky here, depends on structure of xml file completely.
    List<Element> resourceList = document.getRootElement().getChild(Constants.REST_NODE).getChild(Constants.RESOURCES_NODE).getChildren();
    // Navigates to element tag, it's a little tricky here, depends on structure of xml file completely.
    List<Element> elementList = document.getRootElement().getChild(Constants.DATA_NODE).getChild(Constants.DATA_SCHEMA_NODE).getChild(Constants.ELEMENTS_NODE).getChildren();
    return new ServiceCatalog(parseResource(resourceList), parseElement(elementList), serviceName, version);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 43 with Element

use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.

the class XmlDiff method compareXml.

/**
 * Compares two documents and outputs different part info.
 * <p>
 * 1. ignore sequence 2. ignore element text value 3. ignore xml comment element
 * </p>
 *
 * @param oldDocument
 *            The old xml document
 * @param newDocument
 *            The new xml document
 * @return
 *         The instance of diff
 */
public static Pair<String, String> compareXml(Document oldDocument, Document newDocument) {
    Element oldRootElement = oldDocument.getRootElement();
    Element newRootElement = newDocument.getRootElement();
    if (compareElement(oldRootElement, newRootElement)) {
        return null;
    }
    XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    return new Pair<String, String>(xmlOutputter.outputString(oldRootElement), xmlOutputter.outputString(newRootElement));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element)

Example 44 with Element

use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.

the class XmlDiffTest method testElementAdd.

@Test
public void testElementAdd() {
    Element oldElement = oldDocument.getRootElement().getChild("add").clone();
    Element newElement = newDocument.getRootElement().getChild("add").clone();
    boolean ret = XmlDiff.compareElement(oldElement, newElement);
    Assert.assertFalse(ret);
    Assert.assertEquals(oldElement.getChildren().size() + 1, newElement.getChildren().size());
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 45 with Element

use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.

the class XmlDiffTest method testSameElement.

@Test
public void testSameElement() {
    Element oldElement = oldDocument.getRootElement().getChild("same").clone();
    Element newElement = newDocument.getRootElement().getChild("same").clone();
    boolean ret = XmlDiff.compareElement(oldElement, newElement);
    Assert.assertTrue(ret);
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Aggregations

Element (org.jdom2.Element)1444 Document (org.jdom2.Document)242 Test (org.junit.Test)157 ArrayList (java.util.ArrayList)111 Attribute (org.jdom2.Attribute)106 IOException (java.io.IOException)76 File (java.io.File)71 JDOMException (org.jdom2.JDOMException)65 XMLOutputter (org.jdom2.output.XMLOutputter)54 List (java.util.List)51 SAXBuilder (org.jdom2.input.SAXBuilder)51 HashMap (java.util.HashMap)49 Test (org.junit.jupiter.api.Test)34 Map (java.util.Map)33 Node (gov.cms.qpp.conversion.model.Node)29 MCRException (org.mycore.common.MCRException)28 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 Namespace (org.jdom2.Namespace)25 XmlFile (jmri.jmrit.XmlFile)24