use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredFormatProcessor method formatFileName.
public void formatFileName(String fileName, int start, int length) throws IOException, CoreException {
if (fileName == null)
return;
IStructuredModel structuredModel = null;
InputStream inputStream = null;
// OutputStream outputStream = null;
try {
// setup structuredModel
// Note: We are getting model for edit. Will save model if model
// changed.
inputStream = new FileInputStream(fileName);
structuredModel = StructuredModelManager.getModelManager().getModelForEdit(fileName, inputStream, null);
// format
formatModel(structuredModel, start, length);
// save model if needed
if (!structuredModel.isSharedForEdit() && structuredModel.isSaveNeeded())
structuredModel.save();
} finally {
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredFormatProcessor method formatFile.
public void formatFile(IFile file) throws IOException, CoreException {
if (file == null)
return;
IStructuredModel structuredModel = null;
// OutputStream outputStream = null;
try {
// setup structuredModel
// Note: We are getting model for edit. Will save model if model
// changed.
structuredModel = StructuredModelManager.getModelManager().getModelForEdit(file);
// format
formatModel(structuredModel);
// save model if needed
if (!structuredModel.isSharedForEdit() && structuredModel.isSaveNeeded())
structuredModel.save();
} finally {
// release from model manager
if (structuredModel != null) {
structuredModel.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredFormatProcessor method formatDocument.
public void formatDocument(IDocument document) throws IOException, CoreException {
if (document == null)
return;
IStructuredModel structuredModel = null;
// OutputStream outputStream = null;
try {
// setup structuredModel
// Note: We are getting model for edit. Will save model if model
// changed.
structuredModel = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
// format
formatModel(structuredModel);
// save model if needed
if (!structuredModel.isSharedForEdit() && structuredModel.isSaveNeeded())
structuredModel.save();
} finally {
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredFormatProcessor method formatFileName.
public void formatFileName(String fileName) throws IOException, CoreException {
if (fileName == null)
return;
IStructuredModel structuredModel = null;
InputStream inputStream = null;
// OutputStream outputStream = null;
try {
// setup structuredModel
// Note: We are getting model for edit. Will save model if model
// changed.
inputStream = new FileInputStream(fileName);
structuredModel = StructuredModelManager.getModelManager().getModelForEdit(fileName, inputStream, null);
// format
formatModel(structuredModel);
// save model if needed
if (!structuredModel.isSharedForEdit() && structuredModel.isSaveNeeded())
structuredModel.save();
} finally {
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredFormatProcessor method formatContent.
public String formatContent(String input) throws IOException, CoreException {
if (input == null)
return input;
IStructuredModel structuredModel = null;
InputStream inputStream = null;
try {
// setup structuredModel
// Note: We are getting model for read. Will return formatted
// string and NOT save model.
// $NON-NLS-1$
inputStream = new ByteArrayInputStream(input.getBytes("UTF8"));
// $NON-NLS-1$
String id = inputStream.toString() + "." + getFileExtension();
structuredModel = StructuredModelManager.getModelManager().getModelForRead(id, inputStream, null);
// format
formatModel(structuredModel);
// return output
return structuredModel.getStructuredDocument().get();
} finally {
ensureClosed(null, inputStream);
// release from model manager
if (structuredModel != null)
structuredModel.releaseFromRead();
}
}
Aggregations