Search in sources :

Example 26 with DocumentException

use of org.dom4j.DocumentException in project Openfire by igniterealtime.

the class KrakenPlugin method getOptionsConfig.

/**
     * Returns the web global options, if it exists.
     *
     * @return XML document with the options config.
     */
public Document getOptionsConfig() {
    // Load any custom-defined servlets.
    File optConf = new File(this.pluginDirectory, "web" + File.separator + "WEB-INF" + File.separator + "options" + File.separator + "global.xml");
    Document optConfXML;
    try {
        FileReader reader = new FileReader(optConf);
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        optConfXML = xmlReader.read(reader);
    } catch (FileNotFoundException e) {
        // Non-existent: Return empty config
        optConfXML = DocumentHelper.createDocument();
        optConfXML.addElement("optionsconfig");
    } catch (DocumentException e) {
        // Bad config: Return empty config
        optConfXML = DocumentHelper.createDocument();
        optConfXML.addElement("optionsconfig");
    }
    return optConfXML;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) Document(org.dom4j.Document) File(java.io.File)

Example 27 with DocumentException

use of org.dom4j.DocumentException in project reflections by ronmamo.

the class XmlSerializer method read.

public Reflections read(InputStream inputStream) {
    Reflections reflections;
    try {
        Constructor<Reflections> constructor = Reflections.class.getDeclaredConstructor();
        constructor.setAccessible(true);
        reflections = constructor.newInstance();
    } catch (Exception e) {
        reflections = new Reflections(new ConfigurationBuilder());
    }
    try {
        Document document = new SAXReader().read(inputStream);
        for (Object e1 : document.getRootElement().elements()) {
            Element index = (Element) e1;
            for (Object e2 : index.elements()) {
                Element entry = (Element) e2;
                Element key = entry.element("key");
                Element values = entry.element("values");
                for (Object o3 : values.elements()) {
                    Element value = (Element) o3;
                    reflections.getStore().getOrCreate(index.getName()).put(key.getText(), value.getText());
                }
            }
        }
    } catch (DocumentException e) {
        throw new ReflectionsException("could not read.", e);
    } catch (Throwable e) {
        throw new RuntimeException("Could not read. Make sure relevant dependencies exist on classpath.", e);
    }
    return reflections;
}
Also used : ReflectionsException(org.reflections.ReflectionsException) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document) ReflectionsException(org.reflections.ReflectionsException) DocumentException(org.dom4j.DocumentException) Reflections(org.reflections.Reflections)

Example 28 with DocumentException

use of org.dom4j.DocumentException in project atlas by alibaba.

the class TPatchDiffResAPBuildTask method doAction.

@TaskAction
protected void doAction() throws IOException {
    manifestFile = getManifestFile();
    aaptOptions = getAaptOptions();
    diffResDir = getDiffResDir();
    resourceConfigs = getResourceConfigs();
    preferredDensity = getPreferredDensity();
    //TODO  minifyManifest
    File miniManifest = new File(packageOutputFile.getParentFile(), "AndroidManifest.xml");
    try {
        ManifestFileUtils.minifyManifest(manifestFile, miniManifest);
    } catch (DocumentException e) {
        throw new GradleException(e.getMessage());
    }
    File assetsFolder = new File(diffResDir, "assets");
    File resFolder = new File(diffResDir, "res");
    if (!assetsFolder.exists()) {
        assetsFolder.mkdirs();
    }
    if (!resFolder.exists()) {
        resFolder.mkdirs();
    }
    AaptPackageProcessBuilder aaptPackageCommandBuilder = new AaptPackageProcessBuilder(miniManifest, aaptOptions).setAssetsFolder(assetsFolder).setResFolder(resFolder).setLibraries(libraries).setPackageForR(packageForR).setResPackageOutput(packageOutputFile.getAbsolutePath()).setType(type).setDebuggable(debuggable).setPseudoLocalesEnabled(pseudoLocalesEnabled).setResourceConfigs(resourceConfigs).setSplits(splits).setPreferredDensity(preferredDensity);
    @NonNull AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(mergeBlameLogFolder);
    ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new AaptOutputParser(), getILogger()), new MergingLogRewriter(mergingLog, builder.getErrorReporter()));
    try {
        if (builder instanceof AtlasBuilder) {
            ((AtlasBuilder) builder).processResources(aaptPackageCommandBuilder, enforceUniquePackageName, processOutputHandler);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ProcessException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) MergingLog(com.android.ide.common.blame.MergingLog) AaptOutputParser(com.android.ide.common.blame.parser.aapt.AaptOutputParser) IOException(java.io.IOException) MergingLogRewriter(com.android.ide.common.blame.MergingLogRewriter) ProcessException(com.android.ide.common.process.ProcessException) AaptPackageProcessBuilder(com.android.builder.core.AaptPackageProcessBuilder) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DocumentException(org.dom4j.DocumentException) GradleException(org.gradle.api.GradleException) NonNull(com.android.annotations.NonNull) AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 29 with DocumentException

use of org.dom4j.DocumentException in project atlas by alibaba.

the class ManifestFileUtils method getApplicationId.

/**
     * 获取制定manifest文件的packageId
     *
     * @param manifestFile
     * @return
     */
public static String getApplicationId(File manifestFile) {
    SAXReader reader = new SAXReader();
    if (manifestFile.exists()) {
        // 读取XML文件
        Document document = null;
        try {
            document = reader.read(manifestFile);
            // 得到根节点
            Element root = document.getRootElement();
            String packageName = root.attributeValue("package");
            return packageName;
        } catch (DocumentException e) {
        }
    }
    return null;
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document)

Example 30 with DocumentException

use of org.dom4j.DocumentException in project springside4 by springside.

the class XmlMapperTest method assertXmlByDom4j.

/**
	 * 使用Dom4j验证Jaxb所生成XML的正确性.
	 */
private static void assertXmlByDom4j(String xml) {
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml);
    } catch (DocumentException e) {
        fail(e.getMessage());
    }
    Element user = doc.getRootElement();
    assertThat(user.attribute("id").getValue()).isEqualTo("1");
    Element interests = (Element) doc.selectSingleNode("//interests");
    assertThat(interests.elements()).hasSize(2);
    assertThat(((Element) interests.elements().get(0)).getText()).isEqualTo("movie");
}
Also used : DocumentException(org.dom4j.DocumentException) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Element(org.dom4j.Element) XmlElement(javax.xml.bind.annotation.XmlElement) Document(org.dom4j.Document)

Aggregations

DocumentException (org.dom4j.DocumentException)36 Document (org.dom4j.Document)20 SAXReader (org.dom4j.io.SAXReader)19 Element (org.dom4j.Element)13 IOException (java.io.IOException)8 StringReader (java.io.StringReader)8 File (java.io.File)7 ConfigException (com.zimbra.common.localconfig.ConfigException)4 ArrayList (java.util.ArrayList)4 LocalConfig (com.zimbra.common.localconfig.LocalConfig)3 ServiceException (com.zimbra.common.service.ServiceException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Server (com.zimbra.cs.account.Server)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 XMLWriter (org.dom4j.io.XMLWriter)2 LoginCms (afip.wsaa.wsdl.LoginCms)1 NonNull (com.android.annotations.NonNull)1 DirectoryInput (com.android.build.api.transform.DirectoryInput)1