Search in sources :

Example 1 with IStructuredModel

use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project liferay-ide by liferay.

the class LayoutTplEditor method initSourceModel.

protected void initSourceModel() {
    if (_sourceModel == null) {
        if ((_sourcePage != null) && (_sourcePage.getDocumentProvider() != null)) {
            IDocumentProvider documentProvider = _sourcePage.getDocumentProvider();
            IDocument doc = documentProvider.getDocument(getEditorInput());
            _sourceModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(doc);
            _sourceModel.addModelStateListener(new IModelStateListener() {

                public void modelAboutToBeChanged(IStructuredModel model) {
                }

                public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
                }

                public void modelChanged(IStructuredModel model) {
                    setSourceModelChanged(true);
                }

                public void modelDirtyStateChanged(IStructuredModel model, boolean dirty) {
                }

                public void modelReinitialized(IStructuredModel structuredModel) {
                }

                public void modelResourceDeleted(IStructuredModel model) {
                }

                public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
                }
            });
        }
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 2 with IStructuredModel

use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel 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 IStructuredModel

use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project liferay-ide by liferay.

the class LiferayLanguageFileEncodingTests method removeSpecifiedNode.

private void removeSpecifiedNode(IFile file, String nodeName, String content) throws Exception {
    final IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit(file);
    final IDOMDocument document = ((IDOMModel) model).getDocument();
    final NodeList elements = document.getElementsByTagName(nodeName);
    for (int i = 0; i < elements.getLength(); i++) {
        Node node = elements.item(i);
        if (content.equals(node.getTextContent())) {
            node.getParentNode().removeChild(node);
            break;
        }
    }
    model.save(file);
    model.releaseFromEdit();
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 4 with IStructuredModel

use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project liferay-ide by liferay.

the class WorkflowDefinitionValidator method detectProblems.

@SuppressWarnings("unchecked")
public Map<String, Object>[] detectProblems(IFile workflowDefinitionXml, IScopeContext[] preferenceScopes) throws CoreException {
    List<Map<String, Object>> problems = new ArrayList<>();
    IStructuredModel model = null;
    try {
        IModelManager modelManage = StructuredModelManager.getModelManager();
        model = modelManage.getModelForRead(workflowDefinitionXml);
        if ((model != null) && model instanceof IDOMModel) {
            IDOMDocument document = ((IDOMModel) model).getDocument();
            try {
                IWorkflowValidation workflowValidation = KaleoCore.getWorkflowValidation(ServerUtil.getRuntime(workflowDefinitionXml.getProject()));
                Exception error = workflowValidation.validate(workflowDefinitionXml.getContents());
                if ((error != null) && !CoreUtil.isNullOrEmpty(error.getMessage())) {
                    Map<String, Object> problem = createMarkerValues(PREFERENCE_NODE_QUALIFIER, preferenceScopes, WORKFLOW_DEFINITION_VALIDATE, (IDOMNode) document.getFirstChild(), error.getMessage());
                    problems.add(problem);
                }
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
    } finally {
        if (model != null) {
            model.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) ArrayList(java.util.ArrayList) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CoreException(org.eclipse.core.runtime.CoreException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Map(java.util.Map)

Example 5 with IStructuredModel

use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project liferay-ide by liferay.

the class LiferayMavenProjectProvider method updateDtdVersion.

protected void updateDtdVersion(IProject project, String dtdVersion, String archetypeVesion) {
    String tmpPublicId = dtdVersion;
    String tmpSystemId = dtdVersion.replaceAll("\\.", "_");
    IStructuredModel editModel = null;
    IFile[] metaFiles = _getLiferayMetaFiles(project);
    for (IFile file : metaFiles) {
        try {
            editModel = StructuredModelManager.getModelManager().getModelForEdit(file);
            if ((editModel != null) && editModel instanceof IDOMModel) {
                IDOMDocument xmlDocument = ((IDOMModel) editModel).getDocument();
                DocumentTypeImpl docType = (DocumentTypeImpl) xmlDocument.getDoctype();
                String publicId = docType.getPublicId();
                String newPublicId = _getNewDoctTypeSetting(publicId, tmpPublicId, _publicid_pattern);
                if (newPublicId != null) {
                    docType.setPublicId(newPublicId);
                }
                String systemId = docType.getSystemId();
                String newSystemId = _getNewDoctTypeSetting(systemId, tmpSystemId, _systemid_pattern);
                if (newSystemId != null) {
                    docType.setSystemId(newSystemId);
                }
                editModel.save();
            }
        } catch (Exception e) {
            IStatus error = ProjectCore.createErrorStatus("Unable to upgrade deployment meta file for " + file.getName(), e);
            ProjectCore.logError(error);
        } finally {
            if (editModel != null) {
                editModel.releaseFromEdit();
            }
        }
    }
    ProjectCore.operate(project, UpdateDescriptorVersionOperation.class, archetypeVesion, dtdVersion);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DocumentTypeImpl(org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CoreException(org.eclipse.core.runtime.CoreException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Aggregations

IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)482 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)110 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)102 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)81 IFile (org.eclipse.core.resources.IFile)75 IOException (java.io.IOException)69 CoreException (org.eclipse.core.runtime.CoreException)49 IDocument (org.eclipse.jface.text.IDocument)46 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)42 InputStream (java.io.InputStream)40 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)36 Path (org.eclipse.core.runtime.Path)35 BadLocationException (org.eclipse.jface.text.BadLocationException)34 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)32 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)32 IProject (org.eclipse.core.resources.IProject)31 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)31 IPath (org.eclipse.core.runtime.IPath)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Document (org.w3c.dom.Document)19