Search in sources :

Example 76 with IModelManager

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

the class DelegatingSourceValidator method getModelForResource.

/**
 * @param file
 *            the file to get the model for
 * @return the file's XMLModel or null
 */
protected IDOMModel getModelForResource(IFile file) {
    IStructuredModel model = null;
    IModelManager manager = StructuredModelManager.getModelManager();
    try {
        model = manager.getModelForRead(file);
    // TODO.. HTML validator tries again to get a model a 2nd way
    } catch (Exception e) {
        Logger.log(Logger.ERROR_DEBUG, file.getFullPath().toString(), e);
    }
    if (model instanceof IDOMModel)
        return (IDOMModel) model;
    if (model != null)
        model.releaseFromRead();
    return null;
}
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) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) BadLocationException(org.eclipse.jface.text.BadLocationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 77 with IModelManager

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

the class JsTranslation method setBaseLocation.

private void setBaseLocation() {
    IDOMModel xmlModel = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        xmlModel = (IDOMModel) modelManager.getExistingModelForRead(fHtmlDocument);
        if (xmlModel == null) {
            xmlModel = (IDOMModel) modelManager.getModelForRead(fHtmlDocument);
        }
        if (xmlModel != null) {
            fModelBaseLocation = xmlModel.getBaseLocation();
        }
    } finally {
        if (xmlModel != null)
            xmlModel.releaseFromRead();
    }
// return xmlModel;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager)

Example 78 with IModelManager

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

the class AddJavaDocStubOperation method applyChanges.

protected void applyChanges() {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = null;
    IStructuredDocument doc = node.getStructuredDocument();
    try {
        MultiTextEdit edits = textEditListener.getTextEdits();
        model = modelManager.getExistingModelForEdit(doc);
        model.aboutToChangeModel();
        // $NON-NLS-1$ //$NON-NLS-2$
        model.beginRecording(this, Messages.getString("AddJavaDocStubOperation.0"), Messages.getString("AddJavaDocStubOperation.1"));
        edits.apply(doc);
    } catch (MalformedTreeException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } catch (BadLocationException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } finally {
        if (model != null) {
            model.endRecording(this);
            model.changedModel();
            model.releaseFromEdit();
        }
    }
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 79 with IModelManager

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

the class StructuredTextUndoManager method findStructuredModel.

/**
 * Utility method to find model given document
 */
private IStructuredModel findStructuredModel(IDocument document) {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel structuredModel = modelManager.getExistingModelForRead(document);
    return structuredModel;
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 80 with IModelManager

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

the class DelegatingSourceValidator method getModelForResource.

/**
 * @param file
 *            the file to get the model for
 * @return the file's JSONModel or null
 */
protected IJSONModel getModelForResource(IFile file) {
    IStructuredModel model = null;
    IModelManager manager = StructuredModelManager.getModelManager();
    try {
        model = manager.getModelForRead(file);
    // TODO.. HTML validator tries again to get a model a 2nd way
    } catch (Exception e) {
        Logger.log(Logger.ERROR_DEBUG, file.getFullPath().toString(), e);
    }
    if (model instanceof IJSONModel)
        return (IJSONModel) model;
    if (model != null)
        model.releaseFromRead();
    return null;
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IJSONModel(org.eclipse.wst.json.core.document.IJSONModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) BadLocationException(org.eclipse.jface.text.BadLocationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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