2006/unicorn/src/org/w3c/unicorn/output OutputModule.java,1.2,1.3 OutputFactory.java,1.4,1.5 OutputFormater.java,1.3,1.4 SimpleOutputModule.java,1.2,1.3 SimpleOutputFormater.java,1.3,1.4

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/output
In directory hutz:/tmp/cvs-serv8956/src/org/w3c/unicorn/output

Modified Files:
	OutputModule.java OutputFactory.java OutputFormater.java 
	SimpleOutputModule.java SimpleOutputFormater.java 
Log Message:
removed exceptions never thrown
+ change parameter Exception to Message type for error output

Index: OutputFormater.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/OutputFormater.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- OutputFormater.java	1 Sep 2009 16:00:24 -0000	1.3
+++ OutputFormater.java	7 Sep 2009 16:32:20 -0000	1.4
@@ -12,6 +12,7 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.unicorn.util.Message;
 
 /**
  * SimpleOutputFormater<br />
@@ -26,26 +27,13 @@
 	/**
 	 * @param mapOfStringObject
 	 * @param output
-	 * @throws ResourceNotFoundException
-	 * @throws ParseErrorException
-	 * @throws MethodInvocationException
-	 * @throws Exception
 	 */
-	public abstract void produceOutput(
-			final Map<String, Object> mapOfStringObject, final Writer output)
-			throws ResourceNotFoundException, ParseErrorException,
-			MethodInvocationException, Exception;
+	public abstract void produceOutput(Map<String, Object> mapOfStringObject, Writer output);
 
 	/**
-	 * @param aException
+	 * @param errorMessage 
 	 * @param aWriter
-	 * @throws Exception
-	 * @throws MethodInvocationException
-	 * @throws ParseErrorException
-	 * @throws ResourceNotFoundException
 	 */
-	public abstract void produceError(final Exception aException,
-			final Writer output) throws ResourceNotFoundException,
-			ParseErrorException, MethodInvocationException, Exception;
+	public abstract void produceError(Message errorMessage, Writer output);
 
 }
\ No newline at end of file

