Ignore:
Timestamp:
03/08/12 17:20:11 (12 years ago)
Author:
vmipsl
Message:

clean
mise en place message d'erreurs javascript

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tapas/web/src/com/ether/WebHelper.java

    r389 r402  
    11package com.ether; 
    22 
    3 import java.io.IOException; 
    4 import java.io.PrintWriter; 
    5 import java.security.InvalidParameterException; 
    6  
    7 import javax.servlet.ServletOutputStream; 
    8 import javax.servlet.http.HttpServletRequest; 
    9 import javax.servlet.http.HttpServletResponse; 
    10  
     3import com.ether.WebException.WebCode; 
    114import org.apache.commons.logging.Log; 
    125import org.apache.commons.logging.LogFactory; 
     
    147import org.jetbrains.annotations.Nullable; 
    158 
    16 import com.ether.WebException.WebCode; 
     9import javax.servlet.ServletOutputStream; 
     10import javax.servlet.http.HttpServletRequest; 
     11import javax.servlet.http.HttpServletResponse; 
     12import java.io.IOException; 
     13import java.io.PrintWriter; 
     14import java.security.InvalidParameterException; 
    1715 
    1816public final class WebHelper 
     
    2321 
    2422    @NotNull 
    25     public static String getRequestParameter(@NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull ) 
    26         throws InvalidParameterException 
     23    public static String getRequestParameter( @NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull ) 
     24            throws InvalidParameterException 
    2725    { 
    28         String parameterValue; 
    29         if(null == parameterName) 
    30                 parameterValue = defaultParameterValue; 
    31          
     26        String parameterValue; 
     27        if( null == parameterName ) 
     28            parameterValue = defaultParameterValue; 
     29 
    3230        parameterValue = httpServletRequest.getParameter( parameterName ); 
    3331 
     
    4846 
    4947        final PrintWriter writer = httpServletResponse.getWriter(); 
    50  
    51         writer.write( JSON_TAG_BEGIN ); 
    5248        writer.write( data ); 
    53         writer.write( JSON_TAG_END ); 
    5449    } 
    5550 
    56     public static void displayAjaxError(@NotNull final HttpServletResponse response, @Nullable final String methodName)  
    57         throws WebException 
    58     {            
    59         try { 
    60                 response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); 
    61                 response.setCharacterEncoding(UTF8Charset.getEncoding()); 
    62                 response.setContentType("text/plain;charset="+ UTF8Charset.getEncoding()); 
    63                 final ServletOutputStream outputStream = response.getOutputStream(); 
    64                 outputStream.print("error.method_not_implemented : " + methodName+ " is not implemented."); 
    65                 outputStream.flush(); 
    66                 outputStream.close(); 
    67         } catch (IOException e) { 
    68                 throw new WebException(WebCode.IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, e); 
    69         } 
     51    public static void displayAjaxError( @NotNull final HttpServletResponse response, @Nullable final String methodName ) 
     52            throws WebException 
     53    { 
     54        try 
     55        { 
     56            response.setStatus( HttpServletResponse.SC_NOT_IMPLEMENTED ); 
     57            response.setCharacterEncoding( UTF8Charset.getEncoding() ); 
     58            response.setContentType( "text/plain;charset=" + UTF8Charset.getEncoding() ); 
     59            final ServletOutputStream outputStream = response.getOutputStream(); 
     60            outputStream.print( "error.method_not_implemented : " + methodName + " is not implemented." ); 
     61            outputStream.flush(); 
     62            outputStream.close(); 
     63        } 
     64        catch( IOException e ) 
     65        { 
     66            throw new WebException( WebCode.IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, e ); 
     67        } 
    7068    } 
    7169 
    7270    private static final Log LOGGER = LogFactory.getLog( WebHelper.class ); 
    73      
     71 
     72    public static final int STATUS_CODE_SERVICE_EXCEPTION = 500; 
    7473    private static final String CONTENT_TYPE_TEXT_JSON = "text/javascript;charset=" + UTF8Charset.getEncoding(); 
    75     private static final char JSON_TAG_BEGIN = ' ' ;  // '('; 
    76     private static final char JSON_TAG_END = ' ';     // ')'; 
    7774} 
Note: See TracChangeset for help on using the changeset viewer.