Search in sources :

Example 66 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 67 with DocumentException

use of org.dom4j.DocumentException in project hibernate-orm by hibernate.

the class TestDataReader method read.

public List<TestDataElement> read(String fileName) {
    if (fileName == null) {
        throw new RuntimeException("Null testsuite-suite data file specified.");
    }
    List<TestDataElement> testDataElements = new ArrayList<TestDataElement>();
    SAXReader reader = new SAXReader();
    try {
        Document document = reader.read(getInputStream(fileName));
        addDataElements(document, testDataElements);
    } catch (DocumentException e) {
        throw new RuntimeException(e);
    }
    return testDataElements;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) ArrayList(java.util.ArrayList) Document(org.dom4j.Document)

Example 68 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)

Example 69 with DocumentException

use of org.dom4j.DocumentException in project cubrid-manager by CUBRID.

the class Parser method createDocument.

/**
	 * sqlmap 파일의 내용으로 XML Document를 생성한다.
	 *
	 * @param fileContent sqlmap 파일의 내용
	 * @return XML Document
	 */
private Document createDocument(String fileContent) throws Exception {
    SAXReader reader = new SAXReader(false);
    Document document = null;
    try {
        reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        fileContent = SqlMapParserUtil.replaceInvalidDtdUrl(fileContent);
        InputSource source = new InputSource(new StringReader(fileContent));
        document = reader.read(source);
    } catch (DocumentException e) {
        ExceptionUtils.printRootCauseStackTrace(e);
        throw new IllegalArgumentException("fail to parse source sqlMap file", e);
    }
    return document;
}
Also used : InputSource(org.xml.sax.InputSource) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader) Document(org.dom4j.Document)

Example 70 with DocumentException

use of org.dom4j.DocumentException in project tdi-studio-se by Talend.

the class AlfrescoOutputModelManager method removeModel.

/**
     * Removes an Alfresco model definition file.
     * 
     * @param oldModelFilePath
     * @throws AlfrescoOutputException
     */
public void removeModel(String oldModelFilePath) throws AlfrescoOutputException {
    if (!this.availableModels.remove(oldModelFilePath)) {
        //$NON-NLS-1$
        throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.notYetAdded"));
    }
    // parsing the model
    org.dom4j.Document modelDoc = null;
    try {
        modelDoc = new SAXReader().read(new File(oldModelFilePath));
    } catch (DocumentException dex) {
        throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + oldModelFilePath, dex);
    }
    Element modelElt = modelDoc.getRootElement();
    //$NON-NLS-1$
    Element namespacesElt = modelElt.element("namespaces");
    if (namespacesElt != null) {
        //$NON-NLS-1$
        List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
        for (Element namespace : namespaces) {
            //$NON-NLS-1$
            String namespacePrefix = namespace.attributeValue("prefix");
            this.availablePrefixToNamespaceMap.remove(namespacePrefix);
        }
    }
    //$NON-NLS-1$
    Element typesElt = modelElt.element("types");
    if (typesElt != null) {
        //$NON-NLS-1$
        List<Element> types = (List<Element>) typesElt.elements("type");
        this.availableTypes.removeAllAlfrescoModelElement(types);
    }
    //$NON-NLS-1$
    Element aspectsElt = modelElt.element("aspects");
    if (aspectsElt != null) {
        //$NON-NLS-1$
        List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
        this.availableAspects.removeAllAlfrescoModelElement(aspects);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) File(java.io.File)

Aggregations

DocumentException (org.dom4j.DocumentException)123 Document (org.dom4j.Document)80 SAXReader (org.dom4j.io.SAXReader)73 Element (org.dom4j.Element)51 IOException (java.io.IOException)45 File (java.io.File)27 InputStream (java.io.InputStream)21 StringReader (java.io.StringReader)15 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)10 XMLWriter (org.dom4j.io.XMLWriter)9 InputSource (org.xml.sax.InputSource)9 FileInputStream (java.io.FileInputStream)7 URL (java.net.URL)7 List (java.util.List)7 Node (org.dom4j.Node)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 FileNotFoundException (java.io.FileNotFoundException)5 Reader (java.io.Reader)5