Search in sources :

Example 6 with IDOMDocument

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

the class LiferayDisplayDescriptorHelper method addDescriptorOperations.

@Override
protected void addDescriptorOperations() {
    AddNewPortletOperation anpOperation = new AddNewPortletOperation() {

        @Override
        public IStatus addNewPortlet(IDataModel model) {
            IStatus status = Status.OK_STATUS;
            IFile descriptorFile = getDescriptorFile();
            if (descriptorFile != null) {
                DOMModelEditOperation domModelOperation = new DOMModelEditOperation(descriptorFile) {

                    protected void createDefaultFile() {
                        createDefaultDescriptor(_DESCRIPTOR_TEMPLATE, getDescriptorVersion());
                    }

                    protected IStatus doExecute(IDOMDocument document) {
                        return doAddNewPortlet(document, model);
                    }
                };
                status = domModelOperation.execute();
            }
            return status;
        }
    };
    addDescriptorOperation(anpOperation);
    RemoveAllPortletsOperation rapOperation = new RemoveAllPortletsOperation() {

        @Override
        public IStatus removeAllPortlets() {
            return removeAllPortlets();
        }
    };
    addDescriptorOperation(rapOperation);
    RemoveSampleElementsOperation rseOperation = new RemoveSampleElementsOperation() {

        @Override
        public IStatus removeSampleElements() {
            return removeAllPortlets();
        }
    };
    addDescriptorOperation(rseOperation);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) RemoveSampleElementsOperation(com.liferay.ide.project.core.descriptor.RemoveSampleElementsOperation) RemoveAllPortletsOperation(com.liferay.ide.project.core.descriptor.RemoveAllPortletsOperation) AddNewPortletOperation(com.liferay.ide.project.core.descriptor.AddNewPortletOperation) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel)

Example 7 with IDOMDocument

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

the class LiferayDisplayDescriptorHelper method getAllPortletCategories.

public String[] getAllPortletCategories() {
    List<String> allPortletCategories = new ArrayList<>();
    IFile descriptorFile = getDescriptorFile();
    if (descriptorFile != null) {
        DOMModelOperation op = new DOMModelReadOperation(descriptorFile) {

            protected IStatus doExecute(IDOMDocument document) {
                NodeList nodeList = document.getElementsByTagName("category");
                if ((nodeList != null) && (nodeList.getLength() > 0)) {
                    for (int i = 0; i < nodeList.getLength(); i++) {
                        Element categoryElemnt = (Element) nodeList.item(i);
                        String categoryName = categoryElemnt.getAttribute("name");
                        if ((categoryName != null) && !categoryName.matches("\\s*")) {
                            allPortletCategories.add(categoryName);
                        }
                    }
                }
                return Status.OK_STATUS;
            }
        };
        op.execute();
    }
    return allPortletCategories.toArray(new String[0]);
}
Also used : IFile(org.eclipse.core.resources.IFile) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 8 with IDOMDocument

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

the class LiferayPortletDescriptorHelper method configureLiferayPortletXml.

public IStatus configureLiferayPortletXml(String newPortletName) {
    IStatus status = Status.OK_STATUS;
    IFile descriptorFile = getDescriptorFile();
    if (descriptorFile != null) {
        DOMModelEditOperation operation = new DOMModelEditOperation(descriptorFile) {

            protected IStatus doExecute(IDOMDocument document) {
                Element rootElement = document.getDocumentElement();
                NodeList portletNodes = rootElement.getElementsByTagName("portlet");
                if (portletNodes.getLength() > 0) {
                    Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);
                    Element portletName = NodeUtil.findChildElement(lastPortletElement, "portlet-name");
                    portletName.replaceChild(document.createTextNode(newPortletName), portletName.getFirstChild());
                }
                return Status.OK_STATUS;
            }
        };
        status = operation.execute();
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 9 with IDOMDocument

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

the class LiferayPortletDescriptorHelper method addDescriptorOperations.

@Override
protected void addDescriptorOperations() {
    AddNewPortletOperation apOperation = new AddNewPortletOperation() {

        @Override
        public IStatus addNewPortlet(IDataModel model) {
            IStatus status = Status.OK_STATUS;
            if (canAddNewPortlet(model)) {
                IFile descriptorFile = getDescriptorFile();
                if (descriptorFile != null) {
                    DOMModelEditOperation domModelOperation = new DOMModelEditOperation(descriptorFile) {

                        protected void createDefaultFile() {
                            createDefaultDescriptor(_DESCRIPTOR_TEMPLATE, getDescriptorVersion());
                        }

                        protected IStatus doExecute(IDOMDocument document) {
                            return doAddNewPortlet(document, model);
                        }
                    };
                    status = domModelOperation.execute();
                }
            }
            return status;
        }
    };
    addDescriptorOperation(apOperation);
    RemoveAllPortletsOperation rapOperation = new RemoveAllPortletsOperation() {

        @Override
        public IStatus removeAllPortlets() {
            return doRemoveAllPortlets();
        }
    };
    addDescriptorOperation(rapOperation);
    RemoveSampleElementsOperation rseOperation = new RemoveSampleElementsOperation() {

        @Override
        public IStatus removeSampleElements() {
            return doRemoveAllPortlets();
        }
    };
    addDescriptorOperation(rseOperation);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) RemoveSampleElementsOperation(com.liferay.ide.project.core.descriptor.RemoveSampleElementsOperation) RemoveAllPortletsOperation(com.liferay.ide.project.core.descriptor.RemoveAllPortletsOperation) AddNewPortletOperation(com.liferay.ide.project.core.descriptor.AddNewPortletOperation) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel)

Example 10 with IDOMDocument

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

the class PortletDescriptorHelper method configurePortletXml.

public IStatus configurePortletXml(String newPortletName) {
    IFile descriptorFile = getDescriptorFile();
    IStatus status = new DOMModelEditOperation(descriptorFile) {

        protected IStatus doExecute(IDOMDocument document) {
            Element rootElement = document.getDocumentElement();
            NodeList portletNodes = rootElement.getElementsByTagName("portlet");
            if (portletNodes.getLength() > 0) {
                Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);
                Element portletName = NodeUtil.findChildElement(lastPortletElement, "portlet-name");
                portletName.replaceChild(document.createTextNode(newPortletName), portletName.getFirstChild());
            }
            return Status.OK_STATUS;
        }
    }.execute();
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9