List of usage examples for org.dom4j Element remove
boolean remove(Text text);
Text
if the node is an immediate child of this element. From source file:org.snipsnap.snip.XMLSnipExport.java
License:Open Source License
private static void storeSnips(XMLWriter xmlWriter, List snips, String filter, List ignoreElements, File fileStore) throws IOException { if (snips != null && snips.size() > 0) { SnipSerializer snipSerializer = SnipSerializer.getInstance(); Iterator snipListIterator = snips.iterator(); while (snipListIterator.hasNext()) { snipsnap.api.snip.Snip snip = (Snip) snipListIterator.next(); if (filter == null || !snip.getName().matches(filter)) { Element snipEl = snipSerializer.serialize(snip); if (null != ignoreElements) { Iterator filterIt = ignoreElements.iterator(); while (filterIt.hasNext()) { String el = (String) filterIt.next(); if (snipEl.element(el) != null) { snipEl.remove(snipEl.element(el)); }/*from ww w . j a v a2 s . c o m*/ } } storeAttachments(snipEl, fileStore); storeVersions(snipEl, snip); xmlWriter.write(snipEl); } getStatus().inc(); } } }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private void handleSpringXml(String targetFilePath, ProcessItem processItem, InputStream springInput, ExportFileResource osgiResource, boolean convertToBP, boolean convertImports) { File targetFile = new File(getTmpFolder() + PATH_SEPARATOR + targetFilePath); try {/*from w w w .j av a2s .co m*/ SAXReader saxReader = new SAXReader(); saxReader.setStripWhitespaceText(false); Document document = saxReader.read(springInput); Element root = document.getRootElement(); if (convertToBP) { if ("blueprint".equals(root.getName())) { formatSchemaLocation(root, false, false); InputStream inputStream = new ByteArrayInputStream(root.asXML().getBytes()); FilesUtils.copyFile(inputStream, targetFile); osgiResource.addResource(FileConstants.BLUEPRINT_FOLDER_NAME, targetFile.toURI().toURL()); return; } String bpPrefix = "bp"; int cnt = 0; while (root.getNamespaceForPrefix(bpPrefix) != null) { bpPrefix = "bp" + (++cnt); } root.setQName(QName.get("blueprint", bpPrefix, BLUEPRINT_NSURI)); } Namespace springCamelNsp = Namespace.get("camel", CAMEL_SPRING_NSURI); boolean addCamel = springCamelNsp.equals(root.getNamespaceForPrefix("camel")); formatSchemaLocation(root, convertToBP, addCamel); for (Iterator<?> i = root.elementIterator("import"); i.hasNext();) { Element ip = (Element) i.next(); Attribute resource = ip.attribute("resource"); URL path = dummyURL(resource.getValue()); for (ResourceDependencyModel resourceModel : RouteResourceUtil .getResourceDependencies(processItem)) { if (matches(path, resourceModel)) { IFile resourceFile = RouteResourceUtil.getSourceFile(resourceModel.getItem()); String cpUrl = adaptedClassPathUrl(resourceModel, convertImports); handleSpringXml(cpUrl, processItem, resourceFile.getContents(), osgiResource, convertImports, convertImports); resource.setValue(IMPORT_RESOURCE_PREFIX + cpUrl); } } if (convertImports) { i.remove(); } } if (CONVERT_CAMEL_CONTEXT) { if (CONVERT_CAMEL_CONTEXT_ALL) { moveNamespace(root, CAMEL_SPRING_NSURI, CAMEL_BLUEPRINT_NSURI); } else { Namespace blueprintCamelNsp = Namespace.get("camel", CAMEL_BLUEPRINT_NSURI); moveNamespace(root, springCamelNsp, blueprintCamelNsp); if (springCamelNsp.equals(root.getNamespaceForPrefix("camel"))) { root.remove(springCamelNsp); root.add(blueprintCamelNsp); } Namespace springCamelDefNsp = Namespace.get(CAMEL_SPRING_NSURI); Namespace blueprintCamelDefNsp = Namespace.get(CAMEL_BLUEPRINT_NSURI); for (Iterator<?> i = root.elementIterator("camelContext"); i.hasNext();) { Element cc = (Element) i.next(); if (springCamelDefNsp.equals(cc.getNamespace())) { moveNamespace(cc, springCamelDefNsp, blueprintCamelDefNsp); } } } } InputStream inputStream = new ByteArrayInputStream(root.asXML().getBytes()); FilesUtils.copyFile(inputStream, targetFile); osgiResource.addResource(adaptedResourceFolderName(targetFilePath, convertToBP), targetFile.toURI().toURL()); } catch (Exception e) { Logger.getAnonymousLogger().log(Level.WARNING, "Custom Spring to OSGi conversion failed. ", e); } finally { try { springInput.close(); } catch (IOException e) { Logger.getAnonymousLogger().log(Level.WARNING, "Unexpected File closing failure. ", e); } } }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private static void moveNamespace(Element treeRoot, Namespace oldNsp, Namespace newNsp) { if (treeRoot.getNamespace().equals(oldNsp)) { treeRoot.setQName(QName.get(treeRoot.getName(), newNsp)); treeRoot.remove(oldNsp); }/*from ww w.ja v a2 s.c om*/ moveNamespaceInChildren(treeRoot, oldNsp, newNsp); }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private static void moveNamespaceInChildren(Element treeRoot, Namespace oldNsp, Namespace newNsp) { for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) { Element e = (Element) i.next(); if (e.getNamespace().equals(oldNsp)) { e.setQName(QName.get(e.getName(), newNsp)); e.remove(oldNsp); }/*from www . j av a 2 s . c o m*/ moveNamespaceInChildren(e, oldNsp, newNsp); } }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private static void moveNamespace(Element treeRoot, String oldNspURI, String newNspURI) { Namespace oldNsp = treeRoot.getNamespace(); if (oldNspURI.equals(oldNsp.getURI())) { Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI); treeRoot.setQName(QName.get(treeRoot.getName(), newNsp)); treeRoot.remove(oldNsp); }/* w w w .jav a 2s .c om*/ moveNamespaceInChildren(treeRoot, oldNspURI, newNspURI); }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private static void moveNamespaceInChildren(Element treeRoot, String oldNspURI, String newNspURI) { for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) { Element e = (Element) i.next(); Namespace oldNsp = e.getNamespace(); if (oldNspURI.equals(oldNsp.getURI())) { Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI); e.setQName(QName.get(e.getName(), newNsp)); e.remove(oldNsp); }//ww w . j av a2s. c o m moveNamespaceInChildren(e, oldNspURI, newNspURI); } }
From source file:org.talend.core.utils.TemplateFileUtils.java
License:Open Source License
public static String handleAssemblyJobTemplate(String content, String launcher) throws DocumentException { if (launcher == null || launcher.equalsIgnoreCase(LAUNCHER_ALL)) { return content; }//w ww . j a v a 2 s .com ByteArrayInputStream source = new ByteArrayInputStream(content.getBytes()); SAXReader reader = new SAXReader(); Document doc = reader.read(source); Element root = doc.getRootElement(); Element files = root.element("files"); //$NON-NLS-1$ if (files == null) { return content; } for (Iterator j = files.elementIterator("file"); j.hasNext();) { //$NON-NLS-1$ Element file = (Element) j.next(); Element destName = file.element("destName"); //$NON-NLS-1$ if (launcher.equalsIgnoreCase(UNIX_ENVIRONMENT)) { if (destName.getStringValue().endsWith(WINDOWS_LAUNCHER)) { files.remove(file); } if (destName.getStringValue().endsWith(POWER_SHELL)) { files.remove(file); } } else if (launcher.equalsIgnoreCase(WINDOWS_ENVIRONMENT)) { if (destName.getStringValue().endsWith(UNIX_LAUNCHER)) { files.remove(file); } } } return root.asXML(); }
From source file:org.talend.mdm.ext.publish.util.SchemaProcessor.java
License:Open Source License
public static String transform2types(String infoXML) { String transformedXml = null; try {/*from w w w . j ava2 s .com*/ Document doc = DocumentHelper.parseText(infoXML); // first level only @SuppressWarnings("unchecked") List<Element> elements = doc.getRootElement().elements(); for (Iterator<Element> iterator = elements.iterator(); iterator.hasNext();) { Element element = (Element) iterator.next(); // remove concept element if (element.getQualifiedName().equals(elementID)) { Element parentElement = element.getParent(); if (parentElement != null) parentElement.remove(element); } } transformedXml = doc.asXML(); } catch (DocumentException e) { LOGGER.error(e.getLocalizedMessage(), e); return null; } catch (Exception e) { LOGGER.error(e.getLocalizedMessage(), e); return null; } return transformedXml; }
From source file:org.talend.mdm.webapp.base.server.util.XmlUtil.java
License:Open Source License
public static Document mergeDoc(Document mainDoc, Document subDoc, String contextPath) { org.dom4j.Element el = (org.dom4j.Element) mainDoc.selectSingleNode(contextPath); org.dom4j.Element root = subDoc.getRootElement(); List children = root.elements(); for (int i = 0; i < children.size(); i++) { org.dom4j.Element child = (org.dom4j.Element) children.get(i); root.remove(child); el.add(child);// w w w . j a v a 2 s. c om } return mainDoc; }
From source file:org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobJavaScriptsWSManager.java
License:Open Source License
/** * DOC x Comment method "genWebInfoForder". * /*from w ww . j a va2 s. com*/ * @param list */ private void editWSDDFile(ProcessItem processItem) { String projectName = getCorrespondingProjectName(processItem); String selectedProcessVersion = processItem.getProperty().getVersion(); if (!isMultiNodes() && this.getSelectedJobVersion() != null) { selectedProcessVersion = this.getSelectedJobVersion(); } String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem), selectedProcessVersion); String deployFileName = getTmpFolder() + PATH_SEPARATOR + projectName + PATH_SEPARATOR + jobFolderName + PATH_SEPARATOR + "deploy.wsdd"; //$NON-NLS-1$ String serverConfigFile = getTmpFolder() + PATH_SEPARATOR + "server-config.wsdd"; //$NON-NLS-1$ File deployFile = new File(deployFileName); if (!deployFile.exists()) { log.error(org.talend.repository.i18n.Messages.getString("JobJavaScriptsWSManager.errorMessage")); //$NON-NLS-1$ return; } // edit the server-config.wsdd file try { File wsddFile = new File(serverConfigFile); BufferedReader reader = new BufferedReader(new FileReader(wsddFile)); SAXReader saxReader = new SAXReader(); Document doc = saxReader.read(reader); BufferedReader wsdlreader = new BufferedReader(new FileReader(deployFile)); SAXReader wsdlsaxReader = new SAXReader(); Document wsdldoc = wsdlsaxReader.read(wsdlreader); Element wsdlroot = wsdldoc.getRootElement(); Element element = wsdlroot.element("service"); //$NON-NLS-1$ List<Element> elements = element.elements("arrayMapping"); //$NON-NLS-1$ for (Element item : elements) { Attribute attribute = item.attribute("qname"); //$NON-NLS-1$ item.remove(attribute); attribute.setValue(attribute.getValue().replaceFirst(">", "")); //$NON-NLS-1$ //$NON-NLS-2$ item.add(attribute); } Element root = doc.getRootElement(); List<Node> content = root.content(); for (int i = 0; i < content.size(); i++) { Node n = content.get(i); if (n instanceof Element) { if (n.getName().equals("transport")) { //$NON-NLS-1$ content.add(i - 1, element); break; } } } BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(serverConfigFile), "UTF-8")); //$NON-NLS-1$ OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter output = new XMLWriter(writer, format); output.write(doc); output.flush(); output.close(); } catch (Exception e) { ExceptionHandler.process(e); } }