Java Code Examples for org.w3c.dom.Element#removeChild()

The following examples show how to use org.w3c.dom.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: IOUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static void removeNodeByAttributeValue(Document doc, String parentTag, String tagName, String attributeName, String value){
    NodeList parentNodes = doc.getElementsByTagName(parentTag);
    if (parentNodes.getLength() != 1) {
        log.warn("Not able or ambiguous to find element: " + parentTag);
        return;
    }

    Element parentElement = (Element) parentNodes.item(0);
    if (parentElement == null) {
        log.warn("Not able to find element: " + parentTag);
        return;
    }

    NodeList nodes = doc.getElementsByTagName(tagName);
    for (int i = 0; i < nodes.getLength(); i++){
        Node node = nodes.item(i).getAttributes().getNamedItem(attributeName);
        if (node.getTextContent().equals(value)){
            parentElement.removeChild(nodes.item(i));
            return;
        }
    }
}
 
Example 2
Source File: OpenImmo_1_2_2.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Remove &lt;provisionspflichtig&gt; elements.
 * <p>
 * OpenImmo 1.2.1 does not support &lt;provisionspflichtig&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException if xpath evaluation failed
 */
protected void removeProvisionspflichtigElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:provisionspflichtig",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}
 
Example 3
Source File: RemovePluginXMLAction.java    From walkmod-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doAction() throws Exception {
	Document document = provider.getDocument();
	Element rootElement = document.getDocumentElement();
	NodeList children = rootElement.getChildNodes();
	int childSize = children.getLength();
	for (int i = 0; i < childSize; i++) {
		Node childNode = children.item(i);
		if (childNode instanceof Element) {
			Element child = (Element) childNode;
			final String nodeName = child.getNodeName();
			if ("plugins".equals(nodeName)) {

				NodeList pluginNodes = child.getChildNodes();
				int modulesSize = pluginNodes.getLength();
				for (int j = 0; j < modulesSize; j++) {
					Node pluginNode = pluginNodes.item(j);
					if ("plugin".equals(pluginNode.getNodeName())) {
						Element aux = (Element) pluginNode;
						String groupId = aux.getAttribute("groupId");
						String artifactId = aux.getAttribute("artifactId");
						if (groupId.equals(pluginConfig.getGroupId())
								&& artifactId.equals(pluginConfig.getArtifactId())) {
							child.removeChild(aux);
							provider.persist();
							return;
						}
					}
				}

			}
		}
	}

}
 
Example 4
Source File: Ligacao.java    From brModelo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void ToXmlValores(Document doc, Element me) {
    super.ToXmlValores(doc, me);

    //remover Bounds.
    NodeList nl = me.getElementsByTagName("Bounds");
    me.removeChild(nl.item(0));

    me.appendChild(util.XMLGenerate.ValorBoolean(doc, "Inteligente", isInteligente()));

    if (!getForeColor().equals(Elementar.defaultColor)) {
        me.appendChild(util.XMLGenerate.ValorColor(doc, "ForeColor", getForeColor()));
    }
    me.appendChild(util.XMLGenerate.ValorInteger(doc, "Largura", (int) getLargura()));
    //me.appendChild(util.XMLGenerate.ValorInteger(doc, "Fator_Largura", (int)fator_largura));

    Element lig = doc.createElement("Ligacoes");
    util.XMLGenerate.AtributoRefFormElementar(lig, "PontaA", getFormaPontaA());
    util.XMLGenerate.AtributoRefFormElementar(lig, "PontaB", getFormaPontaB());
    me.appendChild(lig);

    Element sbPontos = doc.createElement("Pontos");
    for (PontoDeLinha pl : getPontos()) {
        sbPontos.appendChild(util.XMLGenerate.ValorPoint(doc, "Ponto", pl.getLocation()));
    }
    me.appendChild(sbPontos);
    
    PreCardinalidade card = getCard();
    if (card != null) {
        card.ToXlm(doc, me);
    }
}
 
