Changeset 295:922738f06e80

Show
Ignore:
Timestamp:
09/07/09 16:32:20 (4 years ago)
Author:
tgambet
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@296
Message:

removed exceptions never thrown
+ change parameter Exception to Message type for error output

Location:
src/org/w3c/unicorn/output
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • src/org/w3c/unicorn/output/OutputFactory.java

    r244 r295  
    1 // $Id: OutputFactory.java,v 1.4 2009-09-01 16:00:24 jean-gui Exp $ 
     1// $Id: OutputFactory.java,v 1.5 2009-09-07 16:32:20 tgambet Exp $ 
    22// Author: Damien LEROY. 
    33// (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. 
     
    3131        public static OutputModule createOutputModule(String module) { 
    3232                OutputFactory.logger.trace("createOutputModule"); 
    33                 if (OutputFactory.logger.isDebugEnabled()) { 
    34                         OutputFactory.logger.debug("Output module : " + module); 
    35                 } 
     33                OutputFactory.logger.debug("Output module : " + module); 
    3634                 
    3735                /* Commented out for now as this is unnecessary and that doesn't seem quite safe */              
     
    5957         *            The format who the output formatter must produce. 
    6058         * @return The new output formatter. 
    61          * @throws ResourceNotFoundException 
    62          * @throws ParseErrorException 
    63          * @throws Exception 
    6459         */ 
    65         public static OutputFormater createOutputFormater( 
    66                         final String sOutputFormat, final String sLang, 
    67                         final String sMimeType) throws ResourceNotFoundException, 
    68                         ParseErrorException, Exception { 
    69                 OutputFactory.logger.trace("createOutputformater"); 
    70                 if (OutputFactory.logger.isDebugEnabled()) { 
    71                         OutputFactory.logger 
    72                                         .debug("Output format : " + sOutputFormat + "."); 
    73                         OutputFactory.logger.debug("Language : " + sLang + "."); 
    74                         OutputFactory.logger.debug("Mime type : " + sMimeType + "."); 
    75                 } 
     60        public static OutputFormater createOutputFormater(final String sOutputFormat, 
     61                        final String sLang, final String sMimeType)  { 
     62                 
     63                logger.trace("createOutputformater"); 
     64                logger.debug("Output format : " + sOutputFormat + "."); 
     65                logger.debug("Language : " + sLang + "."); 
     66                logger.debug("Mime type : " + sMimeType + "."); 
    7667 
    77                 final OutputFormater aOutputFormater; 
     68                OutputFormater aOutputFormater; 
    7869                 
    79                 final String sFormaterName = Property.getProps("specialFormaters.properties") 
    80                                                                                          .getProperty(sMimeType); 
     70                String sFormaterName = Property.getProps("specialFormaters.properties").getProperty(sMimeType); 
     71                 
    8172                if (null != sFormaterName) { 
    82                         final Class<?> aFormaterClass = Class 
    83                                         .forName("org.w3c.unicorn.output." + sFormaterName); 
    84                         final Class<?>[] tClassParamType = { String.class, String.class }; 
    85                         final Object[] tObjectParamValue = { sOutputFormat, sLang }; 
    86  
    87                         aOutputFormater = (OutputFormater) aFormaterClass.getConstructor( 
    88                                         tClassParamType).newInstance(tObjectParamValue); 
     73                        try { 
     74                                final Class<?> aFormaterClass = Class.forName("org.w3c.unicorn.output." + sFormaterName); 
     75                                final Class<?>[] tClassParamType = { String.class, String.class }; 
     76                                final Object[] tObjectParamValue = { sOutputFormat, sLang }; 
     77                                aOutputFormater = (OutputFormater) aFormaterClass.getConstructor(tClassParamType).newInstance(tObjectParamValue); 
     78                        } catch (Exception e) { 
     79                                logger.error("Error instanciating outputFormater: " + sFormaterName + ". Using SimpleOutputFormater instead.", e); 
     80                                aOutputFormater = new SimpleOutputFormater(sOutputFormat, sLang); 
     81                        }  
    8982                } 
    9083                else { 
  • src/org/w3c/unicorn/output/OutputFormater.java

    r244 r295  
    1 // $Id: OutputFormater.java,v 1.3 2009-09-01 16:00:24 jean-gui Exp $ 
     1// $Id: OutputFormater.java,v 1.4 2009-09-07 16:32:20 tgambet Exp $ 
    22// Author: Jean-Guilhem Rouel 
    33// (c) COPYRIGHT MIT, ERCIM and Keio, 2006. 
     
    1313import org.apache.velocity.exception.ParseErrorException; 
    1414import org.apache.velocity.exception.ResourceNotFoundException; 
     15import org.w3c.unicorn.util.Message; 
    1516 
    1617/** 
     
    2728         * @param mapOfStringObject 
    2829         * @param output 
    29          * @throws ResourceNotFoundException 
    30          * @throws ParseErrorException 
    31          * @throws MethodInvocationException 
    32          * @throws Exception 
    3330         */ 
    34         public abstract void produceOutput( 
    35                         final Map<String, Object> mapOfStringObject, final Writer output) 
    36                         throws ResourceNotFoundException, ParseErrorException, 
    37                         MethodInvocationException, Exception; 
     31        public abstract void produceOutput(Map<String, Object> mapOfStringObject, Writer output); 
    3832 
    3933        /** 
    40          * @param aException 
     34         * @param errorMessage  
    4135         * @param aWriter 
    42          * @throws Exception 
    43          * @throws MethodInvocationException 
    44          * @throws ParseErrorException 
    45          * @throws ResourceNotFoundException 
    4636         */ 
    47         public abstract void produceError(final Exception aException, 
    48                         final Writer output) throws ResourceNotFoundException, 
    49                         ParseErrorException, MethodInvocationException, Exception; 
     37        public abstract void produceError(Message errorMessage, Writer output); 
    5038 
    5139} 
  • src/org/w3c/unicorn/output/OutputModule.java

    r214 r295  
    1 // $Id: OutputModule.java,v 1.2 2009-08-28 12:40:06 jean-gui Exp $ 
     1// $Id: OutputModule.java,v 1.3 2009-09-07 16:32:20 tgambet Exp $ 
    22// Author: Damien LEROY. 
    33// (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. 
     
    1414import org.apache.velocity.exception.ParseErrorException; 
    1515import org.apache.velocity.exception.ResourceNotFoundException; 
     16import org.w3c.unicorn.util.Message; 
    1617 
    1718/** 
     
    2728         * Generate the output of all response. 
    2829         *  
    29          * @throws IOException 
    30          * @throws Exception 
    31          * @throws MethodInvocationException 
    32          * @throws ParseErrorException 
    33          * @throws ResourceNotFoundException 
    3430         */ 
    35         public abstract void produceOutput(final OutputFormater aOutputFormater, 
    36                         final Map<String, Object> mapOfStringObject, 
    37                         final Map<String, String[]> mapOfParameter, final Writer aWriter) 
    38                         throws IOException, ResourceNotFoundException, ParseErrorException, 
    39                         MethodInvocationException, Exception; 
     31        public abstract void produceOutput(final OutputFormater aOutputFormater, Map<String, Object> mapOfStringObject, 
     32                        final Map<String, String[]> mapOfParameter, final Writer aWriter); 
    4033 
    4134        /** 
    4235         * Generates an error output 
    4336         *  
    44          * @throws IOException 
    45          * @throws Exception 
    46          * @throws MethodInvocationException 
    47          * @throws ParseErrorException 
    48          * @throws ResourceNotFoundException 
    4937         */ 
    50         public abstract void produceError(final OutputFormater aOutputFormater, 
    51                         final Exception error, final Map<String, String[]> mapOfParameter, 
    52                         final Writer aWriter) throws IOException, 
    53                         ResourceNotFoundException, ParseErrorException, 
    54                         MethodInvocationException, Exception; 
     38        public abstract void produceError(final OutputFormater aOutputFormater, Message errorMessage, 
     39                        final Map<String, String[]> mapOfParameter, final Writer aWriter); 
    5540 
    5641} 
  • src/org/w3c/unicorn/output/SimpleOutputFormater.java

    r244 r295  
    1 // $Id: SimpleOutputFormater.java,v 1.3 2009-09-01 16:00:24 jean-gui Exp $ 
     1// $Id: SimpleOutputFormater.java,v 1.4 2009-09-07 16:32:20 tgambet Exp $ 
    22// Author: Damien LEROY. 
    33// (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. 
     
    55package org.w3c.unicorn.output; 
    66 
     7import java.io.IOException; 
    78import java.io.Writer; 
    89import java.util.Map; 
    910 
    1011import org.apache.velocity.VelocityContext; 
    11 import org.apache.velocity.exception.MethodInvocationException; 
    12 import org.apache.velocity.exception.ParseErrorException; 
    13 import org.apache.velocity.exception.ResourceNotFoundException; 
    1412import org.w3c.unicorn.Framework; 
     13import org.w3c.unicorn.util.Message; 
    1514import org.w3c.unicorn.util.Property; 
    1615import org.w3c.unicorn.util.Templates; 
     
    6463        } 
    6564         
    66         /* 
    67          * (non-Javadoc) 
    68          *  
    69          * @see org.w3c.unicorn.output.OutputFormater#produceOutput(java.util.Map, 
    70          *      java.io.Writer) 
    71          */ 
    72         public void produceOutput(final Map<String, Object> mapOfStringObject, 
    73                         final Writer output) throws ResourceNotFoundException, 
    74                         ParseErrorException, MethodInvocationException, Exception { 
     65        public void produceOutput(final Map<String, Object> mapOfStringObject, final Writer output) { 
    7566 
    7667                OutputFormater.logger.trace("produceOutput"); 
    77                 OutputFormater.logger.debug("Map of String -> Object : " 
    78                                 + mapOfStringObject + "."); 
     68                OutputFormater.logger.debug("Map of String -> Object : " + mapOfStringObject + "."); 
    7969                OutputFormater.logger.debug("Writer : " + output + "."); 
    8070                 
    81                 for (final String sObjectName : mapOfStringObject.keySet()) { 
    82                         aVelocityContext.put(sObjectName, mapOfStringObject 
    83                                         .get(sObjectName)); 
    84                 } 
     71                for (final String sObjectName : mapOfStringObject.keySet()) 
     72                        aVelocityContext.put(sObjectName, mapOfStringObject.get(sObjectName)); 
    8573                 
    8674                Templates.write(format + ".vm", aVelocityContext, output); 
    87                 output.close(); 
     75                try { 
     76                        output.close(); 
     77                } catch (IOException e) { 
     78                        logger.error("Error closing output writer: " + e.getMessage(), e); 
     79                } 
    8880        } 
    8981 
    90         /* 
    91          * (non-Javadoc) 
    92          *  
    93          * @see org.w3c.unicorn.output.OutputFormater#produceError(java.lang.Exception, 
    94          *      java.io.Writer) 
    95          */ 
    96         public void produceError(final Exception aException, final Writer output) 
    97                         throws ResourceNotFoundException, ParseErrorException, 
    98                         MethodInvocationException, Exception { 
     82        public void produceError(Message errorMessage, final Writer output) { 
    9983                 
    100                 OutputFormater.logger.trace("produceError"); 
    101                 OutputFormater.logger.debug("Error : " + aException.getMessage() 
    102                                 + "."); 
    103                 OutputFormater.logger.debug("Writer : " + output + "."); 
    104                 if (aException != null) 
    105                         aVelocityContext.put("error", aException); 
     84                logger.trace("produceError"); 
     85                logger.debug("ErrorMessage : " + errorMessage.getMessage() + "."); 
     86                logger.debug("Writer : " + output + "."); 
     87                 
     88                Message[] messages = {errorMessage}; 
     89                aVelocityContext.put("messages", messages); 
    10690                 
    10791                Templates.write(format + ".error.vm", aVelocityContext, output); 
    108                 output.close(); 
     92                try { 
     93                        output.close(); 
     94                } catch (IOException e) { 
     95                        logger.error("Error closing output writer: " + e.getMessage(), e); 
     96                } 
    10997        } 
    11098 
  • src/org/w3c/unicorn/output/SimpleOutputModule.java

    r214 r295  
    1 // $Id: SimpleOutputModule.java,v 1.2 2009-08-28 12:40:06 jean-gui Exp $ 
     1// $Id: SimpleOutputModule.java,v 1.3 2009-09-07 16:32:20 tgambet Exp $ 
    22// Author: Damien LEROY. 
    33// (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. 
     
    88import java.util.Map; 
    99 
    10 import org.apache.velocity.exception.MethodInvocationException; 
    11 import org.apache.velocity.exception.ParseErrorException; 
    12 import org.apache.velocity.exception.ResourceNotFoundException; 
     10import org.w3c.unicorn.util.Message; 
    1311 
    1412/** 
     
    1917public class SimpleOutputModule implements OutputModule { 
    2018 
    21         public void produceOutput(final OutputFormater aOutputFormater, 
    22                         final Map<String, Object> mapOfStringObject, 
    23                         final Map<String, String[]> mapOfParameter, final Writer aWriter) 
    24                         throws ResourceNotFoundException, ParseErrorException, 
    25                         MethodInvocationException, Exception { 
    26                 OutputModule.logger.trace("Constructor"); 
     19        public void produceOutput(final OutputFormater aOutputFormater, Map<String, Object> mapOfStringObject, 
     20                        final Map<String, String[]> mapOfParameter, final Writer aWriter) { 
    2721                aOutputFormater.produceOutput(mapOfStringObject, aWriter); 
    2822        } 
    2923 
    30         public void produceError(final OutputFormater aOutputFormater, 
    31                         final Exception aException, 
    32                         final Map<String, String[]> mapOfParameter, final Writer aWriter) 
    33                         throws ResourceNotFoundException, ParseErrorException, 
    34                         MethodInvocationException, Exception { 
    35                 OutputModule.logger.trace("produceError"); 
    36                 aOutputFormater.produceError(aException, aWriter); 
     24        public void produceError(final OutputFormater aOutputFormater, Message errorMessage, 
     25                        final Map<String, String[]> mapOfParameter, final Writer aWriter) { 
     26                aOutputFormater.produceError(errorMessage, aWriter); 
    3727        } 
    3828