Skip to content

Commit 96cd7ab

Browse files
committed
make it easier to add/modify parameters
1 parent 7a09842 commit 96cd7ab

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

org/w3c/css/servlet/CssValidator.java

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,24 @@
5151
public final class CssValidator extends HttpServlet {
5252

5353
final static String texthtml = "text/html";
54-
5554
final static String applxhtml = "application/xhtml+xml";
56-
5755
final static String textplain = "text/plain";
58-
5956
final static String textcss = "text/css";
60-
6157
final static String textunknwon = "text/unknown";
62-
6358
final static String soap12 = "application/soap+xml";
64-
6559
final static String json = "application/json";
6660

61+
final static String opt_file = "file";
62+
final static String opt_text = "text";
63+
final static String opt_lang = "lang";
64+
final static String opt_output = "output";
65+
final static String opt_warning = "warning";
66+
final static String opt_error = "error";
67+
final static String opt_profile = "profile";
68+
final static String opt_usermedium = "usermedium";
69+
final static String opt_vextwarning = "vextwarning";
70+
final static String opt_type = "type";
71+
6772
public final static String server_name =
6873
"Jigsaw/2.3.0 W3C_CSS_Validator_JFouffa/2.0 (See <http://validator.w3.org/services>)";
6974

@@ -231,7 +236,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
231236

232237
String lang = null;
233238
try {
234-
lang = req.getParameter("lang");
239+
lang = req.getParameter(opt_lang);
235240
} catch (Exception e) {
236241
lang = null;
237242
}
@@ -244,7 +249,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
244249
ApplContext ac = new ApplContext(lang);
245250
ac.setLink(req.getQueryString());
246251
ac.setContentEncoding(req.getHeader("Accept-Charset"));
247-
String output = req.getParameter("output");
252+
String output = req.getParameter(opt_output);
248253

249254
String uri = null;
250255
try {
@@ -257,7 +262,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
257262
}
258263
String text = null;
259264
try {
260-
text = req.getParameter("text");
265+
text = req.getParameter(opt_text);
261266
} catch (Exception ex) {
262267
// pb in URI decoding (bad escaping, most probably)
263268
// not sure it will work here, as it may be catched by the first
@@ -266,11 +271,11 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
266271
"Invalid escape sequence in URI"), false);
267272
}
268273

269-
String warning = req.getParameter("warning");
270-
String error = req.getParameter("error");
271-
String profile = req.getParameter("profile");
272-
String usermedium = req.getParameter("usermedium");
273-
String type = req.getParameter("type");
274+
String warning = req.getParameter(opt_warning);
275+
String error = req.getParameter(opt_error);
276+
String profile = req.getParameter(opt_profile);
277+
String usermedium = req.getParameter(opt_usermedium);
278+
String type = req.getParameter(opt_type);
274279

275280
InputStream in = req.getInputStream();
276281

@@ -347,7 +352,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
347352
}
348353

349354
// Allow vendor extensions to just show up as warnings.
350-
processVendorExtensionParameter(req.getParameter("vextwarning"), ac);
355+
processVendorExtensionParameter(req.getParameter(opt_vextwarning), ac);
351356

352357
// debug mode
353358
Util.verbose("\nServlet request ");
@@ -554,37 +559,36 @@ public void doPost(HttpServletRequest req, HttpServletResponse res)
554559
try {
555560
buf = new byte[count];
556561
System.arraycopy(general, 0, buf, 0, count);
557-
NVPair[] tmp = Codecs.mpFormDataDecode(buf, req.getContentType());
558-
for (NVPair pair : tmp) {
562+
for (NVPair pair : Codecs.mpFormDataDecode(buf, req.getContentType())) {
559563
switch (pair.getName()) {
560-
case "file":
564+
case opt_file:
561565
file = (FakeFile) pair.getValue();
562566
break;
563-
case "text":
567+
case opt_text:
564568
text = (String) pair.getValue();
565569
break;
566-
case "lang":
570+
case opt_lang:
567571
lang = (String) pair.getValue();
568572
break;
569-
case "output":
573+
case opt_output:
570574
output = (String) pair.getValue();
571575
break;
572-
case "warning":
576+
case opt_warning:
573577
warning = (String) pair.getValue();
574578
break;
575-
case "error":
579+
case opt_error:
576580
error = (String) pair.getValue();
577581
break;
578-
case "profile":
582+
case opt_profile:
579583
profile = (String) pair.getValue();
580584
break;
581-
case "usermedium":
585+
case opt_usermedium:
582586
usermedium = (String) pair.getValue();
583587
break;
584-
case "vextwarning":
588+
case opt_vextwarning:
585589
vendorExtensionAsWarnings = (String) pair.getValue();
586590
break;
587-
case "type":
591+
case opt_type:
588592
inputType = (String) pair.getValue();
589593
break;
590594
default:
@@ -736,24 +740,30 @@ private void handleRequest(ApplContext ac, HttpServletResponse res,
736740
throw new IOException(ac.getMsg().getServletString("process") + " "
737741
+ title);
738742
}
743+
String outformat;
739744

740745
// if the output parameter was a mime type, we convert it
741746
// to an understandable value for the StyleReportFactory
742-
if ("text/xml".equals(ac.getInput()) && texthtml.equals(output)) {
743-
output = "xhtml";
744-
} else if (texthtml.equals(output)) {
745-
output = "html";
746-
} else if (soap12.equals(output)) {
747-
output = "soap12";
748-
} else if (json.equals(output)) {
749-
output = "json";
750-
} else if (textplain.equals(output)) {
751-
output = "text";
747+
switch (output) {
748+
case texthtml:
749+
outformat = ("text/xml".equals(ac.getInput())) ? "xhtml" : "html";
750+
break;
751+
case soap12:
752+
outformat = soap12;
753+
break;
754+
case json:
755+
outformat = "json";
756+
break;
757+
case textplain:
758+
outformat = "text";
759+
break;
760+
default:
761+
outformat = output;
752762
}
753763
styleSheet.findConflicts(ac);
754764

755765
StyleReport style = StyleReportFactory.getStyleReport(ac, title,
756-
styleSheet, output, warningLevel);
766+
styleSheet, outformat, warningLevel);
757767
if (!errorReport) {
758768
style.desactivateError();
759769
}

0 commit comments

Comments
 (0)