Example 5
Source File: OpenImmo_1_2_5.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Remove unsupported children from all &lt;verwaltung_techn&gt; elements.
 * <p>
 * OpenImmo 1.2.4 does not support the following children for
 * &lt;verwaltung_techn&gt; elements: &lt;gruppen_kennung&gt;, &lt;master&gt;,
 * &lt;sprache&gt;
 * <p>
 * These elements are removed by this function.
 *
 * @param doc OpenImmo document in version 1.2.5
 * @throws JaxenException if xpath evaluation failed
 */
protected void removeVerwaltungTechnChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:verwaltung_techn/io:gruppen_kennung |" +
                    "/io:openimmo/io:anbieter/io:immobilie/io:verwaltung_techn/io:master |" +
                    "/io:openimmo/io:anbieter/io:immobilie/io:verwaltung_techn/io:sprache",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}
 
Example 6
Source File: ProjectXMLManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setModuleType(NbModuleType moduleType) {
    Element _confData = getConfData();
    Document doc = _confData.getOwnerDocument();

    Element standaloneEl = findElement(_confData, ProjectXMLManager.STANDALONE);
    if (standaloneEl != null && moduleType == NbModuleType.STANDALONE) {
        // nothing needs to be done - standalone is already set
        return;
    }

    Element suiteCompEl = findElement(_confData, ProjectXMLManager.SUITE_COMPONENT);
    if (suiteCompEl != null && moduleType == NbModuleType.SUITE_COMPONENT) {
        // nothing needs to be done - suiteCompEl is already set
        return;
    }

    if (suiteCompEl == null && standaloneEl == null && moduleType == NbModuleType.NETBEANS_ORG) {
        // nothing needs to be done - nb.org modules don't have any element
        return;
    }

    // Ok, we get here. So clean up....
    if (suiteCompEl != null) {
        _confData.removeChild(suiteCompEl);
    }
    if (standaloneEl != null) {
        _confData.removeChild(standaloneEl);
    }

    // ....and create element for new module type.
    Element newModuleType = createTypeElement(doc, moduleType);
    if (newModuleType != null) {
        _confData.insertBefore(newModuleType, findModuleDependencies(_confData));
    }
    project.putPrimaryConfigurationData(_confData);
}
 
Example 7
Source File: SamlSignatureTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void applyXSW8(Document document){
    Element evilAssertion = (Element) document.getElementsByTagNameNS(ASSERTION_NSURI.get(), "Assertion").item(0);
    Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
    Element assertion = (Element) evilAssertion.cloneNode(true);
    Element copiedSignature = (Element) assertion.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
    Assume.assumeThat("Assertion needs to be signed", copiedSignature, notNullValue());
    assertion.removeChild(copiedSignature);
    Element object = document.createElement("Object");
    originalSignature.appendChild(object);
    object.appendChild(assertion);
}
 
Example 8
Source File: OpenImmo_1_2_4.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Downgrade &lt;anhang&gt; elements to OpenImmo 1.2.3.
 * <p>
 * The options "QRCODE", "FILM", "FILMLINK" for the "gruppe" attribute of
 * &lt;anhang&gt; elements are not available in version 1.2.3.
 * <p>
 * The option "REMOTE" for the "location" attribute of
 * &lt;anhang&gt; elements is not available in version 1.2.3.
 * <p>
 * The the child element &lt;check&gt; of &lt;anhang&gt; elements is not
 * available in version 1.2.3.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException if xpath evaluation failed
 */
protected void downgradeAnhangElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:anhang | " +
                    "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String value = StringUtils.trimToNull(node.getAttribute("gruppe"));
        if ("QRCODE".equalsIgnoreCase(value))
            node.removeAttribute("gruppe");
        else if ("FILM".equalsIgnoreCase(value))
            node.removeAttribute("gruppe");
        else if ("FILMLINK".equalsIgnoreCase(value))
            node.removeAttribute("gruppe");

        value = StringUtils.trimToNull(node.getAttribute("location"));
        if ("REMOTE".equalsIgnoreCase(value))
            node.setAttribute("location", "EXTERN");

        List childNodes = XmlUtils.newXPath("io:check", doc)
                .selectNodes(node);
        for (Object childItem : childNodes) {
            node.removeChild((Node) childItem);
        }
    }
}
 
