- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 28 Jul 2009 10:36:33 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/output
In directory hutz:/tmp/cvs-serv26546/org/w3c/unicorn/output
Modified Files:
SimpleOutputFormater.java XMLOutputFormater.java
Log Message:
Internationalisation
Index: XMLOutputFormater.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/output/XMLOutputFormater.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- XMLOutputFormater.java 24 Jul 2009 13:47:46 -0000 1.5
+++ XMLOutputFormater.java 28 Jul 2009 10:36:31 -0000 1.6
@@ -4,6 +4,7 @@
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.output;
+import java.io.File;
import java.io.Writer;
import java.net.URL;
import java.util.Map;
@@ -18,6 +19,8 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.unicorn.util.ListFiles;
+import org.w3c.unicorn.util.MergeProperties;
import org.w3c.unicorn.util.Property;
/**
@@ -51,6 +54,8 @@
* Apache velocity engine for the error
*/
private static VelocityEngine aVelocityEngineError = new VelocityEngine();
+
+ private static VelocityContext aVelocityContext = new VelocityContext();
/**
* Write the result of the XML in a file
@@ -68,9 +73,24 @@
+ ".");
XMLOutputFormater.logger.debug("Output language : " + sLang + ".");
}
- String sFileName;
- sFileName = sLang + "_" + sOutputFormat
- + Property.get("TEMPLATE_FILE_EXTENSION");
+
+ // Template file for this output
+ String sFileName = sOutputFormat + Property.get("TEMPLATE_FILE_EXTENSION");
+
+ // Language file for this output
+ File langFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") +
+ sOutputFormat + "." + sLang + ".properties");
+
+ // Default language file
+ File defaultLangFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") +
+ sOutputFormat + "." + Property.get("DEFAULT_LANGUAGE") + ".properties");
+
+ // Merge the properties
+ Properties props = MergeProperties.getMergeProperties(defaultLangFile, langFile);
+
+ // Load in velocity context
+ MergeProperties.loadInVelocityContext(props, aVelocityContext);
+
// check if sFileName exist
try {
this.aTemplateOutput = XMLOutputFormater.aVelocityEngineOutput
@@ -85,6 +105,8 @@
this.aTemplateOutput = XMLOutputFormater.aVelocityEngineOutput
.getTemplate(sFileName);
}
+ sFileName = sOutputFormat + ".error" + Property.get("TEMPLATE_FILE_EXTENSION");
+
try {
this.aTemplateError = XMLOutputFormater.aVelocityEngineError
.getTemplate(sFileName);
@@ -116,7 +138,6 @@
XMLOutputFormater.logger.debug("Writer : " + aWriter + ".");
}
- final VelocityContext aVelocityContext = new VelocityContext();
final EventCartridge aEventCartridge = new EventCartridge();
aEventCartridge.addEventHandler(new XHTMLize());
// aEventCartridge.addEventHandler(new EscapeXMLEntities());
@@ -143,7 +164,6 @@
XMLOutputFormater.logger.debug("Error : " + aException + ".");
XMLOutputFormater.logger.debug("Writer : " + aWriter + ".");
}
- final VelocityContext aVelocityContext = new VelocityContext();
final EventCartridge aEventCartridge = new EventCartridge();
aEventCartridge.addEventHandler(new EscapeXMLEntities());
aEventCartridge.attachToContext(aVelocityContext);
@@ -155,19 +175,18 @@
static {
try {
final Properties aProperties = new Properties();
- //aProperties.load(new URL("file:"
- // + Property.get("VELOCITY_CONFIG_FILE")).openStream());
aProperties.load(new URL(Property.class.getResource("/"),
Property.get("REL_PATH_TO_CONF_FILES") + "velocity.properties").openStream());
aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
- .get("PATH_TO_OUTPUT_TEMPLATES"));
+ .get("PATH_TO_TEMPLATES"));
+
XMLOutputFormater.aVelocityEngineOutput.init(aProperties);
XMLOutputFormater.logger.debug("OutputEngine "
+ Velocity.FILE_RESOURCE_LOADER_PATH);
aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
- .get("PATH_TO_OUTPUT_ERROR_TEMPLATES"));
+ .get("PATH_TO_TEMPLATES"));
XMLOutputFormater.aVelocityEngineError.init(aProperties);
} catch (final Exception e) {
XMLOutputFormater.logger.error("Exception : " + e.getMessage(), e);
Index: SimpleOutputFormater.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/output/SimpleOutputFormater.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- SimpleOutputFormater.java 24 Jul 2009 13:47:46 -0000 1.4
+++ SimpleOutputFormater.java 28 Jul 2009 10:36:31 -0000 1.5
@@ -4,6 +4,7 @@
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.output;
+import java.io.File;
import java.io.Writer;
import java.net.URL;
import java.util.Map;
@@ -17,6 +18,7 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.unicorn.util.MergeProperties;
import org.w3c.unicorn.util.Property;
/**
@@ -35,6 +37,8 @@
private static VelocityEngine aVelocityEngineOutput = new VelocityEngine();
private static VelocityEngine aVelocityEngineError = new VelocityEngine();
+
+ private static VelocityContext aVelocityContext = new VelocityContext();
public SimpleOutputFormater(final String sOutputFormat, final String sLang)
throws ResourceNotFoundException, ParseErrorException, Exception {
@@ -45,9 +49,23 @@
SimpleOutputFormater.logger.debug("Output language : " + sLang
+ ".");
}
- final String sFileName;
- sFileName = sLang + "_" + sOutputFormat
- + Property.get("TEMPLATE_FILE_EXTENSION");
+
+ String sFileName = sOutputFormat + Property.get("TEMPLATE_FILE_EXTENSION");
+
+ // Language file for this output
+ File langFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") +
+ sOutputFormat + "." + sLang + ".properties");
+
+ // Default language file
+ File defaultLangFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") +
+ sOutputFormat + "." + Property.get("DEFAULT_LANGUAGE") + ".properties");
+
+ // Merge the properties
+ Properties props = MergeProperties.getMergeProperties(defaultLangFile, langFile);
+
+ // Load in velocity context
+ MergeProperties.loadInVelocityContext(props, aVelocityContext);
+
this.aTemplateOutput = SimpleOutputFormater.aVelocityEngineOutput
.getTemplate(sFileName,"UTF-8");
this.aTemplateError = SimpleOutputFormater.aVelocityEngineError
@@ -69,7 +87,6 @@
+ mapOfStringObject + ".");
SimpleOutputFormater.logger.debug("Writer : " + aWriter + ".");
}
- final VelocityContext aVelocityContext = new VelocityContext();
for (final String sObjectName : mapOfStringObject.keySet()) {
aVelocityContext.put(sObjectName, mapOfStringObject
.get(sObjectName));
@@ -92,7 +109,6 @@
+ aException.getMessage() + ".");
SimpleOutputFormater.logger.debug("Writer : " + aWriter + ".");
}
- final VelocityContext aVelocityContext = new VelocityContext();
aVelocityContext.put("error", aException);
this.aTemplateError.merge(aVelocityContext, aWriter);
}
@@ -100,19 +116,17 @@
static {
try {
final Properties aProperties = new Properties();
- //aProperties.load(new URL("file:"
- // + Property.get("VELOCITY_CONFIG_FILE")).openStream());
aProperties.load(new URL(Property.class.getResource("/"),
Property.get("REL_PATH_TO_CONF_FILES") + "velocity.properties").openStream());
aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
- .get("PATH_TO_OUTPUT_TEMPLATES"));
+ .get("PATH_TO_TEMPLATES"));
SimpleOutputFormater.aVelocityEngineOutput.init(aProperties);
SimpleOutputFormater.logger.debug("OutputEngine "
+ Velocity.FILE_RESOURCE_LOADER_PATH);
aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
- .get("PATH_TO_OUTPUT_ERROR_TEMPLATES"));
+ .get("PATH_TO_TEMPLATES"));
SimpleOutputFormater.aVelocityEngineError.init(aProperties);
} catch (final Exception e) {
SimpleOutputFormater.logger.error("Exception : " + e.getMessage(),
Received on Tuesday, 28 July 2009 10:36:48 UTC