Skip to content

Pair replacement #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions org/w3c/css/parser/CssSelectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
9 changes: 4 additions & 5 deletions org/w3c/css/properties/css2/font/FontFamily.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions org/w3c/css/servlet/CssValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, ?> pair : Codecs.mpFormDataDecode(buf, req.getContentType())) {
switch (pair.getKey()) {
case opt_file:
file = (FakeFile) pair.getValue();
break;
Expand Down
44 changes: 22 additions & 22 deletions org/w3c/css/util/Codecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Pair<String, ?>> mpFormDataDecode(byte[] data,
String cont_type)
throws IOException {

ArrayList<Pair<String, ?>> pList = new ArrayList<>();

// Find and extract boundary string
String bndstr = getParameter("boundary", cont_type);
if (bndstr == null) {
Expand All @@ -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]");
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -364,22 +364,22 @@ 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) {
System.err.println("[DEBUG] p is [" + hdr.substring(pbeg, pend) + "]");
}
// 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;
Expand All @@ -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)) {
Expand Down
119 changes: 0 additions & 119 deletions org/w3c/css/util/NVPair.java

This file was deleted.

Loading