Java Code Examples for org.jdom2.Element#setNamespace()

The following examples show how to use org.jdom2.Element#setNamespace() . These examples are extracted from open source projects. 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 Project: n2o-framework   File: PersisterJdomUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void replaceNamespace(Element element, Namespace source, Namespace target) {
    if (target == null) return;
    if (element == null) return;
    if ((element.getNamespace() != null) && (element.getNamespace().equals(target))) return;
    if ((element.getNamespace() != null) && (!element.getNamespace().equals(source))) return;
    element.setNamespace(target);
    for (Object child : element.getChildren()) {
        if (child instanceof Element)
            replaceNamespace((Element) child, source, target);
    }
}
 
Example 2
Source Project: n2o-framework   File: IOProcessorImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Установить схему всем дочерним элементам
 *
 * @param element   элемент
 * @param namespace схема
 */
private void installNamespace(Element element, Namespace namespace) {
    if (element.getNamespace().equals(Namespace.NO_NAMESPACE)) {
        element.setNamespace(namespace);
        for (Object o : element.getChildren()) {
            Element child = (Element) o;
            installNamespace(child, namespace);
        }
    }
}
 
Example 3
Source Project: n2o-framework   File: IOProcessorImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Установить схему всем дочерним элементам
 *
 * @param element   элемент
 * @param namespace схема
 */
private void installNamespace(Element element, Namespace namespace, Namespace oldNamespace) {
    if (element.getNamespace().equals(oldNamespace)) {
        element.setNamespace(namespace);
        for (Object o : element.getChildren()) {
            Element child = (Element) o;
            installNamespace(child, namespace, oldNamespace);
        }
    }
}
 
Example 4
Source Project: yawl   File: YTask.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addDefaultValuesAsRequired(Document dataDoc) {
    if (dataDoc == null) return;
    Element dataElem = dataDoc.getRootElement();
    List<YParameter> outputParams = new ArrayList<YParameter>(
            _decompositionPrototype.getOutputParameters().values());
    Collections.sort(outputParams);
    for (int index = 0; index < outputParams.size(); index++) {
        YParameter param = outputParams.get(index);
        String defaultValue = param.getDefaultValue();
        if (! StringUtil.isNullOrEmpty(defaultValue)) {
            Element paramElem = dataElem.getChild(param.getPreferredName());

            // if there's no element, or it has with no content, add the default
            if (paramElem == null || paramElem.getContent().isEmpty()) {
                Element defElem = JDOMUtil.stringToElement(
                        StringUtil.wrap(defaultValue,
                                param.getPreferredName())).detach();
                defElem.setNamespace(dataElem.getNamespace());
                if (paramElem != null) {                     // insert content
                    paramElem.addContent(defElem.removeContent());
                }
                else {                                       // insert whole element
                    dataElem.addContent(index, defElem);
                }
            }
        }
    }
}
 
Example 5
Source Project: rome   File: Atom10Parser.java    License: Apache License 2.0 5 votes vote down vote up
private String parseTextConstructToString(final Element e) {

        String type = getAttributeValue(e, "type");
        if (type == null) {
            type = Content.TEXT;
        }

        String value = null;
        if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
            // XHTML content needs special handling
            final XMLOutputter outputter = new XMLOutputter();
            final List<org.jdom2.Content> contents = e.getContent();
            for (final org.jdom2.Content content : contents) {
                if (content instanceof Element) {
                    final Element element = (Element) content;
                    if (element.getNamespace().equals(getAtomNamespace())) {
                        element.setNamespace(Namespace.NO_NAMESPACE);
                    }
                }
            }
            value = outputter.outputString(contents);
        } else {
            // Everything else comes in verbatim
            value = e.getText();
        }

        return value;

    }
 
Example 6
Source Project: iaf   File: IbisXmlLayout.java    License: Apache License 2.0 5 votes vote down vote up
private void addNamespaces(Element element, Namespace namespace) {
	if (StringUtils.isEmpty(element.getNamespaceURI())) {
		element.setNamespace(namespace);
		List<Element> childList = element.getChildren();
		if (!childList.isEmpty()) {
			for (Element child : childList) {
				addNamespaces(child, namespace);
			}
		}
	}
}
 
Example 7
Source Project: iaf   File: XmlBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void addNamespaceRecursive(Element element, Namespace namespace) {
	if (StringUtils.isEmpty(element.getNamespaceURI())) {
		element.setNamespace(namespace);
		List<Element> childList = element.getChildren();
		if (!childList.isEmpty()) {
			for (Element child : childList) {
				addNamespaceRecursive(child, namespace);
			}
		}
	}
}