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