Search in sources :

Example 86 with Document

use of com.google.cloud.documentai.v1beta2.Document 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 87 with Document

use of com.google.cloud.documentai.v1beta2.Document 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 88 with Document

use of com.google.cloud.documentai.v1beta2.Document 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 89 with Document

use of com.google.cloud.documentai.v1beta2.Document 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 90 with Document

use of com.google.cloud.documentai.v1beta2.Document in project ddf by codice.

the class KmlDocumentToJtsGeometryConverterTest method setupClass.

@BeforeClass
public static void setupClass() {
    InputStream stream = KmlDocumentToJtsGeometryConverterTest.class.getResourceAsStream("/kmlDocument.kml");
    Kml kml = Kml.unmarshal(stream);
    testKmlDocument = ((Document) kml.getFeature());
}
Also used : InputStream(java.io.InputStream) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Document(de.micromata.opengis.kml.v_2_2_0.Document) BeforeClass(org.junit.BeforeClass)

Aggregations

Document (org.jdom2.Document)559 Element (org.jdom2.Element)330 Test (org.junit.Test)170 SAXBuilder (org.jdom2.input.SAXBuilder)160 IOException (java.io.IOException)146 JDOMException (org.jdom2.JDOMException)94 File (java.io.File)84 XMLOutputter (org.jdom2.output.XMLOutputter)80 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)34 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)32 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)31 MCRContent (org.mycore.common.content.MCRContent)30 MCRObject (org.mycore.datamodel.metadata.MCRObject)30 MCRException (org.mycore.common.MCRException)28 InputStream (java.io.InputStream)27 StringReader (java.io.StringReader)26 Path (java.nio.file.Path)26 URL (java.net.URL)24