Mercurial > hg > digilib-old
comparison servlet/src/digilib/pdf/PDFTitlePage.java @ 595:e8668edcb880 stream
Merge from HEAD
85e465e6a6425d91c0704f6584a461492d51de97
author | robcast |
---|---|
date | Sun, 09 Jan 2011 21:11:03 +0100 |
parents | 95417c4615b8 85e465e6a642 |
children |
comparison
equal
deleted
inserted
replaced
593:7768ea8f59cf | 595:e8668edcb880 |
---|---|
1 package digilib.pdf; | 1 package digilib.pdf; |
2 | 2 |
3 import java.io.File; | |
3 import java.io.IOException; | 4 import java.io.IOException; |
4 import java.net.MalformedURLException; | 5 import java.net.MalformedURLException; |
5 import java.net.URL; | 6 import java.net.URL; |
6 | 7 |
7 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
12 import com.itextpdf.text.Element; | 13 import com.itextpdf.text.Element; |
13 import com.itextpdf.text.FontFactory; | 14 import com.itextpdf.text.FontFactory; |
14 import com.itextpdf.text.Image; | 15 import com.itextpdf.text.Image; |
15 import com.itextpdf.text.Paragraph; | 16 import com.itextpdf.text.Paragraph; |
16 | 17 |
17 | 18 import digilib.io.FileOpException; |
18 import digilib.io.DocuDirCache; | |
19 import digilib.servlet.PDFCache; | 19 import digilib.servlet.PDFCache; |
20 import digilib.servlet.PDFRequest; | 20 import digilib.servlet.PDFRequest; |
21 | 21 |
22 /** A class for the generation of title pages for the generated pdf documents. | 22 /** A class for the generation of title pages for the generated pdf documents. |
23 * | 23 * |
25 */ | 25 */ |
26 public class PDFTitlePage { | 26 public class PDFTitlePage { |
27 | 27 |
28 private PDFRequest job_info = null; | 28 private PDFRequest job_info = null; |
29 private DigilibInfoReader info_reader= null; | 29 private DigilibInfoReader info_reader= null; |
30 private DocuDirCache dirCache = null; | |
31 protected static Logger logger = Logger.getLogger("digilib.servlet"); | 30 protected static Logger logger = Logger.getLogger("digilib.servlet"); |
32 | 31 |
33 | 32 |
34 /** | 33 /** |
35 * Initialize a TitlePage | 34 * Initialize a TitlePage |
36 * @param pdfji | 35 * @param pdfji |
37 */ | 36 */ |
38 public PDFTitlePage(PDFRequest pdfji){ | 37 public PDFTitlePage(PDFRequest pdfji){ |
39 job_info = pdfji; | 38 job_info = pdfji; |
40 dirCache = (DocuDirCache) job_info.getDlConfig().getValue("servlet.dir.cache"); | |
41 | 39 |
42 String fn = getBase(dirCache.getDirectory(pdfji.getImageJobInformation().getAsString("fn")).getDir().getPath()) + "presentation/info.xml"; | 40 // use MPIWG-style info.xml |
43 | 41 info_reader = getInfoXmlReader(pdfji); |
44 info_reader = new DigilibInfoReader(fn); | |
45 } | 42 } |
43 | |
44 /** | |
45 * @param pdfji | |
46 * @return | |
47 */ | |
48 protected DigilibInfoReader getInfoXmlReader(PDFRequest pdfji) { | |
49 try { | |
50 // try to load ../presentation/info.xml | |
51 File imgDir = pdfji.getImageJobInformation().getFileDirectory().getDir(); | |
52 File docDir = imgDir.getParentFile(); | |
53 File infoFn = new File(new File(docDir, "presentation"), "info.xml"); | |
54 return new DigilibInfoReader(infoFn.getAbsolutePath()); | |
55 } catch (FileOpException e) { | |
56 logger.warn("info.xml not found"); | |
57 } | |
58 return null; | |
59 } | |
46 | 60 |
47 /** | 61 /** |
48 * generate iText-PDF-Contents for the title page | 62 * generate iText-PDF-Contents for the title page |
49 * | 63 * |
50 * @return | 64 * @return |
55 | 69 |
56 // add vertical whitespace | 70 // add vertical whitespace |
57 for(int i=0; i<8; i++){ | 71 for(int i=0; i<8; i++){ |
58 content.add(Chunk.NEWLINE); | 72 content.add(Chunk.NEWLINE); |
59 } | 73 } |
60 | |
61 | 74 |
62 // add logo | 75 // add logo |
63 content.add(getLogo()); | 76 content.add(getLogo()); |
64 content.add(Chunk.NEWLINE); | 77 content.add(Chunk.NEWLINE); |
65 content.add(Chunk.NEWLINE); | 78 content.add(Chunk.NEWLINE); |
86 | 99 |
87 content.add(Chunk.NEWLINE); | 100 content.add(Chunk.NEWLINE); |
88 content.add(Chunk.NEWLINE); | 101 content.add(Chunk.NEWLINE); |
89 content.add(Chunk.NEWLINE); | 102 content.add(Chunk.NEWLINE); |
90 | 103 |
91 // add credits | |
92 content.add(new Paragraph("MPIWG Berlin 2009", FontFactory.getFont(FontFactory.HELVETICA,10))); | |
93 | |
94 // add digilib version | 104 // add digilib version |
95 content.add(new Paragraph(getDigilibVersion(),FontFactory.getFont(FontFactory.HELVETICA,10))); | 105 content.add(new Paragraph(getDigilibVersion(),FontFactory.getFont(FontFactory.HELVETICA,10))); |
96 | 106 |
97 for(int i=0; i<8; i++){ | 107 for(int i=0; i<8; i++){ |
98 content.add(Chunk.NEWLINE); | 108 content.add(Chunk.NEWLINE); |
106 | 116 |
107 | 117 |
108 return content; | 118 return content; |
109 } | 119 } |
110 | 120 |
111 /** | 121 /* |
112 * return base directory of an image directory | |
113 * | |
114 * @param path | |
115 * @return | |
116 */ | |
117 private String getBase(String path){ | |
118 if(path.contains("/")){ | |
119 String[] x = path.split("/"); | |
120 String newpath = ""; | |
121 for(int i=0; i<x.length-1; i++){ | |
122 newpath += x[i]+"/"; | |
123 } | |
124 return newpath; | |
125 } | |
126 else | |
127 return ""; | |
128 } | |
129 | |
130 | |
131 /** | |
132 * Methods for the different attributes. | 122 * Methods for the different attributes. |
133 * | 123 * |
134 */ | 124 */ |
135 | |
136 | 125 |
137 private Image getLogo(){ | 126 private Image getLogo(){ |
138 try { | 127 try { |
139 URL url = new URL(job_info.getDlConfig().getAsString("pdf-logo")); | 128 URL url = new URL(job_info.getDlConfig().getAsString("pdf-logo")); |
140 if(url!=null && !url.equals("")){ | 129 if(url!=null && !url.equals("")){ |
142 logo.setAlignment(Element.ALIGN_CENTER); | 131 logo.setAlignment(Element.ALIGN_CENTER); |
143 return logo; | 132 return logo; |
144 } | 133 } |
145 } catch (BadElementException e) { | 134 } catch (BadElementException e) { |
146 logger.error(e.getMessage()); | 135 logger.error(e.getMessage()); |
147 e.printStackTrace(); | |
148 } catch (MalformedURLException e) { | 136 } catch (MalformedURLException e) { |
149 logger.error(e.getMessage()); | 137 logger.error(e.getMessage()); |
150 e.printStackTrace(); | |
151 } catch (IOException e) { | 138 } catch (IOException e) { |
152 logger.error(e.getMessage()); | 139 logger.error(e.getMessage()); |
153 e.printStackTrace(); | |
154 } | 140 } |
155 return null; | 141 return null; |
156 } | 142 } |
143 | |
157 private String getTitle(){ | 144 private String getTitle(){ |
158 if(info_reader.hasInfo()) | 145 if(info_reader.hasInfo()) |
159 return info_reader.getAsString("title"); | 146 return info_reader.getAsString("title"); |
160 else | 147 else |
161 return job_info.getImageJobInformation().getAsString("fn"); | 148 return job_info.getImageJobInformation().getAsString("fn"); |
162 } | 149 } |
150 | |
163 private String getAuthor(){ | 151 private String getAuthor(){ |
164 if(info_reader.hasInfo()) | 152 if(info_reader.hasInfo()) |
165 return info_reader.getAsString("author"); | 153 return info_reader.getAsString("author"); |
166 else | 154 else |
167 return " "; | 155 return " "; |
168 } | 156 } |
157 | |
169 private String getDate(){ | 158 private String getDate(){ |
170 if(info_reader.hasInfo()) | 159 if(info_reader.hasInfo()) |
171 return info_reader.getAsString("date"); | 160 return info_reader.getAsString("date"); |
172 else | 161 else |
173 return " "; | 162 return " "; |
174 } | 163 } |
164 | |
175 private String getPages(){ | 165 private String getPages(){ |
176 return "Pages "+job_info.getAsString("pgs") + " (scan page numbers)"; | 166 return "Pages "+job_info.getAsString("pgs") + " (scan page numbers)"; |
177 } | 167 } |
178 | 168 |
179 private String getDigilibVersion(){ | 169 private String getDigilibVersion(){ |