Example 9
Source File: OpenImmo_1_2_2.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Remove &lt;versteigerung&gt; elements.
 * <p>
 * OpenImmo 1.2.1 does not support &lt;versteigerung&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException if xpath evaluation failed
 */
protected void removeVersteigerungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:versteigerung",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}
 
Example 10
Source File: OpenImmo_1_2_5.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Remove &lt;anzahl_logia&gt; elements.
 * <p>
 * OpenImmo 1.2.4 does not support &lt;anzahl_logia&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.5
 * @throws JaxenException if xpath evaluation failed
 */
protected void removeAnzahlLogiaElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_logia",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}
 
Example 11
Source File: ReferenceHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
    // As with addRawReference, do a linear search through.
    for (Element testRefEl : XMLUtil.findSubElements(references)) {
        RawReference testRef = RawReference.create(testRefEl);
        String refID = testRef.getID();
        String refName = testRef.getForeignProjectName();
        if (escaped) {
            refID = getUsableReferenceID(testRef.getID());
            refName = getUsableReferenceID(testRef.getForeignProjectName());
        }
        if (refName.compareTo(foreignProjectName) > 0) {
            // searched past it
            return false;
        }
        if (refName.equals(foreignProjectName)) {
            if (refID.compareTo(id) > 0) {
                // again, searched past it
                return false;
            }
            if (refID.equals(id)) {
                // Key match, remove it.
                references.removeChild(testRefEl);
                return true;
            }
        }
    }
    // Searched through to the end and did not find it.
    return false;
}
 
Example 12
Source File: DOMObligationExpression.java    From XACML with MIT License 5 votes vote down vote up
public static boolean repair(Node nodeObligationExpression) throws DOMStructureException {
	Element elementObligationExpression	= DOMUtil.getElement(nodeObligationExpression);
	boolean result						= false;
	
	NodeList children	= elementObligationExpression.getChildNodes();
	int numChildren;
	if (children != null && (numChildren = children.getLength()) > 0) {
		for (int i = 0 ; i < numChildren ; i++) {
			Node child	= children.item(i);
			if (DOMUtil.isElement(child)) {
				if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_ATTRIBUTEASSIGNMENTEXPRESSION.equals(child.getLocalName())) {
					result	= DOMAttributeAssignmentExpression.repair(child) || result;
				} else {
					logger.warn("Unexpected element {}", child.getNodeName());
					elementObligationExpression.removeChild(child);
					result	= true;
				}
			}
		}
	}
	
	result					= DOMUtil.repairIdentifierAttribute(elementObligationExpression, XACML3.ATTRIBUTE_OBLIGATIONID, logger) || result;
	result					= DOMUtil.repairStringAttribute(elementObligationExpression, XACML3.ATTRIBUTE_FULFILLON, RuleEffect.DENY.getName(), logger) || result;
	
	String string			= DOMUtil.getStringAttribute(elementObligationExpression, XACML3.ATTRIBUTE_FULFILLON);
	RuleEffect ruleEffectType	= RuleEffect.getRuleEffect(string);
	if (ruleEffectType == null) {
		logger.warn("Setting invalid RuleEffect {} to {}", string, RuleEffect.DENY.getName());
		elementObligationExpression.setAttribute(XACML3.ATTRIBUTE_FULFILLON, RuleEffect.DENY.getName());
		result	= true;
	}
	
	return result;
}
 
