- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 29 Jul 2009 09:18:26 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn In directory hutz:/tmp/cvs-serv1802/org/w3c/unicorn Modified Files: UnicornCall.java Log Message: Internationalized IO errors Refactoring of template related functions in TemplateHelper class Index: UnicornCall.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/UnicornCall.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- UnicornCall.java 28 Jul 2009 10:56:56 -0000 1.24 +++ UnicornCall.java 29 Jul 2009 09:18:24 -0000 1.25 @@ -4,8 +4,11 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.net.URL; @@ -14,6 +17,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import javax.activation.MimeType; @@ -26,6 +30,10 @@ import org.apache.commons.fileupload.FileItem; import org.apache.commons.logging.Log; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.app.VelocityEngine; import org.w3c.dom.Document; @@ -36,6 +44,7 @@ import org.w3c.unicorn.exceptions.EmptyDocumentException; import org.w3c.unicorn.exceptions.NoDocumentException; import org.w3c.unicorn.exceptions.NoMimeTypeException; +import org.w3c.unicorn.index.IndexGenerator; import org.w3c.unicorn.input.InputFactory; import org.w3c.unicorn.request.Request; import org.w3c.unicorn.request.RequestList; @@ -50,6 +59,7 @@ import org.w3c.unicorn.tasklisttree.TLTExec; import org.w3c.unicorn.tasklisttree.TLTIf; import org.w3c.unicorn.tasklisttree.TLTNode; +import org.w3c.unicorn.util.TemplateHelper; import org.w3c.unicorn.util.Property; import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl; @@ -842,25 +852,28 @@ this.unicornCall.incCounter(); Response aResponse = null; try { + // Uncomment/comment next lines to test io_error + //throw new Exception(); aResponse = this.aRequest.doRequest(); } catch (final Exception e) { RequestThread.logger.error("Exception : " + e.getMessage(), e); e.printStackTrace(); try { - StringBuilder builder = new StringBuilder(); - // TODO should be first processed as a template - InputStreamReader isr = new InputStreamReader(new URL("file:" - + Property.get("PATH_TO_ERROR_TEMPLATES") - + "en_io_error.vm").openConnection().getInputStream()); - char[] chararray = new char[8192]; - int readLength = 0; - while((readLength = isr.read(chararray, 0, 8192)) > -1) { - builder.append(chararray, 0, readLength); - } - - aResponse = ResponseParserFactory.parse(builder.toString(), - this.aRequest.getResponseType()); - aResponse.setXml(builder); + StringBuilder builder = new StringBuilder(); + String lang = unicornCall.getMapOfStringParameter().get("ucn_lang")[0]; + + // generateFileFromTemplate generates the error xml file if it doesn't exist already + String filePath = TemplateHelper.generateFileFromTemplate("io_error", lang, Property.get("PATH_TO_INDEX_OUTPUT"), "xml"); + + InputStreamReader isr = new InputStreamReader(new URL("file:" + filePath).openConnection().getInputStream()); + + char[] chararray = new char[8192]; + int readLength = 0; + while((readLength = isr.read(chararray, 0, 8192)) > -1) { + builder.append(chararray, 0, readLength); + } + aResponse = ResponseParserFactory.parse(builder.toString(), this.aRequest.getResponseType()); + aResponse.setXml(builder); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) {
Received on Wednesday, 29 July 2009 09:18:36 UTC