- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 22 Jul 2005 09:45:03 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/error In directory hutz:/tmp/cvs-serv22850 Added Files: ErrorReport.java ErrorReportFactory.java ErrorReportHTML.java ErrorReportSOAP12.java error.html soaperror.properties Log Message: Error Handling (Jean-Guilhem Rouel) --- NEW FILE: ErrorReport.java --- // $Id: ErrorReport.java,v 1.1 2005/07/22 09:45:01 ylafon Exp $ // Author: Jean-Guilhem Rouel // (c) COPYRIGHT MIT, ERCIM and Keio, 2003. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.error; import java.io.PrintWriter; /** * ErrorReport<br /> * Created: Jul 13, 2005 2:05:41 PM<br /> */ public abstract class ErrorReport { abstract public void print(PrintWriter out); } --- NEW FILE: ErrorReportSOAP12.java --- // $Id: ErrorReportSOAP12.java,v 1.1 2005/07/22 09:45:01 ylafon Exp $ // Author: Jean-Guilhem Rouel // (c) COPYRIGHT MIT, ERCIM and Keio, 2003. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.error; import java.io.PrintWriter; import java.net.URL; import java.net.UnknownHostException; import org.w3c.css.util.ApplContext; import org.w3c.css.util.Utf8Properties; /** * ErrorReportSOAP12<br /> * Created: Jul 13, 2005 2:06:00 PM<br /> * This class allows to create 2 different soap messages to handle errors: * <ul> * <li>Sender errors if the URI given in parameter of the servlet is invalid</li> * <li>Receiver errors if the URI given is valid but inreachable</li> * </ul> */ public class ErrorReportSOAP12 extends ErrorReport { private String title; private boolean validURI; private Exception exception; private ApplContext ac; private static Utf8Properties messages; private PrintWriter out; ErrorReportSOAP12(ApplContext ac, String title, String output, Exception e, boolean validURI) { this.ac = ac; this.exception = e; this.validURI = validURI; this.title = title; } /** * @see org.w3c.css.error.ErrorReport#print(java.io.PrintWriter) */ public void print(PrintWriter out) { this.out = out; // the error message String errorMessage = exception.getMessage(); // the string containing the soap response pattern String report; if(validURI) { report = messages.getProperty("receiver"); if(exception instanceof UnknownHostException) { errorMessage = "The host name " + errorMessage + " couldn't be resolved"; } } else { report = messages.getProperty("sender"); } processError(report, errorMessage , title + " " + exception); } /** * Prints on the output the soap message str, where each entity<br/> * has been replaced by it's value<br/> * An entity is an xml comment (<!-- -->) containing a single word * beginning by #<br/> * Valid entities names are: * <ul> * <li><i>charset</i>: prints the charset defined in the Applcontext</li> * <li><i>reason</i>: prints the reason of the error</li> * <li><i>details</i>: prints the detailed reason of the error</li> * </ul> * @param str the soap message pattern * @param errorMessage the error message (see reason entity) * @param details the detailed message error (see details entity) */ private void processError(String str, String errorMessage, String details) { try { int i = 0; while ((i = str.indexOf("<!-- #", i)) >= 0) { int lastIndexOfEntity = str.indexOf("-->", i); String entity = str.substring(i + 6, lastIndexOfEntity - 1) .toLowerCase(); // reason entity if (entity.equals("reason")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; out.print(errorMessage); } // details entity else if (entity.equals("details")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; out.print(details); } //charset entity else if (entity.equals("charset")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; out.print(ac.getContentEncoding()); } else { i += 6; // skip this unknown entity } } // print the end of the string if(str != null) { out.print(str); } } catch (Exception e) { e.printStackTrace(); if(str != null) { out.print(str); } } } static { // load the soaperror.properties URL url; messages = new Utf8Properties(); try { url = ErrorReportSOAP12.class.getResource("soaperror.properties"); java.io.InputStream f = url.openStream(); messages.load(f); f.close(); } catch (Exception e) { System.err.println("org.w3c.css.error.ErrorReportSOAP12: " + "couldn't load soap error messages properties "); System.err.println(" " + e.toString()); } } } --- NEW FILE: ErrorReportHTML.java --- // $Id: ErrorReportHTML.java,v 1.1 2005/07/22 09:45:01 ylafon Exp $ // Author: Jean-Guilhem Rouel // (c) COPYRIGHT MIT, ERCIM and Keio, 2003. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.error; import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.io.PrintWriter; import java.net.URL; import org.w3c.css.servlet.CssValidator; import org.w3c.css.util.ApplContext; import org.w3c.css.util.Util; import org.xml.sax.SAXParseException; /** * ErrorReportHTML<br /> * Created: Jul 13, 2005 2:05:51 PM<br /> * This class is used to create an (x)html page when a URI error is thrown by the servlet */ public class ErrorReportHTML extends ErrorReport { //ApplContext ac; String title; Exception e; ErrorReportHTML(ApplContext ac, String title, String output, Exception e) { // ac is not used for now, but may be useful //this.ac = ac; this.title = title; this.e = e; } /** * @see org.w3c.css.error.ErrorReport#print(java.io.PrintWriter) */ public void print(PrintWriter out) { try { URL localURL = ErrorReportHTML.class.getResource("error.html"); DataInputStream in = new DataInputStream(localURL.openStream()); try { while (true) { out.print((char) in.readUnsignedByte()); } } catch (EOFException eof) { out.println("<h2>Target: " + Util.escapeHTML(title) + "</h2>"); out.println("<div class=\"error\">"); if (e instanceof IOException) { out.println("<p>I/O Error: "); out.println(Util.escapeHTML(e.getMessage())); } else if (e instanceof SAXParseException) { SAXParseException saxe = (SAXParseException) e; out.println("<p>Please, validate your XML document" + " first!</p>"); if (saxe.getLineNumber() != -1) { out.print("<p>Line "); out.print(saxe.getLineNumber()); out.println("</p>"); } if (saxe.getColumnNumber() != -1) { out.print("<p>Column "); out.print(saxe.getColumnNumber()); out.print("</p>\n"); } out.println("<p>" + Util.escapeHTML(e.getMessage())); } else if (e instanceof NullPointerException) { out.println("<p>Oups! Internal error!</p><p>"); e.printStackTrace(); } else { out.println(e.toString()); } out.println("</p></div>\n<hr />\n<p><img src='images/mwc" + "ss.gif' alt='made with CSS' /></p>\n<addres" + "s><a href='Email.html'>www-validator-css</a" + "></address>\n</body></html>"); out.flush(); /* * System.err.println("CSS Validator: request failed."); * e.printStackTrace(); */ } } catch (Exception unknown) { if (out != null) { out.println("org.w3c.css.servlet.CssValidator: couldn't " + "load error file"); out.flush(); } unknown.printStackTrace(); } finally { if (out != null) { out.close(); } } } } --- NEW FILE: soaperror.properties --- sender:\ <?xml version='1.0' encoding="<!-- #charset -->"?>\n\ <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"\n\ xmlns:m='http://www.w3.org/2005/07/css-validator'>\n\ <env:Body>\n\ <env:Fault>\n\ <env:Code>\n\ <env:Value>env:Sender</env:Value>\n\ <env:Subcode>\n\ <env:Value>m:Exception</env:Value>\n\ </env:Subcode>\n\ </env:Code>\n\ <env:Reason>\n\ <env:Text xml:lang="en-US"><!-- #reason --></env:Text>\n\ </env:Reason>\n\ <env:Detail>\n\ <m:errordetail xml:lang="en-US">\n\ Target: <!-- #details -->\n\ </m:errordetail>\n\ </env:Detail>\n\ </env:Fault>\n\ </env:Body>\n\ </env:Envelope> receiver:\ <?xml version='1.0' encoding="<!-- #charset -->"?>\n\ <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"\n\ xmlns:m='http://www.w3.org/2005/07/css-validator'>\n\ <env:Body>\n\ <env:Fault>\n\ <env:Code>\n\ <env:Value>env:Receiver</env:Value>\n\ <env:Subcode>\n\ <env:Value>m:IOError</env:Value>\n\ </env:Subcode>\n\ </env:Code>\n\ <env:Reason>\n\ <env:Text xml:lang="en-US"><!-- #reason --></env:Text>\n\ </env:Reason>\n\ <env:Detail>\n\ <m:errordetail xml:lang="en-US">\n\ Details: "<!-- #details -->"\n\ </m:errordetail>\n\ </env:Detail>\n\ </env:Fault>\n\ </env:Body>\n\ </env:Envelope> --- NEW FILE: ErrorReportFactory.java --- // $Id: ErrorReportFactory.java,v 1.1 2005/07/22 09:45:01 ylafon Exp $ // Author: Jean-Guilhem Rouel // (c) COPYRIGHT MIT, ERCIM and Keio, 2003. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.error; import org.w3c.css.util.ApplContext; /** * ErrorReportFactory<br /> * Created: Jul 13, 2005 2:00:54 PM<br /> */ public class ErrorReportFactory { /** * Give back an "ErrorReport" object based on various parameters, but mainly * output" */ public static ErrorReport getErrorReport(ApplContext ac, String title, String output, Exception e, boolean validURI) { if ((output == null) || (output.equals("html")) || (output.equals("xhtml"))) { return new ErrorReportHTML(ac, title, output, e); } if (output.equals("soap12")) { return new ErrorReportSOAP12(ac, title, output, e, validURI); } return new ErrorReportHTML(ac, title, output, e); } } --- NEW FILE: error.html --- <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'> <head> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> <title>CSS Validator : Error</title> <link type="text/css" rel='stylesheet' href='http://jigsaw.w3.org/css-validator/style/error.css' /> </head> <body> <div> <a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="w3c" /></a> </div> <hr /> <div class="t1">CSS</div> <div class="t2">Validator</div> <div class="t3">Error</div>
Received on Friday, 22 July 2005 09:45:08 UTC