Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Validate by File Upload

  • Loading branch information...
commit a8e2bdb8f0967377a5146595d4ab66c025dca78b 1 parent 0c376d5
@zetaben authored
View
67 src/com/feedbooks/opds/webvalidator/OPDSValidatorWebServlet.java
@@ -2,11 +2,18 @@
import java.io.BufferedWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringWriter;
import java.net.URL;
+import java.util.logging.Logger;
+import javax.servlet.ServletException;
import javax.servlet.http.*;
+import org.apache.commons.fileupload.FileItemIterator;
+import org.apache.commons.fileupload.FileItemStream;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.fileupload.util.Streams;
import org.apache.tools.ant.taskdefs.Sleep;
import org.json.JSONString;
@@ -80,20 +87,62 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp)
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws IOException {
+ throws IOException, ServletException {
resp.setContentType("application/json");
- String feed = req.getParameter("feed");
- if (feed != null && !feed.equals("")) {
- String opds_version = "1.0";
- String ve = req.getParameter("opds_version");
- if (ve != null && !ve.equals("")) {
- opds_version = ve;
+
+ // Logger log =
+ // Logger.getLogger(OPDSValidatorWebServlet.class.getName());
+
+ if (req.getHeader("content-type").startsWith("multipart/")) {
+
+ String opds_version = null;
+ String content = null;
+ String filename = null;
+ try {
+ ServletFileUpload upload = new ServletFileUpload();
+
+ FileItemIterator iterator = upload.getItemIterator(req);
+ while (iterator.hasNext()
+ && (opds_version == null || content == null)) {
+ FileItemStream item = iterator.next();
+ InputStream stream = item.openStream();
+
+ if (item.isFormField()) {
+ if (item.getFieldName().equals("opds_version")) {
+ opds_version = Streams.asString(stream);
+ }
+
+ } else {
+ content = Streams.asString(stream);
+ filename = item.getName();
+ }
+ }
+ } catch (Exception ex) {
+ throw new ServletException(ex);
}
- handleValidation(req, resp, feed, "direct", opds_version);
+ if (content != null && !content.equals("")) {
+ handleValidation(req, resp, content, filename, opds_version);
+
+ } else {
+ resp.setStatus(400);
+ }
} else {
- resp.setStatus(400);
+
+ String feed = req.getParameter("feed");
+ if (feed != null && !feed.equals("")) {
+ String opds_version = "1.0";
+ String ve = req.getParameter("opds_version");
+ if (ve != null && !ve.equals("")) {
+ opds_version = ve;
+ }
+
+ handleValidation(req, resp, feed, "direct://", opds_version);
+
+ } else {
+ resp.setStatus(400);
+ }
}
}
}
View
22 war/css/main.css
@@ -32,7 +32,7 @@ form {
font-size: 1.4em;
}
-#uri_input {
+#uri_input,#file_input {
border: 1px solid #BBB;
padding:0.2em;
@@ -73,6 +73,24 @@ form {
#loader_feed{float:right;}
+
+#file_input img {
+ display:none;
+ width: 1.4em;
+ height: 1.4em;
+}
+
+#file_input {padding-right:1.6em}
+#file_input.loading {padding-right:0.2em}
+
+#file_input.loading img {
+ display:inline;
+}
+
+#loader_file {
+ vertical-align: top;
+}
+
#uri {
border: none;
}
@@ -129,7 +147,7 @@ li span.err_type img {
#source {
background-color:#FFF;
- font-family: consolas,courrier,monospace;
+ font-family: consolas,monaco,courrier,monospace;
padding:15px;
}
View
64 war/index.html
@@ -18,8 +18,9 @@
<h2>Unofficial Validator</h2>
</div>
<ul id="tabs">
- <li><a href="#validate-by-uri">Validate By URI</a></li>
- <li><a href="#validate-by-direct">Validate By direct input</a></li>
+ <li><a href="#validate-by-uri">Validate by URI</a></li>
+ <li><a href="#validate-by-direct">Validate by Direct Input</a></li>
+ <li><a href="#validate-by-upload">Validate by File Upload</a></li>
</ul>
<fieldset id="validate-by-uri" class="tabset_content front"><legend class="tabset_label">Validate by URI</legend>
@@ -69,16 +70,41 @@
</div>
</form>
</fieldset>
+ <fieldset id="validate-by-upload" class="tabset_content front"><legend class="tabset_label">Validate by URI</legend>
+ <form method="post" action="/opdsvalidatorweb" id="validation_form_upload" enctype="multipart/form-data">
+ <p class="instructions">
+ Validate a file:
+ </p>
+ <p>
+ <label title="Address of page to Validate" for="file">File:</label>
+ <span id="file_input" class="loadable"><input type="file" name="file" id="file" size="100" /></span>
+ </p>
+ <p class="submit_button">
+ <input type="submit" title="Submit for validation" value="Check" />
+ </p>
+
+ <legend class="toggletext">
+ <a><img id="toggleiconURI" class="toggleicon toggled" src="./img/arrow-open.png" alt="Hide "> More Options</a>
+ </legend>
+ <div class="options">
+ <table>
+ <tr><th>OPDS Version</th><td><select name="opds_version" ><option value="1.0">1.0</option><option value="1.1" selected="selected">1.1 (current)</option></select></td></tr>
+ </table>
+ </div>
+ </form>
+ </fieldset>
<div id="results" class="prepend-1 append-1 last">
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
+ <script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript">
//<![CDATA[
$("#uri").after("<img src=\"img/throbber.gif\" alt=\"Loading\" title=\"Loading\" id=\"loader_uri\"/>");
$("#feed_input").append("<img src=\"img/throbber.gif\" alt=\"Loading\" title=\"Loading\" id=\"loader_feed\"/>");
+$("#file_input").append("<img src=\"img/throbber.gif\" alt=\"Loading\" title=\"Loading\" id=\"loader_file\"/>");
$(".tabset_label").hide();
@@ -99,14 +125,13 @@
closeOptions();
-$("#validate-by-direct").hide();
+$("#validate-by-direct, #validate-by-upload").hide();
function showForm(ev)
{
id=ev.target.href
$("#tabs li").removeClass("selected")
$(".tabset_content").each(function (){
- console.log([this.id,id]);
if(id.search("#"+this.id)!=-1){
$(this).fadeIn()
$(ev.target).parent("li").addClass("selected");
@@ -229,7 +254,7 @@
type:'POST',
dataType: 'json',
url:$("#validation_form_direct")[0].action,
- data:{feed:$("#feed").val(),opds_version:$("#validation_form_feed select[name=opds_version]").val()},
+ data:{feed:$("#feed").val(),opds_version:$("#validation_form_direct select[name=opds_version]").val()},
success:validation_successful
}).error(validation_failed).complete(function(){$(".loadable").removeClass("loading");})
@@ -237,9 +262,38 @@
return false;
}
+function form_submitted_upload(){
+
+ window.validation_method="upload"
+ $("#results").hide();
+ $(".loadable").addClass("loading");
+
+ $.ajaxFileUpload
+ (
+ {
+ url:$("#validation_form_upload")[0].action,
+ secureuri:false,
+ fileElementId:'file',
+ dataType: 'json',
+ data:{opds_version:$("#validation_form_upload select[name=opds_version]").val()},
+ success:validation_successful,
+ error: function (data, status, e)
+ {
+ validation_failed({status: status,responseText: data})
+ },
+ complete:function(){$(".loadable").removeClass("loading")}
+ }
+ )
+
+ return false;
+}
+
+
+
$("#validation_form_uri").submit(form_submitted_uri)
$("#validation_form_direct").submit(form_submitted_direct)
+$("#validation_form_upload").submit(form_submitted_upload)
var urlParams = {};
Please sign in to comment.
Something went wrong with that request. Please try again.