Index: OutputFactory.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/OutputFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- OutputFactory.java	1 Sep 2009 16:00:24 -0000	1.4
+++ OutputFactory.java	7 Sep 2009 16:32:20 -0000	1.5
@@ -30,9 +30,7 @@
 	 */
 	public static OutputModule createOutputModule(String module) {
 		OutputFactory.logger.trace("createOutputModule");
-		if (OutputFactory.logger.isDebugEnabled()) {
-			OutputFactory.logger.debug("Output module : " + module);
-		}
+		OutputFactory.logger.debug("Output module : " + module);
 		
 		/* Commented out for now as this is unnecessary and that doesn't seem quite safe */		
 //		if(null == module || "".equals(module)) {
@@ -58,34 +56,29 @@
 	 * @param sOutputFormat
 	 *            The format who the output formatter must produce.
 	 * @return The new output formatter.
-	 * @throws ResourceNotFoundException
-	 * @throws ParseErrorException
-	 * @throws Exception
 	 */
-	public static OutputFormater createOutputFormater(
-			final String sOutputFormat, final String sLang,
-			final String sMimeType) throws ResourceNotFoundException,
-			ParseErrorException, Exception {
-		OutputFactory.logger.trace("createOutputformater");
-		if (OutputFactory.logger.isDebugEnabled()) {
-			OutputFactory.logger
-					.debug("Output format : " + sOutputFormat + ".");
-			OutputFactory.logger.debug("Language : " + sLang + ".");
-			OutputFactory.logger.debug("Mime type : " + sMimeType + ".");
-		}
+	public static OutputFormater createOutputFormater(final String sOutputFormat,
+			final String sLang, final String sMimeType)  {
+		
+		logger.trace("createOutputformater");
+		logger.debug("Output format : " + sOutputFormat + ".");
+		logger.debug("Language : " + sLang + ".");
+		logger.debug("Mime type : " + sMimeType + ".");
 
-		final OutputFormater aOutputFormater;
+		OutputFormater aOutputFormater;
+		
+		String sFormaterName = Property.getProps("specialFormaters.properties").getProperty(sMimeType);
 		
-		final String sFormaterName = Property.getProps("specialFormaters.properties")
-											 .getProperty(sMimeType);
 		if (null != sFormaterName) {
-			final Class<?> aFormaterClass = Class
-					.forName("org.w3c.unicorn.output." + sFormaterName);
-			final Class<?>[] tClassParamType = { String.class, String.class };
-			final Object[] tObjectParamValue = { sOutputFormat, sLang };
-
-			aOutputFormater = (OutputFormater) aFormaterClass.getConstructor(
-					tClassParamType).newInstance(tObjectParamValue);
+			try {
+				final Class<?> aFormaterClass = Class.forName("org.w3c.unicorn.output." + sFormaterName);
+				final Class<?>[] tClassParamType = { String.class, String.class };
+				final Object[] tObjectParamValue = { sOutputFormat, sLang };
+				aOutputFormater = (OutputFormater) aFormaterClass.getConstructor(tClassParamType).newInstance(tObjectParamValue);
+			} catch (Exception e) {
+				logger.error("Error instanciating outputFormater: " + sFormaterName + ". Using SimpleOutputFormater instead.", e);
+				aOutputFormater = new SimpleOutputFormater(sOutputFormat, sLang);
+			} 
 		}
 		else {
 			aOutputFormater = new SimpleOutputFormater(sOutputFormat, sLang);

Index: OutputModule.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/OutputModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- OutputModule.java	28 Aug 2009 12:40:06 -0000	1.2
+++ OutputModule.java	7 Sep 2009 16:32:20 -0000	1.3
@@ -13,6 +13,7 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.unicorn.util.Message;
 
 /**
  * Interface for all output module.
@@ -26,31 +27,15 @@
 	/**
 	 * Generate the output of all response.
 	 * 
-	 * @throws IOException
-	 * @throws Exception
-	 * @throws MethodInvocationException
-	 * @throws ParseErrorException
-	 * @throws ResourceNotFoundException
 	 */
-	public abstract void produceOutput(final OutputFormater aOutputFormater,
-			final Map<String, Object> mapOfStringObject,
-			final Map<String, String[]> mapOfParameter, final Writer aWriter)
-			throws IOException, ResourceNotFoundException, ParseErrorException,
-			MethodInvocationException, Exception;
+	public abstract void produceOutput(final OutputFormater aOutputFormater, Map<String, Object> mapOfStringObject,
+			final Map<String, String[]> mapOfParameter, final Writer aWriter);
 
 	/**
 	 * Generates an error output
 	 * 
-	 * @throws IOException
-	 * @throws Exception
-	 * @throws MethodInvocationException
-	 * @throws ParseErrorException
-	 * @throws ResourceNotFoundException
 	 */
-	public abstract void produceError(final OutputFormater aOutputFormater,
-			final Exception error, final Map<String, String[]> mapOfParameter,
-			final Writer aWriter) throws IOException,
-			ResourceNotFoundException, ParseErrorException,
-			MethodInvocationException, Exception;
+	public abstract void produceError(final OutputFormater aOutputFormater, Message errorMessage,
+			final Map<String, String[]> mapOfParameter, final Writer aWriter);
 
 }

Index: SimpleOutputFormater.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/SimpleOutputFormater.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- SimpleOutputFormater.java	1 Sep 2009 16:00:24 -0000	1.3
+++ SimpleOutputFormater.java	7 Sep 2009 16:32:20 -0000	1.4
@@ -4,14 +4,13 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.output;
 
+import java.io.IOException;
 import java.io.Writer;
 import java.util.Map;
 
 import org.apache.velocity.VelocityContext;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
 import org.w3c.unicorn.Framework;
+import org.w3c.unicorn.util.Message;
 import org.w3c.unicorn.util.Property;
 import org.w3c.unicorn.util.Templates;
 
@@ -63,49 +62,38 @@
 		this.format = outputFormat;
 	}
 	
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.unicorn.output.OutputFormater#produceOutput(java.util.Map,
-	 *      java.io.Writer)
-	 */
-	public void produceOutput(final Map<String, Object> mapOfStringObject,
-			final Writer output) throws ResourceNotFoundException,
-			ParseErrorException, MethodInvocationException, Exception {
+	public void produceOutput(final Map<String, Object> mapOfStringObject, final Writer output) {
 
 		OutputFormater.logger.trace("produceOutput");
-		OutputFormater.logger.debug("Map of String -> Object : "
-				+ mapOfStringObject + ".");
+		OutputFormater.logger.debug("Map of String -> Object : " + mapOfStringObject + ".");
 		OutputFormater.logger.debug("Writer : " + output + ".");
 		
-		for (final String sObjectName : mapOfStringObject.keySet()) {
-			aVelocityContext.put(sObjectName, mapOfStringObject
-					.get(sObjectName));
-		}
+		for (final String sObjectName : mapOfStringObject.keySet())
+			aVelocityContext.put(sObjectName, mapOfStringObject.get(sObjectName));
 		
 		Templates.write(format + ".vm", aVelocityContext, output);
-		output.close();
+		try {
+			output.close();
+		} catch (IOException e) {
+			logger.error("Error closing output writer: " + e.getMessage(), e);
+		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.w3c.unicorn.output.OutputFormater#produceError(java.lang.Exception,
-	 *      java.io.Writer)
-	 */
-	public void produceError(final Exception aException, final Writer output)
-			throws ResourceNotFoundException, ParseErrorException,
-			MethodInvocationException, Exception {
+	public void produceError(Message errorMessage, final Writer output) {
 		
-		OutputFormater.logger.trace("produceError");
-		OutputFormater.logger.debug("Error : " + aException.getMessage()
-				+ ".");
-		OutputFormater.logger.debug("Writer : " + output + ".");
-		if (aException != null)
-			aVelocityContext.put("error", aException);
+		logger.trace("produceError");
+		logger.debug("ErrorMessage : " + errorMessage.getMessage() + ".");
+		logger.debug("Writer : " + output + ".");
+		
+		Message[] messages = {errorMessage};
+		aVelocityContext.put("messages", messages);
 		
 		Templates.write(format + ".error.vm", aVelocityContext, output);
-		output.close();
+		try {
+			output.close();
+		} catch (IOException e) {
+			logger.error("Error closing output writer: " + e.getMessage(), e);
+		}
 	}
 
 }

Index: SimpleOutputModule.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/SimpleOutputModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SimpleOutputModule.java	28 Aug 2009 12:40:06 -0000	1.2
+++ SimpleOutputModule.java	7 Sep 2009 16:32:20 -0000	1.3
@@ -7,9 +7,7 @@
 import java.io.Writer;
 import java.util.Map;
 
-import org.apache.velocity.exception.MethodInvocationException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.unicorn.util.Message;
 
 /**
  * This module allow to generate output in text format.
@@ -18,22 +16,14 @@
  */
 public class SimpleOutputModule implements OutputModule {
 
-	public void produceOutput(final OutputFormater aOutputFormater,
-			final Map<String, Object> mapOfStringObject,
-			final Map<String, String[]> mapOfParameter, final Writer aWriter)
-			throws ResourceNotFoundException, ParseErrorException,
-			MethodInvocationException, Exception {
-		OutputModule.logger.trace("Constructor");
+	public void produceOutput(final OutputFormater aOutputFormater, Map<String, Object> mapOfStringObject,
+			final Map<String, String[]> mapOfParameter, final Writer aWriter) {
 		aOutputFormater.produceOutput(mapOfStringObject, aWriter);
 	}
 
-	public void produceError(final OutputFormater aOutputFormater,
-			final Exception aException,
-			final Map<String, String[]> mapOfParameter, final Writer aWriter)
-			throws ResourceNotFoundException, ParseErrorException,
-			MethodInvocationException, Exception {
-		OutputModule.logger.trace("produceError");
-		aOutputFormater.produceError(aException, aWriter);
+	public void produceError(final OutputFormater aOutputFormater, Message errorMessage,
+			final Map<String, String[]> mapOfParameter, final Writer aWriter) {
+		aOutputFormater.produceError(errorMessage, aWriter);
 	}
 
 }

Received on Monday, 7 September 2009 16:32:31 UTC