Mercurial > hg > digilib-old
annotate servlet/src/digilib/servlet/PDFJobDescription.java @ 552:785fc58b68b1 digilibPDF
more cleanup and refactoring
author | robcast |
---|---|
date | Wed, 15 Dec 2010 08:58:01 +0100 |
parents | 6c9eba7772cf |
children | d3b29ccdef32 |
rev | line source |
---|---|
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
1 package digilib.servlet; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
2 |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
3 import java.io.UnsupportedEncodingException; |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
4 import java.net.URLEncoder; |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
5 import java.util.ArrayList; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
6 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
7 import javax.servlet.http.HttpServletRequest; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
8 |
505 | 9 import org.apache.log4j.Logger; |
10 | |
541 | 11 import digilib.io.DocuDirectory; |
12 import digilib.io.FileOps; | |
13 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
14 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
15 /** |
533 | 16 * A container class for storing a set of instruction parameters |
511 | 17 * used for content generator classes like MakePDF. |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
18 * |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
19 * |
548 | 20 * @author cmielack, casties |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
21 * |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
22 */ |
548 | 23 public class PDFJobDescription extends ParameterMap { |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
24 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
25 DigilibConfiguration dlConfig = null; |
541 | 26 NumRange pages = null; |
552 | 27 /** general logger for this class */ |
505 | 28 protected static Logger logger = Logger.getLogger("digilib.servlet"); |
29 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
30 |
511 | 31 /** |
32 * Initialize the PDFJobInformation | |
33 * | |
34 * @param dlcfg | |
35 * The DigilibConfiguration. | |
36 */ | |
548 | 37 public PDFJobDescription(DigilibConfiguration dlcfg) { |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
38 super(30); |
551 | 39 dlConfig = dlcfg; |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
40 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
41 |
548 | 42 /** |
43 * Initialize the PDFJobInformation with a request. | |
44 * | |
45 * @param dlcfg The DigilibConfiguration. | |
46 * @param request | |
47 */ | |
48 public PDFJobDescription(HttpServletRequest request, DigilibConfiguration dlcfg) { | |
49 super(30); | |
50 dlConfig = dlcfg; | |
51 this.setWithRequest(request); | |
52 } | |
53 | |
511 | 54 |
552 | 55 protected void initParams() { |
56 // page numbers | |
57 newParameter("pgs", "", null, 's'); | |
58 // url of the page/document (second part) | |
59 newParameter("fn", "", null, 's'); | |
60 // width of client in pixels | |
61 newParameter("dw", new Integer(0), null, 's'); | |
62 // height of client in pixels | |
63 newParameter("dh", new Integer(0), null, 's'); | |
64 } | |
65 | |
511 | 66 /** |
67 * Read in the request object. | |
68 * | |
69 * @param request | |
70 */ | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
71 public void setWithRequest(HttpServletRequest request) { |
552 | 72 for (String k : params.keySet()) { |
73 if (request.getParameterMap().containsKey(k)) { | |
74 setValueFromString(k, request.getParameter(k)); | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
75 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
76 } |
541 | 77 // process parameters |
78 try { | |
79 pages = new NumRange(getAsString("pgs")); | |
552 | 80 ImageJobDescription ij = ImageJobDescription.setFrom(this, dlConfig); |
81 DocuDirectory dir = ij.getFileDirectory(); | |
541 | 82 int dirsize = dir.size(FileOps.CLASS_IMAGE); |
83 pages.setMaxnum(dirsize); | |
84 } catch (Exception e) { | |
85 logger.warn("Problem with parsing page numbers: "+e.toString()); | |
86 } | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
87 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
88 |
511 | 89 |
90 /** | |
91 * Generate the filename of the pdf to be created. | |
92 * | |
93 * @return | |
94 */ | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
95 public String getDocumentId(){ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
96 String id; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
97 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
98 // TODO use complete request information for id generation |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
99 |
552 | 100 String fn = getAsString("fn"); |
101 String dh = getAsString("dh"); | |
102 String dw = getAsString("dw"); | |
103 String pgs = getAsString("pgs"); | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
104 |
552 | 105 id = "fn=" + fn + "&dw=" + dw + "&dh=" + dh + "&pgs=" + pgs + ".pdf"; |
106 // make safe to use as filename by urlencoding | |
107 try { | |
108 id = URLEncoder.encode(id, "UTF-8"); | |
109 } catch (UnsupportedEncodingException e) { | |
110 // this shouldn't happen | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
111 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
112 return id; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
113 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
114 |
511 | 115 |
547 | 116 public ImageJobDescription getImageJobInformation(){ |
552 | 117 return ImageJobDescription.setFrom(this, dlConfig); |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
118 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
119 |
511 | 120 |
541 | 121 public NumRange getPages() { |
122 return pages; | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
123 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
124 |
505 | 125 |
511 | 126 /** |
127 * Check parameters for validity. | |
128 * Returns true if no errors are found. | |
129 * | |
130 * @return | |
131 */ | |
505 | 132 public boolean checkValidity(){ |
541 | 133 if (pages != null) { |
134 return true; | |
135 } | |
136 return false; | |
137 } | |
505 | 138 |
509 | 139 public DigilibConfiguration getDlConfig(){ |
140 return dlConfig; | |
141 } | |
142 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
diff
changeset
|
143 } |