Java Code Examples for org.jdom.Element#removeChild()

The following examples show how to use org.jdom.Element#removeChild() . 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: DockingWindowManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a JDOM element object for saving the window managers state to XML.
 * @param rootXMLElement The root element to which to save XML data.
 */
public void saveToXML(Element rootXMLElement) {
	Element rootNodeElement = saveWindowingDataToXml();
	if (focusedPlaceholder != null) {
		rootNodeElement.setAttribute("FOCUSED_OWNER", focusedPlaceholder.getOwner());
		rootNodeElement.setAttribute("FOCUSED_NAME", focusedPlaceholder.getName());
		rootNodeElement.setAttribute("FOCUSED_TITLE", focusedPlaceholder.getTitle());
	}

	rootXMLElement.removeChild(rootNodeElement.getName());
	rootXMLElement.addContent(rootNodeElement);

	Element preferencesElement = savePreferencesToXML();
	rootXMLElement.removeChild(preferencesElement.getName());
	rootXMLElement.addContent(preferencesElement);
}
 
Example 2
Source File: XMLProperties.java    From jivejdon with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the specified property.
 * 
 * @param name
 *            the property to delete.
 */
public void deleteProperty(String name) {
	String[] propName = parsePropertyName(name);
	// Search for this property by traversing down the XML heirarchy.
	Element element = doc.getRootElement();
	for (int i = 0; i < propName.length - 1; i++) {
		element = element.getChild(propName[i]);
		// Can't find the property so return.
		if (element == null) {
			return;
		}
	}
	// Found the correct element to remove, so remove it...
	element.removeChild(propName[propName.length - 1]);

}
 
Example 3
Source File: Issue.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addTagValue(Element element) {
	@SuppressWarnings("unchecked")
	List<Element> subElems = element.getChildren();
	ArrayList<String> removeList = new ArrayList<String>();

	for (Element subElem : subElems) {
		String elementName = subElem.getName();
		if (isSameValueBefore(subElem)) {
			removeList.add(elementName);
		}
	}

	for (String name : removeList) {
		element.removeChild(name);
	}

	if (element.getChildren().size() > 0) {
		mTagRoot.addContent(element);
	}
}
 
Example 4
Source File: ModifyXMLFile.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	try {

		SAXBuilder builder = new SAXBuilder();

		Document doc = (Document) builder.build(ClassLoader
				.getSystemResource("file.xml"));
		Element rootNode = doc.getRootElement();

		// update staff id attribute
		Element staff = rootNode.getChild("staff");
		staff.getAttribute("id").setValue("2");

		// add new age element
		Element age = new Element("age").setText("28");
		staff.addContent(age);

		// update salary value
		staff.getChild("salary").setText("7000");

		// remove firstname element
		staff.removeChild("firstname");

		XMLOutputter xmlOutput = new XMLOutputter();

		// display nice nice
		xmlOutput.setFormat(Format.getPrettyFormat());
		xmlOutput.output(doc, new FileWriter("target/file.xml"));

		// xmlOutput.output(doc, System.out);

		System.out.println("File updated!");
	} catch (IOException io) {
		io.printStackTrace();
	} catch (JDOMException e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: WmsStoreCommands.java    From geoserver-shell with MIT License 5 votes vote down vote up
@CliCommand(value = "wmsstore modify", help = "Modify a WMS Store.")
public boolean modifyStore(
        @CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
        @CliOption(key = "store", mandatory = true, help = "The name") String store,
        @CliOption(key = "url", mandatory = false, help = "The capabilities url") String capabilitiesUrl,
        @CliOption(key = "maxconnections", mandatory = false, help = "The maximum number of connections") String maxConnections,
        @CliOption(key = "readtimeout", mandatory = false, help = "The read timeout") String readTimeout,
        @CliOption(key = "connecttimeout", mandatory = false, help = "The connect timeout") String connectTimeout,
        @CliOption(key = "enabled", mandatory = false, help = "Whether the store should be enabled") String enabled
) throws Exception {
    String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/wmsstores/" + URLUtil.encode(store) + ".xml";
    Element element = JDOMBuilder.buildElement(HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword()));
    element.removeChild("wmsLayers");
    if (enabled != null) {
        JDOMUtil.getOrAdd(element, "enabled").setText(enabled);
    }
    if (capabilitiesUrl != null) {
        JDOMUtil.getOrAdd(element, "capabilitiesURL").setText(capabilitiesUrl);
    }
    if (maxConnections != null) {
        JDOMUtil.getOrAdd(element, "maxConnections").setText(maxConnections);
    }
    if (readTimeout != null) {
        JDOMUtil.getOrAdd(element, "readTimeout").setText(readTimeout);
    }
    if (connectTimeout != null) {
        JDOMUtil.getOrAdd(element, "connectTimeout").setText(connectTimeout);
    }
    String content = JDOMUtil.toString(element);
    String response = HTTPUtils.putXml(url, content, geoserver.getUser(), geoserver.getPassword());
    return response != null;
}