Changeset 528:1faedac1f0b4

Show
Ignore:
Timestamp:
09/24/09 15:34:35 (4 years ago)
Author:
tgambet
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@529
Message:

createError method removed, redirection on Index is done in ouputModules

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/org/w3c/unicorn/action/ObserveAction.java

    r510 r528  
    1 // $Id: ObserveAction.java,v 1.41 2009-09-23 14:08:46 tgambet Exp $ 
     1// $Id: ObserveAction.java,v 1.42 2009-09-24 15:34:35 tgambet Exp $ 
    22// Author: Jean-Guilhem Rouel 
    33// (c) COPYRIGHT MIT, ERCIM and Keio, 2006. 
     
    1414import java.util.Map; 
    1515 
    16 import javax.servlet.RequestDispatcher; 
    1716import javax.servlet.ServletConfig; 
    1817import javax.servlet.ServletException; 
     
    109108                mapOfStringObject.put("unicorncall", aUnicornCall); 
    110109                 
     110                resp.setContentType(mapOfOutputParameter.get("mimetype") + "; charset=UTF-8"); 
     111                 
    111112                // Retrieve the parameters from the request 
    112113                Map<String, Object> reqParams; 
     
    116117                        OutputModule aOutputModule = OutputFactory.createOutputModule(mapOfOutputParameter, mapOfSpecificParameter); 
    117118                        messages.add(new Message(e)); 
    118                         createError(req, resp, null, mapOfStringObject, aOutputModule); 
     119                        aOutputModule.produceError(mapOfStringObject, resp.getWriter()); 
    119120                        return; 
    120121                } 
     
    155156                                        logger.trace("Task parameter: " + key + " - " + (String) reqParams.get(key)); 
    156157                                        String task = getTask((String) reqParams.get(key), messages); 
     158                                        mapOfStringObject.put("current_task", Framework.mapOfTask.get(task)); 
    157159                                        if (!task.equals(reqParams.get(key))) { 
    158160                                                mapOfStringObject.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); 
     
    206208                        logger.debug("No task parameter found. Task parameter is set to task id: " + task); 
    207209                        mapOfStringObject.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); 
     210                        mapOfStringObject.put("current_task", Framework.mapOfTask.get(task)); 
    208211                        aUnicornCall.setTask(task); 
    209212                } 
     
    213216                if (!reqParams.containsKey(paramPrefix + "uri") && !reqParams.containsKey(paramPrefix + "text") && !reqParams.containsKey(paramPrefix + "file")) { 
    214217                        messages.add(new Message(Message.Level.ERROR, "$message_nothing_to_validate", null)); 
    215                         createError(req, resp, reqParams, mapOfStringObject, aOutputModule); 
     218                        aOutputModule.produceError( mapOfStringObject, resp.getWriter()); 
    216219                        return; 
    217220                } 
    218221                 
    219                 resp.setContentType(mapOfOutputParameter.get("mimetype") + "; charset=" + mapOfOutputParameter.get("charset")); 
     222                //req.setAttribute("unicorn_parameters", reqParams); 
     223                 
     224                for (Object objKey : reqParams.keySet()) { 
     225                        String key = (String) objKey; 
     226                        String ref; 
     227                        if (key.startsWith(Property.get("UNICORN_PARAMETER_OUTPUT_PREFIX"))) 
     228                                continue; 
     229                        if (key.startsWith(paramPrefix)) 
     230                                ref = "param_" + key.substring(paramPrefix.length()); 
     231                        else 
     232                                ref = "param_" + key; 
     233                        if (reqParams.get(key) instanceof String[]) { 
     234                                String[] s = (String[]) reqParams.get(key); 
     235                                ArrayList<String> array = new ArrayList<String>(); 
     236                                for (int i = 0; i < s.length; i++) 
     237                                        array.add(s[i]); 
     238                                mapOfStringObject.put(ref, array); 
     239                        } 
     240                        else { 
     241                                mapOfStringObject.put(ref, reqParams.get(key)); 
     242                        } 
     243                } 
    220244                 
    221245                String s = "Resolved parameters:"; 
     
    236260                // Launch the observation 
    237261                try { 
    238                         aOutputModule.produceFirstOutput( mapOfStringObject, resp.getWriter()); 
     262                        aOutputModule.produceFirstOutput(mapOfStringObject, resp.getWriter()); 
    239263                        aUnicornCall.doTask(); 
    240264                        messages.addAll(aUnicornCall.getMessages()); 
    241265                        if (aUnicornCall.getResponses().size() == 0) { 
    242266                                messages.add(new Message(Message.Level.ERROR, "$message_no_observation_done", null)); 
    243                                 createError(req, resp, reqParams, mapOfStringObject, aOutputModule); 
     267                                aOutputModule.produceError(mapOfStringObject, resp.getWriter()); 
    244268                        } else { 
    245269                                aOutputModule.produceOutput(mapOfStringObject, resp.getWriter()); 
     
    250274                        else 
    251275                                messages.add(new Message(Message.Level.ERROR, ucnException.getMessage(), null)); 
    252                         createError(req, resp, reqParams, mapOfStringObject, aOutputModule); 
     276                        aOutputModule.produceError(mapOfStringObject, resp.getWriter()); 
    253277                } catch (final Exception aException) { 
    254278                        logger.error("Exception : " + aException.getMessage(), aException); 
    255279                        messages.add(new Message(aException)); 
    256                         createError(req, resp, reqParams, mapOfStringObject, aOutputModule); 
     280                        aOutputModule.produceError(mapOfStringObject, resp.getWriter()); 
    257281                } finally { 
    258282                        if ("true".equals(Property.get("DELETE_UPLOADED_FILES")) && aFileItemUploaded != null) 
     
    330354                return params; 
    331355        } 
    332          
    333         private void createError(HttpServletRequest req, HttpServletResponse resp, 
    334                         Map<String, Object> reqParams, Map<String, Object> mapOfStringObject, OutputModule aOutputModule) throws IOException, ServletException { 
    335                  
    336                 // If text/html is the mime-type the error will be displayed directly on index 
    337                 if (aOutputModule.getOutputParameter("mimetype").equals("text/html")) {// mapOfOutputParameter.get("mimetype").equals("text/html")) { 
    338                         redirect(req, resp, reqParams, (ArrayList<?>) mapOfStringObject.get("messages")); 
    339                         return; 
    340                 } 
    341                  
    342                 aOutputModule.produceError( mapOfStringObject, resp.getWriter()); 
    343         } 
    344          
    345         private void redirect(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> reqParams, ArrayList<?> messages) throws IOException, ServletException { 
    346                 req.setAttribute("unicorn_messages", messages); 
    347                 if (reqParams != null) 
    348                         req.setAttribute("unicorn_parameters", reqParams); 
    349                 RequestDispatcher dispatcher = req.getRequestDispatcher("index.html"); 
    350                 dispatcher.forward(req, resp); 
    351                 logger.info("request redirected to index"); 
    352         } 
    353356 
    354357        /**