Search in sources :

Example 11 with IDOMDocument

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

the class PortletDescriptorHelper method getAllPortletNames.

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

            protected IStatus doExecute(IDOMDocument document) {
                NodeList nodeList = document.getElementsByTagName("portlet-name");
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Element portletName = (Element) nodeList.item(i);
                    allPortletNames.add(NodeUtil.getTextContent(portletName));
                }
                return Status.OK_STATUS;
            }
        };
        op.execute();
    }
    return allPortletNames.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 12 with IDOMDocument

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

the class PortletDescriptorHelper method getAllResourceBundles.

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

            protected IStatus doExecute(IDOMDocument document) {
                NodeList nodeList = document.getElementsByTagName("resource-bundle");
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Element resourceBundle = (Element) nodeList.item(i);
                    allResourceBundles.add(NodeUtil.getTextContent(resourceBundle));
                }
                return Status.OK_STATUS;
            }
        };
        op.execute();
    }
    return allResourceBundles.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 13 with IDOMDocument

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

the class LayoutTplElementsFactory method newLayoutTplFromModel.

public LayoutTplElement newLayoutTplFromModel(IDOMModel model, Boolean bootstrapStyle, Boolean is62) {
    if (model == null) {
        return null;
    }
    LayoutTplElement layoutTpl = null;
    IDOMDocument rootDocument = model.getDocument();
    IDOMElement mainContentElement = LayoutTplUtil.findMainContentElement(rootDocument);
    if (mainContentElement != null) {
        layoutTpl = LayoutTplElement.TYPE.instantiate();
        layoutTpl.setBootstrapStyle(bootstrapStyle);
        layoutTpl.setClassName(mainContentElement.getAttribute("class"));
        layoutTpl.setIs62(is62);
        IDOMElement[] portletLayoutElements = LayoutTplUtil.findChildElementsByClassName(mainContentElement, "div", "portlet-layout");
        if (ListUtil.isNotEmpty(portletLayoutElements)) {
            for (IDOMElement portletLayoutElement : portletLayoutElements) {
                PortletLayoutElement portletLayout = layoutTpl.getPortletLayouts().insert();
                initPortletLayoutFromElement(portletLayout, portletLayoutElement);
            }
        }
    }
    return layoutTpl;
}
Also used : IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 14 with IDOMDocument

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

the class LayoutTplDescriptorHelper method addNewLayoutTemplate.

public IStatus addNewLayoutTemplate(IDataModel dm) {
    IFile descriptorFile = getDescriptorFile();
    DOMModelOperation operation = new DOMModelEditOperation(descriptorFile) {

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

        protected IStatus doExecute(IDOMDocument document) {
            return doAddLayoutTemplate(document, dm);
        }
    };
    IStatus status = operation.execute();
    if (!status.isOK()) {
        return status;
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 15 with IDOMDocument

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

the class JSFLiferayPortletDescriptorHelper method doAddNewPortlet.

@Override
protected IStatus doAddNewPortlet(IDOMDocument document, IDataModel model) {
    IStatus status = Status.OK_STATUS;
    status = super.doAddNewPortlet(document, model);
    if (!status.isOK()) {
        return status;
    }
    Version runtimeVersion = ServerUtil.getRuntimeVersion(project);
    if (CoreUtil.compareVersions(runtimeVersion, ILiferayConstants.V620) >= 0) {
        IFile descriptorFile = getDescriptorFile();
        if (descriptorFile != null) {
            DOMModelOperation op = new DOMModelEditOperation(descriptorFile) {

                @Override
                protected void createDefaultFile() {
                // Getting document from super( descriptorFile );
                }

                @Override
                protected IStatus doExecute(IDOMDocument document) {
                    return _updateJSFLiferayPortletXMLTo62(document);
                }
            };
            status = op.execute();
        }
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Version(org.osgi.framework.Version) 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