- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 17 Sep 2009 15:42:43 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn In directory hutz:/tmp/cvs-serv18075/src/org/w3c/unicorn Modified Files: UnicornCall.java Log Message: make use of the new InputParameter classes Index: UnicornCall.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/UnicornCall.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- UnicornCall.java 16 Sep 2009 13:48:38 -0000 1.14 +++ UnicornCall.java 17 Sep 2009 15:42:41 -0000 1.15 @@ -5,7 +5,6 @@ package org.w3c.unicorn; import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -19,7 +18,6 @@ import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; -import org.apache.commons.fileupload.FileItem; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; @@ -27,11 +25,8 @@ import org.w3c.unicorn.contract.EnumInputMethod; import org.w3c.unicorn.contract.InputMethod; import org.w3c.unicorn.contract.Observer; -import org.w3c.unicorn.exceptions.EmptyDocumentException; -import org.w3c.unicorn.exceptions.NoDocumentException; -import org.w3c.unicorn.exceptions.NoMimeTypeException; -import org.w3c.unicorn.exceptions.UnsupportedMimeTypeException; -import org.w3c.unicorn.input.InputFactory; +import org.w3c.unicorn.exceptions.UnicornException; +import org.w3c.unicorn.input.InputParameter; import org.w3c.unicorn.request.Request; import org.w3c.unicorn.request.RequestList; import org.w3c.unicorn.response.Response; @@ -45,6 +40,7 @@ import org.w3c.unicorn.tasklisttree.TLTExec; import org.w3c.unicorn.tasklisttree.TLTIf; import org.w3c.unicorn.tasklisttree.TLTNode; +import org.w3c.unicorn.util.Message; import org.w3c.unicorn.util.Property; import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl; @@ -60,44 +56,32 @@ * Log Object to perform powerful logs */ private static final Log logger = LogFactory.getLog(UnicornCall.class); - - // Request + /** * The task to call */ - private Task aTask = null; - - /** - * Check Method : Upload, URI , Direct... - */ - private EnumInputMethod aEnumInputMethod = null; - - private Object oInputParameterValue = null; - - private String sDocumentName = null; - - private String sLang = null; - - private RequestList aRequestList = null; + private Task aTask; - private Map<String, String[]> mapOfStringParameter = null; + private String sLang; - private LinkedHashMap<String, Response> observationMap; + private InputParameter inputParameter; + private Map<String, String[]> mapOfStringParameter; + /** * Data Structure for the response */ private Map<String, Response> mapOfResponse; + + private LinkedHashMap<String, Response> observationMap; /** * Creates a new UnicornCall. */ public UnicornCall() { UnicornCall.logger.trace("Constructor()"); - - this.mapOfStringParameter = new LinkedHashMap<String, String[]>(); - - this.mapOfResponse = new LinkedHashMap<String, Response>(); + mapOfStringParameter = new LinkedHashMap<String, String[]>(); + mapOfResponse = new LinkedHashMap<String, Response>(); } /** @@ -105,76 +89,50 @@ * * @throws Exception */ - public void doTask() throws Exception { + public void doTask() throws UnicornException, Exception { UnicornCall.logger.trace("doTask."); UnicornCall.logger.debug("String task id : " + aTask.getID() + "."); - UnicornCall.logger.debug("EnumInputMethod : " + aEnumInputMethod + "."); - UnicornCall.logger.debug("Document name : " + sDocumentName + "."); + UnicornCall.logger.debug("EnumInputMethod : " + inputParameter.getInputMethod() + "."); + UnicornCall.logger.debug("Document name : " + inputParameter.getDocumentName() + "."); UnicornCall.logger.debug("Map of string parameter : " + mapOfStringParameter + "."); - - // find mimetype of the document - MimeType aMimeType = this.getMimeType(); - + + inputParameter.check(); + + MimeType aMimeType = inputParameter.getMimeType(); if (!aTask.getSupportedMimeTypes().contains(aMimeType.toString())) { - throw new UnsupportedMimeTypeException("Mime-type: " + aMimeType + " is not supported by this task."); + //throw new UnsupportedMimeTypeException("Mime-type: " + aMimeType + " is not supported by this task."); + Message mess = new Message(Message.Level.ERROR, "$message_unsupported_mime_type", null); + throw new UnicornException(mess); } - // Create input method - final InputFactory aInputFactory = new InputFactory(aMimeType, - this.aEnumInputMethod, this.oInputParameterValue); - - this.doNode(aInputFactory, this.aTask.getTree()); - - aInputFactory.dispose(); + doNode(inputParameter, aTask.getTree()); } /** * Main function called to do the recursion over the Task tree to launch the * requests * - * @param aInputFactory - * InputFactory used for the resquests + * @param inputParameter + * InputParameter used for the requests * @param node * the current node that we're parsing in the Task tree * @throws Exception * raised from generateRequestList and doRequest */ - private void doNode(InputFactory aInputFactory, TLTNode node) - throws Exception { - // Generate the list of request - UnicornCall.logger.trace("doNode."); - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("InputFactory : " + aInputFactory + "."); - UnicornCall.logger.debug("Current node : " + node + "."); - } + private void doNode(InputParameter inputParameter, TLTNode node) throws Exception { if (node != null) { - this.aRequestList = this.generateRequestList(aInputFactory, - this.mapOfStringParameter, node); - - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("RequestList : " + this.aRequestList - + "."); - } - + RequestList aRequestList = generateRequestList(inputParameter, mapOfStringParameter, node); // send requests to observer - this.doRequests(); - - UnicornCall.logger.info("Check the condition of the Ifs"); + doRequests(aRequestList); // browse the conditions to do the connection - for (TLTIf ifs : node.getIfList()) { - if (this.checkCond(ifs)) { - this.doNode(aInputFactory, ifs.getIfOk()); + for (TLTIf iF : node.getIfList()) { + if (checkCond(iF)) { + doNode(inputParameter, iF.getIfOk()); } else { - this.doNode(aInputFactory, ifs.getIfNotOk()); + doNode(inputParameter, iF.getIfNotOk()); } } - } else { - // Inform if the node is null - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("The node is null at this point."); - } } - } /** @@ -188,84 +146,84 @@ */ private boolean checkCond(TLTIf ifs) throws Exception { UnicornCall.logger.trace("checkCond."); - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("If node : " + ifs + "."); - } + UnicornCall.logger.debug("If node : " + ifs + "."); + boolean conditionOK = false; - // boolean to manage the OR in the conditions, if the cond is false we - // change the boolean to true , if not we don't care - // that will simulate the OR for (TLTCond cond : ifs.getCondArray()) { - if (this.checkCond(cond)) { + if (checkCond(cond)) { conditionOK = true; } - } return conditionOK; - - } - - /** - * 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 - */ - private Map<String, Observer> createExecList(TLTNode node) { - Map<String, Observer> mapOfCurrentNodeObserver = new LinkedHashMap<String, Observer>(); - for (TLTExec exec : node.getExecutionList()) { - mapOfCurrentNodeObserver.put(exec.getValue(), exec.getObserver()); - } - return mapOfCurrentNodeObserver; - } - - public boolean isPassed() { - boolean passed = true; - for (String key : this.getObservationList().keySet()) { - if (!observationMap.get(key).isPassed()) { - passed = false; - } - } - return passed; } /** - * Execute the request depending on the priority + * Giving a TLTCond, checks in the map of response if the condition passes + * or fails and consequently returns a boolean. * - * @param aTPriority - * priority of the request - * @throws IOException - * Input/Output error + * @param cond + * The condition to check + * @return true if there is a matching response and if the condition passes + * else false */ - private void doRequests() throws IOException { - UnicornCall.logger.trace("doRequests"); + private boolean checkCond(TLTCond cond) throws Exception { + UnicornCall.logger.trace("checkCond : "); + UnicornCall.logger.trace(cond); + UnicornCall.logger.trace("condId : " + cond.getId()); + UnicornCall.logger.trace("condType : " + cond.getType()); + UnicornCall.logger.trace("condValue : " + cond.getValue()); - final Map<String, Request> requests = this.aRequestList.getRequestMap(); - // Creation of the thread list - ArrayList<Thread> threadsList = new ArrayList<Thread>(); + boolean passed = false; - for (final String obsID : requests.keySet()) { - // send request to observer - threadsList.add(new RequestThread(mapOfResponse, requests - .get(obsID), obsID, this)); - UnicornCall.logger.debug("Request " + requests.get(obsID) + " added to threadsList"); - } - for (int i = 0; i < threadsList.size(); i++) { - threadsList.get(i).start(); - UnicornCall.logger.debug("Request " + ((RequestThread)threadsList.get(i)).getObsID() + " started"); - } + if (cond.getType().equals(EnumCondType.MIMETYPE)) { + passed = cond.getValue().equals(inputParameter.getMimeType().toString()); + } else if (cond.getType().equals(EnumCondType.XPATH)) { + UnicornCall.logger.trace("condObserver : " + cond.getObserver().getID()); + Response res = mapOfResponse.get(cond.getObserver().getID()); + // Testing if there is a matching response in the map + // and if it is passed + if (res != null) { + String xmlStr = res.getXml().toString(); - for (int i = 0; i < threadsList.size(); i++) { - try { - threadsList.get(i).join(); - UnicornCall.logger.debug("Request " + ((RequestThread)threadsList.get(i)).getObsID() + " terminated"); - } catch (InterruptedException e) { - e.printStackTrace(); + 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("UTF-8"))); + + String xpathStr = cond.getValue(); + + XPathFactory xpathFact = new XPathFactoryImpl(); + + XPath xpath = xpathFact.newXPath(); + XPathExpression xpe = xpath.compile(xpathStr); + passed = (Boolean) xpe.evaluate(doc, XPathConstants.BOOLEAN); } + } else if (cond.getType().equals(EnumCondType.PARAMETER)) { + passed = false; + if (!mapOfStringParameter.containsKey(cond.getParameter())) { + cond.setResult(passed); + return passed; + } + + String[] parameterValues = mapOfStringParameter.get(cond.getParameter()); + for (int i=0; i<parameterValues.length; i++) + if (parameterValues[i].equals(cond.getValue())) + passed = true; + } + cond.setResult(passed); + UnicornCall.logger.trace("cond result : " + passed); + return passed; } - + /** * Generate the list of the request for the call * @@ -279,30 +237,17 @@ * @throws Exception * error occured during the process */ - private RequestList generateRequestList(final InputFactory aInputFactory, - final Map<String, String[]> mapOfArrayUseParameter, TLTNode node) - throws Exception { - - // Log information - UnicornCall.logger.trace("generateRequestList"); - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("InputFactory : " + aInputFactory + "."); - UnicornCall.logger.debug("Map of string parameter : " - + mapOfArrayUseParameter + "."); - } - - final MimeType aMimeType = aInputFactory.getMimeType(); - final EnumInputMethod aEnumInputMethod = aInputFactory - .getDefaultInputModule().getEnumInputMethod(); + private RequestList generateRequestList(InputParameter inputParameter, + Map<String, String[]> mapOfArrayUseParameter, TLTNode node) throws Exception { - final RequestList aRequestList = new RequestList(this.sLang); + MimeType aMimeType = inputParameter.getMimeType(); + EnumInputMethod aEnumInputMethod = inputParameter.getInputMethod(); + + RequestList aRequestList = new RequestList(sLang); // Iterate over all observation of this task to build a basic - // request list with only the url of observator and input parameter - // Il faut creer une list avec tous les exec et toutes les rencardeur de - // ifs - // Une liste d'Observer - for (final Observer aObserver : this.createExecList(node).values()) { - final String sObserverID = aObserver.getID(); + // request list with only the url of observer and input parameter + for (Observer aObserver : createExecList(node).values()) { + String sObserverID = aObserver.getID(); // add only observer who handle the current mimetype if (!aObserver.canHandleMimeType(aMimeType)) { if (UnicornCall.logger.isDebugEnabled()) { @@ -319,7 +264,8 @@ // create a new request with input parameter final Request aRequest = Request.createRequest( // the corresponding best input module - aInputFactory.getInputModule(aInputMethod.getMethod()), + //aInputFactory.getInputModule(aInputMethod.getMethod()), + inputParameter.getInputModule(), // URL of the service to call aInputMethod.getCallMethod().getURL().toString(), // Name of the parameter holding resource information @@ -331,14 +277,8 @@ aObserver.getResponseType()); // add this request to request list - aRequestList.addRequest(aRequest, aObserver.getID()); + //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). @@ -360,12 +300,6 @@ // 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 fixed parameter for (final CallParameter aCallParameter : aObserver.getCallMethod( aInputMethod.getMethod()).getMapOfCallParameter().values()) { @@ -383,18 +317,12 @@ .keySet()) { final Parameter aTaskParameter = this.aTask.getMapOfParameter() .get(sTaskParameterName); - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("Parameter : " + sTaskParameterName - + "."); - } + // check if this parameter have a given value String[] tStringUseParameterValue = mapOfArrayUseParameter .get(sTaskParameterName); if (null == tStringUseParameterValue) { - if (UnicornCall.logger.isDebugEnabled()) { - UnicornCall.logger.debug("No value input for parameter " - + sTaskParameterName + "."); - } + // check if this parameter have a default value final Map<String, Value> mapOfDefaultValue = aTaskParameter .getMapOfDefaultValue(); @@ -410,12 +338,7 @@ tStringUseParameterValue[i++] = s; } } - if (UnicornCall.logger.isDebugEnabled()) { - for (final String sParameterValue : tStringUseParameterValue) { - UnicornCall.logger.debug("Parameter Value : " - + sParameterValue + "."); - } - } + final Map<String, Value> mapOfValue = aTaskParameter .getMapOfValue(); // if there no value the parameter allow all string @@ -487,76 +410,98 @@ return aRequestList; } - + /** - * Returns the responses of low priority observations. + * Creates the map of all the Observer to call in the current node * - * @return responses of low priority observations. + * @param node + * the current node of the Task tree we are parsing */ - public Map<String, Response> getResponses() { - return this.mapOfResponse; + private Map<String, Observer> createExecList(TLTNode node) { + Map<String, Observer> mapOfCurrentNodeObserver = new LinkedHashMap<String, Observer>(); + for (TLTExec exec : node.getExecutionList()) { + mapOfCurrentNodeObserver.put(exec.getValue(), exec.getObserver()); + } + return mapOfCurrentNodeObserver; } - + /** - * Set the task to perform + * Execute the request depending on the priority * - * @param sTaskID - * ID of the task to perform + * @param aTPriority + * priority of the request + * @throws IOException + * Input/Output error */ - public void setTask(final String sTaskID) { - if (null == sTaskID) { - UnicornCall.logger.error("Call setTask with null argument."); - return; + private void doRequests(RequestList requestList) throws IOException { + UnicornCall.logger.trace("doRequests"); + + final Map<String, Request> requests = requestList.getRequestMap(); + // Creation of the thread list + ArrayList<Thread> threadsList = new ArrayList<Thread>(); + + for (final String obsID : requests.keySet()) { + // send request to observer + threadsList.add(new RequestThread(mapOfResponse, requests + .get(obsID), obsID, this)); + UnicornCall.logger.debug("Request " + requests.get(obsID) + " added to threadsList"); + } + for (int i = 0; i < threadsList.size(); i++) { + threadsList.get(i).start(); + UnicornCall.logger.debug("Request " + ((RequestThread)threadsList.get(i)).getObsID() + " started"); } - this.aTask = Framework.mapOfTask.get(sTaskID); - if (null == this.aTask) { - UnicornCall.logger.error("The task " + sTaskID - + " does not exists."); + for (int i = 0; i < threadsList.size(); i++) { + try { + threadsList.get(i).join(); + UnicornCall.logger.debug("Request " + ((RequestThread)threadsList.get(i)).getObsID() + " terminated"); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } - + /** - * define the lang of the check + * Enter a new parameter in the list * - * @param sLang - * defines the lang to configure + * @param sName + * Name of the parameter + * @param tStringValue + * value of the parameter */ - public void setLang(final String sLang) { - UnicornCall.logger.debug("setLang(" + sLang + ")"); - this.sLang = sLang; - } + public void addParameter(final String sName, final String[] tStringValue) { - public String getLang() { - return sLang.split(",")[0]; + final String[] tStringValueLocal = mapOfStringParameter.get(sName); + if (tStringValueLocal != null) { + int tValuesLength = tStringValueLocal.length; + int newSize = tStringValue.length + tValuesLength; + final String[] tStringValueNew = new String[newSize]; + for (int i = 0; i < tStringValueLocal.length; i++) { + tStringValueNew[i] = tStringValueLocal[i]; + } + for (int i = 0; i < tStringValue.length; i++) { + tStringValueNew[tValuesLength + i] = tStringValue[i]; + } + this.mapOfStringParameter.put(sName, tStringValueNew); + } else { + this.mapOfStringParameter.put(sName, tStringValue); + } } - - /** - * Returns the document name - * - * @return Returns the documentName. - */ - public String getDocumentName() { - return this.sDocumentName; + + public void addParameter(final String sName, final String tStringValue) { + String[] tab = {tStringValue}; + addParameter(sName, tab); } - - /** - * Set the name of the document - * - * @param sDocumentName - * The documentName to set. - */ - public void setDocumentName(final String sDocumentName) { - this.sDocumentName = sDocumentName; + + public String getObserverName(String observer, String lang) { + return Framework.mapOfObserver.get(observer).getName(lang); } - - /** - * Gives the list of the observations in the order specified in the tasklist file - * - * @return map of the observations of the check - */ + + public String getInputMethod() { + return inputParameter.getInputMethod().toString(); + } + public LinkedHashMap<String, Response> getObservationList() { - if (observationMap == null) { observationMap = new LinkedHashMap<String, Response>(); @@ -592,66 +537,23 @@ } } } - return observationMap; } - public String getObserverName(String observer, String lang) { - return Framework.mapOfObserver.get(observer).getName(lang); - } - - /** - * @return Returns the mapOfStringParameter. - */ - public Map<String, String[]> getMapOfStringParameter() { - return mapOfStringParameter; - } - - /** - * Enter a new parameter in the list - * - * @param sName - * Name of the parameter - * @param tStringValue - * value of the parameter - */ - public void addParameter(final String sName, final String[] tStringValue) { - - final String[] tStringValueLocal = mapOfStringParameter.get(sName); - if (tStringValueLocal != null) { - int tValuesLength = tStringValueLocal.length; - int newSize = tStringValue.length + tValuesLength; - final String[] tStringValueNew = new String[newSize]; - for (int i = 0; i < tStringValueLocal.length; i++) { - tStringValueNew[i] = tStringValueLocal[i]; - } - for (int i = 0; i < tStringValue.length; i++) { - tStringValueNew[tValuesLength + i] = tStringValue[i]; + public boolean isPassed() { + boolean passed = true; + for (String key : getObservationList().keySet()) { + if (!observationMap.get(key).isPassed()) { + passed = false; } - this.mapOfStringParameter.put(sName, tStringValueNew); - } else { - this.mapOfStringParameter.put(sName, tStringValue); } - } - - public void addParameter(final String sName, final String tStringValue) { - - String[] tab = {tStringValue}; - addParameter(sName, tab); - + return passed; } - /** - * Set the map of String Parameter - * - * @param mapOfStringParameter - * The mapOfStringParameter to set. - */ - public void setMapOfStringParameter( - final Map<String, String[]> mapOfStringParameter) { - this.mapOfStringParameter = mapOfStringParameter; + public String getLang() { + return sLang.split(",")[0]; } - + /** * Returns the current task * @@ -660,159 +562,66 @@ public Task getTask() { return this.aTask; } - + /** - * Set the aEnumInputMethod + * Returns the responses of low priority observations. * - * @param enumInputMethod - * The aEnumInputMethod to set. + * @return responses of low priority observations. */ - public void setEnumInputMethod(final EnumInputMethod aEnumInputMethod) { - this.aEnumInputMethod = aEnumInputMethod; + public Map<String, Response> getResponses() { + return this.mapOfResponse; } - - - public EnumInputMethod getInputMethod() { - return aEnumInputMethod; - } - /** - * Set the uploadedFile - * - * @param uploadedFile - * The uploadedFile to set. + * @return Returns the mapOfStringParameter. */ - public void setInputParameterValue(final Object oInputParameterValue) { - this.oInputParameterValue = oInputParameterValue; + public Map<String, String[]> getMapOfStringParameter() { + return mapOfStringParameter; } - + /** - * Giving a TLTCond, checks in the map of response if the condition passes - * or fails and consequently returns a boolean. + * Set the task to perform * - * @param cond - * The condition to check - * @return true if there is a matching response and if the condition passes - * else false + * @param sTaskID + * ID of the task to perform */ - public boolean checkCond(TLTCond cond) throws Exception { - UnicornCall.logger.trace("checkCond : "); - UnicornCall.logger.trace(cond); - UnicornCall.logger.trace("condId : " + cond.getId()); - UnicornCall.logger.trace("condType : " + cond.getType()); - UnicornCall.logger.trace("condValue : " + cond.getValue()); - - boolean passed = false; - - if (cond.getType().equals(EnumCondType.MIMETYPE)) { - passed = cond.getValue().equals(getMimeType().toString()); - } else if (cond.getType().equals(EnumCondType.XPATH)) { - UnicornCall.logger.trace("condObserver : " - + cond.getObserver().getID()); - Response res = mapOfResponse.get(cond.getObserver().getID()); - // Testing if there is a matching response in the map - // 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("UTF-8"))); - - String xpathStr = cond.getValue(); - - XPathFactory xpathFact = new XPathFactoryImpl(); - - XPath xpath = xpathFact.newXPath(); - XPathExpression xpe = xpath.compile(xpathStr); - passed = (Boolean) xpe.evaluate(doc, XPathConstants.BOOLEAN); - } - } else if (cond.getType().equals(EnumCondType.PARAMETER)) { - passed = false; - if (!mapOfStringParameter.containsKey(cond.getParameter())) { - cond.setResult(passed); - return passed; - } - - String[] parameterValues = mapOfStringParameter.get(cond.getParameter()); - for (int i=0; i<parameterValues.length; i++) - if (parameterValues[i].equals(cond.getValue())) - passed = true; - + public void setTask(final String sTaskID) { + if (null == sTaskID) { + UnicornCall.logger.error("Call setTask with null argument."); + return; } + this.aTask = Framework.mapOfTask.get(sTaskID); - cond.setResult(passed); - UnicornCall.logger.trace("cond result : " + passed); - return passed; + if (null == this.aTask) { + UnicornCall.logger.error("The task " + sTaskID + + " does not exists."); + } } /** + * define the lang of the check * - * @return The MimeType of the document - * @throws Exception + * @param sLang + * defines the lang to configure */ - private MimeType getMimeType() throws Exception { - - UnicornCall.logger.trace("getMimeType"); - 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 provided."); - 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(Property - .get("UNICORN_PARAMETER_PREFIX") - + "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; - } - UnicornCall.logger.debug("MimeType : " + aMimeType.toString() + "."); - - return aMimeType; + public void setLang(final String sLang) { + UnicornCall.logger.debug("setLang(" + sLang + ")"); + this.sLang = sLang; + } + /** + * Set the map of String Parameter + * + * @param mapOfStringParameter + * The mapOfStringParameter to set. + */ + public void setMapOfStringParameter( + final Map<String, String[]> mapOfStringParameter) { + this.mapOfStringParameter = mapOfStringParameter; } + public void setInputParameter(final InputParameter inputParameter) { + this.inputParameter = inputParameter; + } + } \ No newline at end of file
Received on Thursday, 17 September 2009 15:42:56 UTC