Search in sources :

Example 26 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method reloadModel.

/**
 * This is similar to the getModel method, except this method does not use
 * the cached version, but forces the cached version to be replaced with a
 * fresh, unchanged version. Note: this method does not change any
 * reference counts. Also, if there is not already a cached version of the
 * model, then this call is essentially ignored (that is, it does not put
 * a model in the cache) and returns null.
 *
 * @deprecated - will become protected, use reload directly on model
 */
public IStructuredModel reloadModel(Object id, java.io.InputStream inputStream) throws java.io.UnsupportedEncodingException {
    // $NON-NLS-1$
    Assert.isNotNull(id, "id parameter can not be null");
    // get the existing model associated with this id
    IStructuredModel structuredModel = getExistingModel(id);
    // that model.
    if (structuredModel != null) {
        // get loader based on existing type
        // dmwTODO evaluate when reload should occur
        // with potentially new type (e.g. html 'save as' jsp).
        IModelHandler handler = structuredModel.getModelHandler();
        IModelLoader loader = handler.getModelLoader();
        // ask the loader to re-load
        loader.reload(Utilities.getMarkSupportedStream(inputStream), structuredModel);
        // $NON-NLS-1$
        trace("re-loading model", id);
    }
    return structuredModel;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 27 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method calculateType.

private IModelHandler calculateType(IFile iFile) throws CoreException {
    // IModelManager mm = ((ModelManagerPlugin)
    // Platform.getPlugin(ModelManagerPlugin.ID)).getModelManager();
    ModelHandlerRegistry cr = getModelHandlerRegistry();
    IModelHandler cd = cr.getHandlerFor(iFile);
    return cd;
}
Also used : ModelHandlerRegistry(org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 28 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method copy.

/**
 * this used to be in loader, but has been moved here
 */
private IStructuredModel copy(IStructuredModel model, String newId) throws ResourceInUse {
    IStructuredModel newModel = null;
    IStructuredModel oldModel = model;
    IModelHandler modelHandler = oldModel.getModelHandler();
    IModelLoader loader = modelHandler.getModelLoader();
    // newModel = loader.newModel();
    newModel = loader.createModel(oldModel);
    // newId, oldModel.getResolver(), oldModel.getModelManager());
    newModel.setModelHandler(modelHandler);
    // IStructuredDocument oldStructuredDocument =
    // oldModel.getStructuredDocument();
    // IStructuredDocument newStructuredDocument =
    // oldStructuredDocument.newInstance();
    // newModel.setStructuredDocument(newStructuredDocument);
    newModel.setResolver(oldModel.getResolver());
    newModel.setModelManager(oldModel.getModelManager());
    // duplicateFactoryRegistry(newModel, oldModel);
    newModel.setId(newId);
    // set text of new one after all initialization is done
    String contents = oldModel.getStructuredDocument().getText();
    newModel.getStructuredDocument().setText(this, contents);
    return newModel;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 29 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createStructuredDocumentFor.

/**
 * Convenience method. This method can be used when the resource does not
 * really exist (e.g. when content is being created, but hasn't been
 * written to disk yet). Note that since the content is being provided as
 * a String, it is assumed to already be decoded correctly so no
 * transformation is done.
 */
public IStructuredDocument createStructuredDocumentFor(String filename, String content, URIResolver resolver) throws IOException {
    IDocumentLoader loader = null;
    IModelHandler handler = calculateType(filename, null);
    loader = handler.getDocumentLoader();
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
    result.setEncodingMemento(new NullMemento());
    result.setText(this, content);
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) NullMemento(org.eclipse.wst.sse.core.internal.NullMemento) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 30 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createStructuredDocumentFor.

/**
 * Conveience method, since a proper IStructuredDocument must have a
 * proper parser assigned. It should only be used when an empty
 * structuredDocument is needed. Otherwise, use IFile form.
 *
 * @deprecated - TODO: to be removed by C4 do we really need this? I
 *             recommend to - use createStructuredDocumentFor(filename,
 *             null, null) - the filename does not need to represent a
 *             real - file, but can take for form of dummy.jsp, test.xml,
 *             etc. - That way we don't hard code the handler, but specify
 *             we - want the handler that "goes with" a certain type of -
 *             file.
 */
public IStructuredDocument createStructuredDocumentFor(String contentTypeId) {
    IDocumentLoader loader = null;
    ModelHandlerRegistry cr = getModelHandlerRegistry();
    IModelHandler handler = cr.getHandlerForContentTypeId(contentTypeId);
    if (handler == null)
        // $NON-NLS-1$
        Logger.log(Logger.ERROR, "Program error: no model handler found for " + contentTypeId);
    loader = handler.getDocumentLoader();
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
    return result;
}
Also used : ModelHandlerRegistry(org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry) IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Aggregations

IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)41 ModelHandlerRegistry (org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 CoreException (org.eclipse.core.runtime.CoreException)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 IContentType (org.eclipse.core.runtime.content.IContentType)5 IModelLoader (org.eclipse.wst.sse.core.internal.provisional.IModelLoader)5 InputStream (java.io.InputStream)4 IFile (org.eclipse.core.resources.IFile)4 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)4 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)4 IOException (java.io.IOException)3 IProject (org.eclipse.core.resources.IProject)3 BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)3 URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IDocument (org.eclipse.jface.text.IDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2