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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations