use of org.dom4j.Document in project Openfire by igniterealtime.
the class PresenceManagerImpl method getLastPresenceStatus.
@Override
public String getLastPresenceStatus(User user) {
String username = user.getUsername();
String presenceStatus = null;
String presenceXML = offlinePresenceCache.get(username);
if (presenceXML == null) {
loadOfflinePresence(username);
}
presenceXML = offlinePresenceCache.get(username);
if (presenceXML != null) {
// If the cached answer is no data, return null.
if (presenceXML.equals(NULL_STRING)) {
return null;
}
// Otherwise, parse out the status from the XML.
try {
// Parse the element
Document element = DocumentHelper.parseText(presenceXML);
presenceStatus = element.getRootElement().elementTextTrim("status");
} catch (DocumentException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
return presenceStatus;
}
use of org.dom4j.Document in project atlas by alibaba.
the class ManifestFileUtils method updatePreProcessManifestFile.
/**
* 更新libManifest文件
*
* @param libManifestFile
* @param mainManifestFileObject param updateSdkVersion
*/
public static void updatePreProcessManifestFile(File libManifestFile, ManifestFileObject mainManifestFileObject, boolean updateSdkVersion) throws IOException, DocumentException {
if (!libManifestFile.exists()) {
return;
}
File orgManifestFile = new File(libManifestFile.getParentFile(), "AndroidManifest-org.xml");
if (orgManifestFile.exists()) {
return;
}
libManifestFile.renameTo(orgManifestFile);
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
// 读取XML文件
Document document = reader.read(orgManifestFile);
// 得到根节点
Element root = document.getRootElement();
if (updateSdkVersion) {
Element useSdkElement = root.element("uses-sdk");
if (null == useSdkElement) {
useSdkElement = root.addElement("uses-sdk");
}
if (null != useSdkElement) {
updateElement(useSdkElement, mainManifestFileObject.getUseSdkProperties());
}
}
// 先人工处理一下tools:remove和tools:replace规则,发现有些通过ManifestMerge不一定可以
Element applicationElement = root.element("application");
Map<String, String> replaceAttrs = mainManifestFileObject.getReplaceApplicationAttribute();
List<String> removeAttrs = mainManifestFileObject.getRemoveApplicationAttribute();
if (null != applicationElement) {
// 去除lib项目里的tools属性
List<Attribute> toRomoved = new ArrayList<Attribute>();
for (Attribute attribute : applicationElement.attributes()) {
if (attribute.getName().equals("replace") || attribute.getName().equals("remove")) {
// applicationElement.remove(attribute);
// applicationElement.attributes().remove(attribute);
toRomoved.add(attribute);
}
}
if (toRomoved.size() > 0) {
for (Attribute attribute : toRomoved) {
applicationElement.remove(attribute);
}
}
updateApplicationElement(applicationElement, replaceAttrs, removeAttrs);
}
//处理packageName TODO
String packageName = root.attributeValue("package");
if (StringUtils.isEmpty(packageName)) {
packageName = ManifestFileUtils.getPackage(orgManifestFile);
}
List<? extends Node> applicatNodes = root.selectNodes("//application");
for (Node node : applicatNodes) {
Element element = (Element) node;
Attribute attribute = element.attribute("name");
if (attribute != null) {
if (!attribute.getValue().startsWith(packageName)) {
attribute.setValue(packageName + attribute.getValue());
}
}
}
fillFullClazzName(root, packageName, "activity");
fillFullClazzName(root, packageName, "provider");
fillFullClazzName(root, packageName, "receiver");
fillFullClazzName(root, packageName, "service");
saveFile(document, format, libManifestFile);
}
use of org.dom4j.Document in project atlas by alibaba.
the class ManifestFileUtils method removeProvider.
public static void removeProvider(File androidManifestFile) throws IOException, DocumentException {
File backupFile = new File(androidManifestFile.getParentFile(), "AndroidManifest-backup.xml");
FileUtils.deleteQuietly(backupFile);
FileUtils.moveFile(androidManifestFile, backupFile);
// 声明写XML的对象
XMLWriter writer = null;
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
FileOutputStream fos = new FileOutputStream(androidManifestFile);
if (androidManifestFile.exists()) {
try {
// 读取XML文件
Document document = reader.read(backupFile);
// 得到根节点
Element root = document.getRootElement();
List<? extends Node> nodes = root.selectNodes("//provider");
for (Node node : nodes) {
Element element = (Element) node;
String name = element.attributeValue("name");
logger.info("[Remove Provider]" + name);
element.getParent().remove(element);
}
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
}
use of org.dom4j.Document in project atlas by alibaba.
the class ManifestFileUtils method postProcessManifests.
/**
* 对manifest做后续处理
*
* @param mainManifest
* @param libManifestMap
* @param baseBunfleInfoFile
* @param manifestOptions
*/
public static void postProcessManifests(File mainManifest, Map<String, File> libManifestMap, Multimap<String, File> libDependenciesMaps, File baseBunfleInfoFile, ManifestOptions manifestOptions, boolean addMultiDex, Set<String> remoteBundles) throws IOException, DocumentException {
File backupFile = new File(mainManifest.getParentFile(), "AndroidManifest-backup.xml");
FileUtils.deleteQuietly(backupFile);
FileUtils.moveFile(mainManifest, backupFile);
// 声明写XML的对象
XMLWriter writer = null;
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
FileOutputStream fos = new FileOutputStream(mainManifest);
if (mainManifest.exists()) {
try {
// 读取XML文件
Document document = reader.read(backupFile);
if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists()) {
addApplicationMetaData(document, libManifestMap, baseBunfleInfoFile, manifestOptions, remoteBundles);
}
if (null != manifestOptions && manifestOptions.isAddBundleLocation()) {
addBundleLocationToDestManifest(document, libManifestMap, libDependenciesMaps, manifestOptions);
}
if (null != manifestOptions && manifestOptions.isReplaceApplication()) {
replaceManifestApplicationName(document);
}
if ((null != manifestOptions && manifestOptions.isAddMultiDexMetaData()) || addMultiDex) {
addMultiDexMetaData(document);
}
if (null != manifestOptions && manifestOptions.isRemoveProvider()) {
removeProvider(document);
}
removeCustomLaunches(document, manifestOptions);
updatePermission(document, manifestOptions);
removeComments(document);
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
}
use of org.dom4j.Document in project tdi-studio-se by Talend.
the class HTMLDocGenerator method handleXMLFile.
/**
* Generates the xml file base on an instance of <code>ExportFileResource</code> and the temporary folder path.
*
* @param resource
* @param tempFolderPath
* @param version
*/
private void handleXMLFile(ExportFileResource resource, String tempFolderPath, String... version) throws Exception {
Item item = resource.getItem();
// Check if generate Job Extra / Stats&Logs Setting Info
if (item instanceof ProcessItem) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
generateExtraSetting = !mrProcessService.isMapReduceItem(item);
generateStatsLogsSetting = generateExtraSetting;
} else if (isRouteProcess(item)) {
generateStatsLogsSetting = generateExtraSetting = !isRouteProcess(item);
}
} else if (item instanceof JobletProcessItem) {
generateStatsLogsSetting = false;
}
targetConnectionMap = new HashMap<String, List>();
sourceConnectionMap = new HashMap<String, List>();
getSourceAndTargetConnection(item);
Document document = DocumentHelper.createDocument();
Element projectElement = generateProjectInfo(document);
Element jobElement = generateJobInfo(item, projectElement, version);
// This two element see feature 4162
generateContextInfo(item, jobElement);
generateJobSettingInfo(item, jobElement);
List<List> allList = seperateNodes(item);
if (allList == null || allList.size() != 3) {
return;
}
List<INode> allComponentsList = allList.get(0);
List<INode> internalNodeComponentsList = allList.get(1);
List<INode> externalNodeComponentsList = allList.get(2);
if (allComponentsList.size() > 0) {
// Generates information for 'Component List' part in exported HTML file.
generateAllComponentsSummaryInfo(item, jobElement, allComponentsList);
}
//$NON-NLS-1$
Element internalNodeElement = jobElement.addElement("internalNodeComponents");
//$NON-NLS-1$
Element externalNodeElement = jobElement.addElement("externalNodeComponents");
if (internalNodeComponentsList.size() > 0) {
InternalNodeComponentHandler internalNodeComponentHandler = new InternalNodeComponentHandler(this.picFilePathMap, internalNodeElement, internalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
// Generates internal node components information.
internalNodeComponentHandler.generateComponentInfo();
}
if (externalNodeComponentsList.size() > 0) {
ExternalNodeComponentHandler externalNodeComponentHandler = new ExternalNodeComponentHandler(this.picFilePathMap, externalNodeElement, externalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
// Generates external node components(tMap etc.) information.
externalNodeComponentHandler.generateComponentInfo();
}
// Generates all connection information(include internal node and external node).
EList connectionList = null;
if (item instanceof ProcessItem) {
connectionList = ((ProcessItem) item).getProcess().getConnection();
} else if (item instanceof JobletProcessItem) {
connectionList = (((JobletProcessItem) item).getJobletProcess().getConnection());
}
if (connectionList != null && connectionList.size() != 0) {
generateConnectionsInfo(jobElement, connectionList);
}
//$NON-NLS-1$
String versionPath = "_";
if (version != null && version.length == 1) {
versionPath = versionPath + version[0];
} else {
versionPath = versionPath + item.getProperty().getVersion();
}
String filePath = tempFolderPath + File.separatorChar + item.getProperty().getLabel() + versionPath + IHTMLDocConstants.XML_FILE_SUFFIX;
// This element see feature 4382
if (item instanceof ProcessItem) {
generateSourceCodeInfo((ProcessItem) item, jobElement);
}
XMLHandler.generateXMLFile(tempFolderPath, filePath, document);
}
Aggregations