Search in sources :

Example 16 with IDOMDocument

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

the class JSFLiferayPortletDescriptorHelper method addDescriptorOperations.

@Override
protected void addDescriptorOperations() {
    super.addDescriptorOperations();
    UpdateDescriptorVersionOperation operation = new UpdateDescriptorVersionOperation() {

        @Override
        public IStatus update(Version preVersion, Version postVersion) {
            if ((CoreUtil.compareVersions(preVersion, ILiferayConstants.V620) >= 0) && (CoreUtil.compareVersions(postVersion, ILiferayConstants.V620) < 0)) {
                IFile descriptorFile = getDescriptorFile();
                IDOMModel domModel = null;
                try {
                    domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(descriptorFile);
                    IDOMDocument document = domModel.getDocument();
                    IStatus status = _downgradeJSFLiferayPortletXMLTo61(document);
                    if (!status.isOK()) {
                        return status;
                    }
                    domModel.save();
                } catch (Exception e) {
                    PortletCore.logError("Error editing liferay-portlet.xml", e);
                } finally {
                    if (domModel != null) {
                        domModel.releaseFromEdit();
                    }
                }
            }
            return Status.OK_STATUS;
        }
    };
    addDescriptorOperation(operation);
}
Also used : UpdateDescriptorVersionOperation(com.liferay.ide.project.core.descriptor.UpdateDescriptorVersionOperation) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Version(org.osgi.framework.Version) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 17 with IDOMDocument

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

the class VaadinLiferayPortletDescriptorHelper 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 _updateVaadinLiferayPortletXMLTo62(document);
                }
            };
            return 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)

Example 18 with IDOMDocument

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

the class BaseValidator method checkAllClassElements.

@SuppressWarnings("unchecked")
protected Map<String, Object>[] checkAllClassElements(Map<String, String> map, IJavaProject javaProject, IFile liferayDescriptorXml, String classExistPreferenceKey, String classHierarchyPreferenceKey, IScopeContext[] preferenceScopes, String preferenceNodeQualifier, List<Map<String, Object>> problems) throws CoreException {
    IStructuredModel liferayDescriptorXmlModel = null;
    IDOMDocument liferayDescriptorXmlDocument = null;
    try {
        liferayDescriptorXmlModel = StructuredModelManager.getModelManager().getModelForRead(liferayDescriptorXml);
        if ((liferayDescriptorXmlModel != null) && liferayDescriptorXmlModel instanceof IDOMModel && (map != null)) {
            liferayDescriptorXmlDocument = ((IDOMModel) liferayDescriptorXmlModel).getDocument();
            for (String elementName : map.keySet()) {
                checkClassElements(liferayDescriptorXmlDocument, javaProject, elementName, preferenceNodeQualifier, preferenceScopes, classExistPreferenceKey, classHierarchyPreferenceKey, problems, map.get(elementName));
            }
        }
    } catch (IOException ioe) {
        ProjectCore.logError(ioe);
    } finally {
        if (liferayDescriptorXmlModel != null) {
            liferayDescriptorXmlModel.releaseFromRead();
        }
    }
    Map<String, Object>[] retval = new Map[problems.size()];
    return (Map<String, Object>[]) problems.toArray(retval);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with IDOMDocument

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

the class JSPFileWTP method createSearchResult.

@Override
protected SearchResult createSearchResult(String searchContext, int startOffset, int endOffset, int startLine, int endLine, boolean fullMatch) {
    IDOMModel jspModel = null;
    try {
        int jspStartOffset = _translation.getJspOffset(startOffset);
        int jspEndOffset = _translation.getJspOffset(endOffset);
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(_translation.getJspFile());
        IDOMDocument domDocument = jspModel.getDocument();
        IStructuredDocument structuredDocument = domDocument.getStructuredDocument();
        int jspStartLine = structuredDocument.getLineOfOffset(jspStartOffset) + 1;
        int jspEndLine = structuredDocument.getLineOfOffset(jspEndOffset) + 1;
        return super.createSearchResult(searchContext, jspStartOffset, jspEndOffset, jspStartLine, jspEndLine, fullMatch);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
    return super.createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, fullMatch);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 20 with IDOMDocument

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

the class SSEXMLFile method findElement.

@Override
public List<SearchResult> findElement(String tagName, String value) {
    List<SearchResult> results = new ArrayList<>();
    IFile xmlFile = getIFile(file);
    IDOMModel domModel = null;
    try {
        domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(xmlFile);
        IDOMDocument document = domModel.getDocument();
        NodeList elements = document.getElementsByTagName(tagName);
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                IDOMElement element = (IDOMElement) elements.item(i);
                String textContent = element.getTextContent();
                if ((textContent != null) && value.trim().equals(textContent.trim())) {
                    int startOffset = element.getStartOffset();
                    int endOffset = element.getEndOffset();
                    int startLine = document.getStructuredDocument().getLineOfOffset(startOffset) + 1;
                    int endLine = document.getStructuredDocument().getLineOfOffset(endOffset) + 1;
                    SearchResult result = new SearchResult(file, "startOffset:" + startOffset, startOffset, endOffset, startLine, endLine, true);
                    results.add(result);
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (domModel != null) {
            domModel.releaseFromRead();
        }
    }
    return results;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

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