Example 13
Source File: FeatureSplitter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
protected void adeGenericElement(Element element, Element parent, ElementDecl lastElement) {
	Schema schema = schemaHandler.getSchema(element.getNamespaceURI());

	if (schema != null) {
		ElementDecl tmp = schema.getElementDecl(element.getLocalName(), lastElement);
		if (tmp != null && 
				parent != null && 
				lastElement != null && 
				splitElement(tmp, parent) &&
				lastElement.hasXLinkAttribute()) {
			parent.setAttributeNS(XLinkModule.v3_1_1.getNamespaceURI(), "href", '#' + getAndSetGmlId(element));
			parent.removeChild(element);
			if (parent.getTextContent().trim().length() == 0)
				parent.setTextContent("");

			result.add(new ADEGenericElement(element));
		}

		lastElement = tmp;
	}

	NodeList nodeList = element.getChildNodes();

	List<Element> children = new ArrayList<Element>(nodeList.getLength());
	for (int i = 0; i < nodeList.getLength(); ++i) {
		Node node = nodeList.item(i);
		if (node.getNodeType() == Node.ELEMENT_NODE)
			children.add((Element)node);
	}			

	for (Element child : children)
		adeGenericElement((Element)child, element, lastElement);
}
 
Example 14
Source File: OpenImmo_1_2_0.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Remove &lt;bieterverfahren&gt; elements.
 * <p>
 * OpenImmo 1.1 does not support &lt;bieterverfahren&gt; elements.
 * <p>
 * Any occurences of these elements are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException if xpath evaluation failed
 */
protected void removeBieterverfahrenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:bieterverfahren",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}
 
Example 15
Source File: OverrideProcessor.java    From vespa with Apache License 2.0 5 votes vote down vote up
/**
 * Prune elements that are not matching our environment and region
 */
private void pruneNonMatching(Element parent, List<Element> children) {
    Iterator<Element> elemIt = children.iterator();
    while (elemIt.hasNext()) {
        Element child = elemIt.next();
        if ( ! matches(getInstances(child), getEnvironments(child), getRegions(child))) {
            parent.removeChild(child);
            elemIt.remove();
        }
    }
}
 
Example 16
Source File: DOMPolicySetCombinerParameter.java    From XACML with MIT License 5 votes vote down vote up
public static boolean repair(Node nodeCombinerParameter) throws DOMStructureException {
	Element elementPolicySetCombinerParameter	= DOMUtil.getElement(nodeCombinerParameter);
	boolean result								= false;
	
	NodeList children	= elementPolicySetCombinerParameter.getChildNodes();
	int numChildren;
	boolean sawAttributeValue	= false;
	if (children != null && (numChildren = children.getLength()) > 0) {
		for (int i = 0 ; i < numChildren ; i++) {
			Node child	= children.item(i);
			if (DOMUtil.isElement(child)) {
				if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_ATTRIBUTEVALUE.equals(child.getLocalName())) {
					if (sawAttributeValue) {
						logger.warn("Unexpected element {}", child.getNodeName());
						elementPolicySetCombinerParameter.removeChild(child);
						result	= true;
					} else {
						sawAttributeValue	= true;
						result				= DOMAttributeValue.repair(child) || result;
					}
				} else {
					logger.warn("Unexpected element {}", child.getNodeName());
					elementPolicySetCombinerParameter.removeChild(child);
					result	= true;
				}
			}
		}
	}
	if (!sawAttributeValue) {
		throw DOMUtil.newMissingElementException(elementPolicySetCombinerParameter, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE);
	}
	result	= DOMUtil.repairStringAttribute(elementPolicySetCombinerParameter, XACML3.ATTRIBUTE_PARAMETERNAME, "parameter", logger) || result;
	result	= DOMUtil.repairIdentifierAttribute(elementPolicySetCombinerParameter, XACML3.ATTRIBUTE_POLICYSETIDREF, logger) || result;
	return result;
}
 
Example 17
Source File: DOMAdvice.java    From XACML with MIT License 5 votes vote down vote up
/**
 * Repairs the given <code>Node</code> representing a XACML Advice element if possible.
 * 
 * @param nodeAdvice the <code>Node</code> to repair
 * @return true if the node was altered, else false
 * @throws DOMStructureException if an error occurred while repairing the <code>Node</code>
 */
