Search in sources :

Example 56 with Document

use of com.google.cloud.language.v1.Document in project ParadoxosModManager by ThibautSF.

the class MyXML method readSettingFile.

/**
 * @param file
 * @throws Exception
 */
public void readSettingFile(String file) throws Exception {
    SAXBuilder sxb = new SAXBuilder();
    File xml = new File(file);
    if (xml.exists()) {
        document = sxb.build(xml);
        root = document.getRootElement();
    } else {
        root = new Element(APP_SETTINGS);
        document = new Document(root);
    }
    this.file = file;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File)

Example 57 with Document

use of com.google.cloud.language.v1.Document in project xwiki-platform by xwiki.

the class DefaultEntityResourceActionLister method initialize.

@Override
public void initialize() throws InitializationException {
    // Parse the Struts config file (struts-config.xml) to extract all available actions
    List<String> actionNames = new ArrayList<>();
    SAXBuilder builder = new SAXBuilder();
    // Make sure we don't require an Internet Connection to parse the Struts config file!
    builder.setEntityResolver(new EntityResolver() {

        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
        }
    });
    // Step 1: Get a stream on the Struts config file if it exists
    InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
    if (strutsConfigStream != null) {
        // Step 2: Parse the Strust config file, looking for action names
        Document document;
        try {
            document = builder.build(strutsConfigStream);
        } catch (JDOMException | IOException e) {
            throw new InitializationException(String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
        }
        Element mappingElement = document.getRootElement().getChild("action-mappings");
        for (Element element : mappingElement.getChildren("action")) {
            // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
            // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
            // "name" element value.
            actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
        }
    }
    this.strutsActionNames = actionNames;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InitializationException(org.xwiki.component.phase.InitializationException) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader)

Example 58 with Document

use of com.google.cloud.language.v1.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 59 with Document

use of com.google.cloud.language.v1.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 60 with Document

use of com.google.cloud.language.v1.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)

Aggregations

Document (org.jdom2.Document)402 Element (org.jdom2.Element)249 Test (org.junit.Test)108 SAXBuilder (org.jdom2.input.SAXBuilder)94 IOException (java.io.IOException)73 File (java.io.File)57 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 ArrayList (java.util.ArrayList)24 DocType (org.jdom2.DocType)24 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 Document (com.google.cloud.language.v1.Document)21 MCRException (org.mycore.common.MCRException)21 HashMap (java.util.HashMap)20 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 InputStream (java.io.InputStream)18