Changeset 295:922738f06e80
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
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 $ |
| 2 | 2 | // Author: Damien LEROY. |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. |
| … |
… |
|
| 31 | 31 | public static OutputModule createOutputModule(String module) { |
| 32 | 32 | OutputFactory.logger.trace("createOutputModule"); |
| 33 | | if (OutputFactory.logger.isDebugEnabled()) { |
| 34 | | OutputFactory.logger.debug("Output module : " + module); |
| 35 | | } |
| | 33 | OutputFactory.logger.debug("Output module : " + module); |
| 36 | 34 | |
| 37 | 35 | /* Commented out for now as this is unnecessary and that doesn't seem quite safe */ |
| … |
… |
|
| 59 | 57 | * The format who the output formatter must produce. |
| 60 | 58 | * @return The new output formatter. |
| 61 | | * @throws ResourceNotFoundException |
| 62 | | * @throws ParseErrorException |
| 63 | | * @throws Exception |
| 64 | 59 | */ |
| 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 + "."); |
| 76 | 67 | |
| 77 | | final OutputFormater aOutputFormater; |
| | 68 | OutputFormater aOutputFormater; |
| 78 | 69 | |
| 79 | | final String sFormaterName = Property.getProps("specialFormaters.properties") |
| 80 | | .getProperty(sMimeType); |
| | 70 | String sFormaterName = Property.getProps("specialFormaters.properties").getProperty(sMimeType); |
| | 71 | |
| 81 | 72 | 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 | } |
| 89 | 82 | } |
| 90 | 83 | else { |
-
|
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 $ |
| 2 | 2 | // Author: Jean-Guilhem Rouel |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM and Keio, 2006. |
| … |
… |
|
| 13 | 13 | import org.apache.velocity.exception.ParseErrorException; |
| 14 | 14 | import org.apache.velocity.exception.ResourceNotFoundException; |
| | 15 | import org.w3c.unicorn.util.Message; |
| 15 | 16 | |
| 16 | 17 | /** |
| … |
… |
|
| 27 | 28 | * @param mapOfStringObject |
| 28 | 29 | * @param output |
| 29 | | * @throws ResourceNotFoundException |
| 30 | | * @throws ParseErrorException |
| 31 | | * @throws MethodInvocationException |
| 32 | | * @throws Exception |
| 33 | 30 | */ |
| 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); |
| 38 | 32 | |
| 39 | 33 | /** |
| 40 | | * @param aException |
| | 34 | * @param errorMessage |
| 41 | 35 | * @param aWriter |
| 42 | | * @throws Exception |
| 43 | | * @throws MethodInvocationException |
| 44 | | * @throws ParseErrorException |
| 45 | | * @throws ResourceNotFoundException |
| 46 | 36 | */ |
| 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); |
| 50 | 38 | |
| 51 | 39 | } |
-
|
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 $ |
| 2 | 2 | // Author: Damien LEROY. |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. |
| … |
… |
|
| 14 | 14 | import org.apache.velocity.exception.ParseErrorException; |
| 15 | 15 | import org.apache.velocity.exception.ResourceNotFoundException; |
| | 16 | import org.w3c.unicorn.util.Message; |
| 16 | 17 | |
| 17 | 18 | /** |
| … |
… |
|
| 27 | 28 | * Generate the output of all response. |
| 28 | 29 | * |
| 29 | | * @throws IOException |
| 30 | | * @throws Exception |
| 31 | | * @throws MethodInvocationException |
| 32 | | * @throws ParseErrorException |
| 33 | | * @throws ResourceNotFoundException |
| 34 | 30 | */ |
| 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); |
| 40 | 33 | |
| 41 | 34 | /** |
| 42 | 35 | * Generates an error output |
| 43 | 36 | * |
| 44 | | * @throws IOException |
| 45 | | * @throws Exception |
| 46 | | * @throws MethodInvocationException |
| 47 | | * @throws ParseErrorException |
| 48 | | * @throws ResourceNotFoundException |
| 49 | 37 | */ |
| 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); |
| 55 | 40 | |
| 56 | 41 | } |
-
|
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 $ |
| 2 | 2 | // Author: Damien LEROY. |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. |
| … |
… |
|
| 5 | 5 | package org.w3c.unicorn.output; |
| 6 | 6 | |
| | 7 | import java.io.IOException; |
| 7 | 8 | import java.io.Writer; |
| 8 | 9 | import java.util.Map; |
| 9 | 10 | |
| 10 | 11 | import 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; |
| 14 | 12 | import org.w3c.unicorn.Framework; |
| | 13 | import org.w3c.unicorn.util.Message; |
| 15 | 14 | import org.w3c.unicorn.util.Property; |
| 16 | 15 | import org.w3c.unicorn.util.Templates; |
| … |
… |
|
| 64 | 63 | } |
| 65 | 64 | |
| 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) { |
| 75 | 66 | |
| 76 | 67 | OutputFormater.logger.trace("produceOutput"); |
| 77 | | OutputFormater.logger.debug("Map of String -> Object : " |
| 78 | | + mapOfStringObject + "."); |
| | 68 | OutputFormater.logger.debug("Map of String -> Object : " + mapOfStringObject + "."); |
| 79 | 69 | OutputFormater.logger.debug("Writer : " + output + "."); |
| 80 | 70 | |
| 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)); |
| 85 | 73 | |
| 86 | 74 | 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 | } |
| 88 | 80 | } |
| 89 | 81 | |
| 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) { |
| 99 | 83 | |
| 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); |
| 106 | 90 | |
| 107 | 91 | 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 | } |
| 109 | 97 | } |
| 110 | 98 | |
-
|
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 $ |
| 2 | 2 | // Author: Damien LEROY. |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. |
| … |
… |
|
| 8 | 8 | import java.util.Map; |
| 9 | 9 | |
| 10 | | import org.apache.velocity.exception.MethodInvocationException; |
| 11 | | import org.apache.velocity.exception.ParseErrorException; |
| 12 | | import org.apache.velocity.exception.ResourceNotFoundException; |
| | 10 | import org.w3c.unicorn.util.Message; |
| 13 | 11 | |
| 14 | 12 | /** |
| … |
… |
|
| 19 | 17 | public class SimpleOutputModule implements OutputModule { |
| 20 | 18 | |
| 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) { |
| 27 | 21 | aOutputFormater.produceOutput(mapOfStringObject, aWriter); |
| 28 | 22 | } |
| 29 | 23 | |
| 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); |
| 37 | 27 | } |
| 38 | 28 | |