Search in sources :

Example 76 with IStructuredModel

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

the class ModelManagerImpl method _doCommonCreateModel.

private void _doCommonCreateModel(InputStream inputStream, String id, IModelHandler handler, URIResolver resolver, ReadEditType rwType, String encoding, String lineDelimiter, SharedObject sharedObject) throws IOException {
    boolean doRemove = true;
    try {
        synchronized (sharedObject) {
            IStructuredModel model = null;
            try {
                model = _commonCreateModel(id, handler, resolver);
                IModelLoader loader = handler.getModelLoader();
                if (inputStream == null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    Logger.log(Logger.WARNING, "model was requested for id " + id + " without a content InputStream");
                }
                loader.load(id, Utilities.getMarkSupportedStream(inputStream), model, encoding, lineDelimiter);
            } catch (ResourceInUse e) {
                // impossible, since we've already found
                handleProgramError(e);
            }
            if (model != null) {
                /**
                 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=264228
                 *
                 * Ensure that the content type identifier field of the model
                 * is properly set. This is normally handled by the
                 * FileBufferModelManager when working with files as it knows
                 * the content type in advance; here is where we handle it for
                 * streams.
                 */
                if (model instanceof AbstractStructuredModel) {
                    DocumentReader reader = new DocumentReader(model.getStructuredDocument());
                    IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(reader, id, new QualifiedName[0]);
                    reader.close();
                    if (description != null && description.getContentType() != null) {
                        ((AbstractStructuredModel) model).setContentTypeIdentifier(description.getContentType().getId());
                    }
                }
                sharedObject.theSharedModel = model;
                _initCount(sharedObject, rwType);
                doRemove = false;
            }
        }
    } finally {
        if (doRemove) {
            SYNC.acquire();
            // remove it if we didn't get one back
            fManagedObjects.remove(id);
            SYNC.release();
        }
        sharedObject.setLoaded();
    }
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 77 with IStructuredModel

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

the class ModelManagerImpl method getModelForEdit.

public IStructuredModel getModelForEdit(String id, InputStream inputStream, URIResolver resolver) throws IOException {
    if (id == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Program Error: id may not be null");
    }
    IStructuredModel result = null;
    InputStream istream = Utilities.getMarkSupportedStream(inputStream);
    IModelHandler handler = calculateType(id, istream);
    if (handler != null) {
        result = _commonCreateModel(istream, id, handler, resolver, EDIT, null, null);
    } else {
        // $NON-NLS-1$
        Logger.log(Logger.INFO, "no model handler found for id");
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 78 with IStructuredModel

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

the class ModelManagerImpl method createUnManagedStructuredModelFor.

/**
 * Conveience method. It depends on the loaders newModel method to return
 * an appropriate StrucuturedModel appropriately initialized.
 */
public IStructuredModel createUnManagedStructuredModelFor(String contentTypeId, URIResolver resolver) {
    IStructuredModel result = null;
    ModelHandlerRegistry cr = getModelHandlerRegistry();
    IModelHandler handler = cr.getHandlerForContentTypeId(contentTypeId);
    try {
        // $NON-NLS-1$
        result = _commonCreateModel(UNMANAGED_MODEL, handler, resolver);
    } catch (ResourceInUse e) {
        // this may need to be re-examined.
        if (Logger.DEBUG_MODELMANAGER)
            // $NON-NLS-1$ //$NON-NLS-2$
            Logger.log(Logger.INFO, "ModelMangerImpl::createUnManagedStructuredModelFor. Model unexpectedly in use.");
    }
    return result;
}
Also used : ModelHandlerRegistry(org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 79 with IStructuredModel

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

the class AbstractStructuredModel method copy.

/**
 * Provides a copy of the model, but a new ID must be provided. The
 * principle of this copy is not to copy fields, etc., as is typically
 * done in a clone method, but to return a model with the same content in
 * the structuredDocument. Note: It is the callers responsibility to
 * setBaseLocation, listners, etc., as appropriate. Type and Encoding are
 * the only fields set by this method. If the newId provided already exist
 * in the model manager, a ResourceInUse exception is thrown.
 */
public IStructuredModel copy(String newId) throws ResourceInUse {
    IStructuredModel newModel = null;
    // this first one should fail, if not, its treated as an error
    // If the caller wants to use an existing one, they can call
    // getExisting
    // after this failure
    newModel = getModelManager().getExistingModelForEdit(newId);
    if (newModel != null) {
        // be sure to release the reference we got "by accident" (and
        // no
        // longer need)
        newModel.releaseFromEdit();
        throw new ResourceInUse();
    }
    newModel = getModelManager().copyModelForEdit(getId(), newId);
    return newModel;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 80 with IStructuredModel

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

the class AbstractStructuredModel method reload.

/**
 * This function replenishes the model with the resource without saving
 * any possible changes. It is used when one editor may be closing, and
 * specifially says not to save the model, but another "display" of the
 * model still needs to hang on to some model, so needs a fresh copy.
 */
public IStructuredModel reload(InputStream inputStream) throws IOException {
    IStructuredModel result = null;
    try {
        aboutToChangeModel();
        result = _getModelManager().reloadModel(getId(), inputStream);
    } catch (UnsupportedEncodingException e) {
        // log for now, unless we find reason not to
        Logger.log(Logger.INFO, e.getMessage());
    } finally {
        changedModel();
    }
    return result;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

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