- From: Jean-Guilhem Rouel via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 19 Sep 2008 18:57:13 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn
In directory hutz:/tmp/cvs-serv10640/org/w3c/unicorn
Modified Files:
Framework.java UnicornCall.java
Log Message:
MimeTypes work again for DirectInput
Index: Framework.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/Framework.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Framework.java 12 Sep 2008 18:01:51 -0000 1.16
+++ Framework.java 19 Sep 2008 18:57:11 -0000 1.17
@@ -183,6 +183,7 @@
.getMapOfInputMethod());
aObserver.setResponseType(aWADLUnmarshaller
.getResponseType());
+ aObserver.setSupportedMimeTypes(aWADLUnmarshaller.getSupportedMimeTypes());
Framework.mapOfObserver.put(new String(aObserver.getID()),
aObserver);
} catch (final Exception e) {
@@ -211,7 +212,7 @@
try {
// parse all the task files
final File[] tFileXML = ListFiles.listFiles(Property
- .get("PATH_TO_TASKLIST"), "\\.xml");
+ .get("PATH_TO_TASKLIST"), "\\.xml$");
final TasksListUnmarshaller aTaskListUnmarshaller =
new TaskListUnmarshallerBeans(Framework.mapOfObserver);
@@ -221,7 +222,7 @@
aTaskListUnmarshaller.unmarshal();
final File[] tFileRDF = ListFiles.listFiles(Property
- .get("PATH_TO_TASKLIST"), "\\.rdf");
+ .get("PATH_TO_TASKLIST"), "\\.rdf$");
final RDFUnmarshaller aRDFUnmarshaller = new RDFUnmarshallerJena();
aRDFUnmarshaller.setMapOfTask(aTaskListUnmarshaller.getMapOfTask());
aRDFUnmarshaller.setMapOfObserver(Framework.mapOfObserver);
Index: UnicornCall.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/UnicornCall.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- UnicornCall.java 12 Sep 2008 18:01:51 -0000 1.21
+++ UnicornCall.java 19 Sep 2008 18:57:11 -0000 1.22
@@ -56,7 +56,7 @@
/**
* UnicornCall Created: Jun 29, 2006 2:44:12 PM
- *
+ *
* @author Jean-Guilhem Rouel
*/
public class UnicornCall {
@@ -116,7 +116,7 @@
/**
* Execute the task aTask
- *
+ *
* @throws Exception
*/
public void doTask() throws Exception {
@@ -133,55 +133,7 @@
}
// find mimetype of the document
- UnicornCall.logger.info("Check MimeType.");
- MimeType aMimeType = null;
- String sMimeType;
- switch (this.aEnumInputMethod) {
- case URI:
- sMimeType = (new URL(this.sDocumentName)).openConnection()
- .getContentType();
- if (null == sMimeType || "".equals(sMimeType)) {
- UnicornCall.logger.error("No specified mimetype for upload.");
- throw new NoMimeTypeException("Mimetype not found");
- }
- if (UnicornCall.logger.isDebugEnabled()) {
- UnicornCall.logger.debug("URI MimeType : " + sMimeType + ".");
- }
- sMimeType = sMimeType.split(";")[0];
- aMimeType = new MimeType(sMimeType);
- break;
- case UPLOAD:
- FileItem f = (FileItem) this.oInputParameterValue;
- if (f.getName() == null || f.getName().equals("")) {
- UnicornCall.logger.error("No document privided.");
- throw new NoDocumentException("No document provided");
- }
- if (f.getSize() == 0) {
- UnicornCall.logger.error("Empty document provided.");
- throw new EmptyDocumentException("Empty document provided");
- }
-
- sMimeType = ((FileItem) this.oInputParameterValue).getContentType();
- if (null == sMimeType || "".equals(sMimeType)) {
- UnicornCall.logger.error("No specified mimetype for upload.");
- throw new NoMimeTypeException("Mimetype not found");
- }
- aMimeType = new MimeType(sMimeType);
- break;
- case DIRECT:
- sMimeType = this.mapOfStringParameter.get("ucn_mime")[0];
- if (null == sMimeType || "".equals(sMimeType)) {
- UnicornCall.logger
- .error("No mimetype specified for direct input.");
- throw new NoMimeTypeException("Mimetype not found.");
- }
- aMimeType = new MimeType(sMimeType);
- break;
- }
- if (UnicornCall.logger.isDebugEnabled()) {
- UnicornCall.logger
- .debug("MimeType : " + aMimeType.toString() + ".");
- }
+ MimeType aMimeType = this.getMimeType();
// Create input method
final InputFactory aInputFactory = new InputFactory(aMimeType,
@@ -195,7 +147,7 @@
/**
* Main function called to do the recursion over the Task tree to launch the
* requests
- *
+ *
* @param aInputFactory
* InputFactory used for the resquests
* @param node
@@ -243,7 +195,7 @@
/**
* Check the conditions of the if branch it makes a OR between all
* conditions
- *
+ *
* @param ifs
* the if branch to check
* @return whether or not the conditions are true
@@ -269,7 +221,7 @@
/**
* Creates the map of all the Observer to call in the current node
- *
+ *
* @param node
* the current node of the Task tree we are parsing
*/
@@ -297,7 +249,7 @@
/**
* Change the value the boolean bPassed
- *
+ *
* @param b
* new value
*/
@@ -307,7 +259,7 @@
/**
* getter for bPassed
- *
+ *
* @return the value of bPassed
*/
public boolean getBPassed() {
@@ -316,7 +268,7 @@
/**
* Execute the request depending on the priority
- *
+ *
* @param aTPriority
* priority of the request
* @throws IOException
@@ -357,7 +309,7 @@
/**
* Generate the list of the request for the call
- *
+ *
* @param aInputFactory
* Input factory for the parameter
* @param mapOfArrayUseParameter
@@ -393,89 +345,41 @@
for (final Observer aObserver : this.createExecList(node).values()) {
final String sObserverID = aObserver.getID();
// add only observer who handle the current mimetype
- if (!aObserver.canHandleMimeType(aMimeType, aEnumInputMethod)) {
+ if (!aObserver.canHandleMimeType(aMimeType)) {
if (UnicornCall.logger.isDebugEnabled()) {
UnicornCall.logger.debug("Observer " + sObserverID
- + " not handle mime type " + aMimeType.toString()
- + " with input method "
- + aEnumInputMethod.toString() + ".");
- }
-
- for (final EnumInputMethod aEIM : EnumInputMethod.values()) {
- if (aEnumInputMethod == aEIM) {
- continue;
- }
- if (!aObserver.canHandleMimeType(aMimeType, aEIM)) {
-
- if (UnicornCall.logger.isDebugEnabled()) {
- UnicornCall.logger.debug("Observer " + sObserverID
- + " not handle mime type "
- + aMimeType.toString()
- + " with input method " + aEIM.toString()
- + ".");
- }
- continue;
- }
-
- if (UnicornCall.logger.isDebugEnabled()) {
- UnicornCall.logger
- .debug("Observer " + sObserverID
- + " handle mime type "
- + aMimeType.toString()
- + " with input method "
- + aEIM.toString() + ".");
- }
-
- final InputMethod aInputMethod = aObserver
- .getInputMethod(aEIM);
- // create a new request with input parameter
- final Request aRequest = Request.createRequest(
- aInputFactory.getInputModule(aEIM), aInputMethod
- .getCallMethod().getURL().toString(),
- aInputMethod.getCallParameter().getName(),
- aInputMethod.getCallMethod().isPost(), aObserver
- .getResponseType());
- // add this request to request list
-
- aRequestList.addRequest(aRequest, aObserver.getID());
- // log debug information
- if (UnicornCall.logger.isDebugEnabled()) {
- UnicornCall.logger.debug("Redirect request " + aRequest
- + " from " + aEnumInputMethod + " to " + aEIM
- + " added to request list.");
- }
- // add required parameter
- for (final CallParameter aCallParameter : aObserver
- .getCallMethod(aEIM).getMapOfCallParameter()
- .values()) {
- if (aCallParameter.isRequired()
- && aCallParameter.isFixed()) {
- aRequest.addParameter(aCallParameter.getName(),
- aCallParameter.getFixed());
- }
- }
- break;
+ + " does not handle mime type " + aMimeType.toString());
}
+ continue;
+ }
+ // the best available observation method
+ final InputMethod aInputMethod = aObserver.getBestInputMethod(aEnumInputMethod);
- // check the code to redirect to an other
- // input method if it handle mime type
- if (UnicornCall.logger.isDebugEnabled()) {
- UnicornCall.logger.debug("Observation " + sObserverID
- + " does not handle mimetype "
- + aMimeType.toString() + " with any input method.");
- }
- continue;
- }
- final InputMethod aInputMethod = aObserver
- .getInputMethod(aEnumInputMethod);
+ // create a new request with input parameter
+ final Request aRequest = Request.createRequest(
+ // the corresponding best input module
+ aInputFactory.getInputModule(aInputMethod.getMethod()),
+ // URL of the service to call
+ aInputMethod.getCallMethod().getURL().toString(),
+ // Name of the parameter holding resource information
+ // (uri,url,txt,text,file,...)
+ aInputMethod.getCallParameter().getName(),
+ // Has a file been uploaded?
+ aInputMethod.getCallMethod().isPost(),
+ // Response format
+ aObserver.getResponseType());
- // Create a new request with input parameter
- final Request aRequest = Request.createRequest(aInputFactory
- .getInputModule(aEnumInputMethod), aInputMethod
- .getCallMethod().getURL().toString(), aInputMethod
- .getCallParameter().getName(), aInputMethod.getCallMethod()
- .isPost(), aObserver.getResponseType());
+ // add this request to request list
+ aRequestList.addRequest(aRequest, aObserver.getID());
+
+ // log debug information
+ if (UnicornCall.logger.isDebugEnabled()) {
+ UnicornCall.logger.debug("Redirect request " + aRequest
+ + " from " + aEnumInputMethod + " to " + aInputMethod.getMethod()
+ + " added to request list.");
+ }
+
// Get value of ucn_lang parameter to associate it with parameter
// lang of the observer (if it has one).
// ucn_lang is defined in forms of index templates
@@ -493,20 +397,24 @@
// Add this request to request list
aRequestList.addRequest(aRequest, aObserver.getID());
+
// Log debug information
if (UnicornCall.logger.isDebugEnabled()) {
UnicornCall.logger.debug("Request " + aRequest
+ " added to request list.");
}
- // Add required parameter
+
+ // Add fixed parameter
+ for (final CallParameter aCallParameter : aObserver
+ .getCallMethod(aInputMethod.getMethod()).getMapOfCallParameter()
+ .values()) {
+ if (aCallParameter.isRequired()
+ && aCallParameter.isFixed()) {
+ aRequest.addParameter(aCallParameter.getName(),
+ aCallParameter.getFixed());
+ }
+ }
- for (final CallParameter aCallParameter : aObserver.getCallMethod(
- aEnumInputMethod).getMapOfCallParameter().values()) {
- if (aCallParameter.isRequired() && aCallParameter.isFixed()) {
- aRequest.addParameter(aCallParameter.getName(),
- aCallParameter.getFixed());
- }
- }
} // foreach this.aTask.getMapOfObservation().values()
// Iterate over all parameter of this task to add at the
@@ -586,8 +494,9 @@
final Value aValue = mapOfValue.get(sUseParameterValue);
final Map<String, List<Mapping>> mapOfMapping = aValue
.getMapOfMapping();
+
for (final String sObserverName : mapOfMapping.keySet()) {
-
+
if (aRequestList.getRequest(sObserverName)!=null) {
final Request aRequest = aRequestList
.getRequest(sObserverName);
@@ -615,7 +524,7 @@
/**
* Returns the responses of low priority observations.
- *
+ *
* @return responses of low priority observations.
*/
public Map<String, Response> getResponses() {
@@ -624,7 +533,7 @@
/**
* Set the task to perform
- *
+ *
* @param sTaskID
* ID of the task to perform
*/
@@ -643,7 +552,7 @@
/**
* define the lang of the check
- *
+ *
* @param sLang
* defines the lang to configure
*/
@@ -654,7 +563,7 @@
/**
* Returns the document name
- *
+ *
* @return Returns the documentName.
*/
public String getDocumentName() {
@@ -663,7 +572,7 @@
/**
* Set the name of the document
- *
+ *
* @param sDocumentName
* The documentName to set.
*/
@@ -673,7 +582,7 @@
/**
* Gives the list of the observations
- *
+ *
* @return map of the observations of the check
*/
public Map<String, Response> getObservationList() {
@@ -689,7 +598,7 @@
/**
* Enter a new parameter in the list
- *
+ *
* @param sName
* Name of the parameter
* @param tStringValue
@@ -716,7 +625,7 @@
/**
* Set the map of String Parameter
- *
+ *
* @param mapOfStringParameter
* The mapOfStringParameter to set.
*/
@@ -727,7 +636,7 @@
/**
* Returns the current task
- *
+ *
* @return Returns the current task.
*/
public Task getTask() {
@@ -736,7 +645,7 @@
/**
* Set the aEnumInputMethod
- *
+ *
* @param enumInputMethod
* The aEnumInputMethod to set.
*/
@@ -746,7 +655,7 @@
/**
* Set the uploadedFile
- *
+ *
* @param uploadedFile
* The uploadedFile to set.
*/
@@ -757,7 +666,7 @@
/**
* Giving a TLTCond, checks in the map of response if the condition passes
* or fails and consequently returns a boolean.
- *
+ *
* @param cond
* The condition to check
* @return true if there is a matching response and if the condition passes
@@ -771,7 +680,7 @@
UnicornCall.logger.trace("condValue : " + cond.getValue());
boolean passed = false;
-
+
if (cond.getType().equals(EnumCondType.MIMETYPE)) {
passed = cond.getValue().equals(getMimeType().toString());
}
@@ -782,23 +691,23 @@
// and if it is passed
if (res != null) {
String xmlStr = res.getXml().toString();
-
+
DocumentBuilderFactory xmlFact = DocumentBuilderFactory
.newInstance();
-
+
// namespace awareness is escaped since we don't use it
// for the moment
xmlFact.setNamespaceAware(false);
-
+
DocumentBuilder builder = xmlFact.newDocumentBuilder();
-
+
Document doc = builder.parse(new java.io.ByteArrayInputStream(
xmlStr.getBytes()));
-
+
String xpathStr = cond.getValue();
-
+
XPathFactory xpathFact = new XPathFactoryImpl();
-
+
XPath xpath = xpathFact.newXPath();
XPathExpression xpe = xpath.compile(xpathStr);
passed = (Boolean) xpe.evaluate(doc, XPathConstants.BOOLEAN);
@@ -811,11 +720,11 @@
}
/**
- *
+ *
* @return The MimeType of the document
* @throws Exception
*/
- public MimeType getMimeType() throws Exception {
+ private MimeType getMimeType() throws Exception {
UnicornCall.logger.trace("getMimeType");
MimeType aMimeType = null;
@@ -875,9 +784,9 @@
/**
* Thread executing a request
- *
+ *
* @author Damien Leroy
- *
+ *
*/
class RequestThread extends Thread {
/**
@@ -907,7 +816,7 @@
/**
* Initialize the thread by filling the properties
- *
+ *
* @param mapOfResponse
* the map of the responses
* @param aRequest
@@ -930,7 +839,6 @@
* Allow to launch the thread
*/
public void run() {
-
this.unicornCall.incCounter();
Response aResponse = null;
try {
@@ -949,8 +857,8 @@
while((readLength = isr.read(chararray, 0, 8192)) > -1) {
builder.append(chararray, 0, readLength);
}
-
- aResponse = ResponseParserFactory.parse(builder.toString(),
+
+ aResponse = ResponseParserFactory.parse(builder.toString(),
this.aRequest.getResponseType());
aResponse.setXml(builder);
} catch (MalformedURLException e1) {
Received on Friday, 19 September 2008 19:22:27 UTC