Mercurial > hg > digilib-old
annotate servlet/src/digilib/servlet/Scaler.java @ 536:e758a49258e8 digilibPDF
Merge with 9936604d466e3c44d8a2609519848f33f2801629 (changes to HEAD)
author | casties |
---|---|
date | Wed, 25 Aug 2010 18:29:08 +0200 |
parents | 9cedd170b581 5658b2e5d444 |
children | e2ff961001af |
rev | line source |
---|---|
1 | 1 package digilib.servlet; |
2 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
3 import java.io.File; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
4 import java.io.IOException; |
500 | 5 import java.io.OutputStream; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
6 import java.util.List; |
1 | 7 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
8 import javax.servlet.ServletConfig; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
9 import javax.servlet.ServletContext; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
10 import javax.servlet.ServletException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
11 import javax.servlet.http.HttpServletRequest; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
12 import javax.servlet.http.HttpServletResponse; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
13 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
14 import digilib.auth.AuthOpException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
15 import digilib.auth.AuthOps; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
16 import digilib.image.ImageOpException; |
86 | 17 import digilib.io.DocuDirCache; |
335 | 18 import digilib.io.DocuDirectory; |
19 import digilib.io.DocuDirent; | |
181 | 20 import digilib.io.FileOpException; |
21 import digilib.io.FileOps; | |
161 | 22 import digilib.io.ImageFile; |
1 | 23 |
24 | |
511 | 25 // TODO digilibError is not used anymore and may need to get reintegrated |
1 | 26 |
500 | 27 public class Scaler extends RequestHandler { |
263 | 28 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
29 /** digilib servlet version (for all components) */ |
527 | 30 public static final String dlVersion = "1.8.0a"; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
31 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
32 /** general error code */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
33 public static final int ERROR_UNKNOWN = 0; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
34 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
35 /** error code for authentication error */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
36 public static final int ERROR_AUTH = 1; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
37 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
38 /** error code for file operation error */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
39 public static final int ERROR_FILE = 2; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
40 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
41 /** error code for image operation error */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
42 public static final int ERROR_IMAGE = 3; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
43 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
44 /** DocuDirCache instance */ |
86 | 45 DocuDirCache dirCache; |
161 | 46 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
47 /** authentication error image file */ |
153 | 48 File denyImgFile; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
49 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
50 /** image error image file */ |
153 | 51 File errorImgFile; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
52 |
363 | 53 /** not found error image file */ |
54 File notfoundImgFile; | |
55 | |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
56 /** subsampling before scaling */ |
153 | 57 float minSubsample = 2f; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
58 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
59 /** send files as is? */ |
153 | 60 boolean sendFileAllowed = true; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
61 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
62 /** default scaling quality */ |
153 | 63 int defaultQuality = 1; |
1 | 64 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
65 /** DigilibConfiguration instance */ |
73 | 66 DigilibConfiguration dlConfig; |
1 | 67 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
68 /** use authorization database */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
69 boolean useAuthorization = true; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
70 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
71 /** AuthOps instance */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
72 AuthOps authOp; |
1 | 73 |
100 | 74 // EXPRIMENTAL |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
75 /** try to enlarge cropping area for "oblique" angles */ |
100 | 76 boolean wholeRotArea = false; |
77 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
78 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
79 protected long getLastModified(HttpServletRequest request) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
80 accountlog.debug("GetLastModified from " + request.getRemoteAddr() |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
81 + " for " + request.getQueryString()); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
82 long mtime = -1; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
83 // create new request with defaults |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
84 DigilibRequest dlReq = new DigilibRequest(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
85 // set with request parameters |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
86 dlReq.setWithRequest(request); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
87 // find the requested file |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
88 DocuDirent f = findFile(dlReq); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
89 if (f != null) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
90 DocuDirectory dd = (DocuDirectory) f.getParent(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
91 mtime = dd.getDirMTime() / 1000 * 1000; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
92 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
93 return mtime; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
94 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
95 /** |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
96 * Returns the DocuDirent corresponding to the DigilibRequest. |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
97 * |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
98 * @param dlRequest |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
99 * @return |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
100 */ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
101 public DocuDirent findFile(DigilibRequest dlRequest) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
102 // find the file(set) |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
103 DocuDirent f = dirCache.getFile(dlRequest.getFilePath(), dlRequest |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
104 .getAsInt("pn"), FileOps.CLASS_IMAGE); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
105 return f; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
106 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
107 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
108 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
109 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
110 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
111 * Initialisation on first run. |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
112 * @throws ServletException |
73 | 113 * |
114 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) | |
115 */ | |
116 public void init(ServletConfig config) throws ServletException { | |
117 super.init(config); | |
1 | 118 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
119 System.out |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
120 .println("***** Digital Image Library Image Scaler Servlet (version " |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
121 + dlVersion + ") *****"); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
122 // say hello in the log file |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
123 logger |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
124 .info("***** Digital Image Library Image Scaler Servlet (version " |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
125 + dlVersion + ") *****"); |
1 | 126 |
73 | 127 // get our ServletContext |
128 ServletContext context = config.getServletContext(); | |
129 // see if there is a Configuration instance | |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
130 dlConfig = (DigilibConfiguration) context |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
131 .getAttribute("digilib.servlet.configuration"); |
73 | 132 if (dlConfig == null) { |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
133 // no Configuration |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
134 throw new ServletException("No Configuration!"); |
335 | 135 } |
73 | 136 // set our AuthOps |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
137 useAuthorization = dlConfig.getAsBoolean("use-authorization"); |
153 | 138 authOp = (AuthOps) dlConfig.getValue("servlet.auth.op"); |
181 | 139 |
86 | 140 // DocuDirCache instance |
153 | 141 dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); |
394
31643c12d939
digilib can now take its error-icons from the web app
robcast
parents:
363
diff
changeset
|
142 denyImgFile = ServletOps.getFile((File) dlConfig.getValue("denied-image"), config); |
31643c12d939
digilib can now take its error-icons from the web app
robcast
parents:
363
diff
changeset
|
143 errorImgFile = ServletOps.getFile((File) dlConfig.getValue("error-image"), config); |
31643c12d939
digilib can now take its error-icons from the web app
robcast
parents:
363
diff
changeset
|
144 notfoundImgFile = ServletOps.getFile((File) dlConfig.getValue("notfound-image"), config); |
153 | 145 sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed"); |
146 minSubsample = dlConfig.getAsFloat("subsample-minimum"); | |
147 defaultQuality = dlConfig.getAsInt("default-quality"); | |
73 | 148 } |
1 | 149 |
511 | 150 |
151 | |
152 | |
500 | 153 @Override |
154 public void processRequest(HttpServletRequest request, | |
155 HttpServletResponse response) throws ServletException, ImageOpException { | |
1 | 156 |
500 | 157 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
158 if (dlConfig == null) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
159 throw new ServletException("ERROR: No Configuration!"); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
160 } |
502 | 161 |
335 | 162 accountlog.debug("request: " + request.getQueryString()); |
163 logger.debug("request: " + request.getQueryString()); | |
500 | 164 |
1 | 165 |
500 | 166 // define the job information |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
167 ImageJobInformation jobdeclaration = new ImageJobInformation(dlConfig); |
500 | 168 jobdeclaration.setWithRequest(request); |
169 | |
502 | 170 ImageFile fileToLoad = null; |
171 try { | |
172 fileToLoad = jobdeclaration.get_fileToLoad(); | |
173 } catch (IOException e2) { | |
174 // TODO Auto-generated catch block | |
175 e2.printStackTrace(); | |
176 return; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
177 } |
500 | 178 |
179 | |
502 | 180 // if requested, send image as a file |
181 if(sendFileAllowed && jobdeclaration.checkSendAsFile()){ | |
182 String mt = null; | |
183 if (jobdeclaration.hasOption("mo", "rawfile")) { | |
184 mt = "application/octet-stream"; | |
185 } | |
186 logger.debug("Sending RAW File as is."); | |
187 try { | |
188 ServletOps.sendFile(fileToLoad.getFile(), mt, response); | |
189 } catch (FileOpException e) { | |
190 e.printStackTrace(); | |
191 } | |
1 | 192 |
502 | 193 return; |
73 | 194 } |
487 | 195 |
500 | 196 |
197 | |
502 | 198 // if possible, send the image without actually having to transform it |
199 if(jobdeclaration.noTransformRequired()){ | |
200 logger.debug("Sending File as is."); | |
201 | |
202 try { | |
203 ServletOps.sendFile(fileToLoad.getFile(), null, response); | |
204 } catch (FileOpException e) { | |
205 e.printStackTrace(); | |
206 } | |
207 | |
208 //logger.info("Done in " | |
209 // + (System.currentTimeMillis() - startTime) + "ms"); | |
210 return; | |
149 | 211 } |
502 | 212 |
213 | |
214 | |
500 | 215 |
216 OutputStream outputstream = null; | |
217 try { | |
218 outputstream = response.getOutputStream(); | |
219 } catch (IOException e1) { | |
220 // TODO Auto-generated catch block | |
221 e1.printStackTrace(); | |
222 logger.error(e1.getMessage()); | |
73 | 223 } |
502 | 224 |
225 if (! DigilibWorker.canRun()) { | |
226 logger.error("Servlet overloaded!"); | |
227 try { | |
228 response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); | |
229 } catch (IOException e) { | |
230 e.printStackTrace(); | |
231 } | |
232 return; | |
335 | 233 } |
1 | 234 |
502 | 235 |
500 | 236 DigilibWorker job=null; |
73 | 237 try { |
500 | 238 |
239 long startTime = System.currentTimeMillis(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
240 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
241 /* check permissions */ |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
242 if (useAuthorization) { |
73 | 243 // get a list of required roles (empty if no restrictions) |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
527
diff
changeset
|
244 List<String> rolesRequired; |
501 | 245 try { |
246 rolesRequired = authOp.rolesForPath(jobdeclaration.getFilePath(), request); | |
247 if (rolesRequired != null) { | |
248 authlog.debug("Role required: " + rolesRequired); | |
249 authlog.debug("User: " + request.getRemoteUser()); | |
250 // is the current request/user authorized? | |
251 if (!authOp.isRoleAuthorized(rolesRequired, request)) { | |
252 // send deny answer and abort | |
253 throw new AuthOpException(); | |
254 } | |
487 | 255 } |
256 | |
501 | 257 } catch (AuthOpException e) { |
258 // TODO Auto-generated catch block | |
259 e.printStackTrace(); | |
181 | 260 } |
261 } | |
262 | |
500 | 263 |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
264 job = new DigilibImageWorker(dlConfig, outputstream , jobdeclaration); |
73 | 265 |
500 | 266 job.run(); |
1 | 267 |
348 | 268 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
269 if (job.hasError()) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
270 throw new ImageOpException(job.getError().toString()); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
271 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
272 |
500 | 273 try { |
274 outputstream.flush(); | |
275 logger.debug("Job Processing Time: "+ (System.currentTimeMillis()-startTime) + "ms"); | |
276 } catch (IOException e) { | |
277 e.printStackTrace(); | |
278 logger.error(e.getMessage()); | |
279 response.sendError(1); | |
280 } | |
1 | 281 |
500 | 282 |
283 } catch (IOException e) { | |
284 e.printStackTrace(); | |
285 logger.error(e.getClass()+": "+ e.getMessage()); | |
286 //response.sendError(1); | |
73 | 287 } catch (ImageOpException e) { |
500 | 288 e.printStackTrace(); |
289 logger.error(e.getClass()+": "+ e.getMessage()); | |
290 //response.sendError(1); | |
73 | 291 } |
405
ffb2036da205
first stab at PDF printer servlet. DOES NOT WORK YET!
robcast
parents:
394
diff
changeset
|
292 |
500 | 293 |
511 | 294 /* boolean errorMsgHtml = false; |
500 | 295 |
296 if(jobdeclaration.hasOption("mo","errtxt")){ | |
297 errorMsgHtml = true; | |
298 } else if (jobdeclaration.hasOption("mo","errimg")) { | |
299 errorMsgHtml = true; | |
511 | 300 } */ |
500 | 301 |
335 | 302 } |
500 | 303 |
304 | |
335 | 305 /** |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
306 * Sends an error to the client as text or image. |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
307 * |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
308 * @param asHTML |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
309 * @param type |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
310 * @param msg |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
311 * @param response |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
312 */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
313 public void digilibError(boolean asHTML, int type, String msg, |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
314 HttpServletResponse response) { |
335 | 315 try { |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
316 File img = null; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
317 if (type == ERROR_AUTH) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
318 if (msg == null) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
319 msg = "ERROR: Unauthorized access!"; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
320 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
321 img = denyImgFile; |
363 | 322 } else if (type == ERROR_FILE) { |
323 if (msg == null) { | |
324 msg = "ERROR: Image file not found!"; | |
325 } | |
326 img = notfoundImgFile; | |
335 | 327 } else { |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
328 if (msg == null) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
329 msg = "ERROR: Other image error!"; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
330 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
331 img = this.errorImgFile; |
335 | 332 } |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
333 if (asHTML && (img != null)) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
334 ServletOps.htmlMessage(msg, response); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
335 } else { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
336 ServletOps.sendFile(img, null, response); |
335 | 337 } |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
338 } catch (IOException e) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
339 logger.error("Error sending error!", e); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
340 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
341 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
342 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
343 |
500 | 344 public static String getVersion(){ |
489
882ee6a055bd
try to fix small problem with version number display
robcast
parents:
487
diff
changeset
|
345 return dlVersion; |
882ee6a055bd
try to fix small problem with version number display
robcast
parents:
487
diff
changeset
|
346 } |
500 | 347 |
489
882ee6a055bd
try to fix small problem with version number display
robcast
parents:
487
diff
changeset
|
348 |
500 | 349 } |