- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Sat, 04 Aug 2012 21:17:09 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv31218/w3c/css/util
Modified Files:
HTTPURL.java Messages.java Utf8Properties.java Util.java
Log Message:
font revamp, still some missing properties for CSS3 and @font-face for CSS2 and CSS3
Index: Utf8Properties.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Utf8Properties.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Utf8Properties.java 23 Oct 2011 19:47:21 -0000 1.5
+++ Utf8Properties.java 4 Aug 2012 21:17:07 -0000 1.6
@@ -100,8 +100,8 @@
if (!property.equals("")) {
int endOfKey = 0;
// calculates the ending index of the key
- while (endOfKey < property.length() &&
- (keyValueSeparators.indexOf(property.charAt(endOfKey)) == -1)) {
+ int l = property.length();
+ while (endOfKey < l && (keyValueSeparators.indexOf(property.charAt(endOfKey)) == -1)) {
endOfKey++;
}
String key = property.substring(0, endOfKey);
@@ -291,10 +291,10 @@
BufferedWriter output;
output = new BufferedWriter(new OutputStreamWriter(out, ENCODING));
if (header != null) {
- output.write("#" + header);
+ output.write('#' + header);
output.newLine();
}
- output.write("#" + new Date());
+ output.write('#' + (new Date()).toString());
output.newLine();
// we do not want that a Thread could modify this Utf8Properties
// while storing it
@@ -304,7 +304,7 @@
String key = storeConversion((String) e.nextElement());
String val = storeConversion((String) get(key));
- output.write(key + "=" + val);
+ output.write(key + '=' + val);
output.newLine();
}
}
Index: Util.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Util.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Util.java 29 Aug 2011 07:21:02 -0000 1.7
+++ Util.java 4 Aug 2012 21:17:07 -0000 1.8
@@ -46,342 +46,348 @@
*/
public final class Util {
- // Constructors
+ // Constructors
- /**
- * This class isn't meant to be instantiated.
- */
- private Util() {}
+ /**
+ * This class isn't meant to be instantiated.
+ */
+ private Util() {
+ }
- // Methods
+ // Methods
- public final static NVPair[] resizeArray(NVPair[] src, int new_size) {
- NVPair tmp[] = new NVPair[new_size];
- System.arraycopy(src, 0, tmp, 0,
- (src.length < new_size ? src.length : new_size));
- return (NVPair[]) tmp;
- }
+ public final static NVPair[] resizeArray(NVPair[] src, int new_size) {
+ NVPair tmp[] = new NVPair[new_size];
+ System.arraycopy(src, 0, tmp, 0,
+ (src.length < new_size ? src.length : new_size));
+ return (NVPair[]) tmp;
+ }
- /**
- * Creates an array of distances to speed up the search in findStr().
- * The returned array should be passed as the second argument to
- * findStr().
- *
- * @param search the search string (same as the first argument to
- * findStr()).
- * @return an array of distances (to be passed as the second argument to
- * findStr()).
- */
- public final static int[] compile_search(byte[] search) {
- int[] cmp = {0, 1, 0, 1, 0, 1};
- int end;
+ /**
+ * Creates an array of distances to speed up the search in findStr().
+ * The returned array should be passed as the second argument to
+ * findStr().
+ *
+ * @param search the search string (same as the first argument to
+ * findStr()).
+ * @return an array of distances (to be passed as the second argument to
+ * findStr()).
+ */
+ public final static int[] compile_search(byte[] search) {
+ int[] cmp = {0, 1, 0, 1, 0, 1};
+ int end;
- for (int idx=0; idx<search.length; idx++) {
- for (end=idx+1; end<search.length; end++) {
- if (search[idx] == search[end]) break;
- }
- if (end < search.length) {
- if ((end-idx) > cmp[1]) {
- cmp[4] = cmp[2];
- cmp[5] = cmp[3];
- cmp[2] = cmp[0];
- cmp[3] = cmp[1];
- cmp[0] = idx;
- cmp[1] = end - idx;
- }
- else if ((end-idx) > cmp[3]) {
- cmp[4] = cmp[2];
- cmp[5] = cmp[3];
- cmp[2] = idx;
- cmp[3] = end - idx;
- }
- else if ((end-idx) > cmp[3]) {
- cmp[4] = idx;
- cmp[5] = end - idx;
- }
- }
- }
+ for (int idx = 0; idx < search.length; idx++) {
+ for (end = idx + 1; end < search.length; end++) {
+ if (search[idx] == search[end]) break;
+ }
+ if (end < search.length) {
+ if ((end - idx) > cmp[1]) {
+ cmp[4] = cmp[2];
+ cmp[5] = cmp[3];
+ cmp[2] = cmp[0];
+ cmp[3] = cmp[1];
+ cmp[0] = idx;
+ cmp[1] = end - idx;
+ } else if ((end - idx) > cmp[3]) {
+ cmp[4] = cmp[2];
+ cmp[5] = cmp[3];
+ cmp[2] = idx;
+ cmp[3] = end - idx;
+ } else if ((end - idx) > cmp[3]) {
+ cmp[4] = idx;
+ cmp[5] = end - idx;
+ }
+ }
+ }
- cmp[1] += cmp[0];
- cmp[3] += cmp[2];
- cmp[5] += cmp[4];
- return cmp;
- }
+ cmp[1] += cmp[0];
+ cmp[3] += cmp[2];
+ cmp[5] += cmp[4];
+ return cmp;
+ }
- /**
- * Search for a string. Use compile_search() to first generate the second
- * argument.
- *
- * @param search the string to search for.
- * @param cmp the the array returned by compile_search.
- * @param str the string in which to look for <var>search</var>.
- * @param beg the position at which to start the search in
- * <var>str</var>.
- * @param end the position at which to end the search in <var>str</var>.
- * @return the position in <var>str</var> where <var>search</var> was
- * found, or -1 if not found.
- */
- public final static int findStr(byte[] search, int[] cmp, byte[] str,
- int beg, int end) {
- int c1f = cmp[0],
- c1l = cmp[1],
- d1 = c1l - c1f,
- c2f = cmp[2],
- c2l = cmp[3],
- d2 = c2l - c2f,
- c3f = cmp[4],
- c3l = cmp[5],
- d3 = c3l - c3f;
+ /**
+ * Search for a string. Use compile_search() to first generate the second
+ * argument.
+ *
+ * @param search the string to search for.
+ * @param cmp the the array returned by compile_search.
+ * @param str the string in which to look for <var>search</var>.
+ * @param beg the position at which to start the search in
+ * <var>str</var>.
+ * @param end the position at which to end the search in <var>str</var>.
+ * @return the position in <var>str</var> where <var>search</var> was
+ * found, or -1 if not found.
+ */
+ public final static int findStr(byte[] search, int[] cmp, byte[] str,
+ int beg, int end) {
+ int c1f = cmp[0],
+ c1l = cmp[1],
+ d1 = c1l - c1f,
+ c2f = cmp[2],
+ c2l = cmp[3],
+ d2 = c2l - c2f,
+ c3f = cmp[4],
+ c3l = cmp[5],
+ d3 = c3l - c3f;
- Find:
- while (beg+search.length <= end) {
- if (search[c1l] == str[beg+c1l]) {
- Comp:
- if (search[c1f] == str[beg+c1f]) {
- for (int idx=0; idx<search.length; idx++)
- if (search[idx] != str[beg+idx]) break Comp;
+ Find:
+ while (beg + search.length <= end) {
+ if (search[c1l] == str[beg + c1l]) {
+ Comp:
+ if (search[c1f] == str[beg + c1f]) {
+ for (int idx = 0; idx < search.length; idx++)
+ if (search[idx] != str[beg + idx]) break Comp;
- break Find; // we found it
- }
- beg += d1;
- }
- else if (search[c2l] == str[beg+c2l])
- beg += d2;
- else if (search[c3l] == str[beg+c3l])
- beg += d3;
- else
- beg++;
- }
+ break Find; // we found it
+ }
+ beg += d1;
+ } else if (search[c2l] == str[beg + c2l])
+ beg += d2;
+ else if (search[c3l] == str[beg + c3l])
+ beg += d3;
+ else
+ beg++;
+ }
- if (beg+search.length > end)
- return -1;
- else
- return beg;
- }
+ if (beg + search.length > end)
+ return -1;
+ else
+ return beg;
+ }
- // ADD 09/15/97
+ // ADD 09/15/97
- public final static boolean isSpace(char c) {
- return c == ' ';
- }
+ public final static boolean isSpace(char c) {
+ return c == ' ';
+ }
- /**
- * Print a message on System.err only if the user wants debug trace.
- */
- public static final void verbose(String s) {
- if (onDebug) {
- System.err.println( s );
- }
- }
+ /**
+ * Print a message on System.err only if the user wants debug trace.
+ */
+ public static final void verbose(String s) {
+ if (onDebug) {
+ System.err.println(s);
+ }
+ }
- /**
- * Suppressed all white spaces in the beginning of the string
- */
- public static final String suppressWhiteSpace(String s) {
- if (s != null) {
- int len = s.length();
- int i = 0;
- while ((i < len) &&
- (isWhiteSpace(s.charAt(i)))) {
- i++;
- }
- if (i == len) {
- return null;
- } else {
- return s.substring(i);
- }
- } else {
- return null;
- }
- }
+ /**
+ * Suppressed all white spaces in the beginning of the string
+ */
+ public static final String suppressWhiteSpace(String s) {
+ if (s != null) {
+ int len = s.length();
+ int i = 0;
+ while (i < len && isWhiteSpace(s.charAt(i))) {
+ i++;
+ }
+ if (i == 0) {
+ return s;
+ } else {
+ return (i == len) ? null : s.substring(i);
+ }
+ }
+ return null;
+ }
- /**
- * Suppress all white spaces
- *
- * @param s the string.
- */
- public final static String strip(String s) {
- int index = 0;
- char[] olds = s.toCharArray();
- char[] news = new char[olds.length];
- for (int i = 0; i < olds.length; i++) {
- if (!isWhiteSpace(olds[i])) { // inline isWhiteSpace
- news[index++] = olds[i];
- }
- }
- return new String(news, 0, index);
- }
+ /**
+ * Suppress all white spaces
+ *
+ * @param s the string.
+ */
+ public final static String strip(String s) {
+ int index = 0;
+ char[] news = new char[s.length()];
- /**
- * Returns <code>true</code> if the character is not a white space
- *
- * @param c the character
- */
- public final static boolean isWhiteSpace(char c) {
- return c == ' ' || c == '\n' || c == '\r' || c == '\t';
- }
+ for (char c : s.toCharArray()) {
+ if (!isWhiteSpace(c)) {
+ news[index++] = c;
+ }
+ }
+ return new String(news, 0, index);
+ }
- /**
- * Display a float without .0 if necessary
- */
- public final static String displayFloat(Float value) {
- int intValue = value.intValue();
- float floatValue = value.floatValue();
- if (((float) intValue) == floatValue) {
- return Integer.toString(intValue, 10);
- } else {
- return value.toString();
- }
- }
+ /**
+ * Returns <code>true</code> if the character is not a white space
+ *
+ * @param c the character
+ */
+ public final static boolean isWhiteSpace(char c) {
+ return c == ' ' || c == '\n' || c == '\r' || c == '\t';
+ }
- /**
- * Display a float without .0 if necessary
- */
- public final static String displayFloat(float value) {
- int intValue = (int) value;
- if (((float) intValue) == value) {
- return Integer.toString(intValue, 10);
- } else {
- return Float.toString(value);
- }
- }
+ /**
+ * Display a float without .0 if necessary
+ */
+ public final static String displayFloat(Float value) {
+ int intValue = value.intValue();
+ float floatValue = value.floatValue();
+ if (((float) intValue) == floatValue) {
+ return Integer.toString(intValue, 10);
+ } else {
+ return value.toString();
+ }
+ }
- /**
- * Replaces characters that may be confused by a HTML
- * parser with their equivalent character entity references
- * to prevent inserted code to be executed while displaying
- * the validation results in HTML format.
- * <p>
- * This method will replace HTML characters such as > with their
- * HTML entity reference (&gt;) so that the html parser will
- * be sure to interpret them as plain text rather than HTML or script.
- * <p>
- *
- * @param s String to be escaped
- * @return escaped String
- * @throws NullPointerException if s is null.
- *
- */
- public static String escapeHTML(String s){
- int length = s.length();
- int newLength = length;
- boolean someCharacterEscaped = false;
- // first check for characters that might
- // be dangerous and calculate a length
- // of the string that has escapes.
- for (int i=0; i<length; i++){
- char c = s.charAt(i);
- int cint = 0xffff & c;
- if (cint < 32){
- switch(c){
- case '\r':
- case '\n':
- case '\t':
- case '\f':{
- } break;
- default: {
- newLength -= 1;
- someCharacterEscaped = true;
- }
- }
- } else {
- switch(c){
- case '\"':{
- newLength += 5;
- someCharacterEscaped = true;
- } break;
- case '&':
- case '\'':{
- newLength += 4;
- someCharacterEscaped = true;
- } break;
- case '<':
- case '>':{
- newLength += 3;
- someCharacterEscaped = true;
- } break;
- }
- }
- }
- if (!someCharacterEscaped){
- // nothing to escape in the string
- return s;
- }
- StringBuilder sb = new StringBuilder(newLength);
- for (int i=0; i<length; i++){
- char c = s.charAt(i);
- int cint = 0xffff & c;
- if (cint < 32){
- switch(c){
- case '\r':
- case '\n':
- case '\t':
- case '\f':{
- sb.append(c);
- } break;
- default: {
- // Remove this character
- }
- }
- } else {
- switch(c){
- case '\"':{
- sb.append(""");
- } break;
- case '\'':{
- sb.append("'");
- } break;
- case '&':{
- sb.append("&");
- } break;
- case '<':{
- sb.append("<");
- } break;
- case '>':{
- sb.append(">");
- } break;
- default: {
- sb.append(c);
- }
- }
- }
-
- }
- return sb.toString();
- }
+ /**
+ * Display a float without .0 if necessary
+ */
+ public final static String displayFloat(float value) {
+ int intValue = (int) value;
+ if (((float) intValue) == value) {
+ return Integer.toString(intValue, 10);
+ } else {
+ return Float.toString(value);
+ }
+ }
+ /**
+ * Replaces characters that may be confused by a HTML
+ * parser with their equivalent character entity references
+ * to prevent inserted code to be executed while displaying
+ * the validation results in HTML format.
+ * <p/>
+ * This method will replace HTML characters such as > with their
+ * HTML entity reference (&gt;) so that the html parser will
+ * be sure to interpret them as plain text rather than HTML or script.
+ * <p/>
+ *
+ * @param s String to be escaped
+ * @return escaped String
+ * @throws NullPointerException if s is null.
+ */
+ public static String escapeHTML(String s) {
+ int length = s.length();
+ int newLength = length;
+ boolean someCharacterEscaped = false;
+ // first check for characters that might
+ // be dangerous and calculate a length
+ // of the string that has escapes.
+ for (int i = 0; i < length; i++) {
+ char c = s.charAt(i);
+ int cint = 0xffff & c;
+ if (cint < 32) {
+ switch (c) {
+ case '\r':
+ case '\n':
+ case '\t':
+ case '\f': {
+ }
+ break;
+ default: {
+ newLength -= 1;
+ someCharacterEscaped = true;
+ }
+ }
+ } else {
+ switch (c) {
+ case '\"': {
+ newLength += 5;
+ someCharacterEscaped = true;
+ }
+ break;
+ case '&':
+ case '\'': {
+ newLength += 4;
+ someCharacterEscaped = true;
+ }
+ break;
+ case '<':
+ case '>': {
+ newLength += 3;
+ someCharacterEscaped = true;
+ }
+ break;
+ }
+ }
+ }
+ if (!someCharacterEscaped) {
+ // nothing to escape in the string
+ return s;
+ }
+ StringBuilder sb = new StringBuilder(newLength);
+ for (int i = 0; i < length; i++) {
+ char c = s.charAt(i);
+ int cint = 0xffff & c;
+ if (cint < 32) {
+ switch (c) {
+ case '\r':
+ case '\n':
+ case '\t':
+ case '\f': {
+ sb.append(c);
+ }
+ break;
+ default: {
+ // Remove this character
+ }
+ }
+ } else {
+ switch (c) {
+ case '\"': {
+ sb.append(""");
+ }
+ break;
+ case '\'': {
+ sb.append("'");
+ }
+ break;
+ case '&': {
+ sb.append("&");
+ }
+ break;
+ case '<': {
+ sb.append("<");
+ }
+ break;
+ case '>': {
+ sb.append(">");
+ }
+ break;
+ default: {
+ sb.append(c);
+ }
+ }
+ }
- /**
- * <code>true</code> if the validator runs in a servlet (security pbs)
- */
- public static boolean servlet;
+ }
+ return sb.toString();
+ }
- /**
- * <code>true</code> if the validator can import URL.
- */
- public static boolean importSecurity;
- /**
- * <code>true</code> if the validator doesn't need errors
- */
- public static boolean noErrorTrace;
+ /**
+ * <code>true</code> if the validator runs in a servlet (security pbs)
+ */
+ public static boolean servlet;
- /**
- * <code>true</code> if the input is a HTML file
- * @@BUG in thread 'coz this a static variable ... :-]
- */
- public static boolean fromHTMLFile;
+ /**
+ * <code>true</code> if the validator can import URL.
+ */
+ public static boolean importSecurity;
- /**
- * <code>true</code> if the user wants debug traces.
- *
- * @see #verbose
- */
- public static boolean onDebug = Boolean.getBoolean("CSS.debug");
- // public static boolean onDebug = false;
+ /**
+ * <code>true</code> if the validator doesn't need errors
+ */
+ public static boolean noErrorTrace;
- // default maximum size for checked entities
- public static long maxEntitySize = 1048576L ;
+ /**
+ * <code>true</code> if the input is a HTML file
+ *
+ * @@BUG in thread 'coz this a static variable ... :-]
+ */
+ public static boolean fromHTMLFile;
+
+ /**
+ * <code>true</code> if the user wants debug traces.
+ *
+ * @see #verbose
+ */
+ public static boolean onDebug = Boolean.getBoolean("CSS.debug");
+ // public static boolean onDebug = false;
+
+ // default maximum size for checked entities
+ public static long maxEntitySize = 1048576L;
}
Index: HTTPURL.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/HTTPURL.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- HTTPURL.java 5 Nov 2011 09:16:11 -0000 1.27
+++ HTTPURL.java 4 Aug 2012 21:17:07 -0000 1.28
@@ -34,370 +34,369 @@
*/
public class HTTPURL {
- /**
- * Don't create this class
- */
- private HTTPURL() {
- }
-
+ /**
+ * Don't create this class
+ */
+ private HTTPURL() {
+ }
- public static String getHTTPStatusCode(int status) {
- switch (status) {
- case 100:
- return "Continue";
- case 101:
- return "Switching Protocols";
- case 200:
- return "OK";
- case 201:
- return "Created";
- case 202:
- return "Accepted";
- case 203:
- return "Non-Authoritative Information";
- case 204:
- return "No Content";
- case 205:
- return "Reset Content";
- case 206:
- return "Partial Content";
- case 300:
- return "Multiple Choices";
- case 301:
- return "Moved Permanently";
- case 302:
- return "Found";
- case 303:
- return "See Other";
- case 304:
- return "Not Modified";
- case 305:
- return "Use Proxy";
- case 306:
- return "(Unused)";
- case 307:
- return "Temporary Redirect";
- case 400:
- return "Bad Request";
- case 401:
- return "Unauthorized";
- case 402:
- return "Payment Required";
- case 403:
- return "Forbidden";
- case 404:
- return "Not Found";
- case 405:
- return "Method Not Allowed";
- case 406:
- return "Not Acceptable";
- case 407:
- return "Proxy Authentication Required";
- case 408:
- return "Request Timeout";
- case 409:
- return "Conflict";
- case 410:
- return "Gone";
- case 411:
- return "Length Required";
- case 412:
- return "Precondition Failed";
- case 413:
- return "Request Entity Too Large";
- case 414:
- return "Request-URI Too Long";
- case 415:
- return "Unsupported Media Type";
- case 416:
- return "Requested Range Not Satisfiable";
- case 417:
- return "Expectation Failed";
- case 500:
- return "Internal Server Error";
- case 501:
- return "Not Implemented";
- case 502:
- return "Bad Gateway";
- case 503:
- return "Service Unavailable";
- case 504:
- return "Gateway Timeout";
- case 505:
- return "HTTP Version Not Supported";
- default:
- return Integer.toString(status, 10);
- }
- }
- public static URL getURL(String url) throws IOException {
- // url = URLEncoder.encode(url);
- try {
- return new URL(url);
- } catch (MalformedURLException e) {
- //if (!url.startsWith("http:")) { // ook!? dkfj://wwww.3.org -> http://dkfj://www.w3.org
- if (url.indexOf("://") == -1) { // the protocol is missing
- return new URL("http://" + url);
- } else {
- throw (IOException) e.fillInStackTrace();
- }
- }
- }
+ public static String getHTTPStatusCode(int status) {
+ switch (status) {
+ case 100:
+ return "Continue";
+ case 101:
+ return "Switching Protocols";
+ case 200:
+ return "OK";
+ case 201:
+ return "Created";
+ case 202:
+ return "Accepted";
+ case 203:
+ return "Non-Authoritative Information";
+ case 204:
+ return "No Content";
+ case 205:
+ return "Reset Content";
+ case 206:
+ return "Partial Content";
+ case 300:
+ return "Multiple Choices";
+ case 301:
+ return "Moved Permanently";
+ case 302:
+ return "Found";
+ case 303:
+ return "See Other";
+ case 304:
+ return "Not Modified";
+ case 305:
+ return "Use Proxy";
+ case 306:
+ return "(Unused)";
+ case 307:
+ return "Temporary Redirect";
+ case 400:
+ return "Bad Request";
+ case 401:
+ return "Unauthorized";
+ case 402:
+ return "Payment Required";
+ case 403:
+ return "Forbidden";
+ case 404:
+ return "Not Found";
+ case 405:
+ return "Method Not Allowed";
+ case 406:
+ return "Not Acceptable";
+ case 407:
+ return "Proxy Authentication Required";
+ case 408:
+ return "Request Timeout";
+ case 409:
+ return "Conflict";
+ case 410:
+ return "Gone";
+ case 411:
+ return "Length Required";
+ case 412:
+ return "Precondition Failed";
+ case 413:
+ return "Request Entity Too Large";
+ case 414:
+ return "Request-URI Too Long";
+ case 415:
+ return "Unsupported Media Type";
+ case 416:
+ return "Requested Range Not Satisfiable";
+ case 417:
+ return "Expectation Failed";
+ case 500:
+ return "Internal Server Error";
+ case 501:
+ return "Not Implemented";
+ case 502:
+ return "Bad Gateway";
+ case 503:
+ return "Service Unavailable";
+ case 504:
+ return "Gateway Timeout";
+ case 505:
+ return "HTTP Version Not Supported";
+ default:
+ return Integer.toString(status, 10);
+ }
+ }
- public static URL getURL(URL base, String url)
- throws MalformedURLException {
- // url = URLEncoder.encode(url);
+ public static URL getURL(String url) throws IOException {
+ // url = URLEncoder.encode(url);
+ try {
+ return new URL(url);
+ } catch (MalformedURLException e) {
+ //if (!url.startsWith("http:")) { // ook!? dkfj://wwww.3.org -> http://dkfj://www.w3.org
+ if (url.indexOf("://") == -1) { // the protocol is missing
+ return new URL("http://" + url);
+ } else {
+ throw (IOException) e.fillInStackTrace();
+ }
+ }
+ }
- return new URL(base, url);
- }
+ public static URL getURL(URL base, String url)
+ throws MalformedURLException {
+ // url = URLEncoder.encode(url);
+ return new URL(base, url);
+ }
- private static URLConnection getConnection(URL url, int count)
- throws IOException {
- return getConnection(url, null, count, null);
- }
+ private static URLConnection getConnection(URL url, int count)
+ throws IOException {
+ return getConnection(url, null, count, null);
+ }
- private static void setSSLVerifier(HttpsURLConnection uConn) {
- TrustManager[] trustAllCerts = new TrustManager[]{
- new X509TrustManager() {
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
+ private static void setSSLVerifier(HttpsURLConnection uConn) {
+ TrustManager[] trustAllCerts = new TrustManager[]{
+ new X509TrustManager() {
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
- public void checkClientTrusted(
- java.security.cert.X509Certificate[] certs, String authType) {
- }
+ public void checkClientTrusted(
+ java.security.cert.X509Certificate[] certs, String authType) {
+ }
- public void checkServerTrusted(
- java.security.cert.X509Certificate[] certs, String authType) {
- }
- }
- };
+ public void checkServerTrusted(
+ java.security.cert.X509Certificate[] certs, String authType) {
+ }
+ }
+ };
- // Install the all-trusting trust manager
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, trustAllCerts, new java.security.SecureRandom());
- uConn.setSSLSocketFactory(sc.getSocketFactory());
- } catch (Exception e) {
- }
+ // Install the all-trusting trust manager
+ try {
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, trustAllCerts, new java.security.SecureRandom());
+ uConn.setSSLSocketFactory(sc.getSocketFactory());
+ } catch (Exception e) {
+ }
- // Step 2: hostname verifier
- HostnameVerifier hv = new HostnameVerifier() {
- public boolean verify(String urlHostName, SSLSession session) {
- return true;
- }
- };
- uConn.setHostnameVerifier(hv);
- }
+ // Step 2: hostname verifier
+ HostnameVerifier hv = new HostnameVerifier() {
+ public boolean verify(String urlHostName, SSLSession session) {
+ return true;
+ }
+ };
+ uConn.setHostnameVerifier(hv);
+ }
- private static URLConnection getConnection(URL url, URL referrer, int count,
- ApplContext ac)
- throws IOException {
- if (count > 5) {
- throw new ProtocolException("Server redirected too many " +
- "times (5)");
- }
- // add the referrer, if not the same as the target URL
- URL ref = (url.equals(referrer) ? null : referrer);
+ private static URLConnection getConnection(URL url, URL referrer, int count,
+ ApplContext ac)
+ throws IOException {
+ if (count > 5) {
+ throw new ProtocolException("Server redirected too many " +
+ "times (5)");
+ }
+ // add the referrer, if not the same as the target URL
+ URL ref = (url.equals(referrer) ? null : referrer);
- if (Util.servlet) {
- String protocol = url.getProtocol();
- if (!(("https".equalsIgnoreCase(protocol)) || ("http".equalsIgnoreCase(protocol)))) {
- System.err.println("[WARNING] : someone is trying to get the file: "
- + url);
- throw new FileNotFoundException("import " + url +
- ": Operation not permitted");
- }
- }
+ if (Util.servlet) {
+ String protocol = url.getProtocol();
+ if (!(("https".equalsIgnoreCase(protocol)) || ("http".equalsIgnoreCase(protocol)))) {
+ System.err.println("[WARNING] : someone is trying to get the file: "
+ + url);
+ throw new FileNotFoundException("import " + url +
+ ": Operation not permitted");
+ }
+ }
- URLConnection urlC = url.openConnection();
+ URLConnection urlC = url.openConnection();
- if (Util.onDebug) {
- System.err.println("Accessing " + url);
- if (ac.getCredential() != null) {
- System.err.println("with [" + ac.getCredential() + ']');
- }
- }
- // avoid all kind of caches
- urlC.setRequestProperty("Pragma", "no-cache");
- urlC.setRequestProperty("Cache-Control", "no-cache, no-store");
- // for the fun
- urlC.setRequestProperty("User-Agent",
- "Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0");
- // referrer
- setReferrer(urlC, ref);
- // relay authorization information
- if (ac.getCredential() != null) {
- urlC.setRequestProperty("Authorization", ac.getCredential());
- }
- // relay languages
- if (ac.getLang() != null) {
- if (ac.getLang().indexOf('*') == -1) {
- urlC.setRequestProperty("Accept-Language", ac.getLang() + ",*");
- } else {
- urlC.setRequestProperty("Accept-Language", ac.getLang());
- }
- }
- // should I put an Accept header?
- urlC.setRequestProperty("Accept",
- "text/css,text/html,text/xml,"
- + "application/xhtml+xml,application/xml,"
- + "image/svg+xml,*/*;q=0.1");
+ if (Util.onDebug) {
+ System.err.println("Accessing " + url);
+ if (ac.getCredential() != null) {
+ System.err.println("with [" + ac.getCredential() + ']');
+ }
+ }
+ // avoid all kind of caches
+ urlC.setRequestProperty("Pragma", "no-cache");
+ urlC.setRequestProperty("Cache-Control", "no-cache, no-store");
+ // for the fun
+ urlC.setRequestProperty("User-Agent",
+ "Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0");
+ // referrer
+ setReferrer(urlC, ref);
+ // relay authorization information
+ if (ac.getCredential() != null) {
+ urlC.setRequestProperty("Authorization", ac.getCredential());
+ }
+ // relay languages
+ if (ac.getLang() != null) {
+ if (ac.getLang().indexOf('*') == -1) {
+ urlC.setRequestProperty("Accept-Language", ac.getLang() + ",*");
+ } else {
+ urlC.setRequestProperty("Accept-Language", ac.getLang());
+ }
+ }
+ // should I put an Accept header?
+ urlC.setRequestProperty("Accept",
+ "text/css,text/html,text/xml,"
+ + "application/xhtml+xml,application/xml,"
+ + "image/svg+xml,*/*;q=0.1");
- if (urlC instanceof HttpURLConnection) {
- HttpURLConnection httpURL = (HttpURLConnection) urlC;
- int status;
+ if (urlC instanceof HttpURLConnection) {
+ HttpURLConnection httpURL = (HttpURLConnection) urlC;
+ int status;
- httpURL.setInstanceFollowRedirects(false);
- if (urlC instanceof HttpsURLConnection) {
- setSSLVerifier((HttpsURLConnection) urlC);
- }
- urlC.connect();
+ httpURL.setInstanceFollowRedirects(false);
+ if (urlC instanceof HttpsURLConnection) {
+ setSSLVerifier((HttpsURLConnection) urlC);
+ }
+ urlC.connect();
- try {
- status = httpURL.getResponseCode();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- throw new FileNotFoundException(url + ": " +
- getHTTPStatusCode(404));
- }
+ try {
+ status = httpURL.getResponseCode();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ throw new FileNotFoundException(url + ": " +
+ getHTTPStatusCode(404));
+ }
- switch (status) {
- case HttpURLConnection.HTTP_OK:
- // nothing to do
- break;
- case HttpURLConnection.HTTP_MOVED_PERM:
- case HttpURLConnection.HTTP_MOVED_TEMP:
- case 307:
- try {
- URL u = getURL(httpURL.getHeaderField("Location"));
- return getConnection(u, ref, count + 1, ac);
- } finally {
- httpURL.disconnect();
- }
- case HttpURLConnection.HTTP_UNAUTHORIZED:
- String realm = httpURL.getHeaderField("WWW-Authenticate");
- httpURL.disconnect();
- if (realm != null) {
- throw new ProtocolException(realm);
- }
- default:
- try {
- if (httpURL.getResponseMessage() != null) {
- throw new FileNotFoundException(url + ": " +
- httpURL.getResponseMessage());
- } else {
- throw new FileNotFoundException(url + ": " +
- getHTTPStatusCode(status));
- }
- } finally {
- httpURL.disconnect();
- }
- }
- } else {
- urlC.connect();
- }
- return urlC;
- }
+ switch (status) {
+ case HttpURLConnection.HTTP_OK:
+ // nothing to do
+ break;
+ case HttpURLConnection.HTTP_MOVED_PERM:
+ case HttpURLConnection.HTTP_MOVED_TEMP:
+ case 307:
+ try {
+ URL u = getURL(httpURL.getHeaderField("Location"));
+ return getConnection(u, ref, count + 1, ac);
+ } finally {
+ httpURL.disconnect();
+ }
+ case HttpURLConnection.HTTP_UNAUTHORIZED:
+ String realm = httpURL.getHeaderField("WWW-Authenticate");
+ httpURL.disconnect();
+ if (realm != null) {
+ throw new ProtocolException(realm);
+ }
+ default:
+ try {
+ if (httpURL.getResponseMessage() != null) {
+ throw new FileNotFoundException(url + ": " +
+ httpURL.getResponseMessage());
+ } else {
+ throw new FileNotFoundException(url + ": " +
+ getHTTPStatusCode(status));
+ }
+ } finally {
+ httpURL.disconnect();
+ }
+ }
+ } else {
+ urlC.connect();
+ }
+ return urlC;
+ }
- public static URLConnection getConnection(URL url)
- throws IOException {
- return getConnection(url, 0);
- }
+ public static URLConnection getConnection(URL url)
+ throws IOException {
+ return getConnection(url, 0);
+ }
- public static URLConnection getConnection(URL url, ApplContext ac)
- throws IOException {
- return getConnection(url, ac.getReferrer(), 0, ac);
- }
+ public static URLConnection getConnection(URL url, ApplContext ac)
+ throws IOException {
+ return getConnection(url, ac.getReferrer(), 0, ac);
+ }
- /* more madness */
- public static InputStream getInputStream(ApplContext ac, URLConnection uco)
- throws IOException {
- InputStream orig_stream = uco.getInputStream();
- String charset;
- String encoding;
- if (orig_stream == null) {
- return orig_stream; // let it fail elsewhere
- }
- encoding = uco.getContentEncoding();
- // not set -> return
- if (encoding != null) {
- if (encoding.equalsIgnoreCase("gzip")) {
- orig_stream = new GZIPInputStream(orig_stream);
- }
- }
- charset = getCharacterEncoding(ac, uco);
- if ((charset == null) || (charset.regionMatches(true, 0, "utf", 0, 3))) {
- UnicodeInputStream is = new UnicodeInputStream(orig_stream);
- charset = is.getEncodingFromStream();
- if (charset != null) {
- ac.setCharsetForURL(uco.getURL(), charset);
- }
- return is;
- }
- return orig_stream;
- }
+ /* more madness */
+ public static InputStream getInputStream(ApplContext ac, URLConnection uco)
+ throws IOException {
+ InputStream orig_stream = uco.getInputStream();
+ String charset;
+ String encoding;
+ if (orig_stream == null) {
+ return orig_stream; // let it fail elsewhere
+ }
+ encoding = uco.getContentEncoding();
+ // not set -> return
+ if (encoding != null) {
+ if (encoding.equalsIgnoreCase("gzip")) {
+ orig_stream = new GZIPInputStream(orig_stream);
+ }
+ }
+ charset = getCharacterEncoding(ac, uco);
+ if ((charset == null) || (charset.regionMatches(true, 0, "utf", 0, 3))) {
+ UnicodeInputStream is = new UnicodeInputStream(orig_stream);
+ charset = is.getEncodingFromStream();
+ if (charset != null) {
+ ac.setCharsetForURL(uco.getURL(), charset);
+ }
+ return is;
+ }
+ return orig_stream;
+ }
- public static String getCharacterEncoding(ApplContext ac,
- URLConnection uco) {
- String charset = ac.getCharsetForURL(uco.getURL());
- if (charset != null) {
- return charset;
- }
- String mtypestr = uco.getContentType();
- if (mtypestr == null) {
- return mtypestr;
- }
- MimeType mt;
- try {
- mt = new MimeType(mtypestr);
- } catch (MimeTypeFormatException mex) {
- return null;
- }
- charset = mt.getParameterValue("charset");
- if (charset != null) {
- ac.setCharsetForURL(uco.getURL(), charset);
- }
- return charset;
- }
+ public static String getCharacterEncoding(ApplContext ac,
+ URLConnection uco) {
+ String charset = ac.getCharsetForURL(uco.getURL());
+ if (charset != null) {
+ return charset;
+ }
+ String mtypestr = uco.getContentType();
+ if (mtypestr == null) {
+ return mtypestr;
+ }
+ MimeType mt;
+ try {
+ mt = new MimeType(mtypestr);
+ } catch (MimeTypeFormatException mex) {
+ return null;
+ }
+ charset = mt.getParameterValue("charset");
+ if (charset != null) {
+ ac.setCharsetForURL(uco.getURL(), charset);
+ }
+ return charset;
+ }
- // used to set referrer
- private static void setReferrer(URLConnection connection, URL referrer) {
- if (referrer == null) {
- return;
- }
- URL current = connection.getURL();
- String curProtocol = current.getProtocol();
- String refProtocol = referrer.getProtocol();
- if ("https".equalsIgnoreCase(refProtocol)) {
- if (!"https".equalsIgnoreCase(curProtocol)) {
- // exit, we won't disclose information on non-https
- // connections (ref using https, req using http)
- return;
- }
- // ok so we have https for both, avoid leaking information
- // so check that hosts are the same
- if (!current.getHost().equalsIgnoreCase(referrer.getHost())) {
- return;
- }
- }
- // ok good, let's do it
- connection.setRequestProperty("Referer", referrer.toExternalForm());
- }
+ // used to set referrer
+ private static void setReferrer(URLConnection connection, URL referrer) {
+ if (referrer == null) {
+ return;
+ }
+ URL current = connection.getURL();
+ String curProtocol = current.getProtocol();
+ String refProtocol = referrer.getProtocol();
+ if ("https".equalsIgnoreCase(refProtocol)) {
+ if (!"https".equalsIgnoreCase(curProtocol)) {
+ // exit, we won't disclose information on non-https
+ // connections (ref using https, req using http)
+ return;
+ }
+ // ok so we have https for both, avoid leaking information
+ // so check that hosts are the same
+ if (!current.getHost().equalsIgnoreCase(referrer.getHost())) {
+ return;
+ }
+ }
+ // ok good, let's do it
+ connection.setRequestProperty("Referer", referrer.toExternalForm());
+ }
- /**
- *
- */
- public static void main(String[] args)
- throws Exception {
- int c;
- InputStream in = HTTPURL.getConnection(
- getURL(args[0])).getInputStream();
+ /**
+ *
+ */
+ public static void main(String[] args)
+ throws Exception {
+ int c;
+ InputStream in = HTTPURL.getConnection(
+ getURL(args[0])).getInputStream();
- while ((c = in.read()) != -1) {
- System.err.print((char) c);
- }
- System.exit(0);
- }
+ while ((c = in.read()) != -1) {
+ System.err.print((char) c);
+ }
+ System.exit(0);
+ }
}
Index: Messages.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Messages.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- Messages.java 17 Sep 2011 06:02:27 -0000 1.43
+++ Messages.java 4 Aug 2012 21:17:07 -0000 1.44
@@ -8,9 +8,9 @@
package org.w3c.css.util;
import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
/**
* @version $Revision$
@@ -22,7 +22,7 @@
*/
public Utf8Properties<String, String> properties = null;
- public static final Hashtable<String, Utf8Properties<String, String>> languages;
+ public static final ConcurrentHashMap<String, Utf8Properties<String, String>> languages;
public static final ArrayList<String> languages_name;
/**
@@ -205,7 +205,7 @@
}
static {
- languages = new Hashtable<String, Utf8Properties<String, String>>();
+ languages = new ConcurrentHashMap<String, Utf8Properties<String, String>>();
languages_name = new ArrayList<String>();
Utf8Properties<String, String> tmp;
Received on Saturday, 4 August 2012 21:17:12 UTC