org.symbian.tools.wrttools/cssvalidator-removed-src/servlet/check.java
author John Kern <johnk@symbian.org>
Wed, 03 Feb 2010 08:22:09 -0800
changeset 91 ca4b5c63386b
parent 3 d3477de62514
permissions -rw-r--r--
provide win32 and macosx tarballs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     1
//
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     2
// $Id: check.java,v 1.14 2009-02-24 21:45:14 ylafon Exp $
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     3
// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     4
//
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     5
// (c) COPYRIGHT MIT and INRIA, 1997.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     6
// Please first read the full copyright statement in file COPYRIGHT.html
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     7
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     8
package org.w3c.css.servlet;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
     9
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    10
import java.io.IOException;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    11
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    12
import java.net.URLEncoder;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    13
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    14
import java.util.Enumeration;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    15
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    16
import javax.servlet.ServletConfig;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    17
import javax.servlet.ServletException;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    18
import javax.servlet.http.HttpServlet;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    19
import javax.servlet.http.HttpServletRequest;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    20
import javax.servlet.http.HttpServletResponse;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    21
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    22
/**
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    23
 * This class is a servlet to use the validator.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    24
 *
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    25
 * @version $Revision: 1.14 $
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    26
 */
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    27
public final class check extends HttpServlet {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    28
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    29
    private static String validatorURI = null;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    30
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    31
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    32
    /**
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    33
     * Performs the HTTP GET operation.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    34
     * It redirects to the value contained in "Referer"
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    35
     *
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    36
     * @param req encapsulates the request to the servlet.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    37
     * @param resp encapsulates the response from the servlet.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    38
     * @exception ServletException if the request could not be handled.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    39
     * @exception IOException if detected when handling the request.
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    40
     */
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    41
    public void doGet(HttpServletRequest req, HttpServletResponse res)
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    42
	throws ServletException, IOException
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    43
    {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    44
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    45
	String uri = req.getHeader("Referer");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    46
	String encodeEnc = req.getCharacterEncoding();
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    47
	if (encodeEnc == null) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    48
	    encodeEnc = "8859_1";
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    49
	}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    50
	uri = URLEncoder.encode(uri, encodeEnc);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    51
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    52
	if (uri == null) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    53
	    res.setContentType("text/plain");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    54
	    res.sendError(400, "Referer field empty");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    55
	    return;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    56
	}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    57
	res.setHeader("Cache-Control", "max-age=86400");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    58
	res.setHeader("Vary", "Referer");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    59
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    60
	Enumeration e = req.getParameterNames();
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    61
	StringBuilder sb = new StringBuilder(validatorURI);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    62
	boolean first = true;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    63
	boolean uridone = false;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    64
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    65
	if (e != null) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    66
	    while (e.hasMoreElements()) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    67
		String paramname = (String) e.nextElement();
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    68
		String paramvalue = req.getParameter(paramname);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    69
		if ("uri".equals(paramname)) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    70
		    uridone = true;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    71
		    paramvalue = uri;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    72
		}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    73
		if (first) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    74
		    sb.append('?');
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    75
		    first = false;
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    76
		} else {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    77
		    sb.append('&');
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    78
		}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    79
		sb.append(paramname);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    80
		if (paramvalue != null) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    81
		    sb.append('=');
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    82
		    sb.append(paramvalue);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    83
		}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    84
	    }
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    85
	}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    86
	if (!uridone) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    87
	    if (first) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    88
		sb.append("?uri=");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    89
	    } else {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    90
		sb.append("&uri=");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    91
	    }
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    92
	    sb.append(uri);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    93
	}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    94
	res.sendRedirect(sb.toString());
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    95
    }
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    96
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    97
    public void init(ServletConfig config) throws ServletException {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    98
	super.init(config);
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
    99
	if (config.getInitParameter("validatorURI") == null) {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
   100
	    validatorURI = "validator";
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
   101
	} else {
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
   102
	    validatorURI = config.getInitParameter("validatorURI");
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
   103
	}
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
   104
    }
d3477de62514 Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff changeset
   105
}