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:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void removeExternalsFor(String pipelineName, String materialName) { Element material = material(pipelineName, materialName); if (material.attribute("checkexternals") != null) { material.remove(material.attribute("checkexternals")); }/* www . j a va2 s .co m*/ }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
private void removeAttribute(Element serverTag, String attributeName) { serverTag.remove(serverTag.attribute(attributeName)); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void createPipelineAsFirstPipelineInGroup(String pipelineName, String groupName) { Element groupContents = getGroup(groupName); ArrayList<Element> pipelines = new ArrayList<Element>(); while (groupContents.elementIterator().hasNext()) { Element pipelineElement = (Element) groupContents.elementIterator().next(); pipelines.add(pipelineElement);/*www .j a v a 2s . c om*/ groupContents.remove(pipelineElement); } createASimpleGitPipeline(pipelineName); for (Element e : pipelines) { groupContents.add(e); } }
From source file:com.thoughtworks.go.helper.ConfigFileFixture.java
License:Apache License
private static String addLicense(Document document, String user, String license) { Element server = (Element) document.selectSingleNode("/cruise/server"); Node oldLicense = server.selectSingleNode("./license"); if (oldLicense != null) { server.remove(oldLicense); }//from w w w . j a v a2 s . c o m server.add(new DefaultElement("license").addAttribute("user", user).addText(license)); return document.asXML(); }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath//from w w w . ja v a2s. co m * @param attributeName ???xpath */ @Override public XMLEditor removeAttribute(String xPath, final String attributeName) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { element.remove(element.attribute(attributeName)); return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath//from www .ja va2 s .c om * @param attributeNames key ?? value */ public XMLEditor removeAttributes(String xPath, final Set<String> attributeNames) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { for (String attributeName : attributeNames) { element.remove(element.attribute(attributeName)); } return element; } }); return this; }
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = element.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); Namespace namespace = attribute.getNamespace(); Namespace elementNamespace = element.getNamespace(); if (!namespace.hasContent() && elementNamespace.hasContent()) namespace = elementNamespace; // String prefix = namespace.getPrefix(); // System.err.println( "attribute: name=" + attribute.getName() + // "\t" + // "qualified name=" + attribute.getQualifiedName() + "\t" + // "ns prefix=" + namespace.getPrefix() + "\t" + // "ns uri=" + namespace.getURI() ); // String qualifiedName = attribute.getName(); // String name = qualifiedName; // if ( qualifiedName.startsWith( prefix + ":" ) ) { // name = qualifiedName.substring( prefix.length() + 1 ); // }/*from w w w . j ava2 s .c o m*/ String name = attribute.getName(); // Handle JPT attributes // if ( prefix.equals( talNamespacePrefix ) ) { if (TAL_NAMESPACE_URI.equals(namespace.getURI()) || (!strict && TAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) { // tal:define if (name.equals("define")) { expressions.define = attribute.getValue(); } // tal:condition else if (name.equals("condition")) { expressions.condition = attribute.getValue(); } // tal:repeat else if (name.equals("repeat")) { expressions.repeat = attribute.getValue(); } // tal:content else if (name.equals("content")) { expressions.content = attribute.getValue(); } // tal:replace else if (name.equals("replace")) { if (expressions.omitTag == null) { expressions.omitTag = ""; } expressions.content = attribute.getValue(); } // tal:attributes else if (name.equals("attributes")) { expressions.attributes = attribute.getValue(); } // tal:omit-tag else if (name.equals("omit-tag")) { expressions.omitTag = attribute.getValue(); } // error else { throw new PageTemplateException("unknown tal attribute: " + name); } } // else if ( prefix.equals( metalNamespacePrefix ) ) else if (METAL_NAMESPACE_URI.equals(namespace.getURI()) || (!strict && METAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) { // metal:use-macro if (name.equals("use-macro")) { expressions.useMacro = attribute.getValue(); } // metal:define-slot else if (name.equals("define-slot")) { expressions.defineSlot = attribute.getValue(); } // metal:define-macro else if (name.equals("define-macro")) { //System.out.println("Defining macro: " + attribute.getValue()); Element el = element.createCopy(); el.remove(attribute); macros.put(attribute.getValue(), new MacroImpl(el)); expressions.macro = true; } // metal:fill-slot else if (name.equals("fill-slot")) { // these are ignored here, as they don't affect processing // of current template, but are called from other templates } // error else { throw new PageTemplateException("unknown metal attribute: " + name); } } // Pass on all other attributes else { String nsURI = namespace.getURI(); // String qualifiedName = namespace.getPrefix() + ":" + name; attributes.addAttribute(nsURI, name, attribute.getQualifiedName(), "CDATA", attribute.getValue()); if (nsURI != "" && namespace != elementNamespace) { String prefix = namespace.getPrefix(); String qName = "xmlns:" + prefix; if (attributes.getIndex(qName) == -1) { // add xmlns for this attribute attributes.addAttribute("", prefix, qName, "CDATA", nsURI); } } // attributes.addAttribute( getNamespaceURIFromPrefix(prefix), // name, qualifiedName, "CDATA", attribute.getValue() ); } } return attributes; }
From source file:com.weibo.wesync.notify.xml.XMLProperties.java
License:Open Source License
/** * Sets a property to an array of values. Multiple values matching the same property * is mapped to an XML file as multiple elements containing each value. * For example, using the name "foo.bar.prop", and the value string array containing * {"some value", "other value", "last value"} would produce the following XML: * <pre>//from w w w. j a va 2 s .c om * <foo> * <bar> * <prop>some value</prop> * <prop>other value</prop> * <prop>last value</prop> * </bar> * </foo> * </pre> * * @param name the name of the property. * @param values the values for the property (can be empty but not null). */ public void setProperties(String name, List<String> values) { String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML heirarchy, // stopping one short. Element element = document.getRootElement(); for (int i = 0; i < propName.length - 1; i++) { // If we don't find this part of the property in the XML heirarchy // we add it as a new node if (element.element(propName[i]) == null) { element.addElement(propName[i]); } element = element.element(propName[i]); } String childName = propName[propName.length - 1]; // We found matching property, clear all children. List<Element> toRemove = new ArrayList<Element>(); Iterator iter = element.elementIterator(childName); while (iter.hasNext()) { toRemove.add((Element) iter.next()); } for (iter = toRemove.iterator(); iter.hasNext();) { element.remove((Element) iter.next()); } // Add the new children. for (String value : values) { Element childElement = element.addElement(childName); if (value.startsWith("<![CDATA[")) { Iterator it = childElement.nodeIterator(); while (it.hasNext()) { Node node = (Node) it.next(); if (node instanceof CDATA) { childElement.remove(node); break; } } childElement.addCDATA(value.substring(9, value.length() - 3)); } else { childElement.setText(StringEscapeUtils.escapeXml(value)); } } saveProperties(); // Generate event. Map<String, Object> params = new HashMap<String, Object>(); params.put("value", values); }
From source file:com.weibo.wesync.notify.xml.XMLProperties.java
License:Open Source License
/** * Sets the value of the specified property. If the property doesn't * currently exist, it will be automatically created. * * @param name the name of the property to set. * @param value the new value for the property. *///from w w w .j a v a2s . c o m public synchronized void setProperty(String name, String value) { if (!StringEscapeUtils.escapeXml(name).equals(name)) { throw new IllegalArgumentException("Property name cannot contain XML entities."); } if (name == null) { return; } if (value == null) { value = ""; } // Set cache correctly with prop name and value. propertyCache.put(name, value); String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML heirarchy. Element element = document.getRootElement(); for (String aPropName : propName) { // If we don't find this part of the property in the XML heirarchy // we add it as a new node if (element.element(aPropName) == null) { element.addElement(aPropName); } element = element.element(aPropName); } // Set the value of the property in this node. if (value.startsWith("<![CDATA[")) { Iterator it = element.nodeIterator(); while (it.hasNext()) { Node node = (Node) it.next(); if (node instanceof CDATA) { element.remove(node); break; } } element.addCDATA(value.substring(9, value.length() - 3)); } else { element.setText(value); } // Write the XML properties to disk saveProperties(); // Generate event. Map<String, Object> params = new HashMap<String, Object>(); params.put("value", value); }
From source file:com.weibo.wesync.notify.xml.XMLProperties.java
License:Open Source License
/** * Deletes the specified property./*from ww w. j av a 2s . co m*/ * * @param name the property to delete. */ public synchronized void deleteProperty(String name) { // Remove property from cache. propertyCache.remove(name); String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML heirarchy. Element element = document.getRootElement(); for (int i = 0; i < propName.length - 1; i++) { element = element.element(propName[i]); // Can't find the property so return. if (element == null) { return; } } // Found the correct element to remove, so remove it... element.remove(element.element(propName[propName.length - 1])); // .. then write to disk. saveProperties(); // Generate event. Map<String, Object> params = Collections.emptyMap(); }