W3C home > Mailing lists > Public > www-validator-cvs@w3.org > August 2009

2006/unicorn/src/org/w3c/unicorn/output XMLOutputFormater.java,1.1.2.2,1.1.2.3 SimpleOutputFormater.java,1.1.2.1,1.1.2.2

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 24 Aug 2009 12:51:01 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MfZ0n-0004yW-WB@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/output
In directory hutz:/tmp/cvs-serv19058/src/org/w3c/unicorn/output

Modified Files:
      Tag: dev2
	XMLOutputFormater.java SimpleOutputFormater.java 
Log Message:
updated to use the new template system

Index: XMLOutputFormater.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/Attic/XMLOutputFormater.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- XMLOutputFormater.java	12 Aug 2009 13:15:19 -0000	1.1.2.2
+++ XMLOutputFormater.java	24 Aug 2009 12:50:59 -0000	1.1.2.3
@@ -8,13 +8,14 @@
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
-import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.event.EventCartridge;
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
-import org.w3c.unicorn.util.TemplateHelper;
+import org.w3c.unicorn.Framework;
+import org.w3c.unicorn.util.Property;
+import org.w3c.unicorn.util.Templates;
 
 /**
  * Class for XML output formater.
@@ -29,19 +30,11 @@
 	private static final Log logger = OutputFactory.logger;
 
 	/**
-	 * Template for the standard output
-	 */
-	private Template aTemplateOutput = null;
-
-	/**
-	 * Template used for the standard error
-	 */
-	private Template aTemplateError = null;
-
-	/**
 	 * Apache velocity context
 	 */
