Search in sources :

Example 26 with XmlElement

use of org.eclipse.sapphire.modeling.xml.XmlElement in project liferay-ide by liferay.

the class QNamespaceValueBinding method write.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.modeling.ValuePropertyBinding#write(java.lang.String)
 */
@Override
public void write(String value) {
    String val = value;
    // System.out.println( "VALUE ___________________ " + val );
    XmlElement parent = xml(true);
    /*
		 * In some cases the parent node and the child nodes will be same, we need to
		 * ensure that we dont create them accidentally again
		 */
    // System.out.println( "QNamespaceValueBinding.write() - Parent local name:" +
    // parent.getLocalName() );
    XmlElement qNameElement = null;
    if (parent.getLocalName().equals(params[0])) {
        qNameElement = parent;
    } else {
        qNameElement = parent.getChildElement(params[0], true);
    }
    if ((qNameElement != null) && (val != null)) {
        // System.out.println( "QNamespaceValueBinding.write() - 1" );
        val = value.trim();
        org.w3c.dom.Element qnameDef = qNameElement.getDomNode();
        /*
			 * Check to ensure that the attribute is not added multiple times, check if the
			 * attribute already exist if yes remove it add add it afresh
			 */
        Attr oldQnsAttribute = qnameDef.getAttributeNode(PortletAppModelConstants.QNAME_NS_DECL);
        if (oldQnsAttribute == null) {
            // System.out.println( "QNamespaceValueBinding.write() - Attrib does not
            // exist");
            qnameDef.setAttributeNS(PortletAppModelConstants.XMLNS_NS_URI, PortletAppModelConstants.QNAME_NS_DECL, val);
        } else {
            // System.out.println( "QNamespaceValueBinding.write() - Attrib exist" );
            qnameDef.removeAttributeNode(oldQnsAttribute);
            qnameDef.setAttributeNS(PortletAppModelConstants.XMLNS_NS_URI, PortletAppModelConstants.QNAME_NS_DECL, val);
        }
    } else if ((qNameElement != null) && (val == null)) {
        qNameElement.remove();
    }
}
Also used : XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) Attr(org.w3c.dom.Attr)

Example 27 with XmlElement

use of org.eclipse.sapphire.modeling.xml.XmlElement in project liferay-ide by liferay.

the class TextNodeValueBinding method read.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.modeling.ValuePropertyBinding#read()
 */
@Override
public String read() {
    String value = null;
    XmlElement element = xml(false);
    if (element != null) {
        value = xml(true).getText();
        if (value != null) {
            value = value.trim();
        }
    }
    return value;
}
Also used : XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement)

Example 28 with XmlElement

use of org.eclipse.sapphire.modeling.xml.XmlElement in project liferay-ide by liferay.

the class PortletModelUtil method defineNS.

/**
 * @param domNode
 * @param namespaceURI
 * @param currValue
 * @return
 */
public static String defineNS(XmlElement element, QName currValueAsQName) {
    String qualifiedNodeValue = null;
    String namespaceURI = currValueAsQName.getNamespaceURI();
    String defaultPrefix = PortletAppModelConstants.DEFAULT_QNAME_PREFIX;
    Element domNode = element.getDomNode();
    boolean nsDefined = false;
    String currNodeValue = element.getText();
    Attr attrib = null;
    if ((currNodeValue != null) && (currNodeValue.indexOf(":") != -1)) {
        String name = PortletUtil.stripSuffix(currNodeValue);
        // Check if the NS is already declared
        attrib = domNode.getAttributeNode(String.format(PortletAppModelConstants.NS_DECL, name));
        if (attrib != null) {
            String nsURI = attrib.getValue();
            if (namespaceURI.equals(nsURI)) {
                nsDefined = true;
                defaultPrefix = name;
            } else {
                // only NS changed, update it and send the existing value
                attrib.setNodeValue(namespaceURI);
                return element.getText();
            }
        }
    }
    if (nsDefined) {
        if (attrib != null) {
            domNode.removeAttributeNode(attrib);
        }
    }
    // update the element
    String qualifiedName = String.format(PortletAppModelConstants.NS_DECL, defaultPrefix);
    Attr attr = domNode.getAttributeNodeNS(namespaceURI, defaultPrefix);
    if (attr == null) {
        domNode.setAttributeNS(namespaceURI, qualifiedName, namespaceURI);
    }
    qualifiedNodeValue = defaultPrefix + ":" + currValueAsQName.getLocalPart();
    return qualifiedNodeValue;
}
Also used : Element(org.w3c.dom.Element) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) Attr(org.w3c.dom.Attr)

Example 29 with XmlElement

use of org.eclipse.sapphire.modeling.xml.XmlElement in project liferay-ide by liferay.

the class WorkflowNodeMetadataResource method saveMetadata.

public void saveMetadata() {
    XmlResource xmlResource = parent().adapt(XmlResource.class);
    XmlElement xmlElement = xmlResource.getXmlElement();
    XmlElement metadataElement = xmlElement.getChildElement("metadata", true);
    Element domElement = metadataElement.getDomNode();
    try {
        Document document = domElement.getOwnerDocument();
        CDATASection cdata = document.createCDATASection(this._metadata.toJSONString());
        CoreUtil.removeChildren(domElement);
        domElement.insertBefore(cdata, null);
    } catch (JSONException jsone) {
        KaleoCore.logError(jsone);
    }
}
Also used : XmlResource(org.eclipse.sapphire.modeling.xml.XmlResource) CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) JSONException(org.json.JSONException) Document(org.w3c.dom.Document)

Aggregations

XmlElement (org.eclipse.sapphire.modeling.xml.XmlElement)29 Attr (org.w3c.dom.Attr)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 BeforeAfterFilterType (com.liferay.ide.hook.core.model.BeforeAfterFilterType)2 QName (javax.xml.namespace.QName)2 XmlResource (org.eclipse.sapphire.modeling.xml.XmlResource)2 Node (org.w3c.dom.Node)2 IOException (java.io.IOException)1 Locale (java.util.Locale)1 TransformerException (javax.xml.transform.TransformerException)1 Element (org.eclipse.sapphire.Element)1 Resource (org.eclipse.sapphire.Resource)1 XmlAttribute (org.eclipse.sapphire.modeling.xml.XmlAttribute)1 XmlNode (org.eclipse.sapphire.modeling.xml.XmlNode)1 JSONException (org.json.JSONException)1 CDATASection (org.w3c.dom.CDATASection)1