Search in sources :

Example 6 with FormatProcessorXML

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;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ParamValue(org.eclipse.jst.j2ee.common.ParamValue) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 7 with FormatProcessorXML

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;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 8 with FormatProcessorXML

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;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 9 with FormatProcessorXML

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;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 10 with FormatProcessorXML

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);
}
Also used : Node(org.w3c.dom.Node) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Aggregations

FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)28 Element (org.w3c.dom.Element)16 Node (org.w3c.dom.Node)14 NodeList (org.w3c.dom.NodeList)9 IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)8 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)6 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)6 CoreException (org.eclipse.core.runtime.CoreException)3 IWebProject (com.liferay.ide.core.IWebProject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 ITemplateContext (com.liferay.ide.core.templates.ITemplateContext)1 ITemplateOperation (com.liferay.ide.core.templates.ITemplateOperation)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1