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();
}
}
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;
}
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;
}
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);
}
}
Aggregations