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;
}
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;
}
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");
}
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;
}
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);
}
}
Aggregations