use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class PortletDescriptorHelper method doAddNewPortlet.
public IStatus doAddNewPortlet(IDOMDocument document, IDataModel model) {
// <portlet-app> element
Element rootElement = document.getDocumentElement();
// new <portlet> element
Element newPortletElement = document.createElement("portlet");
NodeUtil.appendChildElement(newPortletElement, "portlet-name", model.getStringProperty(PORTLET_NAME));
NodeUtil.appendChildElement(newPortletElement, "display-name", model.getStringProperty(DISPLAY_NAME));
NodeUtil.appendChildElement(newPortletElement, "portlet-class", getPortletClassText(model));
// add <init-param> elements as needed
List<ParamValue> initParams = (List<ParamValue>) model.getProperty(INIT_PARAMS);
for (ParamValue initParam : initParams) {
Element newInitParamElement = NodeUtil.appendChildElement(newPortletElement, "init-param");
NodeUtil.appendChildElement(newInitParamElement, "name", initParam.getName());
NodeUtil.appendChildElement(newInitParamElement, "value", initParam.getValue());
}
// expiration cache
NodeUtil.appendChildElement(newPortletElement, "expiration-cache", "0");
// supports node
Element newSupportsElement = NodeUtil.appendChildElement(newPortletElement, "supports");
NodeUtil.appendChildElement(newSupportsElement, "mime-type", "text/html");
for (String portletMode : ALL_PORTLET_MODES) {
if (model.getBooleanProperty(portletMode)) {
NodeUtil.appendChildElement(newSupportsElement, "portlet-mode", model.getPropertyDescriptor(portletMode).getPropertyDescription());
}
}
if (model.getBooleanProperty(CREATE_RESOURCE_BUNDLE_FILE)) {
// need to remove .properties off the end of the bundle_file_path
String bundlePath = model.getStringProperty(CREATE_RESOURCE_BUNDLE_FILE_PATH);
String bundleValue = bundlePath.replaceAll("\\.properties$", StringPool.EMPTY);
String validBuildValue = bundleValue.replaceAll("\\/", ".");
NodeUtil.appendChildElement(newPortletElement, "resource-bundle", validBuildValue);
}
// add portlet-info
Element newPortletInfoElement = NodeUtil.appendChildElement(newPortletElement, "portlet-info");
NodeUtil.appendChildElement(newPortletInfoElement, "title", model.getStringProperty(TITLE));
NodeUtil.appendChildElement(newPortletInfoElement, "short-title", model.getStringProperty(SHORT_TITLE));
NodeUtil.appendChildElement(newPortletInfoElement, "keywords", model.getStringProperty(KEYWORDS));
for (String roleName : DEFAULT_SECURITY_ROLE_NAMES) {
NodeUtil.appendChildElement(NodeUtil.appendChildElement(newPortletElement, "security-role-ref"), "role-name", roleName);
}
// check for event-definition elements
Node refNode = null;
String[] refElementNames = { "custom-portlet-mode", "custom-window-state", "user-attribute", "security-constraint", "resource-bundle", "filter", "filter-mapping", "default-namespace", "event-definition", "public-render-parameter", "listener", "container-runtime-option" };
for (int i = 0; i < refElementNames.length; i++) {
refNode = NodeUtil.findFirstChild(rootElement, refElementNames[i]);
if (refNode != null) {
break;
}
}
rootElement.insertBefore(newPortletElement, refNode);
// append a newline text node
rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
// format the new node added to the model;
FormatProcessorXML processor = new FormatProcessorXML();
processor.formatNode(newPortletElement);
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class PortletDescriptorHelper method doAddResourceBundle.
protected IStatus doAddResourceBundle(IDOMDocument document, String resourceBundle, String portletName) {
FormatProcessorXML processor = new FormatProcessorXML();
NodeList portletNameList = document.getElementsByTagName("portlet-name");
if ((portletNameList != null) && (portletNameList.getLength() > 0) && !CoreUtil.isNullOrEmpty(resourceBundle)) {
Node portletNameNode = null;
for (int i = 0; i < portletNameList.getLength(); i++) {
if (NodeUtil.getTextContent(portletNameList.item(i)).equals(portletName)) {
portletNameNode = portletNameList.item(i);
}
}
if (portletNameNode == null) {
return Status.CANCEL_STATUS;
}
Element newResourceBundleElement = null;
Node portlet = portletNameNode.getParentNode();
Node refNode = null;
Node supports = NodeUtil.findLastChild((Element) portlet, "supports");
if (supports != null) {
Node supportedLocale = NodeUtil.findLastChild((Element) portlet, "supported-locale");
if (supportedLocale != null) {
refNode = supportedLocale;
} else {
refNode = supports;
}
} else {
return Status.CANCEL_STATUS;
}
newResourceBundleElement = NodeUtil.insertChildElementAfter((Element) portlet, refNode, "resource-bundle", resourceBundle);
processor.formatNode(newResourceBundleElement);
}
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class LayoutTplDescriptorHelper method doAddLayoutTemplate.
public IStatus doAddLayoutTemplate(IDOMDocument document, IDataModel model) {
Element rootElement = document.getDocumentElement();
Element layoutTemplateElement = document.createElement("layout-template");
layoutTemplateElement.setAttribute("id", model.getStringProperty(LAYOUT_TEMPLATE_ID));
layoutTemplateElement.setAttribute("name", model.getStringProperty(LAYOUT_TEMPLATE_NAME));
// find the <custom> element and if it doesn't exist create it
Node customElement = NodeUtil.getFirstNamedChildNode(rootElement, "custom");
if (customElement == null) {
// if we are going to create a new <custom> it must be after the <standard>
Node standardElement = NodeUtil.getFirstNamedChildNode(rootElement, "standard");
customElement = document.createElement("custom");
rootElement.insertBefore(customElement, standardElement);
NodeUtil.appendTextNode(rootElement, "\n");
}
customElement.appendChild(layoutTemplateElement);
/*
* now that we have the new <layout-template> element added to custom element,
* add the child nodes to layout
*/
String templatePath = model.getStringProperty(LAYOUT_TEMPLATE_FILE);
String wapTemplatePath = model.getStringProperty(LAYOUT_WAP_TEMPLATE_FILE);
String thumbnailPath = model.getStringProperty(LAYOUT_THUMBNAIL_FILE);
NodeUtil.appendChildElement(layoutTemplateElement, "template-path", templatePath);
if (getDescriptorVersion().equals("6.2.0")) {
NodeUtil.appendChildElement(layoutTemplateElement, "wap-template-path", wapTemplatePath);
}
NodeUtil.appendChildElement(layoutTemplateElement, "thumbnail-path", thumbnailPath);
// format the new node added to the model;
FormatProcessorXML processor = new FormatProcessorXML();
processor.formatNode(customElement);
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class JSFLiferayPortletDescriptorHelper method _downgradeJSFLiferayPortletXMLTo61.
private IStatus _downgradeJSFLiferayPortletXMLTo61(IDOMDocument document) {
Element rootElement = document.getDocumentElement();
NodeList requiresELements = rootElement.getElementsByTagName("requires-namespaced-parameters");
for (int i = 0; i < requiresELements.getLength(); i++) {
Node requiresElement = requiresELements.item(i);
Node prevNode = requiresElement.getPreviousSibling();
Node parentNode = requiresElement.getParentNode();
String nodeValue = prevNode.getNodeValue();
if ((prevNode != null) && (prevNode.getNodeType() == Node.TEXT_NODE) && (nodeValue.trim().length() == 0)) {
parentNode.removeChild(prevNode);
}
parentNode.removeChild(requiresElement);
}
new FormatProcessorXML().formatNode(rootElement);
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class KaleoEdits method format.
/**
* formats the node (and content). please make sure to only format the node
* you have created..
*
* @param newNode
*/
public static void format(Node newNode) {
if ((newNode.getParentNode() != null) && newNode.equals(newNode.getParentNode().getLastChild())) {
// add a new line to get the newly generated content correctly
// formatted.
Node parentNode = newNode.getParentNode();
newNode.getParentNode().appendChild(parentNode.getOwnerDocument().createTextNode("\n"));
}
FormatProcessorXML formatProcessor = new FormatProcessorXML();
// ignore any line width settings, causes wrong formatting of
// <foo>bar</foo>
formatProcessor.getFormatPreferences().setLineWidth(2000);
formatProcessor.formatNode(newNode);
}
Aggregations