org.dom4j.CDATA Java Examples
The following examples show how to use
org.dom4j.CDATA.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementWrapper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void add(CDATA cdata) { element.add( cdata ); }
Example #2
Source File: ElementWrapper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public boolean remove(CDATA cdata) { return element.remove( cdata ); }
Example #3
Source File: Dom4jProxy.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void add(CDATA cdata) { target().add( cdata ); }
Example #4
Source File: Dom4jProxy.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public boolean remove(CDATA cdata) { return target().remove( cdata ); }
Example #5
Source File: XMLProperties.java From Openfire with Apache License 2.0 | 4 votes |
/** * 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> * <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 hierarchy, // 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 hierarchy // 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<>(); Iterator<Element> iter = element.elementIterator(childName); while (iter.hasNext()) { toRemove.add(iter.next()); } for (iter = toRemove.iterator(); iter.hasNext();) { element.remove(iter.next()); } // Add the new children. for (String value : values) { Element childElement = element.addElement(childName); if (value.startsWith("<![CDATA[")) { Iterator<Node> it = childElement.nodeIterator(); while (it.hasNext()) { Node node = it.next(); if (node instanceof CDATA) { childElement.remove(node); break; } } childElement.addCDATA(value.substring(9, value.length()-3)); } else { String propValue = value; // check to see if the property is marked as encrypted if (JiveGlobals.isPropertyEncrypted(name)) { propValue = JiveGlobals.getPropertyEncryptor().encrypt(value); childElement.addAttribute(ENCRYPTED_ATTRIBUTE, "true"); } childElement.setText(propValue); } } saveProperties(); // Generate event. Map<String, Object> params = new HashMap<>(); params.put("value", values); PropertyEventDispatcher.dispatchEvent(name, PropertyEventDispatcher.EventType.xml_property_set, params); }
Example #6
Source File: XMLProperties.java From Openfire with Apache License 2.0 | 4 votes |
/** * 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. * @return {@code true} if the property was correctly saved to file, otherwise {@code false} */ public synchronized boolean setProperty(String name, String value) { if (name == null) { return false; } if (!StringEscapeUtils.escapeXml10(name).equals(name)) { throw new IllegalArgumentException("Property name cannot contain XML entities."); } 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 hierarchy. Element element = document.getRootElement(); for (String aPropName : propName) { // If we don't find this part of the property in the XML hierarchy // 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 { String propValue = value; // check to see if the property is marked as encrypted if (JiveGlobals.isXMLPropertyEncrypted(name)) { propValue = JiveGlobals.getPropertyEncryptor(true).encrypt(value); element.addAttribute(ENCRYPTED_ATTRIBUTE, "true"); } element.setText(propValue); } // Write the XML properties to disk final boolean saved = saveProperties(); // Generate event. Map<String, Object> params = new HashMap<>(); params.put("value", value); PropertyEventDispatcher.dispatchEvent(name, PropertyEventDispatcher.EventType.xml_property_set, params); return saved; }