use of org.dom4j.Document in project Openfire by igniterealtime.
the class AdminConsole method addModel.
/**
* Adds XML stream to the tabs/sidebar model.
*
* @param name the name.
* @param in the XML input stream.
* @throws Exception if an error occurs when parsing the XML or adding it to the model.
*/
public static void addModel(String name, InputStream in) throws Exception {
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(in);
addModel(name, (Element) doc.selectSingleNode("/adminconsole"));
}
use of org.dom4j.Document in project Openfire by igniterealtime.
the class AdminConsole method rebuildModel.
/**
* Rebuilds the generated model.
*/
private static synchronized void rebuildModel() {
Document doc = DocumentFactory.getInstance().createDocument();
generatedModel = coreModel.createCopy();
doc.add(generatedModel);
// Add in all overrides.
for (Element element : overrideModels.values()) {
// See if global settings are overriden.
Element appName = (Element) element.selectSingleNode("//adminconsole/global/appname");
if (appName != null) {
Element existingAppName = (Element) generatedModel.selectSingleNode("//adminconsole/global/appname");
existingAppName.setText(appName.getText());
if (appName.attributeValue("plugin") != null) {
existingAppName.addAttribute("plugin", appName.attributeValue("plugin"));
}
}
Element appLogoImage = (Element) element.selectSingleNode("//adminconsole/global/logo-image");
if (appLogoImage != null) {
Element existingLogoImage = (Element) generatedModel.selectSingleNode("//adminconsole/global/logo-image");
existingLogoImage.setText(appLogoImage.getText());
if (appLogoImage.attributeValue("plugin") != null) {
existingLogoImage.addAttribute("plugin", appLogoImage.attributeValue("plugin"));
}
}
Element appLoginImage = (Element) element.selectSingleNode("//adminconsole/global/login-image");
if (appLoginImage != null) {
Element existingLoginImage = (Element) generatedModel.selectSingleNode("//adminconsole/global/login-image");
existingLoginImage.setText(appLoginImage.getText());
if (appLoginImage.attributeValue("plugin") != null) {
existingLoginImage.addAttribute("plugin", appLoginImage.attributeValue("plugin"));
}
}
Element appVersion = (Element) element.selectSingleNode("//adminconsole/global/version");
if (appVersion != null) {
Element existingVersion = (Element) generatedModel.selectSingleNode("//adminconsole/global/version");
if (existingVersion != null) {
existingVersion.setText(appVersion.getText());
if (appVersion.attributeValue("plugin") != null) {
existingVersion.addAttribute("plugin", appVersion.attributeValue("plugin"));
}
} else {
((Element) generatedModel.selectSingleNode("//adminconsole/global")).add(appVersion.createCopy());
}
}
// Tabs
for (Object o : element.selectNodes("//tab")) {
Element tab = (Element) o;
String id = tab.attributeValue("id");
Element existingTab = getElemnetByID(id);
// Simple case, there is no existing tab with the same id.
if (existingTab == null) {
// url of the first item.
if (tab.attributeValue("url") == null) {
Element firstItem = (Element) tab.selectSingleNode("//item[@url]");
if (firstItem != null) {
tab.addAttribute("url", firstItem.attributeValue("url"));
}
}
generatedModel.add(tab.createCopy());
} else // More complex case -- a tab with the same id already exists.
// In this case, we have to overrite only the difference between
// the two elements.
{
overrideTab(existingTab, tab);
}
}
}
}
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 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);
}
use of org.dom4j.Document in project tdi-studio-se by Talend.
the class HTMLDocGenerator method parseXml2HtmlPdf.
private List<URL> parseXml2HtmlPdf(String tempFolderPath, String jobName, String xslFilePath) throws Exception {
// clear the cache, maybe need improve it latter.
HTMLHandler.clearExternalNodeFileCache();
String htmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
String xmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, xmlFilePath, htmlFilePath, this.externalNodeHTMLMap);
// for pdf
File originalXmlFile = new File(xmlFilePath);
if (originalXmlFile.exists()) {
//$NON-NLS-1$
String pdfXmlPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
File pdfXmlFile = new File(pdfXmlPath);
if (pdfXmlFile.exists()) {
pdfXmlFile.delete();
}
FilesUtils.copyFile(originalXmlFile, pdfXmlFile);
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(pdfXmlPath);
//$NON-NLS-1$
Attribute attri = (Attribute) document.selectNodes("/project/job/preview/@picture").get(0);
//$NON-NLS-1$
attri.setValue(IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + jobName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX);
//$NON-NLS-1$
List attributeList = document.selectNodes("/project/job/externalNodeComponents/component/@preview");
for (int i = 0; i < attributeList.size(); i++) {
Attribute at = (Attribute) attributeList.get(i);
//$NON-NLS-1$
String externalValue = at.getValue().substring(at.getValue().indexOf("/") + 1);
//$NON-NLS-1$
String value = IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + externalValue;
at.setValue(value);
}
XMLHandler.generateXMLFile(tempFolderPath, pdfXmlPath, document);
HTMLHandler.clearExternalNodeFileCache();
//$NON-NLS-1$
String htmlPdfPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, pdfXmlPath, htmlPdfPath, this.externalNodeHTMLMap);
}
return getParsedUrl(tempFolderPath);
}
Aggregations