use of org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector in project webtools.sourceediting by eclipse.
the class HTMLEncodingTests method doTestFileStream.
private void doTestFileStream(String filename, String expectedIANAEncoding, IResourceCharsetDetector detector) throws IOException {
File file = HTMLEncodingTestsPlugin.getTestFile(filename);
if (!file.exists())
throw new IllegalArgumentException(filename + " was not found");
InputStream inputStream = new FileInputStream(file);
// InputStream inStream = getClass().getResourceAsStream(filename);
InputStream istream = getMarkSupportedStream(inputStream);
try {
detector.set(istream);
EncodingMemento encodingMemento = ((HTMLResourceEncodingDetector) detector).getEncodingMemento();
String foundIANAEncoding = null;
if (encodingMemento != null) {
foundIANAEncoding = encodingMemento.getJavaCharsetName();
}
// I changed many "equals" to "equalsIgnoreCase" on 11/4/2002,
// since
// some issues with SHIFT_JIS vs. Shift_JIS were causing failures.
// We do want to be tolerant on input, and accept either, but I
// think
// that SupportedJavaEncodings needs to be changed to "recommend"
// Shift_JIS.
boolean expectedIANAResult = false;
if (expectedIANAEncoding == null) {
expectedIANAResult = (expectedIANAEncoding == foundIANAEncoding);
} else {
expectedIANAResult = expectedIANAEncoding.equalsIgnoreCase(foundIANAEncoding);
}
assertTrue("encoding test file " + filename + " expected: " + expectedIANAEncoding + " found: " + foundIANAEncoding, expectedIANAResult);
// throws exception.
if (expectedIANAEncoding != null) {
ensureCanRead(filename, foundIANAEncoding, istream);
}
} finally {
if (istream != null) {
istream.close();
}
if (inputStream != null) {
inputStream.close();
}
}
}
use of org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector in project webtools.sourceediting by eclipse.
the class HTMLEncodingTests method testNoEncoding.
public void testNoEncoding() throws IOException {
String filename = fileLocation + "NoEncoding.html";
// HTML has no spec default encoding. Will use platform default encoding.
doTestFileStream(filename, System.getProperty("file.encoding"), new HTMLResourceEncodingDetector());
}
use of org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector in project webtools.sourceediting by eclipse.
the class HTMLEncodingTests method testEmptyFile.
public void testEmptyFile() throws IOException {
String filename = fileLocation + "EmptyFile.html";
// HTML has no spec default encoding. Will use platform default encoding.
doTestFileStream(filename, System.getProperty("file.encoding"), new HTMLResourceEncodingDetector());
}
use of org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector in project webtools.sourceediting by eclipse.
the class HTMLEncodingTests method testIllformedNormalNonDefault.
public void testIllformedNormalNonDefault() throws IOException {
String filename = fileLocation + "IllformedNormalNonDefault.html";
String ianaInFile = "UTF-8";
doTestFileStream(filename, ianaInFile, new HTMLResourceEncodingDetector());
}
use of org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector in project webtools.sourceediting by eclipse.
the class HTMLEncodingTests method testMultiNonDefault.
public void testMultiNonDefault() throws IOException {
String filename = fileLocation + "MultiNonDefault.html";
doTestFileStream(filename, "ISO-8859-6", new HTMLResourceEncodingDetector());
}
Aggregations