Search in sources :

Example 21 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.

the class AbstractCommand method formatChild.

protected void formatChild(Element child) {
    if (child instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) child).getModel();
        try {
            // tell the model that we are about to make a big model change
            model.aboutToChangeModel();
            IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
            formatProcessor.formatNode(child);
        } finally {
            // tell the model that we are done with the big model change
            model.changedModel();
        }
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 22 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.

the class HookDescriptorHelper method doSetCustomJSPDir.

public IStatus doSetCustomJSPDir(IDOMDocument document, IDataModel model) {
    // <hook> element
    Element rootElement = document.getDocumentElement();
    String customJSPsFolder = model.getStringProperty(CUSTOM_JSPS_FOLDER);
    IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
    if (lrproject != null) {
        IPath defaultWebappRootFolderFullPath = lrproject.getDefaultDocrootFolder().getFullPath();
        String relativeJspFolderPath = ProjectUtil.getRelativePathFromDocroot(lrproject, defaultWebappRootFolderFullPath.append(customJSPsFolder).toPortableString());
        Element customJspElement = null;
        // check for existing element
        NodeList nodeList = rootElement.getElementsByTagName("custom-jsp-dir");
        if ((nodeList != null) && (nodeList.getLength() > 0)) {
            customJspElement = (Element) nodeList.item(0);
            NodeUtil.removeChildren(customJspElement);
            Node textNode = document.createTextNode(relativeJspFolderPath);
            customJspElement.appendChild(textNode);
        } else {
            // need to insert customJspElement before any <service>
            NodeList serviceTags = rootElement.getElementsByTagName("service");
            if ((serviceTags != null) && (serviceTags.getLength() > 0)) {
                customJspElement = NodeUtil.insertChildElement(rootElement, serviceTags.item(0), "custom-jsp-dir", relativeJspFolderPath);
            } else {
                customJspElement = NodeUtil.appendChildElement(rootElement, "custom-jsp-dir", relativeJspFolderPath);
                // 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(customJspElement);
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) 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 23 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.

the class JSFLiferayPortletDescriptorHelper method _updateJSFLiferayPortletXMLTo62.

private IStatus _updateJSFLiferayPortletXMLTo62(IDOMDocument document) {
    Element rootElement = document.getDocumentElement();
    NodeList portletNodes = rootElement.getElementsByTagName("portlet");
    if (portletNodes.getLength() > 1) {
        Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);
        Node headerPortletClassElement = lastPortletElement.getElementsByTagName("header-portlet-css").item(0);
        NodeUtil.insertChildElement(lastPortletElement, headerPortletClassElement, "requires-namespaced-parameters", "false");
        new FormatProcessorXML().formatNode(lastPortletElement);
    }
    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 24 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.

the class WebXMLDescriptorHelper method doAddTagLib.

protected IStatus doAddTagLib(IDOMDocument document, TagLibRefType tagLibRefType) {
    if (tagLibReferenceExists(document, tagLibRefType)) {
        return Status.OK_STATUS;
    }
    String typeId = document.getDocumentTypeId();
    Element rootElement = document.getDocumentElement();
    if ((typeId != null) && typeId.contains("2.3")) {
        Element taglibNextSibling = NodeUtil.findChildElement(rootElement, "resource-env-ref");
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "resource-ref");
        }
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "security-constraint");
        }
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "login-config");
        }
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "security-role");
        }
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "env-entry");
        }
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "ejb-ref");
        }
        if (taglibNextSibling == null) {
            taglibNextSibling = NodeUtil.findChildElement(rootElement, "ejb-local-ref");
        }
        Element taglib = NodeUtil.insertChildElement(rootElement, taglibNextSibling, "taglib", StringPool.EMPTY);
        NodeUtil.appendChildElement(taglib, "taglib-uri", tagLibRefType.getTaglibURI());
        NodeUtil.appendChildElement(taglib, "taglib-location", tagLibRefType.getTaglibLocation());
        if (taglibNextSibling == null) {
            rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
        }
        // format the new node added to the model;
        FormatProcessorXML processor = new FormatProcessorXML();
        processor.formatNode(taglib);
    } else {
        Element jspConfig = NodeUtil.findChildElement(rootElement, "jsp-config");
        if (jspConfig == null) {
            jspConfig = NodeUtil.appendChildElement(rootElement, "jsp-config");
        }
        Element taglib = NodeUtil.appendChildElement(jspConfig, "taglib");
        NodeUtil.appendChildElement(taglib, "taglib-uri", tagLibRefType.getTaglibURI());
        NodeUtil.appendChildElement(taglib, "taglib-location", tagLibRefType.getTaglibLocation());
        rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
        // format the new node added to the model;
        FormatProcessorXML processor = new FormatProcessorXML();
        processor.formatNode(jspConfig);
    }
    return Status.OK_STATUS;
}
Also used : Element(org.w3c.dom.Element) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 25 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.

the class ExtPluginFacetInstall method fixTilesDefExtFile.

protected void fixTilesDefExtFile() {
    IWebProject webproject = LiferayCore.create(IWebProject.class, project);
    IFolder webappRoot = webproject.getDefaultDocrootFolder();
    IFile tilesDefExtFile = webappRoot.getFile("WEB-INF/ext-web/docroot/WEB-INF/tiles-defs-ext.xml");
    if (FileUtil.notExists(tilesDefExtFile)) {
        return;
    }
    try {
        IDOMModel domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tilesDefExtFile);
        domModel.aboutToChangeModel();
        IDOMDocument document = domModel.getDocument();
        Element root = document.getDocumentElement();
        Element def = document.createElement("definition");
        def.setAttribute("name", StringPool.EMPTY);
        root.appendChild(def);
        root.appendChild(document.createTextNode("\n"));
        new FormatProcessorXML().formatNode(def);
        domModel.changedModel();
        domModel.save();
        domModel.releaseFromEdit();
        tilesDefExtFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (Exception e) {
        ProjectCore.logError(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

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