- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 22 Aug 2005 11:25:41 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/servlet In directory hutz:/tmp/cvs-serv9520 Modified Files: check.java Log Message: the "check" servlet moved to a bare version, with the righ referer and cache information. Note that it will pass the relevant information, so a reference to http://example.org/randompath/check?profile=css1 will send the request to the validator with the right profile information. Index: check.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/servlet/check.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- check.java 8 Aug 2005 13:19:34 -0000 1.5 +++ check.java 22 Aug 2005 11:25:38 -0000 1.6 @@ -4,40 +4,6 @@ // // (c) COPYRIGHT MIT and INRIA, 1997. // Please first read the full copyright statement in file COPYRIGHT.html -/* - * $Log$ - * Revision 1.5 2005/08/08 13:19:34 ylafon - * All those changed made by Jean-Guilhem Rouel: - * - * Huge patch, imports fixed (automatic) - * Bug fixed: 372, 920, 778, 287, 696, 764, 233 - * Partial bug fix for 289 - * - * Issue with "inherit" in CSS2. - * The validator now checks the number of values (extraneous values were previously ignored) - * - * Revision 1.4 2004/11/25 13:23:25 sijtsche - * HTML output escaped - * - * Revision 1.3 2002/05/19 04:12:37 plehegar - * Replaced the email address - * - * Revision 1.2 2002/04/08 21:18:10 plehegar - * New - * - * Revision 3.1 1997/08/29 13:23:27 plehegar - * Freeze - * - * Revision 2.2 1997/08/20 11:42:09 plehegar - * Freeze - * - * Revision 2.1 1997/08/11 08:05:17 plehegar - * Freeze - * - * Revision 1.1 1997/07/28 21:32:31 plehegar - * Initial revision - * - */ package org.w3c.css.servlet; @@ -47,6 +13,7 @@ import java.io.InputStream; import java.io.PrintWriter; import java.net.URL; +import java.util.Enumeration; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -71,308 +38,73 @@ */ public final class check extends HttpServlet { - private CssParser parser; - private URL htmlURL; - private boolean debug; - private boolean auralMode; - - /** - * Initializes the servlet and logs the initialization. The init - * method is called once, automatically, by the network service each - * time it loads the servlet. It is guaranteed to finish before any - * service requests are accepted. On fatal initialization errors, an - * UnavailableException should be thrown. Do not call the method - * System.exit. - * - * <p> The init method stores the ServletConfig object. Servlet - * writers who specialize this method should call either super.init, - * or store the ServletConfig object themselves. If an implementor - * decides to store the ServletConfig object in a different location, - * then the getServletConfig method must also be overridden. - * - * <P> - * <DL><STRONG>Init parameters:</STRONG> - * <DT>debug - * <DD><code>true</code> if you want to be in debug mode. - * <DT>aural - * <DD><code>true</code> if you want to be in aural mode. - * <DT>import - * <DD><code>false</code> if you don't want to activate the import statement. - * For security reasons, you shoud be careful when you lunch the servlet - * on a HTTP server with special access authorization. - * <DT>input - * <DD><code>html</code> if the user have an HTML input or <code>xml</code> - * otherwise. <strong>deprecated</strong> - * </DL> - * - * @param config servlet configuration information. - * @exception ServletException if a servlet exception has occurred. - */ - public void init(ServletConfig config) throws ServletException { - super.init(config); + private static String validatorURI = null; - // [SECURITY] don't forget this ! - Util.servlet = true; - - if (config.getInitParameter("debug") != null) { - // servlet debug mode - // define a boolean property CSS.StyleSheet.debug if you want more debug. - this.debug = config.getInitParameter("debug").equals("true"); - } - - parser = new StyleSheetParser(); - - if ((config.getInitParameter("import") != null) && - (config.getInitParameter("import").equals("false"))) { - Util.importSecurity = true; - } - - } - /** - * Performs the HTTP GET operation. An HTTP BAD_REQUEST error is - * reported if an error occurs. This servlet writers shouldn't set the - * headers for the requested entity (content type and encoding). - * - * <P> Note that the GET operation is expected to be <em>safe</em>, - * without any side effects for which users might be held responsible. - * For example, most form queries have no side effects. Requests - * intended to change stored data should use some other HTTP method. - * (There have been cases of significant security breaches reported - * because web-based applications used GET inappropriately.) - * - * <P> The GET operation is also expected to be <em>idempotent</em>, - * meaning that it can safely be repeated. This is not quite the same - * as being safe, but in some common examples the requirements have - * the same result. For example, repeating queries is both safe and - * idempotent (unless payment is required!), but buying something or - * modifying data is neither safe nor idempotent. - * - * <P> - * <DL><STRONG>Forms parameters:</STRONG> - * <DT>URL - * <DD>the URL to be parsed. - * <DT>submitURL - * <DD>if the user want to parse an URL. - * <DT>text - * <DD>The text to be parsed. - * <DT>submitTEXT - * <DD>if the user want to parse the text. - * <DT>output - * <DD>HTML if the user want an HTML output or XML otherwise. - * <DT>input - * <DD>HTML if the user have an HTML input or XML otherwise. - * </DL> + * Performs the HTTP GET operation. + * It redirects to the value contained in "Referer" * * @param req encapsulates the request to the servlet. * @param resp encapsulates the response from the servlet. * @exception ServletException if the request could not be handled. * @exception IOException if detected when handling the request. - * @see org.w3c.css.css.StyleSheetGenerator */ public void doGet(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { - int warningLevel = 2; - - String uri = null; - String warning = req.getParameter("warning"); - String output = req.getParameter("output"); - ApplContext ac = new ApplContext(req.getHeader("Accept-Language")); - InputStream in = req.getInputStream(); - - // Here is a little joke :-) - res.setHeader("Server", CssValidator.server_name); - - // I don't want cache for the response (inhibits proxy) - res.setHeader("Pragma", "no-cache"); // @@deprecated - res.setHeader("Cache-Control", "no-cache"); - - if (req.getParameter("debug") != null) { - Util.onDebug = req.getParameter("debug").equals("true"); - if (Util.onDebug) { - debug = true; - System.err.println("SWITCH DEBUG MODE REQUEST"); - } - } - - uri = req.getHeader("Referer"); - if (req.getPathInfo() == null) { - res.setHeader("Content-Length", "0"); - res.sendRedirect("http://" + req.getServerName() + ":" - + req.getServerPort() + - "/css-validator/"); - return; - } - if (!req.getPathInfo().equals("/referer")) { - res.setHeader("Content-Length", "0"); - res.sendRedirect("http://" + req.getServerName() + ":" - + req.getServerPort() + "/css-validator" - + req.getPathInfo()); - - //handleError(out, "No file", - // new IOException("You have send an invalid request.")); - return; - } - if (uri == null) { - res.setHeader("Content-Length", "0"); - res.sendRedirect("http://" + req.getServerName() + ":" - + req.getServerPort() + - "/css-validator/"); - return; - } - - uri = Util.suppressWhiteSpace(uri); - - if (output == null) { - output = CssValidator.texthtml; - } - - in.close(); - - PrintWriter out = new PrintWriter(res.getOutputStream()); - - // set the content-type for the response - // set the content-type for the response - if (ac.getContentType() != null) { - res.setContentType(ac.getContentType()); - } else if (output.equals(CssValidator.texthtml)) { - res.setContentType(CssValidator.texthtml); - } else { - res.setContentType(CssValidator.textplain); - } - if (ac.getContentLanguage() != null) { - res.setHeader("Content-Language", ac.getContentLanguage()); - } else { - res.setHeader("Content-Language", "en"); - } - if (ac.getContentEncoding() != null) { - res.setHeader("Content-Encoding", ac.getContentEncoding()); - } /* else { - res.setHeader("Content-Encoding", "identity"); - } */ - - // Here is a little joke :-) - res.setHeader("Server", CssValidator.server_name); - - // set the warning output - if (warning != null) { - if (warning.equals("no")) { - warningLevel = -1; - } else { - try { - warningLevel = Integer.parseInt(warning); - } catch (Exception e) { - System.err.println( e ); - } - } - } - - // debug mode - verbose("\nServlet request "); - verbose("Source file : " + uri ); - - // HTML document - try { - uri = HTTPURL.getURL(uri).toString(); - HTMLStyleSheetParser URLparser = new HTMLStyleSheetParser(ac, uri); - handleRequest(ac, out, uri, URLparser.getStyleSheet(), output, - warningLevel, true); + throws ServletException, IOException + { - } catch (Exception e) { - handleError(out, uri, e); - } finally { - out.close(); - } + String uri = req.getHeader("Referer"); - verbose("CssValidator: Request terminated.\n"); - } + if (uri == null) { + res.setContentType("text/plain"); + res.sendError(400, "Referer field empty"); + return; + } + res.setHeader("Cache-Control", "max-age=86400"); + res.setHeader("Vary", "Referer"); - public void doPost(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + Enumeration e = req.getParameterNames(); + StringBuffer sb = new StringBuffer(validatorURI); + boolean first = true; + boolean uridone = false; - handleError(new PrintWriter(res.getOutputStream()), "No file", - new IOException("You have send an invalid request.")); - } - - private void handleRequest(ApplContext ac, PrintWriter out, String title, - StyleSheet styleSheet, String output, - int warningLevel, boolean errorReport) - throws Exception { - if (styleSheet == null) { - throw new IOException("Can't process the file : " + title); + if (e != null) { + while (e.hasMoreElements()) { + String paramname = (String) e.nextElement(); + String paramvalue = req.getParameter(paramname); + if ("uri".equals(paramname)) { + uridone = true; + paramvalue = uri; + } + if (first) { + sb.append('?'); + first = false; + } else { + sb.append('&'); + } + sb.append(paramname); + if (paramvalue != null) { + sb.append('='); + sb.append(paramvalue); + } + } + } + if (!uridone) { + if (first) { + sb.append("?uri="); + } else { + sb.append("&uri="); + } + sb.append(uri); + } + res.sendRedirect(sb.toString()); } - - styleSheet.findConflicts(ac); - if ("text/xml".equals(ac.getInput()) - && "text/html".equals(output)) { - output = "xhtml"; - } else if ("text/html".equals(output)) { - output = "html"; - } - - StyleSheetGeneratorHTML2 style; - style = new StyleSheetGeneratorHTML2(ac, title, styleSheet, - output, warningLevel); - if (!errorReport) { - style.desactivateError(); - } - style.print(out); - } - - private void handleError(PrintWriter out, String title, Exception e) { - try { - URL localURL = CssValidator.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.println("<p>Line " + saxe.getLineNumber() + "</p>"); - } - if (saxe.getColumnNumber() != -1) { - out.println("<p>Column " + saxe.getColumnNumber() + "</p>"); - } - out.println("<p>" + 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>"); - - out.println("<hr />"); - out.println("<p><img src='images/mwcss.gif' alt='made with CSS' width='72' height='48' /></p>"); - out.println("<address><a href='Email.html'>www-validator-css</a></address>"); - out.println("</body></html>"); - out.flush(); - System.err.println("CSS Validator: request failed."); - e.printStackTrace(); - } - } catch (Exception unknown) { - out.println("org.w3c.css.servlet.CssValidator: couldn't load error file"); - out.flush(); - unknown.printStackTrace(); - } - } - - // trace function - private final void verbose(String s) { - if (debug) { - System.err.println( s ); - } + public void init(ServletConfig config) throws ServletException { + super.init(config); + if (config.getInitParameter("validatorURI") != null) { + validatorURI = "validator"; + } } - }
Received on Monday, 22 August 2005 11:25:53 UTC