Skip to content

Remove the dependency on Jigsaw #449

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 4 additions & 14 deletions autotest/AutoTestContentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
// (c) COPYRIGHT MIT, ERCIM and Keio, 2003.
// Please first read the full copyright statement in file COPYRIGHT.html

import org.w3c.www.http.HTTP;
import org.w3c.www.protocol.http.HttpException;
import org.w3c.www.protocol.http.HttpManager;
import org.w3c.www.protocol.http.Reply;
import org.w3c.www.protocol.http.Request;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
Expand All @@ -20,6 +15,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

Expand Down Expand Up @@ -293,22 +289,18 @@ public void endElement(String nameSpaceURI, String localName, String rawName)
val += PARAMS;

try {
HttpManager manager = HttpManager.getManager();
Request request = manager.createRequest();
request.setMethod(HTTP.GET);
HttpURLConnection conn = (HttpURLConnection) new URL(val).openConnection();
System.err.println(val);
request.setURL(new URL(val));
Reply reply = manager.runRequest(request);
// Get the reply input stream that contains the actual data:
InputStream res = reply.getInputStream();
InputStream res = conn.getInputStream();

int currentChar;
StringBuffer buf = new StringBuffer();
while ((currentChar = res.read()) != -1) {
buf.append((char) currentChar);
}

if (reply.getStatus() == 500) { // Internal Server Error
if (conn.getResponseCode() == 500) { // Internal Server Error
if (buf.indexOf("env:Sender") != -1) {
printError(val, "Reply status code: 500<br/>"
+ "Invalid URL: Sender error");
Expand Down Expand Up @@ -348,8 +340,6 @@ public void endElement(String nameSpaceURI, String localName, String rawName)
printError(val, e.getMessage());
} catch (IOException e) {
printError(val, e.getMessage());
} catch (HttpException e) {
printError(val, e.getMessage());
}

isFile = false;
Expand Down
3 changes: 0 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<target name="prepare.check">
<condition property="prepare.run">
<and>
<available file="lib/jigsaw-2.2.6.jar"/>
<available file="lib/commons-beanutils-1.10.0.jar"/>
<available file="lib/commons-collections4-4.4.jar"/>
<available file="lib/commons-digester3-3.2.jar"/>
Expand All @@ -57,7 +56,6 @@
<mkdir dir="lib"/>
<mkdir dir="tmp"/>

<get dest="tmp/jigsaw-2.2.6.jar" src="https://repo1.maven.org/maven2/org/w3c/jigsaw/jigsaw/2.2.6/jigsaw-2.2.6.jar" usetimestamp="true"/>
<get dest="tmp/commons-beanutils-1.10.0.jar" src="https://repo1.maven.org/maven2/commons-beanutils/commons-beanutils/1.10.0/commons-beanutils-1.10.0.jar" usetimestamp="true"/>
<get dest="tmp/commons-collections4-4.4.jar" src="https://repo1.maven.org/maven2/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar" usetimestamp="true"/>
<get dest="tmp/commons-digester3-3.2.jar" src="https://repo1.maven.org/maven2/org/apache/commons/commons-digester3/3.2/commons-digester3-3.2.jar" usetimestamp="true"/>
Expand All @@ -77,7 +75,6 @@


<copy file="tmp/servlet-api-2.5-6.0.1.jar" tofile="lib/servlet-api-2.5-6.0.1.jar"/>
<copy file="tmp/jigsaw-2.2.6.jar" tofile="lib/jigsaw-2.2.6.jar"/>
<copy file="tmp/commons-beanutils-1.10.0.jar" tofile="lib/commons-beanutils-1.10.0.jar"/>
<copy file="tmp/commons-collections4-4.4.jar" tofile="lib/commons-collections4-4.4.jar"/>
<copy file="tmp/commons-digester3-3.2.jar" tofile="lib/commons-digester3-3.2.jar"/>
Expand Down
7 changes: 3 additions & 4 deletions org/w3c/css/util/ApplContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.w3c.css.parser.Frame;
import org.w3c.www.http.HttpAcceptCharset;
import org.w3c.www.http.HttpAcceptCharsetList;
import org.w3c.www.http.HttpFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -367,10 +366,10 @@ public void setContentEncoding(String acceptCharset) {
// uses some Jigsaw classes to parse the Accept-Charset
// these classes need to load a lot of stuff, so it may be quite
// long the first time
HttpAcceptCharsetList charsetList;
HttpAcceptCharset[] charsets;
HttpAcceptCharsetList charsetList = new HttpAcceptCharsetList();
charsetList.setString(acceptCharset);

charsetList = HttpFactory.parseAcceptCharsetList(acceptCharset);
HttpAcceptCharset[] charsets;
charsets = (HttpAcceptCharset[]) charsetList.getValue();

String encoding = null;
Expand Down
14 changes: 14 additions & 0 deletions org/w3c/tools/resources/ProtocolException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ProtocolException.java
// $Id: ProtocolException.java,v 1.2 2000/08/16 21:37:53 ylafon Exp $
// (c) COPYRIGHT MIT and INRIA, 1996.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.tools.resources ;

public class ProtocolException extends Exception {

public ProtocolException (String msg) {
super (msg) ;
}

}
164 changes: 164 additions & 0 deletions org/w3c/www/http/HeaderValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// HeaderValue.java
// $Id$
// (c) COPYRIGHT MIT and INRIA, 1996.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.www.http;

public abstract class HeaderValue implements Cloneable {
/**
* The header value, as a byte array, if available.
*/
protected byte raw[] = null;
/**
* The offset of the value in the above buffer, in case the buffer is
* shared.
*/
protected int roff = -1;
/**
* The length of the byte value in case the above buffer is shared.
*/
protected int rlen = -1;
/**
* Are the parsed values up to date with the lastly set unparsed value ?
*/
protected boolean isValid = false;

/**
* Parse this header value into its various components.
* @exception HttpParserException if unable to parse.
*/

abstract protected void parse()
throws HttpParserException;

/**
* Update the RFC822 compatible header value for this object.
*/

abstract protected void updateByteValue();

/**
* Compute the new RFC822 compatible representation of this header value.
* If our value is up to date, we just return, otherwise, the abstract
* <code>updateByteValue</code> is called to perform the job.
*/

protected final void checkByteValue() {
if ( raw == null ) {
updateByteValue();
roff = 0;
rlen = raw.length;
}
}

/**
* Validate the parsed value according to the last set raw value.
* This will trigger the header value parsing, if it is required at this
* point.
* @exception HttpInvalidValueException If the value couldn't be parsed
* properly.
*/

protected final void validate()
throws HttpInvalidValueException
{
if ( isValid )
return;
try {
parse();
} catch (HttpParserException ex) {
throw new HttpInvalidValueException(ex.getMessage());
}
isValid = true;
}

/**
* Invalidate the current byte value for this header, if any.
*/

protected void invalidateByteValue() {
raw = null;
}

/**
* Emit a parsing error.
* @param msg The error message.
* @exception HttpParserException If the parsing failed.
*/

protected void error(String msg)
throws HttpParserException
{
throw new HttpParserException(msg);
}

/**
* Append this header byte value to the given buffer.
* @param buf The buffer to append the byte value to.
*/

public void appendValue(HttpBuffer buf) {
checkByteValue();
buf.append(raw, roff, rlen);
}

/**
* Return the HTTP encoding for this header value.
* This method is slow, and defeats nearly all the over-engeneered
* optimization of the HTTP parser.
* @return A String representing the header value in a format compatible
* with HTTP.
*/

public String toExternalForm() {
checkByteValue();
return new String(raw, 0, roff, rlen-roff);
}

/**
* Print this header value as it would be emitted.
* @return A String representation of this header value.
*/

public String toString() {
return toExternalForm();
}

/**
* Set this Header Value by parsing the given String.
* @param strval The String value for that object.
* @return Itself.
*/

public void setString(String strval) {
int slen = strval.length();
raw = new byte[slen];
roff = 0;
rlen = slen;
strval.getBytes(0, slen, raw, 0);
isValid = false;
}

/**
* Get this header parsed value, in its native type.
* HeaderValue implementors can be used as wrappers for the actual
* parsed header value. In such case this method should return the wrapped
* value (you would otherwise, probably want to return
* <strong>this</strong>).
*/

abstract public Object getValue() ;

// needs to define it as this is an abstract class
protected Object clone()
throws CloneNotSupportedException
{
return super.clone();
}

public HeaderValue() {
isValid = false;
}

}
111 changes: 111 additions & 0 deletions org/w3c/www/http/HttpAcceptCharset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// HttpAcceptCharset.java
// $Id$
// (c) COPYRIGHT MIT and INRIA, 1996.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.www.http;

public class HttpAcceptCharset extends HeaderValue {
String charset = null;
double quality = 1.0;
HttpAcceptCharsetList list = null;

/**
* parse.
* @exception HttpParserException if parsing failed.
*/
protected void parse()
throws HttpParserException
{
ParseState ps = new ParseState(roff, rlen);
ps.separator = (byte) ';';
ps.spaceIsSep = false;
// Get the charset:
if ( HttpParser.nextItem(raw, ps) < 0 )
error("Invalid Accept-Charset: no charset.");
this.charset = new String(raw, 0, ps.start, ps.end-ps.start);
// And the optional quality:
ps.prepare();
ps.separator = (byte) '=';
if ( HttpParser.nextItem(raw, ps) < 0 ) {
this.quality = 1.0;
} else {
ps.prepare();
this.quality = HttpParser.parseQuality(raw, ps);
}
}

protected void invalidateByteValue() {
super.invalidateByteValue();
if ( list != null )
list.invalidateByteValue();
}

protected void updateByteValue() {
HttpBuffer buf = new HttpBuffer();
buf.append(charset);
buf.append(';');
buf.append(quality);
raw = buf.getByteCopy();
roff = 0;
rlen = raw.length;
}

public Object getValue() {
validate();
return this;
}

/**
* Get this accept charset clause charset.
* @return A String encoding the charset token.
*/

public String getCharset() {
validate();
return charset;
}

/**
* Set the charset accepted by this clause.
* @param charset The accepted charset.
*/

public void setCharset(String charset) {
if ( this.charset.equals(charset) )
return;
invalidateByteValue();
this.charset = charset;
}

/**
* Get the quality at which this charset is accepted.
* @return A double value, encoding the quality, or <strong>1.0</strong>
* if undefined.
*/

public double getQuality() {
validate();
return quality;
}

/**
* Set the quality under which this charset is accepted.
* @param quality The quality for this charset.
*/

public void setQuality(double quality) {
if ( this.quality != quality )
invalidateByteValue();
this.quality = quality;
}

HttpAcceptCharset(HttpAcceptCharsetList list, byte raw[], int o, int l) {
this.list = list;
this.raw = raw;
this.roff = o;
this.rlen = l;
this.isValid = false;
}

}
Loading