diff --git a/org/w3c/css/parser/CssSelectors.java b/org/w3c/css/parser/CssSelectors.java index 3c1b2c00f..da512a44d 100644 --- a/org/w3c/css/parser/CssSelectors.java +++ b/org/w3c/css/parser/CssSelectors.java @@ -90,7 +90,7 @@ public CssSelectors(ApplContext ac) { super(ac); style = ac.getCssSelectorsStyle(); try { - properties = (CssStyle) style.newInstance(); + properties = (CssStyle) style.getConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); } @@ -101,7 +101,7 @@ private CssSelectors(Class style) { super(); CssSelectors.style = style; try { - properties = (CssStyle) style.newInstance(); + properties = (CssStyle) style.getConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); } @@ -484,7 +484,7 @@ void Invalidate() { if (Init) { // yes I invalidate all properties too ! try { - properties = (CssStyle) style.newInstance(); + properties = (CssStyle) style.getConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); } diff --git a/org/w3c/css/properties/css2/font/FontFamily.java b/org/w3c/css/properties/css2/font/FontFamily.java index 9b2cb3453..84e1915c6 100644 --- a/org/w3c/css/properties/css2/font/FontFamily.java +++ b/org/w3c/css/properties/css2/font/FontFamily.java @@ -13,7 +13,6 @@ import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; -import org.w3c.css.util.Util; import org.w3c.css.values.CssExpression; import org.w3c.css.values.CssIdent; import org.w3c.css.values.CssOperator; @@ -199,7 +198,7 @@ public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { /** * Compares two properties for equality. * - * @param value The other property. + * @param property The other property. */ public boolean equals(CssProperty property) { return false; //@@ FIXME @@ -213,9 +212,9 @@ private static String trimToOneSpace(String name) { name.getChars(0, count, src, 0); for (int i = 0; i < count; i++) - if (i == 0 || !Util.isWhiteSpace(src[i]) || - (Util.isWhiteSpace(src[i]) && - !Util.isWhiteSpace(dst[index]))) + if (i == 0 || !Character.isWhitespace(src[i]) || + (Character.isWhitespace(src[i]) && + !Character.isWhitespace(dst[index]))) dst[++index] = src[i]; return new String(dst, 0, index + 1); diff --git a/org/w3c/css/servlet/CssValidator.java b/org/w3c/css/servlet/CssValidator.java index e02521022..7cbd2aa40 100644 --- a/org/w3c/css/servlet/CssValidator.java +++ b/org/w3c/css/servlet/CssValidator.java @@ -7,6 +7,7 @@ package org.w3c.css.servlet; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.validator.routines.EmailValidator; import org.w3c.css.css.CssParser; import org.w3c.css.css.DocumentParser; @@ -26,7 +27,6 @@ import org.w3c.css.util.FakeFile; import org.w3c.css.util.HTTPURL; import org.w3c.css.util.InvalidParamException; -import org.w3c.css.util.NVPair; import org.w3c.css.util.Utf8Properties; import org.w3c.css.util.Util; import org.w3c.www.mime.MimeType; @@ -576,8 +576,8 @@ public void doPost(HttpServletRequest req, HttpServletResponse res) try { buf = new byte[count]; System.arraycopy(general, 0, buf, 0, count); - for (NVPair pair : Codecs.mpFormDataDecode(buf, req.getContentType())) { - switch (pair.getName()) { + for (Pair pair : Codecs.mpFormDataDecode(buf, req.getContentType())) { + switch (pair.getKey()) { case opt_file: file = (FakeFile) pair.getValue(); break; diff --git a/org/w3c/css/util/Codecs.java b/org/w3c/css/util/Codecs.java index aaf090249..2dcd35455 100644 --- a/org/w3c/css/util/Codecs.java +++ b/org/w3c/css/util/Codecs.java @@ -38,7 +38,12 @@ package org.w3c.css.util; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; /** * This class collects various encoders and decoders. @@ -98,16 +103,18 @@ private Codecs() { * @param cont_type the content type header (must contain the * boundary string). * @return an array of name/value pairs, one for each part; - * the name is the 'name' attribute given in the - * Content-Disposition header; the value is either - * the name of the file if a filename attribute was - * found, or the contents of the part. + * the name is the 'name' attribute given in the + * Content-Disposition header; the value is either + * the name of the file if a filename attribute was + * found, or the contents of the part. * @throws IOException If any file operation fails. */ - public final static synchronized NVPair[] mpFormDataDecode(byte[] data, - String cont_type) + public final static synchronized ArrayList> mpFormDataDecode(byte[] data, + String cont_type) throws IOException { + ArrayList> pList = new ArrayList<>(); + // Find and extract boundary string String bndstr = getParameter("boundary", cont_type); if (bndstr == null) { @@ -119,9 +126,9 @@ public final static synchronized NVPair[] mpFormDataDecode(byte[] data, boundary = new byte[bndstr.length() + 6], endbndry = new byte[bndstr.length() + 6]; - srtbndry = ("--" + bndstr + "\n").getBytes(); - boundary = ("\n--" + bndstr + "\n").getBytes(); - endbndry = ("\n--" + bndstr + "--").getBytes(); + srtbndry = ("--" + bndstr + "\n").getBytes(StandardCharsets.ISO_8859_1); + boundary = ("\n--" + bndstr + "\n").getBytes(StandardCharsets.ISO_8859_1); + endbndry = ("\n--" + bndstr + "--").getBytes(StandardCharsets.ISO_8859_1); if (debugMode) { System.err.println("[START OF DATA]"); @@ -163,7 +170,6 @@ public final static synchronized NVPair[] mpFormDataDecode(byte[] data, start += srtbndry.length; - NVPair[] res = new NVPair[10]; boolean done = false; int idx; @@ -314,20 +320,14 @@ public final static synchronized NVPair[] mpFormDataDecode(byte[] data, } else { // It's simple data value = new String(data, start, end - start); } - - if (idx >= res.length) { - res = Util.resizeArray(res, idx + 10); - } - - res[idx] = new NVPair(name, value); + pList.add(new ImmutablePair<>(name, value)); if (debugMode) { System.err.println("[ADD " + name + ',' + value + ',' + value.getClass() + ']'); } start = end + boundary.length; } - - return Util.resizeArray(res, idx); + return pList; } @@ -364,14 +364,14 @@ public final static String getParameter(String param, String hdr) { pbeg = vend + 1; } while (pbeg < len - 1 - && (Util.isWhiteSpace(hdr.charAt(pbeg)) || (hdr.charAt(pbeg) == ';'))) { + && (Character.isWhitespace(hdr.charAt(pbeg)) || (hdr.charAt(pbeg) == ';'))) { pbeg++; } if (pbeg == len - 1) return null; pend = hdr.indexOf('=', pbeg + 1); // get '=' if (pend == -1) return null; vbeg = pend + 1; - while (Util.isWhiteSpace(hdr.charAt(--pend))) ; + while (Character.isWhitespace(hdr.charAt(--pend))) ; pend++; if (debugMode) { @@ -379,7 +379,7 @@ public final static String getParameter(String param, String hdr) { } // mark parameter value - while (vbeg < len && Util.isWhiteSpace(hdr.charAt(vbeg))) vbeg++; + while (vbeg < len && Character.isWhitespace(hdr.charAt(vbeg))) vbeg++; if (vbeg == len) return null; vend = vbeg; @@ -390,7 +390,7 @@ public final static String getParameter(String param, String hdr) { } else { // is a simple token vend = hdr.indexOf(';', vbeg); if (vend == -1) vend = hdr.length(); - while (Util.isWhiteSpace(hdr.charAt(--vend))) ; + while (Character.isWhitespace(hdr.charAt(--vend))) ; vend++; } if (hdr.regionMatches(true, pbeg, param, 0, pend - pbeg)) { diff --git a/org/w3c/css/util/NVPair.java b/org/w3c/css/util/NVPair.java deleted file mode 100644 index 164058030..000000000 --- a/org/w3c/css/util/NVPair.java +++ /dev/null @@ -1,119 +0,0 @@ -// -// $Id$ -// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) -// -// (c) COPYRIGHT MIT and INRIA, 1997. -// Please first read the full copyright statement in file COPYRIGHT.html -/* - * Be Careful this version is not the original version. - * I modified some sources. Philippe Le Hegaret - * - * @(#)NVPair.java 0.2-2 23/03/1997 - * - * This file is part of the HTTPClient package - * Copyright (C) 1996,1997 Ronald Tschalaer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA - * - * For questions, suggestions, bug-reports, enhancement-requests etc. - * I may be contacted at: - * - * ronald@innovation.ch - * Ronald.Tschalaer@psi.ch - * - */ - -package org.w3c.css.util; - -/** - * This class holds a Name/Value pair of strings. It's used for form-data - * and various internal things. - * - * @version 0.2 (bug fix 2) 23/03/1997 - * @author Ronald Tschalär - */ - -public class NVPair { - /** - * the name - */ - String name; - - /** - * the value - */ - Object value; - - // Constructors - - /** - * Creates an empty name/value pair. - */ - NVPair() { - this("", ""); - } - - /** - * Creates a copy of a given name/value pair. - * - * @param p the name/value pair to copy - */ - public NVPair(NVPair p) { - this(p.name, p.value); - } - - /** - * Creates a new name/value pair and initializes it to the - * specified name and value. - * - * @param name the name - * @param value the value - */ - public NVPair(String name, Object value) { - this.name = name; - this.value = value; - } - - // Methods - - /** - * get the name - * - * @return the name - */ - public final String getName() { - return name; - } - - /** - * get the value - * - * @return the value - */ - public final Object getValue() { - return value; - } - - /** - * produces a string containing the name and value of this instance. - * - * @return a string containing the class name and the name and value - */ - public String toString() { - return getClass().getName() + "[name=" + name + ",value=" + value + "]"; - } -} - diff --git a/org/w3c/css/util/Util.java b/org/w3c/css/util/Util.java index 6d0ec527b..67983f009 100644 --- a/org/w3c/css/util/Util.java +++ b/org/w3c/css/util/Util.java @@ -105,15 +105,6 @@ public static boolean checkURI(String uri) { return true; } - // 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; - } - /** * Creates an array of distances to speed up the search in findStr(). * The returned array should be passed as the second argument to @@ -122,7 +113,7 @@ public final static NVPair[] resizeArray(NVPair[] src, int new_size) { * @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()). + * findStr()). */ public final static int[] compile_search(byte[] search) { int[] cmp = {0, 1, 0, 1, 0, 1}; @@ -145,7 +136,7 @@ public final static int[] compile_search(byte[] search) { cmp[5] = cmp[3]; cmp[2] = idx; cmp[3] = end - idx; - } else if ((end - idx) > cmp[3]) { + } else if ((end - idx) > cmp[5]) { cmp[4] = idx; cmp[5] = end - idx; } @@ -165,23 +156,24 @@ public final static int[] compile_search(byte[] search) { * @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 search. - * @param beg the position at which to start the search in + * @param begin the position at which to start the search in * str. * @param end the position at which to end the search in str. * @return the position in str where search was - * found, or -1 if not found. + * 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; + int begin, int end) { + int beg = begin; + int c1f = cmp[0]; + int c1l = cmp[1]; + int d1 = c1l - c1f; + int c2f = cmp[2]; + int c2l = cmp[3]; + int d2 = c2l - c2f; + int c3f = cmp[4]; + int c3l = cmp[5]; + int d3 = c3l - c3f; Find: while (beg + search.length <= end) { @@ -208,12 +200,6 @@ else if (search[c3l] == str[beg + c3l]) return beg; } - // ADD 09/15/97 - - public final static boolean isSpace(char c) { - return c == ' '; - } - /** * Print a message on System.err only if the user wants debug trace. */ @@ -230,7 +216,7 @@ public static final String suppressWhiteSpace(String s) { if (s != null) { int len = s.length(); int i = 0; - while (i < len && isWhiteSpace(s.charAt(i))) { + while (i < len && Character.isWhitespace(s.charAt(i))) { i++; } if (i == 0) { @@ -252,22 +238,13 @@ public final static String strip(String s) { char[] news = new char[s.length()]; for (char c : s.toCharArray()) { - if (!isWhiteSpace(c)) { + if (!Character.isWhitespace(c)) { news[index++] = c; } } return new String(news, 0, index); } - /** - * Returns true if the character is a whitespace character - * - * @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 */