- From: Jean-Guilhem Rouel via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 11 Aug 2009 13:43:02 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/request In directory hutz:/tmp/cvs-serv6157/org/w3c/unicorn/request Modified Files: DirectRequestGET.java URIRequest.java RequestList.java Request.java DirectRequestPOST.java UploadRequest.java Log Message: Code cleanup Index: DirectRequestPOST.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestPOST.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- DirectRequestPOST.java 23 Sep 2008 13:53:58 -0000 1.9 +++ DirectRequestPOST.java 11 Aug 2009 13:43:00 -0000 1.10 @@ -4,12 +4,9 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.request; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.StringBufferInputStream; import java.net.URL; import java.net.URLConnection; import java.util.Hashtable; @@ -20,11 +17,11 @@ import org.w3c.unicorn.input.DirectInputModule; import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.response.Response; -import org.w3c.unicorn.response.parser.ResponseParserFactory; /** * Class to make a request directly using POST method - * @author Damien LEROY + * + * @author Damien LEROY */ public class DirectRequestPOST extends Request { @@ -88,13 +85,12 @@ final String sInputParameterName, final InputModule aInputModule, final String responseType) throws IOException { super(); - DirectRequestPOST.logger.trace("Constructor"); - if (DirectRequestPOST.logger.isDebugEnabled()) { - DirectRequestPOST.logger.debug("URL : " + sURL + "."); - DirectRequestPOST.logger.debug("Input parameter name : " + Request.logger.trace("Constructor"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("URL : " + sURL + "."); + Request.logger.debug("Input parameter name : " + sInputParameterName + "."); - DirectRequestPOST.logger.debug("Input module : " + aInputModule - + "."); + Request.logger.debug("Input module : " + aInputModule + "."); } if (!(aInputModule instanceof DirectInputModule)) { throw new IllegalArgumentException("InputModule : " @@ -109,17 +105,17 @@ @Override public void addParameter(final String sName, final String sValue) throws IOException { - DirectRequestPOST.logger.trace("addParameter"); - if (DirectRequestPOST.logger.isDebugEnabled()) { - DirectRequestPOST.logger.debug("Name :" + sName + "."); - DirectRequestPOST.logger.debug("Value :" + sValue + "."); + Request.logger.trace("addParameter"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("Name :" + sName + "."); + Request.logger.debug("Value :" + sValue + "."); } this.mapOfParameter.put(sName, sValue); } @Override public Response doRequest() throws IOException { - DirectRequestPOST.logger.trace("doRequest"); + Request.logger.trace("doRequest"); final URL aURL = new URL(sURL); this.aURLConnection = aURL.openConnection(); this.aURLConnection.setDoOutput(true); @@ -132,22 +128,21 @@ } for (final String sName : this.mapOfParameter.keySet()) { final String sValue = this.mapOfParameter.get(sName); - DirectRequestPOST.logger.trace("addParameter"); - if (DirectRequestPOST.logger.isDebugEnabled()) { - DirectRequestPOST.logger.debug("Name :" + sName + "."); - DirectRequestPOST.logger.debug("Value :" + sValue + "."); + Request.logger.trace("addParameter"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("Name :" + sName + "."); + Request.logger.debug("Value :" + sValue + "."); } - DirectRequestPOST.logger.debug("--"); - DirectRequestPOST.logger.debug(this.sBoundary); - DirectRequestPOST.logger.debug("\r\n"); - DirectRequestPOST.logger - .debug("Content-Disposition: form-data; name=\""); - DirectRequestPOST.logger.debug(sName); - DirectRequestPOST.logger.debug('"'); - DirectRequestPOST.logger.debug("\r\n"); - DirectRequestPOST.logger.debug("\r\n"); - DirectRequestPOST.logger.debug(sValue); - DirectRequestPOST.logger.debug("\r\n"); + Request.logger.debug("--"); + Request.logger.debug(this.sBoundary); + Request.logger.debug("\r\n"); + Request.logger.debug("Content-Disposition: form-data; name=\""); + Request.logger.debug(sName); + Request.logger.debug('"'); + Request.logger.debug("\r\n"); + Request.logger.debug("\r\n"); + Request.logger.debug(sValue); + Request.logger.debug("\r\n"); // boundary this.aOutputStream.write("--".getBytes()); this.aOutputStream.write(this.sBoundary.getBytes()); @@ -165,27 +160,28 @@ this.aOutputStream.write(sValue.getBytes()); this.aOutputStream.write("\r\n".getBytes()); } - DirectRequestPOST.logger.debug("--"); - DirectRequestPOST.logger.debug(this.sBoundary); - DirectRequestPOST.logger.debug("--"); - DirectRequestPOST.logger.debug("\r\n"); + Request.logger.debug("--"); + Request.logger.debug(this.sBoundary); + Request.logger.debug("--"); + Request.logger.debug("\r\n"); this.aOutputStream.write("--".getBytes()); this.aOutputStream.write(this.sBoundary.getBytes()); this.aOutputStream.write("--".getBytes()); this.aOutputStream.write("\r\n".getBytes()); this.aOutputStream.close(); - + InputStream is = aURLConnection.getInputStream(); - - return streamToResponse(is); + + return streamToResponse(is); } @Override public EnumInputMethod getInputMethod() { - DirectRequestPOST.logger.trace("getInputMethod"); + Request.logger.trace("getInputMethod"); return EnumInputMethod.DIRECT; } + @Override public String toString() { final int iStringBufferSize = 1000; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); Index: DirectRequestGET.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestGET.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- DirectRequestGET.java 23 Sep 2008 13:53:58 -0000 1.7 +++ DirectRequestGET.java 11 Aug 2009 13:43:00 -0000 1.8 @@ -4,11 +4,8 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.request; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringBufferInputStream; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; @@ -17,7 +14,6 @@ import org.w3c.unicorn.input.DirectInputModule; import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.response.Response; -import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.util.Property; /** @@ -55,13 +51,12 @@ final String sInputParameterName, final InputModule aInputModule, final String responseType) throws IOException { super(); - DirectRequestGET.logger.trace("Constructor"); - if (DirectRequestGET.logger.isDebugEnabled()) { - DirectRequestGET.logger.debug("URL : " + sURL + "."); - DirectRequestGET.logger.debug("Input parameter name : " + Request.logger.trace("Constructor"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("URL : " + sURL + "."); + Request.logger.debug("Input parameter name : " + sInputParameterName + "."); - DirectRequestGET.logger.debug("Input module : " + aInputModule - + "."); + Request.logger.debug("Input module : " + aInputModule + "."); } if (!(aInputModule instanceof DirectInputModule)) { throw new IllegalArgumentException("InputModule : " @@ -75,10 +70,10 @@ @Override public void addParameter(final String sName, final String sValue) throws IOException { - DirectRequestGET.logger.trace("addParameter"); - if (DirectRequestGET.logger.isDebugEnabled()) { - DirectRequestGET.logger.debug("Name :" + sName + "."); - DirectRequestGET.logger.debug("Value :" + sValue + "."); + Request.logger.trace("addParameter"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("Name :" + sName + "."); + Request.logger.debug("Value :" + sValue + "."); } if (null == this.sParameter) { this.sParameter = ""; @@ -87,17 +82,17 @@ } this.sParameter += sName + "=" + URLEncoder.encode(sValue, Property.get("UNICORN_ENCODING")); - DirectRequestGET.logger.debug("Parameters : " + this.sParameter + "."); + Request.logger.debug("Parameters : " + this.sParameter + "."); } @Override public Response doRequest() throws IOException { - DirectRequestGET.logger.trace("doRequest"); + Request.logger.trace("doRequest"); final URL aURL; if (null == this.sParameter) { aURL = new URL(this.sURL); } else { - DirectRequestGET.logger.debug(this.sParameter); + Request.logger.debug(this.sParameter); aURL = new URL(this.sURL + "?" + this.sParameter); } final URLConnection aURLConnection = aURL.openConnection(); @@ -105,15 +100,16 @@ InputStream is = aURLConnection.getInputStream(); - return streamToResponse(is); + return streamToResponse(is); } @Override public EnumInputMethod getInputMethod() { - DirectRequestGET.logger.trace("getInputMethod"); + Request.logger.trace("getInputMethod"); return EnumInputMethod.DIRECT; } + @Override public String toString() { final int iStringBufferSize = 1000; final String sVariableSeparator = " "; Index: UploadRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/UploadRequest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- UploadRequest.java 25 Sep 2008 17:37:44 -0000 1.9 +++ UploadRequest.java 11 Aug 2009 13:43:00 -0000 1.10 @@ -4,11 +4,8 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.request; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringBufferInputStream; import java.net.MalformedURLException; import java.util.Hashtable; import java.util.Map; @@ -17,7 +14,6 @@ import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.input.UploadInputModule; import org.w3c.unicorn.response.Response; -import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.util.ClientHttpRequest; /** @@ -73,12 +69,12 @@ final String responseType) throws MalformedURLException, IOException { super(); - UploadRequest.logger.trace("Constructor"); - if (UploadRequest.logger.isDebugEnabled()) { - UploadRequest.logger.debug("URL : " + sURL + "."); - UploadRequest.logger.debug("Input parameter name : " + Request.logger.trace("Constructor"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("URL : " + sURL + "."); + Request.logger.debug("Input parameter name : " + sInputParameterName + "."); - UploadRequest.logger.debug("Input module : " + aInputModule + "."); + Request.logger.debug("Input module : " + aInputModule + "."); } if (!(aInputModule instanceof UploadInputModule)) { throw new IllegalArgumentException("InputModule : " @@ -94,44 +90,44 @@ @Override public void addParameter(final String sName, final String sValue) throws IOException { - UploadRequest.logger.trace("addParameter"); - if (UploadRequest.logger.isDebugEnabled()) { - UploadRequest.logger.debug("Name :" + sName + "."); - UploadRequest.logger.debug("Value :" + sValue + "."); + Request.logger.trace("addParameter"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("Name :" + sName + "."); + Request.logger.debug("Value :" + sValue + "."); } this.mapOfParameter.put(sName, sValue); } @Override public Response doRequest() throws IOException { - UploadRequest.logger.trace("doRequest"); + Request.logger.trace("doRequest"); this.aClientHttpRequest = new ClientHttpRequest(sURL); - UploadRequest.logger.debug("Lang : " + this.sLang + "."); + Request.logger.debug("Lang : " + this.sLang + "."); this.aClientHttpRequest.setLang(sLang); this.aClientHttpRequest.setParameter(this.sInputParameterName, this.aUploadInputModule.getFileName(), this.aUploadInputModule .getInputStream()); for (final String sName : this.mapOfParameter.keySet()) { final String sValue = this.mapOfParameter.get(sName); - UploadRequest.logger.trace("addParameter"); - if (UploadRequest.logger.isDebugEnabled()) { - UploadRequest.logger.debug("Name :" + sName + "."); - UploadRequest.logger.debug("Value :" + sValue + "."); + Request.logger.trace("addParameter"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("Name :" + sName + "."); + Request.logger.debug("Value :" + sValue + "."); } this.aClientHttpRequest.setParameter(sName, sValue); } - final Response aObservationResponse; InputStream is = this.aClientHttpRequest.post(); - - return streamToResponse(is); + + return streamToResponse(is); } @Override public EnumInputMethod getInputMethod() { - UploadRequest.logger.trace("getInputMethod"); + Request.logger.trace("getInputMethod"); return EnumInputMethod.UPLOAD; } + @Override public String toString() { final int iStringBufferSize = 1000; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); Index: RequestList.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/RequestList.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- RequestList.java 19 Sep 2008 18:57:12 -0000 1.6 +++ RequestList.java 11 Aug 2009 13:43:00 -0000 1.7 @@ -5,7 +5,6 @@ package org.w3c.unicorn.request; import java.io.IOException; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; @@ -46,21 +45,20 @@ */ private final Map<String, Request> mapOfRequest = new LinkedHashMap<String, Request>(); - /** * * @return */ - public Map<String,Request> getRequestMap() { + public Map<String, Request> getRequestMap() { RequestList.logger.trace("getRequestMap"); return this.mapOfRequest; } - /** - * Gives an observer placed in the map + * Gives an observer placed in the map * - * @param String sNodeID the ID of the node into which we'll search the Request + * @param String + * sNodeID the ID of the node into which we'll search the Request * @return */ public Request getRequest(final String sNodeID) { @@ -71,22 +69,22 @@ return this.mapOfRequest.get(sNodeID); } - /** * Adds a request to the map + * * @param aRequest - * @param sNodeID The ID of the corresponding node + * @param sNodeID + * The ID of the corresponding node * @throws IOException */ - public void addRequest(final Request aRequest, - final String sNodeID) throws IOException { + public void addRequest(final Request aRequest, final String sNodeID) + throws IOException { RequestList.logger.trace("addRequest"); if (RequestList.logger.isDebugEnabled()) { RequestList.logger.debug("Request : " + aRequest + "."); - RequestList.logger.debug("String node ID : " + sNodeID - + "."); + RequestList.logger.debug("String node ID : " + sNodeID + "."); } aRequest.setLang(this.sLang); this.mapOfRequest.put(sNodeID, aRequest); @@ -95,9 +93,9 @@ /** * Prints the object */ + @Override public String toString() { final int iStringBufferSize = 1000; - final String sVariableSeparator = " "; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); aStringBuffer.append(mapOfRequest); return aStringBuffer.toString(); Index: URIRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/URIRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- URIRequest.java 23 Sep 2008 13:53:58 -0000 1.8 +++ URIRequest.java 11 Aug 2009 13:43:00 -0000 1.9 @@ -4,11 +4,8 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.request; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringBufferInputStream; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLConnection; @@ -18,7 +15,6 @@ import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.input.URIInputModule; import org.w3c.unicorn.response.Response; -import org.w3c.unicorn.response.parser.ResponseParserFactory; /** * Use to handle a request to a observer. @@ -55,12 +51,12 @@ final InputModule aInputModule, final String responseType) throws IOException { super(); - URIRequest.logger.trace("Constructor"); - if (URIRequest.logger.isDebugEnabled()) { - URIRequest.logger.debug("URL : " + sURL + "."); - URIRequest.logger.debug("Input parameter name : " + Request.logger.trace("Constructor"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("URL : " + sURL + "."); + Request.logger.debug("Input parameter name : " + sInputParameterName + "."); - URIRequest.logger.debug("Input module : " + aInputModule + "."); + Request.logger.debug("Input module : " + aInputModule + "."); } if (!(aInputModule instanceof URIInputModule)) { throw new IllegalArgumentException("InputModule : " @@ -80,12 +76,13 @@ * @param sValue * value of the parameter to add */ + @Override public void addParameter(final String sName, final String sValue) throws UnsupportedEncodingException { - URIRequest.logger.trace("addParameter"); - if (URIRequest.logger.isDebugEnabled()) { - URIRequest.logger.debug("sName : " + sName + "."); - URIRequest.logger.debug("sValue : " + sValue + "."); + Request.logger.trace("addParameter"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("sName : " + sName + "."); + Request.logger.debug("sValue : " + sValue + "."); } if (null == this.sParameter) { this.sParameter = ""; @@ -93,7 +90,7 @@ this.sParameter += "&"; } this.sParameter += sName + "=" + URLEncoder.encode(sValue, "UTF-8"); - URIRequest.logger.debug("Parameters : " + this.sParameter + "."); + Request.logger.debug("Parameters : " + this.sParameter + "."); } /** @@ -102,20 +99,21 @@ * @throws IOException * odd error occured */ + @Override public Response doRequest() throws IOException { - URIRequest.logger.trace("doRequest"); - if (URIRequest.logger.isDebugEnabled()) { - URIRequest.logger.debug("URL : " + this.sURL + " ."); - URIRequest.logger.debug("Parameters : " + this.sParameter + " ."); + Request.logger.trace("doRequest"); + if (Request.logger.isDebugEnabled()) { + Request.logger.debug("URL : " + this.sURL + " ."); + Request.logger.debug("Parameters : " + this.sParameter + " ."); } final URL aURL; if (null == this.sParameter) { aURL = new URL(this.sURL); } else { - URIRequest.logger.debug(this.sParameter); + Request.logger.debug(this.sParameter); aURL = new URL(this.sURL + "?" + this.sParameter); } - URIRequest.logger.debug("URL : " + aURL + " ."); + Request.logger.debug("URL : " + aURL + " ."); final URLConnection aURLConnection = aURL.openConnection(); aURLConnection.setRequestProperty("Accept-Language", this.sLang); @@ -125,13 +123,14 @@ @Override public EnumInputMethod getInputMethod() { - URIRequest.logger.trace("getInputMethod"); + Request.logger.trace("getInputMethod"); return EnumInputMethod.URI; } /** * Prints the object */ + @Override public String toString() { final int iStringBufferSize = 1000; final String sVariableSeparator = " "; Index: Request.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/Request.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Request.java 23 Sep 2008 14:26:19 -0000 1.10 +++ Request.java 11 Aug 2009 13:43:00 -0000 1.11 @@ -123,6 +123,7 @@ return null; } + @Override public String toString() { return "Abstract class org.w3c.unicorn.request.Request, toString function must be overrided."; } @@ -134,20 +135,20 @@ public void setResponseType(String responseType) { this.responseType = responseType; } - - protected Response streamToResponse(InputStream is) throws IOException { - StringBuilder builder = new StringBuilder(); - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - char[] chararray = new char[8192]; - int readLength = 0; - while((readLength = isr.read(chararray, 0, 8192)) > -1) { - builder.append(chararray, 0, readLength); - } - Response res = ResponseParserFactory.parse(builder.toString(), - this.getResponseType()); - res.setXml(builder); + protected Response streamToResponse(InputStream is) throws IOException { + StringBuilder builder = new StringBuilder(); + InputStreamReader isr = new InputStreamReader(is, "UTF-8"); + char[] chararray = new char[8192]; + int readLength = 0; + while ((readLength = isr.read(chararray, 0, 8192)) > -1) { + builder.append(chararray, 0, readLength); + } - return res; - } + Response res = ResponseParserFactory.parse(builder.toString(), this + .getResponseType()); + res.setXml(builder); + + return res; + } }
Received on Tuesday, 11 August 2009 13:43:42 UTC