use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.
the class CodedReaderCreator method getResettableStream.
private InputStream getResettableStream() throws CoreException, IOException {
InputStream resettableStream = null;
if (fIFile != null) {
InputStream inputStream = null;
try {
// note we always get contents, even if out of synch
inputStream = fIFile.getContents(true);
} catch (CoreException e) {
// SHOULD actually check for existence of
// fIStorage, but
// for now will just assume core exception
// means it
// doesn't exist on file system, yet.
// and we'll log, just in case its a noteable error
Logger.logException(e);
inputStream = new NullInputStream();
}
resettableStream = new BufferedInputStream(inputStream, CodedIO.MAX_BUF_SIZE);
} else {
if (fInputStream != null) {
if (fInputStream.markSupported()) {
resettableStream = fInputStream;
// try {
resettableStream.reset();
// }
// catch (IOException e) {
// // assumed just hasn't been marked yet, so ignore
// }
} else {
resettableStream = new BufferedInputStream(fInputStream, CodedIO.MAX_BUF_SIZE);
}
}
}
if (resettableStream == null) {
resettableStream = new NullInputStream();
}
// mark this once, stream at "zero" position
resettableStream.mark(MAX_MARK_SIZE);
return resettableStream;
}
use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.
the class CodedReaderCreator method findMementoFromStreamCase.
/**
* The primary method which contains the highest level rules for how to
* decide appropriate decoding rules: 1. first check for unicode stream 2.
* then looked for encoding specified in content (according to the type of
* content that is it ... xml, html, jsp, etc. 3. then check for various
* settings: file settings first, if null check project settings, if null,
* check user preferences. 4. lastly (or, what is the last user
* preference) is to use "workbench defaults".
*
* @throws IOException
* @throws CoreException
*/
private EncodingMemento findMementoFromStreamCase() throws CoreException, IOException {
EncodingMemento result = null;
InputStream resettableLimitedStream = null;
try {
resettableLimitedStream = getLimitedStream(getResettableStream());
if (resettableLimitedStream != null) {
// first check for unicode stream
result = checkStreamForBOM(resettableLimitedStream);
// if not that, then check contents
if (result == null) {
resettableLimitedStream.reset();
result = checkForEncodingInContents(resettableLimitedStream);
}
} else {
// stream null, may name's not.
if (fFilename != null) {
// filename not null
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
IContentDescription contentDescription = contentTypeManager.getDescriptionFor(new NullInputStream(), fFilename, IContentDescription.ALL);
if (contentDescription != null) {
result = createMemento(contentDescription);
}
}
}
} finally {
if (resettableLimitedStream != null) {
handleStreamClose(resettableLimitedStream);
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.
the class ModelModifications method createXMLModel.
/**
* Be sure to release any models obtained from this method.
*
* @return
* @throws IOException
* @throws UnsupportedEncodingException
*/
private static IDOMModel createXMLModel() throws UnsupportedEncodingException, IOException {
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForEdit("test.xml", new NullInputStream(), null);
// always use the same line delimiter for these tests, regardless
// of
// plaform or preference settings
model.getStructuredDocument().setLineDelimiter(TestWriter.commonEOL);
return (IDOMModel) model;
}
use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testReplaceTrailingSpaceofEqualSignWithTwoSpaces.
public void testReplaceTrailingSpaceofEqualSignWithTwoSpaces() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) before).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 5, 0, " ");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertEquals("Node replaced", before, after);
assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
assertEquals("unexpected document content", "<a b= c></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testAppendWhitespaceToEqualSign.
public void testAppendWhitespaceToEqualSign() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) before).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 5, 0, " ");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertEquals("Node replaced", before, after);
assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
assertEquals("unexpected document content", "<a b= c></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
Aggregations