Search in sources :

Example 26 with IModelManager

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

the class ValidatorGroupListener method validationStarting.

public void validationStarting(IResource resource, IProgressMonitor monitor, ValidationState state) {
    if (_debug)
        System.out.println("Starting: " + resource.getFullPath());
    try {
        if (monitor != null && !monitor.isCanceled()) {
            if (resource.getType() != IResource.FILE)
                return;
            synchronized (LOCK) {
                final IPath path = resource.getFullPath();
                final ValidationModelReference ref = (ValidationModelReference) fDiagnosticMap.get(path);
                if (ref != null) {
                    // The model is already being tracked
                    ++ref.count;
                } else {
                    // The model has not been obtained as part of the validation group yet
                    IModelManager modelManager = StructuredModelManager.getModelManager();
                    // possible when shutting down
                    if (modelManager != null) {
                        IStructuredModel model = modelManager.getModelForRead((IFile) resource);
                        if (model != null) {
                            fDiagnosticMap.put(resource.getFullPath(), new ValidationModelReference(model));
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Logger.logException(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 27 with IModelManager

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

the class Validator method getModel.

protected IStructuredModel getModel(String uriString) {
    URI uri;
    try {
        uri = new URI(uriString);
    } catch (URISyntaxException e) {
        logWarning(e);
        return null;
    }
    IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri);
    if (files == null || files.length <= 0 || !files[0].exists()) {
        return null;
    }
    IFile file = files[0];
    IModelManager manager = StructuredModelManager.getModelManager();
    if (manager == null)
        return null;
    IStructuredModel model = null;
    try {
        file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
    } catch (CoreException e) {
        logWarning(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) {
        logWarning(e);
    }
    return model;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) URI(java.net.URI)

Example 28 with IModelManager

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

the class HTMLConverter method readModel.

/**
 */
private IDOMModel readModel(InputStream input) throws IOException, UnsupportedEncodingException {
    if (input == null)
        return null;
    // create temporary model
    // $NON-NLS-1$
    String id = input.toString() + ".html";
    IModelManager manager = StructuredModelManager.getModelManager();
    IStructuredModel model = manager.getModelForEdit(id, input, null);
    if (!(model instanceof IDOMModel)) {
        if (model != null)
            model.releaseFromEdit();
        return null;
    }
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 29 with IModelManager

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

the class HTMLConverter method readModel.

/**
 */
private IDOMModel readModel(IFile file) throws IOException, CoreException {
    if (file == null)
        return null;
    IModelManager manager = StructuredModelManager.getModelManager();
    IStructuredModel model = manager.getModelForEdit(file);
    if (!(model instanceof IDOMModel)) {
        if (model != null)
            model.releaseFromEdit();
        return null;
    }
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 30 with IModelManager

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

the class FormattingTests method getModelForEdit.

/**
 * must release model (from edit) after
 *
 * @param filename
 *            relative to this class (TestFormatProcessorCSS)
 */
private IStructuredModel getModelForEdit(final String path) {
    IFile file = getFile(path);
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForEdit(file);
    } catch (CoreException ce) {
        ce.printStackTrace();
    } catch (IOException io) {
        io.printStackTrace();
    }
    return model;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) 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