Search in sources :

Example 1 with IModelManager

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

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class HTMLValidator method getModel.

/**
 */
protected IDOMModel getModel(IProject project, IFile file) {
    if (project == null || file == null)
        return null;
    if (!file.exists())
        return null;
    if (!canHandle(file))
        return null;
    IModelManager manager = StructuredModelManager.getModelManager();
    if (manager == null)
        return null;
    IStructuredModel model = null;
    try {
        file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
    } catch (CoreException e) {
        Logger.logException(e);
    }
    try {
        try {
            model = manager.getModelForRead(file);
        } catch (UnsupportedEncodingException ex) {
            // retry ignoring META charset for invalid META charset
            // specification
            // recreate input stream, because it is already partially read
            model = manager.getModelForRead(file, new String(), null);
        }
    } catch (UnsupportedEncodingException ex) {
    } catch (IOException ex) {
    } catch (CoreException e) {
        Logger.logException(e);
    }
    if (model == null)
        return null;
    if (!(model instanceof IDOMModel)) {
        releaseModel(model);
        return null;
    }
    return (IDOMModel) model;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 3 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class URLModelProvider method getModelForEdit.

/**
 */
private IStructuredModel getModelForEdit(IFile file) throws IOException {
    if (file == null)
        return null;
    IModelManager manager = getModelManager();
    // create a fake InputStream
    IStructuredModel model = null;
    try {
        model = manager.getModelForEdit(file);
    } catch (UnsupportedCharsetException ex) {
        try {
            model = manager.getModelForEdit(file, EncodingRule.FORCE_DEFAULT);
        } catch (IOException ioe) {
        } catch (CoreException ce) {
        }
    } catch (CoreException ce) {
    }
    return model;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 4 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class URLModelProvider method getModelForRead.

/**
 */
private IStructuredModel getModelForRead(IFile file) throws IOException {
    if (file == null)
        return null;
    IModelManager manager = getModelManager();
    // create a fake InputStream
    IStructuredModel model = null;
    try {
        model = manager.getModelForRead(file);
    } catch (UnsupportedCharsetException ex) {
        try {
            model = manager.getModelForRead(file, EncodingRule.FORCE_DEFAULT);
        } catch (IOException ioe) {
        } catch (CoreException ce) {
        }
    } catch (CoreException ce) {
    }
    return model;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 5 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerHTML method getModelForEdit.

/**
 * must release model (from edit) after
 * @param filename relative to this class (TestStructuredPartitioner)
 */
private IStructuredModel getModelForEdit(String filename) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        InputStream inStream = getClass().getResourceAsStream(filename);
        if (inStream == null)
            inStream = new StringBufferInputStream("");
        model = modelManager.getModelForEdit(filename, inStream, null);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return model;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Aggregations

IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)139 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)102 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)45 IOException (java.io.IOException)37 InputStream (java.io.InputStream)27 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)27 IFile (org.eclipse.core.resources.IFile)23 CoreException (org.eclipse.core.runtime.CoreException)21 BadLocationException (org.eclipse.jface.text.BadLocationException)13 FileNotFoundException (java.io.FileNotFoundException)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)11 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 IProject (org.eclipse.core.resources.IProject)9 StringBufferInputStream (java.io.StringBufferInputStream)8 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)7 IDocument (org.eclipse.jface.text.IDocument)6 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)6 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5