658cca1e1d53d4c772f5af349145581f065cafd8
[zxing.git] / zxingorg / web / decoderesult.jspx
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  Copyright 2008 ZXing authors
4
5  Licensed under the Apache License, Version 2.0 (the "License");
6  you may not use this file except in compliance with the License.
7  You may obtain a copy of the License at
8
9       http://www.apache.org/licenses/LICENSE-2.0
10
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16  -->
17 <!-- Author: Sean Owen -->
18 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
19 <jsp:directive.page import="
20   java.util.List,
21   com.google.zxing.Result,
22   com.google.zxing.client.result.ResultParser,
23   com.google.zxing.client.result.ParsedResult,
24   org.apache.commons.lang.StringEscapeUtils"/>
25   <jsp:declaration>
26   private static String arrayToString(byte[] bytes) {
27     int length = bytes.length;
28     StringBuilder result = new StringBuilder(length &lt;&lt; 2);
29     int i = 0;
30     while (i &lt; length) {
31       int max = Math.min(i + 8, length);
32       for (int j = i; j &lt; max; j++) {
33         int value = bytes[j] &amp; 0xFF;
34         result.append(Integer.toHexString(value / 16));
35         result.append(Integer.toHexString(value % 16));
36         result.append(' ');
37       }
38       result.append('\n');
39       i += 8;
40     }
41     for (int j = i - 8; j &lt; length; j++) {
42       result.append(Integer.toHexString(bytes[j] &amp; 0xFF));
43       result.append(' ');
44     }
45     return result.toString();
46   }
47 </jsp:declaration>
48 <jsp:directive.page contentType="text/html" session="false"/>
49 <jsp:scriptlet>response.setHeader("Cache-Control", "no-cache");</jsp:scriptlet>
50 <jsp:text><![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">]]></jsp:text>
51 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
52   <head>
53     <title>Decode Succeeded</title>
54     <link rel="stylesheet" href="style.css" type="text/css"/>    
55     <style type="text/css">
56       td { vertical-align: top; padding: 0.1in; background-color: #EEEEEE; font-family: monospace; }
57     </style>
58   </head>
59   <body>
60     <div id="header"><h1><img src="zxing-icon.png" height="32" width="32" alt=""/> Decode Succeeded</h1></div>
61     <jsp:scriptlet>
62       for (Result result : (List&lt;Result&gt;) request.getAttribute("results")) {
63         ParsedResult parsedResult = ResultParser.parseResult(result);
64
65         String text = result.getText();
66         if (text == null) {
67           text = "(Not applicable)";
68         } else {
69           text = StringEscapeUtils.escapeXml(text);
70         }
71
72         byte[] rawBytes = result.getRawBytes();
73         String rawBytesString;
74         if (rawBytes == null) {
75           rawBytesString = "(Not applicable)";
76         } else {
77           rawBytesString = arrayToString(rawBytes);
78         }
79
80         String displayResult = parsedResult.getDisplayResult();
81         if (displayResult == null) {
82           displayResult = "(Not applicable)";
83         } else {
84           displayResult = StringEscapeUtils.escapeXml(displayResult);
85         }
86     </jsp:scriptlet>
87     <table>
88       <tr>
89         <td>Raw text</td>
90         <td><jsp:expression>text</jsp:expression></td>
91       </tr>
92       <tr>
93         <td>Raw bytes</td>
94         <td><jsp:expression>rawBytesString</jsp:expression></td>
95       </tr>
96       <tr>
97         <td>Barcode format</td>
98         <td><jsp:expression>result.getBarcodeFormat()</jsp:expression></td>
99       </tr>
100       <tr>
101         <td>Parsed Result Type</td>
102         <td><jsp:expression>parsedResult.getType()</jsp:expression></td>
103       </tr>
104       <tr>
105         <td>Parsed Result</td>
106         <td><jsp:expression>displayResult</jsp:expression></td>
107       </tr>
108     </table>
109     <hr/>
110     <jsp:scriptlet>
111       }
112     </jsp:scriptlet>
113     <div id="footer"><p>Copyright 2008 and onwards ZXing authors</p></div>
114     <jsp:include page="analytics.jspx"/>
115   </body>
116 </html>
117 </jsp:root>