-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6
-
generic
-
generic
When default file encoding is not ASCII compatible, such as one of EBCDIC encodings (e.g Cp037) javax.swing.text.html.StyleSheet.importStyleSheet(URL) should default to some ASCII compatible encoding (such as UTF-8) when parsing CSS. CSS stylesheets are always ASCII compatible (see: http://www.w3.org/TR/REC-CSS2/syndata.html#q23)
Please use the following test (Also can be found as an attachement to this CR):
#!/bin/sh
cat > ./StyleSheetTest.java <<"EOF"
import java.net.URL;
import java.util.Enumeration;
import javax.swing.text.html.StyleSheet;
public class StyleSheetTest {
public static void main(String[] args) {
URL url = StyleSheetTest.class.getResource("test.html");
StyleSheet styleSheet = new StyleSheet();
styleSheet.importStyleSheet(url);
boolean hasBody = false;
Enumeration styleNames = styleSheet.getStyleNames();
while (styleNames.hasMoreElements()) {
String styleName = (String) styleNames.nextElement();
System.out.println("found style name: "+styleName);
if (styleName.toUpperCase().equals("BODY")) {
hasBody = true;
}
}
if (hasBody) {
System.out.println("Test passed: BODY style name was found");
} else {
System.out.println("Test failed: BODY style name was not found");
}
}
}
EOF
cat > ./Converter.java <<"EOF"
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
/** This simple utility class converts the output of a program
* written in non-default encoding to output in default encoding
*
* Usage java Converter <Encoding>
*
* if encoding is not specified Cp037 is assumed
*
**/
public class Converter {
public static void main(String[] args) {
String inputEncoding = "Cp037";
if(args.length > 0 && args[0] != null){
inputEncoding = args[0];
}
BufferedReader r = new BufferedReader(new InputStreamReader(System.in,Charset.forName(inputEncoding)));
String line;
try {
while((line = r.readLine()) != null){
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
EOF
cd $CURRENT_DIR
cat > ./test.html <<"EOF"
BODY { margin: 1em; font-family: serif; line-height: 1.1; color: black; }
<HTML>
<HEAD>
</HEAD>
<BODY>
</BODY>
</HTML>
EOF
javac StyleSheetTest.java Converter.java
echo
echo "Testing in Default encoding"
echo
java -classpath . StyleSheetTest
echo
echo Testing in Cp037
echo
java -classpath . -Dfile.encoding=Cp037 StyleSheetTest 2>&1 | java -classpath . Converter
--------------------------------------------------------
The output is:
Testing in Default encoding
found style name: body
found style name: default
Test passed: BODY style name was found
Testing in Cp037
found style name: default
Test failed: BODY style name was not found
Please use the following test (Also can be found as an attachement to this CR):
#!/bin/sh
cat > ./StyleSheetTest.java <<"EOF"
import java.net.URL;
import java.util.Enumeration;
import javax.swing.text.html.StyleSheet;
public class StyleSheetTest {
public static void main(String[] args) {
URL url = StyleSheetTest.class.getResource("test.html");
StyleSheet styleSheet = new StyleSheet();
styleSheet.importStyleSheet(url);
boolean hasBody = false;
Enumeration styleNames = styleSheet.getStyleNames();
while (styleNames.hasMoreElements()) {
String styleName = (String) styleNames.nextElement();
System.out.println("found style name: "+styleName);
if (styleName.toUpperCase().equals("BODY")) {
hasBody = true;
}
}
if (hasBody) {
System.out.println("Test passed: BODY style name was found");
} else {
System.out.println("Test failed: BODY style name was not found");
}
}
}
EOF
cat > ./Converter.java <<"EOF"
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
/** This simple utility class converts the output of a program
* written in non-default encoding to output in default encoding
*
* Usage java Converter <Encoding>
*
* if encoding is not specified Cp037 is assumed
*
**/
public class Converter {
public static void main(String[] args) {
String inputEncoding = "Cp037";
if(args.length > 0 && args[0] != null){
inputEncoding = args[0];
}
BufferedReader r = new BufferedReader(new InputStreamReader(System.in,Charset.forName(inputEncoding)));
String line;
try {
while((line = r.readLine()) != null){
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
EOF
cd $CURRENT_DIR
cat > ./test.html <<"EOF"
BODY { margin: 1em; font-family: serif; line-height: 1.1; color: black; }
<HTML>
<HEAD>
</HEAD>
<BODY>
</BODY>
</HTML>
EOF
javac StyleSheetTest.java Converter.java
echo
echo "Testing in Default encoding"
echo
java -classpath . StyleSheetTest
echo
echo Testing in Cp037
echo
java -classpath . -Dfile.encoding=Cp037 StyleSheetTest 2>&1 | java -classpath . Converter
--------------------------------------------------------
The output is:
Testing in Default encoding
found style name: body
found style name: default
Test passed: BODY style name was found
Testing in Cp037
found style name: default
Test failed: BODY style name was not found