-	private static VelocityContext aVelocityContext = new VelocityContext();
+	private static VelocityContext aVelocityContext;
+	
+	private String sOutputFormat;
 
 	/**
 	 * Write the result of the XML in a file
@@ -60,14 +53,16 @@
 	public XMLOutputFormater(final String sOutputFormat, final String sLang)
 			throws ResourceNotFoundException, ParseErrorException, Exception {
 		XMLOutputFormater.logger.trace("Constructor");
-		XMLOutputFormater.logger
-				.debug("Output format : " + sOutputFormat + ".");
+		XMLOutputFormater.logger.debug("Output format : " + sOutputFormat + ".");
 		XMLOutputFormater.logger.debug("Output language : " + sLang + ".");
 
-		aTemplateOutput = TemplateHelper.getInternationalizedTemplate(
-				sOutputFormat, sLang, aVelocityContext);
-		aTemplateError = TemplateHelper.getInternationalizedTemplate(
-				sOutputFormat + ".error", sLang, aVelocityContext);
+		this.sOutputFormat = sOutputFormat;
+		
+		if (Framework.getLanguageContexts().get(sLang) != null) {
+			aVelocityContext = new VelocityContext(Framework.getLanguageContexts().get(sLang));
+		} else {
+			aVelocityContext = new VelocityContext(Framework.getLanguageContexts().get(Property.get("DEFAULT_LANGUAGE")));
+		}
 	}
 
 	/*
@@ -83,15 +78,16 @@
 		XMLOutputFormater.logger.debug("Map of String -> Object : "
 				+ mapOfStringObject + ".");
 		XMLOutputFormater.logger.debug("Writer : " + aWriter + ".");
+		
 		final EventCartridge aEventCartridge = new EventCartridge();
 		aEventCartridge.addEventHandler(new XHTMLize());
-		// aEventCartridge.addEventHandler(new EscapeXMLEntities());
 		aEventCartridge.attachToContext(aVelocityContext);
 		for (final String sObjectName : mapOfStringObject.keySet()) {
 			aVelocityContext.put(sObjectName, mapOfStringObject
 					.get(sObjectName));
 		}
-		this.aTemplateOutput.merge(aVelocityContext, aWriter);
+		
+		Templates.write(sOutputFormat + ".vm", aVelocityContext, aWriter);
 		aWriter.close();
 	}
 
@@ -111,7 +107,7 @@
 		aEventCartridge.addEventHandler(new EscapeXMLEntities());
 		aEventCartridge.attachToContext(aVelocityContext);
 		aVelocityContext.put("error", aException);
-		this.aTemplateError.merge(aVelocityContext, aWriter);
+		Templates.write(sOutputFormat + ".error.vm", aVelocityContext, aWriter);
 		aWriter.close();
 	}
 }

Index: SimpleOutputFormater.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/Attic/SimpleOutputFormater.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -d -r1.1.2.1 -r1.1.2.2
--- SimpleOutputFormater.java	11 Aug 2009 16:20:43 -0000	1.1.2.1
+++ SimpleOutputFormater.java	24 Aug 2009 12:50:59 -0000	1.1.2.2
@@ -8,12 +8,13 @@
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
-import org.apache.velocity.Template;
 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.util.TemplateHelper;
+import org.w3c.unicorn.Framework;
+import org.w3c.unicorn.util.Property;
+import org.w3c.unicorn.util.Templates;
 
 /**
  * Class for simple output formater.
@@ -24,22 +25,23 @@
 
 	private static final Log logger = OutputFactory.logger;
 
-	private Template aTemplateOutput = null;
-
-	private Template aTemplateError = null;
-
-	private static VelocityContext aVelocityContext = new VelocityContext();
+	private static VelocityContext aVelocityContext;
+	
+	private String sOutputFormat;
 
 	public SimpleOutputFormater(final String sOutputFormat, final String sLang)
-			throws ResourceNotFoundException, ParseErrorException, Exception {
+		throws ResourceNotFoundException, ParseErrorException, Exception {
 		SimpleOutputFormater.logger.trace("Constructor");
-		SimpleOutputFormater.logger.debug("Output format : " + sOutputFormat
-				+ ".");
+		SimpleOutputFormater.logger.debug("Output format : " + sOutputFormat + ".");
 		SimpleOutputFormater.logger.debug("Output language : " + sLang + ".");
-		this.aTemplateOutput = TemplateHelper.getInternationalizedTemplate(
-				sOutputFormat, sLang, aVelocityContext);
-		this.aTemplateError = TemplateHelper.getInternationalizedTemplate(
-				sOutputFormat + ".error", sLang, aVelocityContext);
+		
+		this.sOutputFormat = sOutputFormat;
+		
+		if (Framework.getLanguageContexts().get(sLang) != null) {
+			aVelocityContext = new VelocityContext(Framework.getLanguageContexts().get(sLang));
+		} else {
+			aVelocityContext = new VelocityContext(Framework.getLanguageContexts().get(Property.get("DEFAULT_LANGUAGE")));
+		}
 	}
 
 	/*
@@ -55,11 +57,14 @@
 		SimpleOutputFormater.logger.debug("Map of String -> Object : "
 				+ mapOfStringObject + ".");
 		SimpleOutputFormater.logger.debug("Writer : " + aWriter + ".");
+		
 		for (final String sObjectName : mapOfStringObject.keySet()) {
 			aVelocityContext.put(sObjectName, mapOfStringObject
 					.get(sObjectName));
 		}
-		this.aTemplateOutput.merge(aVelocityContext, aWriter);
+		
+		Templates.write(sOutputFormat + ".vm", aVelocityContext, aWriter);
+		aWriter.close();
 	}
 
 	/*
@@ -75,7 +80,10 @@
 		SimpleOutputFormater.logger.debug("Error : " + aException.getMessage()
 				+ ".");
 		SimpleOutputFormater.logger.debug("Writer : " + aWriter + ".");
-		aVelocityContext.put("error", aException);
-		this.aTemplateError.merge(aVelocityContext, aWriter);
+		if (aException != null)
+			aVelocityContext.put("error", aException);
+		
+		Templates.write(sOutputFormat + ".error.vm", aVelocityContext, aWriter);
+		aWriter.close();
 	}
 }
Received on Monday, 24 August 2009 12:51:11 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:38 UTC