1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.plugin.database;
17
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
20
21 import org.seasar.tuigwaa.cms.core.CmsRequest;
22 import org.seasar.tuigwaa.cms.core.CmsResponse;
23 import org.seasar.tuigwaa.cms.core.pdf.PdfUtils;
24 import org.seasar.tuigwaa.cms.core.wiki.base.WikiHelper;
25 import org.seasar.tuigwaa.plugin.PluginException;
26 import org.seasar.tuigwaa.plugin.PluginRequest;
27
28 import com.lowagie.text.Chunk;
29
30 /***
31 * @author someda
32 */
33 public class PdfDataPlugin extends DataPlugin {
34
35 private static Pattern HTML_IMG_PATTERN = Pattern.compile("<img src=(.+)/>");
36 private static Pattern HTML_ANCHOR_PATTERN = Pattern.compile("<a href=.+>(.+)</a>");
37
38
39 public Object doPDFView(CmsRequest request, CmsResponse response, PluginRequest prequest) throws PluginException {
40 String htmlStr = super.doHTMLView(request,response,prequest);
41 String str = extractString(htmlStr);
42 Chunk c = new Chunk(str,PdfUtils.FONT_JA_MINCHO);
43 return c;
44 }
45
46 private static String extractString(String htmlString){
47 String ret = htmlString;
48
49 Matcher m = HTML_ANCHOR_PATTERN.matcher(htmlString);
50 if(m.matches()){
51 ret = m.group(1);
52 }
53
54 m = HTML_IMG_PATTERN.matcher(htmlString);
55 if(m.matches()){
56 ret = m.group(1);
57 }
58 return WikiHelper.deleteParenthesis(ret,"\"","\"");
59 }
60 }