Search in sources :

Example 6 with XmlElement

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

the class QNameLocalPartValueBinding method write.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.modeling.ValuePropertyBinding#write(java.lang.String)
 */
@Override
public void write(String value) {
    String val = value;
    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( "QNameLocalPartValueBinding.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 = val != null ? value.trim() : StringPool.EMPTY;
        if (params.length == 2 && "localpart".equals(params[1])) {
            // update only local part
            // System.out.println( "VALUE
            // ___________________ " + val );
            String existingText = qNameElement.getText();
            if ((existingText != null) && (existingText.indexOf(":") != -1)) {
                String updatedLocalPart = existingText.substring(0, (existingText.indexOf(":") + 1));
                updatedLocalPart = updatedLocalPart + val;
                // System.out.println( "Updated value ___________________ " + updatedLocalPart
                // );
                qNameElement.setText(updatedLocalPart);
            } else {
                qNameElement.setText(PortletAppModelConstants.DEFAULT_QNAME_PREFIX + ":" + val);
            }
        } else {
            qNameElement.setText(PortletAppModelConstants.DEFAULT_QNAME_PREFIX + ":" + val);
        }
    }
}
Also used : XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement)

Example 7 with XmlElement

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

the class QNameLocalPartValueBinding method read.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.modeling.ValuePropertyBinding#read()
 */
@Override
public String read() {
    String value = null;
    XmlElement parent = xml(false);
    // Fix for Alias QName not displayed in list
    XmlElement qNameElement = null;
    if (parent.getLocalName().equals(params[0])) {
        qNameElement = parent;
    } else {
        qNameElement = parent.getChildElement(params[0], false);
    }
    if (qNameElement != null) {
        value = qNameElement.getText();
        if (value != null) {
            value = value.trim();
            value = PortletUtil.stripPrefix(value);
        }
    }
    return value;
}
Also used : XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement)

Example 8 with XmlElement

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

the class QNameTextNodeValueBinding method read.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.modeling.ValuePropertyBinding#read()
 */
@Override
public String read() {
    String value = null;
    XmlElement parent = xml(false);
    if (parent != null) {
        XmlElement qNamedElement = parent.getChildElement(this.params[0], false);
        if (qNamedElement != null) {
            Element domNode = qNamedElement.getDomNode();
            value = qNamedElement.getText();
            if (value != null) {
                String prefix = PortletUtil.stripSuffix(value.trim());
                Attr attrib = domNode.getAttributeNode(String.format(PortletAppModelConstants.NS_DECL, prefix));
                if (attrib != null) {
                    QName qname = new QName(attrib.getValue(), PortletUtil.stripPrefix(value));
                    value = qname.toString();
                }
            }
        }
    }
    return value;
}
Also used : QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) Attr(org.w3c.dom.Attr)

Example 9 with XmlElement

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

the class QNameValueBinding method getXmlNode.

@Override
public XmlNode getXmlNode() {
    XmlElement parent = xml();
    XmlElement element = parent.getChildElement(params[0], false);
    if (element != null) {
        return element;
    }
    return null;
}
Also used : XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement)

Example 10 with XmlElement

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

the class QNameValueBinding method write.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.modeling.ValuePropertyBinding#write(java.lang.String)
 */
@Override
public void write(String value) {
    XmlElement parent = xml(true);
    // System.out.println( "EventDefinitionValueBinding.write()" + parent );
    XmlElement qNameElement = parent.getChildElement(params[0], true);
    qNameElement.setChildNodeText(this.path, value, true);
    try {
        PortletModelUtil.printDocument(parent.getDomNode().getOwnerDocument(), System.out);
    } catch (IOException ioe) {
        PortletCore.logError(ioe);
    } catch (TransformerException te) {
        PortletCore.logError(te);
    }
}
Also used : XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

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