Changeset 304:e64200784188

Show
Ignore:
Timestamp:
09/08/09 14:44:48 (4 years ago)
Author:
tgambet
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@305
Message:

cleaned up

Files:
1 modified

Legend:

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

    r303 r304  
    1 // $Id: ObserveAction.java,v 1.16 2009-09-08 14:42:33 tgambet Exp $ 
     1// $Id: ObserveAction.java,v 1.17 2009-09-08 14:44:48 tgambet Exp $ 
    22// Author: Jean-Guilhem Rouel 
    33// (c) COPYRIGHT MIT, ERCIM and Keio, 2006. 
     
    6767                outputParams.add("mimetype"); 
    6868                outputParams.add("lang"); 
    69         } 
    70          
    71         private Map<String, Object> getRequestParameters(HttpServletRequest req) throws FileUploadException { 
    72                  
    73                 Hashtable<String, Object> params = new Hashtable<String, Object>(); 
    74                  
    75                 if (req.getMethod().equals("POST") && ServletFileUpload.isMultipartContent(new ServletRequestContext(req))) { 
    76                         List<?> listOfItem = upload.parseRequest(req); 
    77                         for (Object fileItem : listOfItem) { 
    78                                 FileItem aFileItem = (FileItem) fileItem; 
    79                                 if (aFileItem.isFormField()) { 
    80                                         params.put(aFileItem.getFieldName(), aFileItem.getString()); 
    81                                 } else if (aFileItem.getFieldName().equals(Property.get("UNICORN_PARAMETER_PREFIX") + "file")) { 
    82                                         params.put(aFileItem.getFieldName(), aFileItem); 
    83                                 } else { 
    84                                         // TODO log "unknown fileItem, ignored" 
    85                                 } 
    86                         } 
    87                 } else { 
    88                         Enumeration<?> paramEnum = req.getParameterNames(); 
    89                         while (paramEnum.hasMoreElements()) { 
    90                                  
    91                                 Object key = paramEnum.nextElement(); 
    92                                 logger.debug("TOM: " + key); 
    93                                 params.put(key.toString(), req.getParameter(key.toString())); 
    94                         } 
    95                 } 
    96                  
    97                 String s = "Parameters: "; 
    98                 for (String key : params.keySet()) { 
    99                         s += "\n\t" + key + " - " + params.get(key); 
    100                 } 
    101                 logger.debug(s); 
    102                  
    103                 return params; 
    10469        } 
    10570         
     
    242207                } 
    243208                 
    244                  
    245                  
    246                 /*for (Object param : req.getParameterMap().keySet()) { 
    247                         String sParamName = (String) param; 
    248                         String[] tStringParamValue = req.getParameterValues(sParamName); 
    249                         addParameter(sParamName, tStringParamValue, aUnicornCall, mapOfSpecificParameter, mapOfOutputParameter); 
    250                 }*/ 
    251                  
    252                 //addParameter(paramPrefix+ "task", task, aUnicornCall, mapOfSpecificParameter, mapOfOutputParameter); 
    253                  
    254                 // POST operations 
    255                 //FileItem aFileItemUploaded = null; 
    256                 /*if (req.getMethod().equals("POST") && ServletFileUpload.isMultipartContent(new ServletRequestContext(req))) { 
    257                         messages.clear(); 
    258                         try { 
    259                                 List<?> listOfItem = upload.parseRequest(req); 
    260                                 // Process the uploaded items 
    261                                 for (Iterator<?> aIterator = listOfItem.iterator(); aIterator.hasNext();) { 
    262                                         FileItem aFileItem = (FileItem) aIterator.next(); 
    263                                         if (aFileItem.isFormField()) { 
    264                                                 addParameter(aFileItem.getFieldName(), aFileItem.getString(), 
    265                                                                 aUnicornCall, mapOfSpecificParameter, mapOfOutputParameter); 
    266                                         } else if (aFileItem.getFieldName().equals(paramPrefix + "file")) { 
    267                                                 aFileItemUploaded = aFileItem; 
    268                                                 aUnicornCall.setDocumentName(aFileItemUploaded.getName()); 
    269                                                 aUnicornCall.setInputParameterValue(aFileItemUploaded); 
    270                                                 aUnicornCall.setEnumInputMethod(EnumInputMethod.UPLOAD); 
    271                                         } 
    272                                 } 
    273                         } catch (final FileUploadException aFileUploadException) { 
    274                                 logger.error("FileUploadException : " + aFileUploadException.getMessage(), aFileUploadException); 
    275                                 //TODO 
    276                                 Message mess = new Message(); 
    277                                 createError(req, resp, mess,mapOfSpecificParameter, mapOfOutputParameter); 
    278                         } 
    279                 }*/ 
    280                  
    281209                try { 
    282210                        aUnicornCall.doTask(); 
     
    308236                doGet(req, resp); 
    309237        } 
    310          
    311         /** 
    312          * Adds a parameter at the correct call. 
    313          *  
    314          * @param sParamName 
    315          *            Name of the parameter. 
    316          * @param sParamValue 
    317          *            Value of the parameter. 
    318          * @param aUnicornCall 
    319          * @param mapOfSpecificParameter 
    320          * @param mapOfOutputParameter 
    321          */ 
    322         /*private void addParameter(final String sParamName, 
    323                         final String sParamValue, final UnicornCall aUnicornCall, 
    324                         final Map<String, String> mapOfSpecificParameter, 
    325                         final Map<String, String> mapOfOutputParameter) { 
    326                 final String[] tStringValues = { sParamValue }; 
    327                 this.addParameter(sParamName, tStringValues, aUnicornCall, 
    328                                 mapOfSpecificParameter, mapOfOutputParameter); 
    329         } 
    330  
    331         /** 
    332          *  
    333          * @param sParamName 
    334          * @param tStringParamValue 
    335          * @param aUnicornCall 
    336          * @param mapOfSpecificParameter 
    337          * @param mapOfOutputParameter 
    338          */ 
    339         /*private void addParameter(String sParamName, 
    340                         final String[] tStringParamValue, final UnicornCall aUnicornCall, 
    341                         final Map<String, String> mapOfSpecificParameter, 
    342                         final Map<String, String> mapOfOutputParameter) { 
    343  
    344                 if (null == tStringParamValue || 0 == tStringParamValue.length) { 
    345                         // no value for this parameter 
    346                         // TODO log this info if necessary 
    347                         return; 
    348                 } 
    349  
    350                 if (!sParamName.startsWith(Property.get("UNICORN_PARAMETER_PREFIX"))) { 
    351                         // task parameter 
    352                         aUnicornCall.addParameter(sParamName, tStringParamValue); 
    353                         return; 
    354                 } 
    355  
    356                 // Output specific parameter 
    357                 if (sParamName.startsWith(Property 
    358                                 .get("UNICORN_PARAMETER_OUTPUT_PREFIX"))) { 
    359                         sParamName = sParamName.substring(Property.get( 
    360                                         "UNICORN_PARAMETER_OUTPUT_PREFIX").length()); 
    361                         mapOfSpecificParameter.put(sParamName, tStringParamValue); 
    362                         return; 
    363                 } 
    364                  
    365                 // Unicorn parameter 
    366                 // TODO: Why is it here? 
    367                 sParamName = sParamName.substring(Property.get( 
    368                                 "UNICORN_PARAMETER_PREFIX").length()); 
    369  
    370                 if (sParamName.equals("lang")) { 
    371                         aUnicornCall.addParameter(Property.get("UNICORN_PARAMETER_PREFIX") 
    372                                         + "lang", tStringParamValue); 
    373                 } 
    374  
    375                 // Global Unicorn parameter 
    376                 if (sParamName.equals("task")) { 
    377                         // FirstServlet.logger.debug(""); 
    378                         aUnicornCall.setTask(tStringParamValue[0]); 
    379                 } else if (sParamName.equals("uri")) { 
    380                         aUnicornCall.setEnumInputMethod(EnumInputMethod.URI); 
    381                         if (tStringParamValue[0].length() < 7 || !tStringParamValue[0].substring(0, 7).equals("http://")) { 
    382                                 ObserveAction.logger.info("URI missing protocol : " 
    383                                                 + tStringParamValue[0]); 
    384                                 tStringParamValue[0] = "http://" + tStringParamValue[0]; 
    385                                 ObserveAction.logger.info("URI modified to : " 
    386                                                 + tStringParamValue[0]); 
    387                         } 
    388                          
    389                         aUnicornCall.setDocumentName(tStringParamValue[0]); 
    390                         aUnicornCall.setInputParameterValue(tStringParamValue[0]); 
    391                 } else if (sParamName.equals("text")) { 
    392                         aUnicornCall.setEnumInputMethod(EnumInputMethod.DIRECT); 
    393                         aUnicornCall.setInputParameterValue(tStringParamValue[0]); 
    394                 } 
    395                 // TODO add upload handle when it work 
    396                 else if (sParamName.equals("output") || sParamName.equals("format") 
    397                                 || sParamName.equals("charset") 
    398                                 || sParamName.equals("mimetype") || sParamName.equals("lang")) { 
    399                         mapOfOutputParameter.put(sParamName, tStringParamValue[0]); 
    400                 } else if (sParamName.equals("text_mime")) { 
    401                         aUnicornCall.addParameter(Property.get("UNICORN_PARAMETER_PREFIX") 
    402                                         + "mime", tStringParamValue); 
    403                 } 
    404         }*/ 
    405  
     238 
     239        private Map<String, Object> getRequestParameters(HttpServletRequest req) throws FileUploadException { 
     240                 
     241                Hashtable<String, Object> params = new Hashtable<String, Object>(); 
     242                 
     243                if (req.getMethod().equals("POST") && ServletFileUpload.isMultipartContent(new ServletRequestContext(req))) { 
     244                        List<?> listOfItem = upload.parseRequest(req); 
     245                        for (Object fileItem : listOfItem) { 
     246                                FileItem aFileItem = (FileItem) fileItem; 
     247                                if (aFileItem.isFormField()) { 
     248                                        params.put(aFileItem.getFieldName(), aFileItem.getString()); 
     249                                } else if (aFileItem.getFieldName().equals(Property.get("UNICORN_PARAMETER_PREFIX") + "file")) { 
     250                                        params.put(aFileItem.getFieldName(), aFileItem); 
     251                                } else { 
     252                                        // TODO log "unknown fileItem, ignored" 
     253                                } 
     254                        } 
     255                } else { 
     256                        Enumeration<?> paramEnum = req.getParameterNames(); 
     257                        while (paramEnum.hasMoreElements()) { 
     258                                 
     259                                Object key = paramEnum.nextElement(); 
     260                                logger.debug("TOM: " + key); 
     261                                params.put(key.toString(), req.getParameter(key.toString())); 
     262                        } 
     263                } 
     264                 
     265                String s = "Parameters: "; 
     266                for (String key : params.keySet()) { 
     267                        s += "\n\t" + key + " - " + params.get(key); 
     268                } 
     269                logger.debug(s); 
     270                 
     271                return params; 
     272        } 
     273         
    406274        private void createError(HttpServletRequest req, HttpServletResponse resp, 
    407275                        Message mess, Map<String, String> mapOfSpecificParameter, 
     
    456324                return ret.substring(0, ret.length() - 1); 
    457325        } 
    458  
     326         
    459327}