Search in sources :

Example 1 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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 2 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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 3 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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 4 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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)

Example 5 with IDOMModel

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

the class CUCacheWTP method _createJSPTranslation.

private JSPTranslationPrime _createJSPTranslation(File file) {
    IDOMModel jspModel = null;
    try {
        // try to find the file in the current workspace, if it can't find
        // it then fall back to copy
        IFile jspFile = getIFile(file);
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(jspFile);
        IDOMDocument domDocument = jspModel.getDocument();
        IDOMNode domNode = (IDOMNode) domDocument.getDocumentElement();
        IProgressMonitor npm = new NullProgressMonitor();
        JSPTranslator translator = new JSPTranslatorPrime();
        if (domNode != null) {
            translator.reset((IDOMNode) domDocument.getDocumentElement(), npm);
        } else {
            translator.reset((IDOMNode) domDocument.getFirstChild(), npm);
        }
        translator.translate();
        IJavaProject javaProject = JavaCore.create(jspFile.getProject());
        return new JSPTranslationPrime(javaProject, translator, jspFile);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IJavaProject(org.eclipse.jdt.core.IJavaProject) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25