Search in sources :

Example 1 with HTMLResourceEncodingDetector

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();
        }
    }
}
Also used : HTMLResourceEncodingDetector(org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EncodingMemento(org.eclipse.wst.sse.core.internal.encoding.EncodingMemento) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with HTMLResourceEncodingDetector

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());
}
Also used : HTMLResourceEncodingDetector(org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector)

Example 3 with 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());
}
Also used : HTMLResourceEncodingDetector(org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector)

Example 4 with 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());
}
Also used : HTMLResourceEncodingDetector(org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector)

Example 5 with 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());
}
Also used : HTMLResourceEncodingDetector(org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector)

Aggregations

HTMLResourceEncodingDetector (org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector)11 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 EncodingMemento (org.eclipse.wst.sse.core.internal.encoding.EncodingMemento)1