use of org.eclipse.wst.sse.core.internal.document.DocumentReader in project webtools.sourceediting by eclipse.
the class JSONSyntaxValidator method validateFile.
/**
* Validates the given file. It will stream the contents of the file without
* creating a model for the file; it will only use existing
*
* @param file
* the file to validate
* @param reporter
* the reporter
*/
private void validateFile(IFile file, IReporter reporter) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
reporter.displaySubtask(JSONSyntaxValidator.this, message);
JSONLineTokenizer tokenizer = null;
try {
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
try {
if (model == null) {
tokenizer = new JSONLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
} else {
tokenizer = new JSONLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
}
JSONSyntaxValidatorHelper.validate(tokenizer, reporter, this, this);
} finally {
if (model != null) {
model.releaseFromRead();
model = null;
}
}
} catch (UnsupportedEncodingException e) {
} catch (CoreException e) {
} catch (IOException e) {
}
}
use of org.eclipse.wst.sse.core.internal.document.DocumentReader in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method saveStructuredDocument.
public void saveStructuredDocument(IStructuredDocument structuredDocument, IFile iFile, EncodingRule encodingRule) throws UnsupportedEncodingException, CoreException, IOException {
// $NON-NLS-1$
Assert.isNotNull(iFile, "file parameter can not be null");
if (FileBufferModelManager.getInstance().isExistingBuffer(structuredDocument)) {
ITextFileBuffer buffer = FileBufferModelManager.getInstance().getBuffer(structuredDocument);
if (iFile.getFullPath().equals(buffer.getLocation()) || (iFile.getLocation() != null && iFile.getLocation().equals(buffer.getLocation())) || (iFile.getLocationURI() != null && buffer.getFileStore() != null && iFile.getLocationURI().equals(buffer.getFileStore().toURI()))) {
buffer.commit(new NullProgressMonitor(), true);
}
} else {
// IModelHandler handler = calculateType(iFile);
// IDocumentDumper dumper = handler.getDocumentDumper();
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
Reader reader = new DocumentReader(structuredDocument);
codedStreamCreator.set(iFile, reader);
codedStreamCreator.setPreviousEncodingMemento(structuredDocument.getEncodingMemento());
EncodingMemento encodingMemento = codedStreamCreator.getCurrentEncodingMemento();
// be sure document's is updated, in case exception is thrown in
// getCodedByteArrayOutputStream
structuredDocument.setEncodingMemento(encodingMemento);
// Convert line delimiters after encoding memento is figured out,
// but
// before writing to output stream.
handleConvertLineDelimiters(structuredDocument, iFile, encodingRule, encodingMemento);
ByteArrayOutputStream codedByteStream = codedStreamCreator.getCodedByteArrayOutputStream(encodingRule);
InputStream codedStream = new ByteArrayInputStream(codedByteStream.toByteArray());
if (iFile.exists())
iFile.setContents(codedStream, true, true, null);
else
iFile.create(codedStream, false, null);
codedByteStream.close();
codedStream.close();
}
}
Aggregations