use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class WebResourceChangeHandler method initialize.
private void initialize() {
IStructuredModel xmlModel = getModel();
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
xmlModel.addModelLifecycleListener(this);
IStructuredDocument fJspDocument = xmlModel.getStructuredDocument();
if (fJspDocument != null) {
fJspDocument.addDocumentListener(this);
}
irritator = new ModelIrritantThread();
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class FileBufferModelManager method getModel.
public IStructuredModel getModel(IFile file) {
if (file == null) {
// $NON-NLS-1$
Exception iae = new IllegalArgumentException("can not get/create a model without an IFile");
Logger.logException(iae);
return null;
}
IStructuredModel model = null;
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
try {
if (Logger.DEBUG_FILEBUFFERMODELMANAGEMENT) {
// $NON-NLS-1$
Logger.log(Logger.INFO, "FileBufferModelManager connecting to IFile " + file.getFullPath());
}
// see TextFileDocumentProvider#createFileInfo about why we use
// IFile#getFullPath
// here, not IFile#getLocation.
IPath location = file.getFullPath();
if (location != null) {
bufferManager.connect(location, LocationKind.IFILE, getProgressMonitor());
ITextFileBuffer buffer = bufferManager.getTextFileBuffer(location, LocationKind.IFILE);
if (buffer != null) {
DocumentInfo info = (DocumentInfo) fDocumentMap.get(buffer.getDocument());
if (info != null) {
/*
* Note: "info" being null at this point is a slight
* error.
*
* The connect call from above (or at some time
* earlier in the session) would have notified the
* FileBufferMapper of the creation of the
* corresponding text buffer and created the
* DocumentInfo object for IStructuredDocuments.
*/
info.selfConnected = true;
info.locationKind = LocationKind.IFILE;
}
/*
* Check the document type. Although returning null for
* unknown documents would be fair, try to get a model if
* the document is at least a valid type.
*/
IDocument bufferDocument = buffer.getDocument();
if (bufferDocument instanceof IStructuredDocument) {
model = getModel((IStructuredDocument) bufferDocument);
} else {
/*
* 190768 - Quick diff marks do not disappear in the
* vertical ruler of JavaScript editor and
*
* 193805 - Changes are not thrown away when close
* with no save for files with no structured model
* associated with them (text files, javascript files,
* etc) in web project
*/
bufferManager.disconnect(location, LocationKind.IFILE, getProgressMonitor());
}
}
}
} catch (CoreException e) {
// $NON-NLS-1$
Logger.logException("Error getting model for " + file.getFullPath(), e);
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredCleanupProcessor method cleanupFile.
public void cleanupFile(IFile file) throws IOException, CoreException {
IStructuredModel structuredModel = null;
// OutputStream outputStream = null;
try {
// setup structuredModel
structuredModel = StructuredModelManager.getModelManager().getModelForRead(file);
// cleanup
cleanupModel(structuredModel, 0, structuredModel.getStructuredDocument().getLength());
// save output to file
// outputStream = new
// FileOutputStream(file.getLocation().toString());
structuredModel.save(file);
} finally {
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromRead();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredCleanupProcessor method cleanupContent.
public String cleanupContent(String input, int start, int length) throws IOException, CoreException {
IStructuredModel structuredModel = null;
InputStream inputStream = null;
try {
// setup structuredModel
// $NON-NLS-1$
inputStream = new ByteArrayInputStream(input.getBytes("UTF8"));
String id = inputStream.toString() + getContentType();
structuredModel = StructuredModelManager.getModelManager().getModelForRead(id, inputStream, null);
// cleanup
cleanupModel(structuredModel, start, length);
// return output
return structuredModel.getStructuredDocument().get();
} finally {
ensureClosed(null, inputStream);
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromRead();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredCleanupProcessor method cleanupContent.
// tests to skip refresh
// of cleanup preferences
// when it's set to false
public String cleanupContent(String input) throws IOException, CoreException {
IStructuredModel structuredModel = null;
InputStream inputStream = null;
try {
// setup structuredModel
// $NON-NLS-1$
inputStream = new ByteArrayInputStream(input.getBytes("UTF8"));
String id = inputStream.toString() + getContentType();
structuredModel = StructuredModelManager.getModelManager().getModelForRead(id, inputStream, null);
// cleanup
cleanupModel(structuredModel, 0, structuredModel.getStructuredDocument().getLength());
// return output
return structuredModel.getStructuredDocument().get();
} finally {
ensureClosed(null, inputStream);
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromRead();
}
}
Aggregations