Search in sources :

Example 66 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project dq-easy-cloud by dq-open-cloud.

the class EcGenerateXmlMybatisBO method updateMybatisXmlData.

/**
 * 更新mybatis的xml数据
 *
 * @throws IOException
 * @throws JDOMException
 */
protected void updateMybatisXmlData(File generateFile) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(generateFile);
    // 获取根元素
    Element rootElement = doc.getRootElement();
    // 操作更新的数据
    doUpdateMybatisXmlData(rootElement);
    doXmlOutputter(doc, generateFile);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 67 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project dq-easy-cloud by dq-open-cloud.

the class XmlUtilsTest method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    // Document doc = token.build(new File("src/test.xml"));
    // Document doc = token.build(new FileInputStream("src/test.xml"));
    // Document doc = token.build(new FileReader("src/test.xml"));
    // Document doc = token.build(new URL("http://localhost:8080/jdomTest/test.xml"));
    Document doc = builder.build(EcSourceCodeRelativePath.RESOURCES + "\\test.xml");
    readXmlFile(doc);
// addXmlElement(doc);
// updateXmlElement(doc);
// deleteXmlElement(doc);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 68 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project dq-easy-cloud by dq-open-cloud.

the class XmlUtilsTest method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    // Document doc = token.build(new File("src/test.xml"));
    // Document doc = token.build(new FileInputStream("src/test.xml"));
    // Document doc = token.build(new FileReader("src/test.xml"));
    // Document doc = token.build(new URL("http://localhost:8080/jdomTest/test.xml"));
    Document doc = builder.build(EcSourceCodeRelativePath.RESOURCES + "\\test.xml");
    readXmlFile(doc);
// addXmlElement(doc);
// updateXmlElement(doc);
// deleteXmlElement(doc);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 69 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project archi by archimatetool.

the class RelationshipsMatrix method loadRelationships.

private void loadRelationships() {
    // URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_FILE);
    URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_FILE);
    // Load the JDOM Document from XML
    Document doc = null;
    try {
        doc = new SAXBuilder().build(url);
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }
    // Iterate through all "source" concepts
    for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_SOURCE)) {
        Element elementSource = (Element) object;
        // Source concept name
        String sourceName = elementSource.getAttributeValue(XML_ATTRIBUTE_CONCEPT);
        if (sourceName == null) {
            continue;
        }
        // Get EClass source from mapping
        EClass source = null;
        // Use "Relationship" as a generic super type
        if (sourceName.equals("Relationship")) {
            // $NON-NLS-1$
            source = IArchimatePackage.eINSTANCE.getArchimateRelationship();
        } else // Else use given class
        {
            source = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(sourceName);
        }
        if (source == null) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Couldn't find source " + sourceName);
            continue;
        }
        // Create a new list of type TargetMatrix
        List<TargetMatrix> matrixList = new ArrayList<TargetMatrix>();
        // Put it in the main matrix map
        matrixMap.put(source, matrixList);
        // Iterate through all child "target" concepts
        for (Object objectChild : elementSource.getChildren(XML_ELEMENT_TARGET)) {
            Element elementTarget = (Element) objectChild;
            // Target concept name
            String targetName = elementTarget.getAttributeValue(XML_ATTRIBUTE_CONCEPT);
            if (targetName == null) {
                continue;
            }
            EClass target = null;
            // Use "Relationship" as a generic super type
            if (targetName.equals("Relationship")) {
                // $NON-NLS-1$
                target = IArchimatePackage.eINSTANCE.getArchimateRelationship();
            } else // Else use given class
            {
                target = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(targetName);
            }
            if (target == null) {
                // $NON-NLS-1$
                System.err.println(getClass() + ": Couldn't find target " + targetName);
                continue;
            }
            // Create a new TargetMatrix and add it to the list
            TargetMatrix matrix = new TargetMatrix();
            matrixList.add(matrix);
            // Set target class
            matrix.targetClass = target;
            // Get relations string
            String relations = elementTarget.getAttributeValue(XML_ATTRIBUTE_RELATIONS);
            if (relations == null) {
                continue;
            }
            // Take each character and add the relationship from the mapping
            for (int i = 0; i < relations.length(); i++) {
                char key = relations.charAt(i);
                EClass relationship = relationsKeyMap.get(key);
                if (relationship != null) {
                    matrix.getRelationships().add(relationship);
                } else {
                    // $NON-NLS-1$
                    System.err.println(getClass() + ": Found unmapped key char: " + key);
                }
            }
        }
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) URL(java.net.URL) EClass(org.eclipse.emf.ecore.EClass)

Example 70 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project archi by archimatetool.

the class RelationshipsMatrix method loadKeyLetters.

private void loadKeyLetters() {
    // URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_KEYS_FILE);
    URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_KEYS_FILE);
    // Load the JDOM Document from XML
    Document doc = null;
    try {
        doc = new SAXBuilder().build(url);
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }
    for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_KEY)) {
        Element elementKey = (Element) object;
        String keyLetter = elementKey.getAttributeValue(XML_ATTRIBUTE_CHAR);
        if (keyLetter == null || keyLetter.length() != 1) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Key letter incorrect: " + keyLetter);
            continue;
        }
        String relationName = elementKey.getAttributeValue(XML_ATTRIBUTE_RELATIONSHIP);
        if (relationName == null) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Relationship name incorrect: " + relationName);
            continue;
        }
        EClass relationship = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(relationName);
        if (relationship == null) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Couldn't find relationship " + relationName);
            continue;
        }
        relationsKeyMap.put(keyLetter.charAt(0), relationship);
        relationsValueMap.put(relationship, keyLetter.charAt(0));
    }
}
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)

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