public static boolean repair(Node nodeAdvice) throws DOMStructureException {
	Element elementAdvice	= DOMUtil.getElement(nodeAdvice);
	boolean result			= false;
	
	result					= result || DOMUtil.repairIdentifierAttribute(elementAdvice, XACML3.ATTRIBUTE_ADVICEID, logger);
	
	NodeList children	= elementAdvice.getChildNodes();
	int numChildren;
	if (children != null && (numChildren = children.getLength()) > 0) {
		for (int i = 0 ; i < numChildren ; i++) {
			Node child	= children.item(i);
			if (DOMUtil.isElement(child)) {
				if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) {
					if (XACML3.ELEMENT_ATTRIBUTEASSIGNMENT.equals(child.getLocalName())) {
						result	=  DOMAttributeAssignment.repair(child) || result;
					} else {
						logger.warn("Unexpected element {}", child.getNodeName());
						elementAdvice.removeChild(child);
						result	= true;
					}
				} else {
					logger.warn("Unexpected element {}", child.getNodeName());
					elementAdvice.removeChild(child);
					result	= true;
				}
			}
		}
	}
	return result;
}
 
Example 18
Source File: OpenImmoFeedbackDocument.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
@Override
public void setDocumentVersion(OpenImmoVersion version) {
    try {
        Document doc = this.getDocument();

        String currentVersion = StringUtils.trimToEmpty(XmlUtils
                .newXPath("/io:openimmo/io:uebertragung/@version", doc)
                .stringValueOf(doc));
        String[] ver = StringUtils.split(currentVersion, "/", 2);

        Element node = (Element) XmlUtils
                .newXPath("/io:openimmo_feedback/io:version", doc)
                .selectSingleNode(doc);

        // versions older then 1.2.4 do not support the <version> element
        if (OpenImmoVersion.V1_2_4.isNewerThen(version)) {
            if (node != null) {
                Element root = XmlUtils.getRootElement(doc);
                root.removeChild(node);
            }
            return;
        }

        if (node == null) {
            Element parentNode = (Element) XmlUtils
                    .newXPath("/io:openimmo_feedback", doc)
                    .selectSingleNode(doc);
            if (parentNode == null) {
                LOGGER.warn("Can't find an <openimmo_feedback> element in the document!");
                return;
            }
            node = doc.createElement("version");
            parentNode.insertBefore(node, parentNode.getFirstChild());
        }

        String newVersion = version.toReadableVersion();
        if (ver.length > 1) newVersion += "/" + ver[1];
        node.setTextContent(newVersion);
    } catch (JaxenException ex) {
        LOGGER.error("Can't evaluate XPath expression!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
    }
}
 
Example 19
Source File: EmbeddedDisplayWidget.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Create a GroupWidget for the border, with this EmbeddedDisplay inside the Group
 *  @param style
 */
private void createGroupWrapper(final Widget widget, final Element embedded_xml, final Style style)
{
    // Create a 'group' widget
    final Document doc = embedded_xml.getOwnerDocument();
    final Element group = doc.createElement(XMLTags.WIDGET);
    group.setAttribute(XMLTags.TYPE, GroupWidget.WIDGET_DESCRIPTOR.getType());

    // Set name, style, and copy location, .. from linking container
    XMLUtil.updateTag(group, XMLTags.NAME, widget.getName());
    XMLUtil.updateTag(group, GroupWidget.propStyle.getName(), Integer.toString(style.ordinal()));
    group.appendChild(doc.importNode(XMLUtil.getChildElement(embedded_xml, XMLTags.X), true));
    group.appendChild(doc.importNode(XMLUtil.getChildElement(embedded_xml, XMLTags.Y), true));
    group.appendChild(doc.importNode(XMLUtil.getChildElement(embedded_xml, XMLTags.WIDTH), true));
    group.appendChild(doc.importNode(XMLUtil.getChildElement(embedded_xml, XMLTags.HEIGHT), true));

    // IMPORTANT: Remove legacy border_style from this widget so when parsed again
    // there is no infinite loop creating more 'group' wrappers.
    Element el = XMLUtil.getChildElement(embedded_xml, "border_style");
    embedded_xml.removeChild(el);

    // Disable the 'custom' border, since the group wrapper now provides the border
    el = XMLUtil.getChildElement(embedded_xml, "border_width");
    if (el != null)
        embedded_xml.removeChild(el);

    // Update name
    XMLUtil.updateTag(embedded_xml, XMLTags.NAME, widget.getName() + "_Content");

    // Adjust X/Y to (0, 0)
    el = XMLUtil.getChildElement(embedded_xml, XMLTags.X);
    if (el != null)
        embedded_xml.removeChild(el);
    el = XMLUtil.getChildElement(embedded_xml, XMLTags.Y);
    if (el != null)
        embedded_xml.removeChild(el);

    // Adjust size to allow for the group's insets
    // .. which are not known until the group is represented.
    // Using a value that looked about right in tests.
    final int x_inset, y_inset;
    switch (style)
    {
    case NONE:   x_inset =  0;  y_inset =  0;  break;
    case LINE:   x_inset =  2;  y_inset =  2;  break;
    case TITLE:  x_inset =  2;  y_inset = 20;  break;
    case GROUP:
    default:     x_inset = 30;  y_inset = 30;  break;
    }
    XMLUtil.updateTag(embedded_xml, XMLTags.WIDTH, Integer.toString(widget.propWidth().getValue() - x_inset));
    XMLUtil.updateTag(embedded_xml, XMLTags.HEIGHT, Integer.toString(widget.propHeight().getValue() - y_inset));

    // Move this widget into the new group
    final Node parent = embedded_xml.getParentNode();
    parent.removeChild(embedded_xml);
    group.appendChild(embedded_xml);

    // .. and add that group to the parent
    parent.appendChild(group);

    // Debug the result
    // XMLUtil.dump(parent);
}
 
Example 20
Source File: XMLWriterTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testXHTMLIndent ()
{
  final XMLWriterSettings xs = XMLWriterSettings.createForXHTML ().setSerializeDocType (EXMLSerializeDocType.IGNORE);
  final String sINDENT = xs.getIndentationString ();

  final Document aDoc = XMLFactory.newDocument ("html", DOCTYPE_XHTML10_QNAME, DOCTYPE_XHTML10_URI);
  final Element aHead = (Element) aDoc.getDocumentElement ()
                                      .appendChild (aDoc.createElementNS (DOCTYPE_XHTML10_URI, "head"));
  aHead.appendChild (aDoc.createTextNode ("Hallo"));
  final Element aBody = (Element) aDoc.getDocumentElement ()
                                      .appendChild (aDoc.createElementNS (DOCTYPE_XHTML10_URI, "body"));
  final Element aPre = (Element) aBody.appendChild (aDoc.createElementNS (DOCTYPE_XHTML10_URI, "pre"));
  final Element aDiv = (Element) aPre.appendChild (aDoc.createElementNS (DOCTYPE_XHTML10_URI, "div"));
  aDiv.appendChild (aDoc.createTextNode ("pre formatted"));

  assertEquals ("<html xmlns=\"" +
                DOCTYPE_XHTML10_URI +
                "\">" +
                CRLF +
                sINDENT +
                "<head>Hallo</head>" +
                CRLF +
                sINDENT +
                "<body>" +
                CRLF +
                sINDENT +
                sINDENT +
                // pre not indented
                "<pre><div>pre formatted</div></pre>" +
                CRLF +
                sINDENT +
                "</body>" +
                CRLF +
                "</html>" +
                CRLF,
                XMLWriter.getNodeAsString (aDoc, xs));

  // Special handling with void element
  aPre.removeChild (aDiv);
  aPre.appendChild (aDoc.createElementNS (DOCTYPE_XHTML10_URI, "img"));

  assertEquals ("<html xmlns=\"" +
                DOCTYPE_XHTML10_URI +
                "\">" +
                CRLF +
                sINDENT +
                "<head>Hallo</head>" +
                CRLF +
                sINDENT +
                "<body>" +
                CRLF +
                sINDENT +
                sINDENT +
                // pre not indented
                "<pre><img /></pre>" +
                CRLF +
                sINDENT +
                "</body>" +
                CRLF +
                "</html>" +
                CRLF,
                XMLWriter.getNodeAsString (aDoc, xs));
}