Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: zetaben/opds-validator-web
base: bb0a42f8e1
...
head fork: zetaben/opds-validator-web
compare: 744cc98135
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
38 src/com/feedbooks/opds/webvalidator/OPDSValidatorWebServlet.java
@@ -1,16 +1,28 @@
package com.feedbooks.opds.webvalidator;
+import java.io.BufferedWriter;
import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URL;
+
import javax.servlet.http.*;
+
+import org.json.JSONString;
+
import com.feedbooks.opds.*;
+import com.google.appengine.api.urlfetch.HTTPMethod;
+import com.google.appengine.api.urlfetch.HTTPRequest;
+import com.google.appengine.api.urlfetch.HTTPResponse;
+import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
+import com.google.appengine.repackaged.org.json.JSONObject;
import com.thaiopensource.xml.sax.ErrorHandlerImpl;
+import static com.google.appengine.api.urlfetch.FetchOptions.Builder.*;
@SuppressWarnings("serial")
public class OPDSValidatorWebServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("application/json");
-
String uri = req.getParameter("uri");
if (uri != null && !uri.equals("") && uri.startsWith("http")) {
Validator v = new Validator();
@@ -20,16 +32,32 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp)
opds_version = ve;
}
v.SetOPDSVersion(opds_version);
- ErrorHandlerImpl eh = new JSONErrorHandlerImpl(resp
- .getOutputStream());
+ StringWriter validation_results=new StringWriter();
+ ErrorHandlerImpl eh = new JSONErrorHandlerImpl(validation_results);
v.SetErrorHandler(eh);
- boolean hadErr = v.validate(req.getParameterValues("uri"));
+
+ URL url=new URL(req.getParameter("uri"));
+ HTTPResponse get =URLFetchServiceFactory.getURLFetchService().fetch(new HTTPRequest(url, HTTPMethod.GET,followRedirects().setDeadline(60.0)));
+ String source=new String(get.getContent());
+ String[] args={source};
+ String[] names={url.toString()};
+ boolean hadErr = v.validate(args,names);
if (hadErr) {
resp.setStatus(409);
}
-
eh.close();
+ //resp.getOutputStream();
+ BufferedWriter w=new BufferedWriter(resp.getWriter());
+ w.append("{ \"results\": ");
+ w.append(validation_results.getBuffer());
+ w.append(", \"source\": ");
+ w.append(JSONObject.quote(source));
+ w.append("}");
+
+
+ w.close();
+
} else {
resp.setStatus(400);
}
View
10 war/css/main.css
@@ -113,4 +113,12 @@ li span.err_type img {
.msg {
font-weight: bold;
line-height: 130%;
-}
+}
+
+#source {
+ background-color:#FFF;
+ font-family: consolas,courrier,monospace;
+ padding:15px;
+
+}
+
View
83 war/index.html
@@ -1,11 +1,4 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
-<!-- above set at the top of the file will set -->
-<!-- the browser's rendering engine into -->
-<!-- "Quirks Mode". Replacing this declaration -->
-<!-- with a "Standards Mode" doctype is supported, -->
-<!-- but may lead to some differences in layout. -->
-
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
@@ -72,13 +65,17 @@
closeOptions();
function res_init(success){
- $("#results").empty().addClass((success ? "successful" : "failed" )).removeClass((!success ? "successful" : "failed" )).append("<h3>Validation "+(success ? "Successful" : "Failed" )+"</h3>")
+ $("#results").empty().addClass((success ? "successful" : "failed" )).removeClass((!success ? "successful" : "failed" ))
+ .append("<a style=\"float:right\" href=\"?uri="+$("#uri").val()+"\" title=\"Link to this validation\">Link</a>")
+ .append("<h3>Validation "+(success ? "Successful" : "Failed" )+"</h3>")
+
}
function validation_successful(errs){
//console.log("success");
res_init(true);
- if(errs.length > 0 ){
+
+ if(errs.results.length > 0 ){
$("#results h3").append(" with warnings");
render_validation_results(errs);
@@ -88,6 +85,7 @@
function validation_failed(req){
// console.log("failure");
+
res_init(false);
if(req.status==409){
var errs=$.parseJSON(req.responseText);
@@ -100,32 +98,51 @@
function render_validation_results(errs){
var resu=" <ol id=\"error_loop\"> "
- for(var i=0;i<errs.length;i++){
+ var errtab=[];
+ for(var i=0;i<errs.results.length;i++){
+ if(errs.results[i].severity){
var txt=""
- if(errs[i].severity=="error"){
+
+ if(errs.results[i].severity=="error"){
txt="<img src=\"img/error.png\" alt=\"Error\" title=\"Error\" />"
- }else if(errs[i].severity=="fatal"){
+ }else if(errs.results[i].severity=="fatal"){
txt="<img src=\"img/fatal.png\" alt=\"Fatal Error\" title=\"Fatal Error\" />"
- }if(errs[i].severity=="warning"){
+ }if(errs.results[i].severity=="warning"){
txt="<img src=\"img/warning.png\" alt=\"Warning\" title=\"Warning\" />"
- }if(errs[i].severity=="info"){
+ }if(errs.results[i].severity=="info"){
txt="<img src=\"img/info.png\" alt=\"Information\" title=\"Information\" />"
}
txt="<span class=\"err_type\">"+txt+"</span>"
txt+="<em>"
- if(errs[i].line > 0 ){
- txt+="Line "+errs[i].line
- if(errs[i].column > 0){txt+=", "}
+ if(errs.results[i].line > 0 ){
+ txt+="<a href=\"#line"+errs.results[i].line+"\">"
+ txt+="Line "+errs.results[i].line
+ txt+="</a>"
+ errtab[errs.results[i].line]=errs.results[i].severity;
+ if(errs.results[i].column > 0){txt+=", "}
}
- if(errs[i].column > 0){
- txt+="Column "+errs[i].column
+ if(errs.results[i].column > 0){
+ txt+="Column "+errs.results[i].column
}
- txt+="</em> \n<span class=\"msg\">"+errs[i].message+"</span>"
+ txt+="</em> \n<span class=\"msg\">"+errs.results[i].message+"</span>"
+ resu+="<li class=\"msg_err sev"+errs.results[i].severity+"\">"+txt+"</li>"
+ }else{
+ resu+="<li class=\"msg_err sevfatal\"><img src=\"img/fatal.png\" alt=\"Fatal Error\" title=\"Fatal Error\" /><em>Fatal</em>\n<span class=\"msg\">"+errs.results[i]+"</span></li>"
+ }
+ }
+ resu+="</ol>"
+
+ resu+="<h3>Source</h3> <div id=\"source\"> <ol>"
+ var lines=errs.source.split("\n");
- resu+="<li class=\"msg_err sev"+errs[i].severity+"\">"+txt+"</li>"
+ for(var i=0;i<lines.length;i++){
+ resu+="<li id=\"line"+(i+1)+"\" "+(errtab[i+1] ? "class=\"sev"+errtab[i+1]+"\"" : "")+">"+lines[i].replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;")+"</li>"
}
- $("#results").append(resu+"</ol>")
+
+
+
+ $("#results").append(resu+"</ol></div>")
}
function form_submitted(){
@@ -133,6 +150,9 @@
$("#results").hide();
$("#uri_input").addClass("loading");
$.getJSON($("#validation_form")[0].action,{uri:$("#uri").val(),opds_version:$("#opds_version").val()},validation_successful).error(validation_failed).complete(function(){$("#uri_input").removeClass("loading");})
+ if(history.pushState){
+ history.pushState({uri:$("#uri").val()},$("#uri").val(),"?uri="+$("#uri").val());
+ }
return false;
}
@@ -141,6 +161,25 @@
$("#validation_form").submit(form_submitted)
+var urlParams = {};
+(function () {
+ var e,
+ a = /\+/g, // Regex for replacing addition symbol with a space
+ r = /([^&=]+)=?([^&]*)/g,
+ d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
+ q = window.location.search.substring(1);
+
+ while (e = r.exec(q))
+ urlParams[d(e[1])] = d(e[2]);
+})();
+
+$(function() {
+ if("uri" in urlParams){
+ $("#uri").val(urlParams["uri"])
+ $("#validation_form").submit();
+ }
+})
+
//]]>
</script>
</body>

No commit comments for this range

Something went wrong with that request. Please try again.