- From: Florent Batard via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 17 Jun 2008 13:41:13 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/request
In directory hutz:/tmp/cvs-serv11946/org/w3c/unicorn/request
Modified Files:
DirectRequestGET.java URIRequest.java RequestList.java
Request.java DirectRequestPOST.java UploadRequest.java
Log Message:
Updating the javadoc for all the project
Index: DirectRequestPOST.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestPOST.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- DirectRequestPOST.java 20 Feb 2008 15:09:57 -0000 1.4
+++ DirectRequestPOST.java 17 Jun 2008 13:41:11 -0000 1.5
@@ -19,41 +19,81 @@
import org.w3c.unicorn.response.parser.ResponseParserFactory;
/**
- * @author Damien LEROY
- *
+ * @author Damien LEROY Class to make a request directly using POST method
*/
public class DirectRequestPOST extends Request {
+ /**
+ * generate a random number
+ */
private static Random aRandom = new Random();
+ /**
+ * URL for the post direct request
+ */
private String sURL = null;
+
+ /**
+ * Data Structure for the parameters
+ */
private Map<String, String> mapOfParameter = null;
- private String sBoundary =
- "---------------------------" +
- DirectRequestPOST.randomString() +
- DirectRequestPOST.randomString() +
- DirectRequestPOST.randomString();
+
+ /**
+ * Random string for hazardous purpose
+ */
+ private String sBoundary = "---------------------------"
+ + DirectRequestPOST.randomString()
+ + DirectRequestPOST.randomString()
+ + DirectRequestPOST.randomString();
+
+ /**
+ * URL to connect
+ */
private URLConnection aURLConnection = null;
+
+ /**
+ * Output stream for the post
+ */
private OutputStream aOutputStream = null;
- private static String randomString () {
+ /**
+ * Generate random strings
+ *
+ * @return a random string
+ */
+ private static String randomString() {
return Long.toString(DirectRequestPOST.aRandom.nextLong(), 36);
}
- protected DirectRequestPOST (
- final String sURL,
- final String sInputParameterName,
- final InputModule aInputModule,
+ /**
+ * Constructor for a direct request using post method
+ *
+ * @param sURL
+ * URL to connect
+ * @param sInputParameterName
+ * parameter name
+ * @param aInputModule
+ * input module for the request
+ * @param responseType
+ * type of the response of the observer
+ * @throws IOException
+ * odd error occurs
+ */
+ protected DirectRequestPOST(final String sURL,
+ 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 : " + sInputParameterName + ".");
- DirectRequestPOST.logger.debug("Input module : " + aInputModule + ".");
+ DirectRequestPOST.logger.debug("Input parameter name : "
+ + sInputParameterName + ".");
+ DirectRequestPOST.logger.debug("Input module : " + aInputModule
+ + ".");
}
if (!(aInputModule instanceof DirectInputModule)) {
- throw new IllegalArgumentException("InputModule : " + aInputModule.toString() + ".");
+ throw new IllegalArgumentException("InputModule : "
+ + aInputModule.toString() + ".");
}
this.mapOfParameter = new Hashtable<String, String>();
this.sURL = sURL;
@@ -62,7 +102,8 @@
}
@Override
- public void addParameter (final String sName, final String sValue) throws IOException {
+ public void addParameter(final String sName, final String sValue)
+ throws IOException {
DirectRequestPOST.logger.trace("addParameter");
if (DirectRequestPOST.logger.isDebugEnabled()) {
DirectRequestPOST.logger.debug("Name :" + sName + ".");
@@ -72,13 +113,12 @@
}
@Override
- public Response doRequest () throws IOException {
+ public Response doRequest() throws IOException {
DirectRequestPOST.logger.trace("doRequest");
final URL aURL = new URL(sURL);
this.aURLConnection = aURL.openConnection();
this.aURLConnection.setDoOutput(true);
- this.aURLConnection.setRequestProperty(
- "Content-Type",
+ this.aURLConnection.setRequestProperty("Content-Type",
"multipart/form-data; boundary=" + sBoundary);
this.aURLConnection.setRequestProperty("Accept-Language", this.sLang);
if (null == this.aOutputStream) {
@@ -94,7 +134,8 @@
DirectRequestPOST.logger.debug("--");
DirectRequestPOST.logger.debug(this.sBoundary);
DirectRequestPOST.logger.debug("\r\n");
- DirectRequestPOST.logger.debug("Content-Disposition: form-data; name=\"");
+ DirectRequestPOST.logger
+ .debug("Content-Disposition: form-data; name=\"");
DirectRequestPOST.logger.debug(sName);
DirectRequestPOST.logger.debug('"');
DirectRequestPOST.logger.debug("\r\n");
@@ -106,7 +147,8 @@
this.aOutputStream.write(this.sBoundary.getBytes());
// writeName
this.aOutputStream.write("\r\n".getBytes());
- this.aOutputStream.write("Content-Disposition: form-data; name=\"".getBytes());
+ this.aOutputStream.write("Content-Disposition: form-data; name=\""
+ .getBytes());
this.aOutputStream.write(sName.getBytes());
this.aOutputStream.write('"');
// newline
@@ -125,34 +167,21 @@
this.aOutputStream.write(this.sBoundary.getBytes());
this.aOutputStream.write("--".getBytes());
this.aOutputStream.write("\r\n".getBytes());
- this.aOutputStream.close();/*
- final InputStream aInputStream = aURLConnection.getInputStream();
- String sResponse = "";
- byte[] tByte = new byte[500];
- while (0 < aInputStream.available()) {
- aInputStream.read(tByte);
- sResponse += new String(tByte);
- }
- DirectRequestPOST.logger.debug(sResponse);*/
- //return this.aResponseParser.parse(aURLConnection.getInputStream());
- return ResponseParserFactory.parse(aURLConnection.getInputStream(), this.getResponseType());
+ this.aOutputStream.close();
+ return ResponseParserFactory.parse(aURLConnection.getInputStream(),
+ this.getResponseType());
}
@Override
- public EnumInputMethod getInputMethod () {
+ public EnumInputMethod getInputMethod() {
DirectRequestPOST.logger.trace("getInputMethod");
return EnumInputMethod.DIRECT;
}
- public String toString () {
+ public String toString() {
final int iStringBufferSize = 1000;
- //final String sVariableSeparator = " ";
final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);
-
aStringBuffer.append("url:").append(this.sURL);
- //aStringBuffer.append(sVariableSeparator);
- //aStringBuffer.append("param:").append(this.sParameter);
-
return aStringBuffer.toString();
}
Index: DirectRequestGET.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestGET.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- DirectRequestGET.java 20 Feb 2008 15:09:57 -0000 1.3
+++ DirectRequestGET.java 17 Jun 2008 13:41:11 -0000 1.4
@@ -17,28 +17,51 @@
import org.w3c.unicorn.util.Property;
/**
+ * Class to make a request directly using GET method
*
* @author Damien LEROY
*/
public class DirectRequestGET extends Request {
+ /**
+ * URL of for the request
+ */
private String sURL = null;
+
+ /**
+ * Parameter for the request
+ */
private String sParameter = null;
- protected DirectRequestGET (
- final String sURL,
- final String sInputParameterName,
- final InputModule aInputModule,
+ /**
+ * Constructor for the direct request with GET method
+ *
+ * @param sURL
+ * URL for the request
+ * @param sInputParameterName
+ * name of the parameter
+ * @param aInputModule
+ * input module to do the request
+ * @param responseType
+ * type of the response of the observer
+ * @throws IOException
+ * odd error occured
+ */
+ protected DirectRequestGET(final String sURL,
+ 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 : " + sInputParameterName + ".");
- DirectRequestGET.logger.debug("Input module : " + aInputModule + ".");
+ DirectRequestGET.logger.debug("Input parameter name : "
+ + sInputParameterName + ".");
+ DirectRequestGET.logger.debug("Input module : " + aInputModule
+ + ".");
}
if (!(aInputModule instanceof DirectInputModule)) {
- throw new IllegalArgumentException("InputModule : " + aInputModule.toString() + ".");
+ throw new IllegalArgumentException("InputModule : "
+ + aInputModule.toString() + ".");
}
this.sURL = sURL;
this.addParameter(sInputParameterName, aInputModule.getStringContent());
@@ -46,7 +69,8 @@
}
@Override
- public void addParameter (final String sName, final String sValue) throws IOException {
+ public void addParameter(final String sName, final String sValue)
+ throws IOException {
DirectRequestGET.logger.trace("addParameter");
if (DirectRequestGET.logger.isDebugEnabled()) {
DirectRequestGET.logger.debug("Name :" + sName + ".");
@@ -57,12 +81,13 @@
} else {
this.sParameter += "&";
}
- this.sParameter += sName + "=" + URLEncoder.encode(sValue, Property.get("UNICORN_ENCODING"));
- DirectRequestGET.logger.debug("Parameters : "+this.sParameter+".");
+ this.sParameter += sName + "="
+ + URLEncoder.encode(sValue, Property.get("UNICORN_ENCODING"));
+ DirectRequestGET.logger.debug("Parameters : " + this.sParameter + ".");
}
@Override
- public Response doRequest () throws IOException {
+ public Response doRequest() throws IOException {
DirectRequestGET.logger.trace("doRequest");
final URL aURL;
if (null == this.sParameter) {
@@ -73,17 +98,17 @@
}
final URLConnection aURLConnection = aURL.openConnection();
aURLConnection.setRequestProperty("Accept-Language", this.sLang);
- //return this.aResponseParser.parse(aURLConnection.getInputStream());
- return ResponseParserFactory.parse(aURLConnection.getInputStream(), this.getResponseType());
+ return ResponseParserFactory.parse(aURLConnection.getInputStream(),
+ this.getResponseType());
}
@Override
- public EnumInputMethod getInputMethod () {
+ public EnumInputMethod getInputMethod() {
DirectRequestGET.logger.trace("getInputMethod");
return EnumInputMethod.DIRECT;
}
- public String toString () {
+ public String toString() {
final int iStringBufferSize = 1000;
final String sVariableSeparator = " ";
final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);
Index: UploadRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/UploadRequest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- UploadRequest.java 20 Feb 2008 15:09:57 -0000 1.4
+++ UploadRequest.java 17 Jun 2008 13:41:11 -0000 1.5
@@ -17,65 +17,97 @@
import org.w3c.unicorn.util.ClientHttpRequest;
/**
+ * Class to deal with the upload request
*
* @author Damien LEROY
*/
public class UploadRequest extends Request {
+ /**
+ * URL for the request
+ */
private String sURL = null;
+
+ /**
+ * Name of the parameter
+ */
private String sInputParameterName = null;
+
+ /**
+ * A http client for the request in upload
+ */
private ClientHttpRequest aClientHttpRequest = null;
+
+ /**
+ * An input module with upload
+ */
private UploadInputModule aUploadInputModule = null;
+
+ /**
+ * Data structure for the parameters
+ */
private Map<String, String> mapOfParameter = null;
- protected UploadRequest (
- final String sURL,
- final String sInputParameterName,
- final InputModule aInputModule,
- final String responseType) throws MalformedURLException, IOException {
+ /**
+ * Create a upload request
+ *
+ * @param sURL
+ * URL for the request
+ * @param sInputParameterName
+ * name of the parameter
+ * @param aInputModule
+ * module for the input of the request
+ * @param responseType
+ * type of the response
+ * @throws MalformedURLException
+ * error if the URL is not well formed
+ * @throws IOException
+ * odd error occured
+ */
+ protected UploadRequest(final String sURL,
+ final String sInputParameterName, final InputModule aInputModule,
+ 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 : " + sInputParameterName + ".");
+ UploadRequest.logger.debug("Input parameter name : "
+ + sInputParameterName + ".");
UploadRequest.logger.debug("Input module : " + aInputModule + ".");
}
if (!(aInputModule instanceof UploadInputModule)) {
- throw new IllegalArgumentException("InputModule : " + aInputModule.toString() + ".");
+ throw new IllegalArgumentException("InputModule : "
+ + aInputModule.toString() + ".");
}
this.sURL = sURL;
this.sInputParameterName = sInputParameterName;
this.aUploadInputModule = (UploadInputModule) aInputModule;
this.mapOfParameter = new Hashtable<String, String>();
- //this.aClientHttpRequest = new ClientHttpRequest(sURL);
- /*this.aClientHttpRequest.setParameter(
- this.sInputParameterName,
- this.aUploadInputModule.getFileName(),
- this.aUploadInputModule.getInputStream());*/
this.setResponseType(responseType);
}
@Override
- public void addParameter (final String sName, final String sValue) throws IOException {
+ 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 + ".");
}
this.mapOfParameter.put(sName, sValue);
- //this.aClientHttpRequest.setParameter(sName, sValue);
}
@Override
public Response doRequest() throws IOException {
UploadRequest.logger.trace("doRequest");
this.aClientHttpRequest = new ClientHttpRequest(sURL);
- UploadRequest.logger.debug("Lang : "+this.sLang+".");
- this.aClientHttpRequest.setLang(sLang); // meme place que pour directpost
- this.aClientHttpRequest.setParameter(
- this.sInputParameterName,
- this.aUploadInputModule.getFileName(),
- this.aUploadInputModule.getInputStream());
+ UploadRequest.logger.debug("Lang : " + this.sLang + ".");
+ this.aClientHttpRequest.setLang(sLang); // meme place que pour
+ // directpost
+ 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);
DirectRequestPOST.logger.trace("addParameter");
@@ -86,21 +118,22 @@
this.aClientHttpRequest.setParameter(sName, sValue);
}
final Response aObservationResponse;
- //aObservationResponse = this.aResponseParser.parse(this.aClientHttpRequest.post());
- aObservationResponse = ResponseParserFactory.parse(this.aClientHttpRequest.post(), this.getResponseType());
+ aObservationResponse = ResponseParserFactory.parse(
+ this.aClientHttpRequest.post(), this.getResponseType());
return aObservationResponse;
}
@Override
- public EnumInputMethod getInputMethod () {
+ public EnumInputMethod getInputMethod() {
UploadRequest.logger.trace("getInputMethod");
return EnumInputMethod.UPLOAD;
}
- public String toString () {
+ public String toString() {
final int iStringBufferSize = 1000;
final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);
- aStringBuffer.append("ClientHttpRequest:").append(this.aClientHttpRequest);
+ aStringBuffer.append("ClientHttpRequest:").append(
+ this.aClientHttpRequest);
return aStringBuffer.toString();
}
Index: RequestList.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/RequestList.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- RequestList.java 21 Sep 2006 16:01:22 -0000 1.2
+++ RequestList.java 17 Jun 2008 13:41:11 -0000 1.3
@@ -14,64 +14,107 @@
/**
* @author Damien LEROY
- *
+ *
*/
public class RequestList {
- private static final Log logger = LogFactory.getLog("org.w3c.unicorn.request");
+ /**
+ * Object used for complex logging purpose
+ */
+ private static final Log logger = LogFactory
+ .getLog("org.w3c.unicorn.request");
+ /**
+ * Language of the list
+ */
private String sLang = null;
- public RequestList (final String sLang) {
- RequestList.logger.debug("Lang : "+sLang+".");
+ /**
+ * Constructor of the list
+ *
+ * @param sLang
+ * language of the list
+ */
+ public RequestList(final String sLang) {
+ RequestList.logger.debug("Lang : " + sLang + ".");
this.sLang = sLang;
}
/**
- * Map of request about the observer who handle the current mime type with a LOW priority.
+ * Map of request about the observer who handle the current mime type with a
+ * LOW priority.
*/
private final Map<String, Request> mapOfRequestLOW = new LinkedHashMap<String, Request>();
/**
- * Map of request about the observer who handle the current mime type with a MEDIUM priority.
+ * Map of request about the observer who handle the current mime type with a
+ * MEDIUM priority.
*/
private final Map<String, Request> mapOfRequestMEDIUM = new LinkedHashMap<String, Request>();
/**
- * Map of request about the observer who handle the current mime type with a HIGH priority.
+ * Map of request about the observer who handle the current mime type with a
+ * HIGH priority.
*/
private final Map<String, Request> mapOfRequestHIGH = new LinkedHashMap<String, Request>();
- public Request getRequest (final String sObserverID) {
+ /**
+ * Get a request from the data structures with its ideas sorted by
+ * priorities
+ *
+ * @param sObserverID
+ * ID of the observer to get
+ * @return a request extracted from the maps of priorities
+ */
+ public Request getRequest(final String sObserverID) {
RequestList.logger.trace("getRequest");
if (RequestList.logger.isDebugEnabled()) {
RequestList.logger.debug("Observer ID : " + sObserverID + ".");
}
Request aRequest = null;
aRequest = this.mapOfRequestHIGH.get(sObserverID);
- if (null != aRequest) return aRequest;
+ if (null != aRequest)
+ return aRequest;
aRequest = this.mapOfRequestMEDIUM.get(sObserverID);
- if (null != aRequest) return aRequest;
+ if (null != aRequest)
+ return aRequest;
return this.mapOfRequestLOW.get(sObserverID);
}
- public Map<String, Request> getRequest (final TPriority aTPriority) {
+ /**
+ * Gives the map of the requests depending on the priorities
+ *
+ * @param aTPriority
+ * priority to get
+ * @return map of the request depending on the priorities
+ */
+ public Map<String, Request> getRequest(final TPriority aTPriority) {
RequestList.logger.trace("getRequest");
if (RequestList.logger.isDebugEnabled()) {
RequestList.logger.debug("Priority : " + aTPriority + ".");
}
switch (aTPriority) {
- case HIGH :
- return this.mapOfRequestHIGH;
- case MEDIUM :
- return this.mapOfRequestMEDIUM;
- case LOW :
- return this.mapOfRequestLOW;
+ case HIGH:
+ return this.mapOfRequestHIGH;
+ case MEDIUM:
+ return this.mapOfRequestMEDIUM;
+ case LOW:
+ return this.mapOfRequestLOW;
}
return null;
}
- public Request getRequest (final TPriority aTPriority, final String sObserverID) {
+ /**
+ * Gives an observer placed in priority list
+ *
+ * @param aTPriority
+ * priority into which it will search
+ * @param sObserverID
+ * ID of the observer to get
+ * @return
+ */
+ public Request getRequest(final TPriority aTPriority,
+ final String sObserverID) {
RequestList.logger.trace("getRequest");
if (RequestList.logger.isDebugEnabled()) {
RequestList.logger.debug("Priority : " + aTPriority + ".");
@@ -80,31 +123,33 @@
return this.getRequest(aTPriority).get(sObserverID);
}
- public void addRequest(
- final Request aRequest,
- final TPriority aTPriority,
+ public void addRequest(final Request aRequest, final TPriority aTPriority,
final String sObserverID) throws IOException {
RequestList.logger.trace("addRequest");
if (RequestList.logger.isDebugEnabled()) {
RequestList.logger.debug("Request : " + aRequest + ".");
RequestList.logger.debug("TPriority : " + aTPriority + ".");
- RequestList.logger.debug("String observer ID : " + sObserverID + ".");
+ RequestList.logger.debug("String observer ID : " + sObserverID
+ + ".");
}
aRequest.setLang(this.sLang);
switch (aTPriority) {
- case HIGH :
- this.mapOfRequestHIGH.put(sObserverID, aRequest);
- return;
- case MEDIUM :
- this.mapOfRequestMEDIUM.put(sObserverID, aRequest);
- return;
- case LOW :
- this.mapOfRequestLOW.put(sObserverID, aRequest);
- return;
+ case HIGH:
+ this.mapOfRequestHIGH.put(sObserverID, aRequest);
+ return;
+ case MEDIUM:
+ this.mapOfRequestMEDIUM.put(sObserverID, aRequest);
+ return;
+ case LOW:
+ this.mapOfRequestLOW.put(sObserverID, aRequest);
+ return;
}
}
- public String toString () {
+ /**
+ * Prints the object
+ */
+ public String toString() {
final int iStringBufferSize = 1000;
final String sVariableSeparator = " ";
final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);
Index: URIRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/URIRequest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- URIRequest.java 20 Feb 2008 15:09:57 -0000 1.4
+++ URIRequest.java 17 Jun 2008 13:41:11 -0000 1.5
@@ -19,27 +19,49 @@
/**
* Use to handle a request to a observer.
+ *
* @author Damien LEROY
*/
public class URIRequest extends Request {
+ /**
+ * URL for the request
+ */
private String sURL = null;
+
+ /**
+ * Parameter of the request
+ */
private String sParameter = null;
- protected URIRequest (
- final String sURL,
- final String sInputParameterName,
- final InputModule aInputModule,
- final String responseType) throws IOException {
+ /**
+ * Create an URI request
+ *
+ * @param sURL
+ * URL for the request
+ * @param sInputParameterName
+ * name of the parameter for the request
+ * @param aInputModule
+ * input module for the request
+ * @param responseType
+ * type of the response by the observer
+ * @throws IOException
+ * odd error occured
+ */
+ protected URIRequest(final String sURL, final String sInputParameterName,
+ 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 : " + sInputParameterName + ".");
+ URIRequest.logger.debug("Input parameter name : "
+ + sInputParameterName + ".");
URIRequest.logger.debug("Input module : " + aInputModule + ".");
}
if (!(aInputModule instanceof URIInputModule)) {
- throw new IllegalArgumentException("InputModule : " + aInputModule.toString() + ".");
+ throw new IllegalArgumentException("InputModule : "
+ + aInputModule.toString() + ".");
}
this.sURL = sURL;
final URIInputModule aURIInputModule = (URIInputModule) aInputModule;
@@ -47,9 +69,16 @@
this.setResponseType(responseType);
}
- public void addParameter (
- final String sName,
- final String sValue) throws UnsupportedEncodingException {
+ /**
+ * Add a parameter to the request
+ *
+ * @param sName
+ * name of the parameter to add
+ * @param sValue
+ * value of the parameter to add
+ */
+ public void addParameter(final String sName, final String sValue)
+ throws UnsupportedEncodingException {
URIRequest.logger.trace("addParameter");
if (URIRequest.logger.isDebugEnabled()) {
URIRequest.logger.debug("sName : " + sName + ".");
@@ -61,14 +90,20 @@
this.sParameter += "&";
}
this.sParameter += sName + "=" + URLEncoder.encode(sValue, "UTF-8");
- URIRequest.logger.debug("Parameters : "+this.sParameter+".");
+ URIRequest.logger.debug("Parameters : " + this.sParameter + ".");
}
- public Response doRequest () throws IOException {
+ /**
+ * Do the request to the observer
+ *
+ * @throws IOException
+ * odd error occured
+ */
+ 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+" .");
+ URIRequest.logger.debug("URL : " + this.sURL + " .");
+ URIRequest.logger.debug("Parameters : " + this.sParameter + " .");
}
final URL aURL;
if (null == this.sParameter) {
@@ -79,21 +114,24 @@
}
URIRequest.logger.debug("URL : " + aURL + " .");
final URLConnection aURLConnection = aURL.openConnection();
-
+
aURLConnection.setRequestProperty("Accept-Language", this.sLang);
InputStream is = aURLConnection.getInputStream();
- //Response res = this.aResponseParser.parse(is);
+ // Response res = this.aResponseParser.parse(is);
Response res = ResponseParserFactory.parse(is, this.getResponseType());
return res;
}
@Override
- public EnumInputMethod getInputMethod () {
+ public EnumInputMethod getInputMethod() {
URIRequest.logger.trace("getInputMethod");
return EnumInputMethod.URI;
}
- public String toString () {
+ /**
+ * Prints the object
+ */
+ public String toString() {
final int iStringBufferSize = 1000;
final String sVariableSeparator = " ";
final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);
Index: Request.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/Request.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Request.java 20 Feb 2008 15:09:57 -0000 1.4
+++ Request.java 17 Jun 2008 13:41:11 -0000 1.5
@@ -17,56 +17,110 @@
* @author Damien LEROY
*/
public abstract class Request {
- protected static final Log logger = LogFactory.getLog("org.w3c.unicorn.request");
-
- //public ResponseParser aResponseParser;
+ /**
+ * Object used for complex logging purpose
+ */
+ protected static final Log logger = LogFactory
+ .getLog("org.w3c.unicorn.request");
+ /**
+ * Language of the request
+ */
protected String sLang = null;
- protected String responseType=null;
-
- public void setLang (final String sLang) throws IOException {
- Request.logger.debug("setLang("+sLang+")");
+ /**
+ * Type of the response for the request
+ */
+ protected String responseType = null;
+
+ /**
+ * Sets the language of the request
+ *
+ * @param sLang
+ * new language to set
+ * @throws IOException
+ * odd error occured
+ */
+ public void setLang(final String sLang) throws IOException {
+ Request.logger.debug("setLang(" + sLang + ")");
this.sLang = sLang;
}
- public abstract void addParameter (final String sName, final String sValue) throws IOException;
+ /**
+ * Add a parameter to the request
+ *
+ * @param sName
+ * name of the parameter
+ * @param sValue
+ * value of the parameter
+ * @throws IOException
+ * odd error occured
+ */
+ public abstract void addParameter(final String sName, final String sValue)
+ throws IOException;
- public abstract org.w3c.unicorn.response.Response doRequest () throws IOException;
+ /**
+ * Do the request to the observer
+ *
+ * @return the response of the observer
+ * @throws IOException
+ * odd error occured
+ */
+ public abstract org.w3c.unicorn.response.Response doRequest()
+ throws IOException;
- public abstract EnumInputMethod getInputMethod ();
+ public abstract EnumInputMethod getInputMethod();
+
+ /**
+ * Create a request for the observer
+ *
+ * @param aInputModule
+ * input module used for the request
+ * @param sURL
+ * url for the request
+ * @param sInputParameterName
+ * name of the parameter of the request
+ * @param bIsPost
+ * to know whether the request is sent or not
+ * @param responseType
+ * type of the response
+ * @return a request ready to be done
+ * @throws IOException
+ * odd error occurend
+ */
+ public static Request createRequest(final InputModule aInputModule,
+ final String sURL, final String sInputParameterName,
+ final boolean bIsPost, final String responseType)
+ throws IOException {
- public static Request createRequest (
- final InputModule aInputModule,
- final String sURL,
- final String sInputParameterName,
- final boolean bIsPost,
- final String responseType) throws IOException {
-
-
Request.logger.trace("createRequest");
if (Request.logger.isDebugEnabled()) {
Request.logger.debug("InputModule : " + aInputModule + ".");
Request.logger.debug("URL : " + sURL + ".");
- Request.logger.debug("Input parameter name : " + sInputParameterName + ".");
+ Request.logger.debug("Input parameter name : "
+ + sInputParameterName + ".");
Request.logger.debug("POST method : " + bIsPost + ".");
}
switch (aInputModule.getEnumInputMethod()) {
- case DIRECT :
- if ( bIsPost) {
- return new DirectRequestPOST(sURL, sInputParameterName, aInputModule, responseType);
- } else {
- return new DirectRequestGET(sURL, sInputParameterName, aInputModule, responseType);
- }
- case UPLOAD :
- return new UploadRequest(sURL, sInputParameterName, aInputModule, responseType);
- case URI :
- return new URIRequest(sURL, sInputParameterName, aInputModule, responseType);
+ case DIRECT:
+ if (bIsPost) {
+ return new DirectRequestPOST(sURL, sInputParameterName,
+ aInputModule, responseType);
+ } else {
+ return new DirectRequestGET(sURL, sInputParameterName,
+ aInputModule, responseType);
+ }
+ case UPLOAD:
+ return new UploadRequest(sURL, sInputParameterName, aInputModule,
+ responseType);
+ case URI:
+ return new URIRequest(sURL, sInputParameterName, aInputModule,
+ responseType);
}
return null;
}
- public String toString () {
+ public String toString() {
return "Abstract class org.w3c.unicorn.request.Request, toString function must be overrided.";
}
Received on Tuesday, 17 June 2008 13:41:49 UTC