comparison 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
comparison
equal deleted inserted replaced
551:6c9eba7772cf 552:785fc58b68b1
20 * @author cmielack, casties 20 * @author cmielack, casties
21 * 21 *
22 */ 22 */
23 public class PDFJobDescription extends ParameterMap { 23 public class PDFJobDescription extends ParameterMap {
24 24
25 ImageJobDescription image_info = null;
26 DigilibConfiguration dlConfig = null; 25 DigilibConfiguration dlConfig = null;
27 NumRange pages = null; 26 NumRange pages = null;
28 /** gengeral logger for this class */ 27 /** general logger for this class */
29 protected static Logger logger = Logger.getLogger("digilib.servlet"); 28 protected static Logger logger = Logger.getLogger("digilib.servlet");
30 29
31 30
32 /** 31 /**
33 * Initialize the PDFJobInformation 32 * Initialize the PDFJobInformation
36 * The DigilibConfiguration. 35 * The DigilibConfiguration.
37 */ 36 */
38 public PDFJobDescription(DigilibConfiguration dlcfg) { 37 public PDFJobDescription(DigilibConfiguration dlcfg) {
39 super(30); 38 super(30);
40 dlConfig = dlcfg; 39 dlConfig = dlcfg;
41 // page numbers
42 newParameter("pgs", "", null, 's');
43 // url of the page/document (second part)
44 newParameter("fn", "", null, 's');
45 // width of client in pixels
46 newParameter("dw", new Integer(0), null, 's');
47 // height of client in pixels
48 newParameter("dh", new Integer(0), null, 's');
49 } 40 }
50 41
51 /** 42 /**
52 * Initialize the PDFJobInformation with a request. 43 * Initialize the PDFJobInformation with a request.
53 * 44 *
59 dlConfig = dlcfg; 50 dlConfig = dlcfg;
60 this.setWithRequest(request); 51 this.setWithRequest(request);
61 } 52 }
62 53
63 54
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
64 /** 66 /**
65 * Read in the request object. 67 * Read in the request object.
66 * 68 *
67 * @param request 69 * @param request
68 */ 70 */
69 public void setWithRequest(HttpServletRequest request) { 71 public void setWithRequest(HttpServletRequest request) {
70 image_info = new ImageJobDescription(dlConfig); 72 for (String k : params.keySet()) {
71 // FIXME: image_info.setWithRequest(request); 73 if (request.getParameterMap().containsKey(k)) {
72 74 setValueFromString(k, request.getParameter(k));
73 for (String param : parameter_list){
74 if (request.getParameterMap().containsKey(param)){
75 setValueFromString(param, request.getParameter(param));
76 } 75 }
77 } 76 }
78 // process parameters 77 // process parameters
79 try { 78 try {
80 pages = new NumRange(getAsString("pgs")); 79 pages = new NumRange(getAsString("pgs"));
81 DocuDirectory dir = image_info.getFileDirectory(); 80 ImageJobDescription ij = ImageJobDescription.setFrom(this, dlConfig);
81 DocuDirectory dir = ij.getFileDirectory();
82 int dirsize = dir.size(FileOps.CLASS_IMAGE); 82 int dirsize = dir.size(FileOps.CLASS_IMAGE);
83 pages.setMaxnum(dirsize); 83 pages.setMaxnum(dirsize);
84 } catch (Exception e) { 84 } catch (Exception e) {
85 logger.warn("Problem with parsing page numbers: "+e.toString()); 85 logger.warn("Problem with parsing page numbers: "+e.toString());
86 } 86 }
95 public String getDocumentId(){ 95 public String getDocumentId(){
96 String id; 96 String id;
97 97
98 // TODO use complete request information for id generation 98 // TODO use complete request information for id generation
99 99
100 if(this.image_info!=null){ 100 String fn = getAsString("fn");
101 String fn = image_info.getAsString("fn"); 101 String dh = getAsString("dh");
102 String dh = image_info.getAsString("dh"); 102 String dw = getAsString("dw");
103 String pgs = getAsString("pgs"); 103 String pgs = getAsString("pgs");
104 104
105 id = "fn=" + fn + "&dh=" + dh + "&pgs=" + pgs + ".pdf"; 105 id = "fn=" + fn + "&dw=" + dw + "&dh=" + dh + "&pgs=" + pgs + ".pdf";
106 // make safe to use as filename by urlencoding 106 // make safe to use as filename by urlencoding
107 try { 107 try {
108 id = URLEncoder.encode(id, "UTF-8"); 108 id = URLEncoder.encode(id, "UTF-8");
109 } catch (UnsupportedEncodingException e) { 109 } catch (UnsupportedEncodingException e) {
110 // TODO Auto-generated catch block 110 // this shouldn't happen
111 e.printStackTrace();
112 }
113 } 111 }
114 else {
115 id = null;
116 }
117
118 return id; 112 return id;
119 } 113 }
120 114
121 115
122 public ImageJobDescription getImageJobInformation(){ 116 public ImageJobDescription getImageJobInformation(){
123 ImageJobDescription new_image_info = new ImageJobDescription(image_info, dlConfig); 117 return ImageJobDescription.setFrom(this, dlConfig);
124 return new_image_info;
125 } 118 }
126 119
127 120
128 public NumRange getPages() { 121 public NumRange getPages() {
129 return pages; 122 return pages;