1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.plugin.basic;
17
18 import java.io.IOException;
19 import java.net.MalformedURLException;
20 import java.net.URL;
21
22 import org.seasar.tuigwaa.cms.core.CmsRequest;
23 import org.seasar.tuigwaa.cms.core.CmsResponse;
24 import org.seasar.tuigwaa.cms.core.Resource;
25 import org.seasar.tuigwaa.cms.core.pdf.PdfUtils;
26 import org.seasar.tuigwaa.cms.core.wiki.base.WikiHelper;
27 import org.seasar.tuigwaa.plugin.PluginException;
28 import org.seasar.tuigwaa.plugin.PluginRequest;
29 import org.seasar.tuigwaa.util.TgwContext;
30
31 import com.lowagie.text.Anchor;
32 import com.lowagie.text.BadElementException;
33 import com.lowagie.text.Element;
34 import com.lowagie.text.Image;
35
36 /***
37 * @author someda
38 */
39 public class PdfRefPlugin extends RefPlugin {
40
41
42 private static final String LOCAL_WEBDAV_PATH = "WEB-INF/classes/webdav/content/webfile";
43
44 public Object doPDFView(CmsRequest request,CmsResponse response,PluginRequest prequest) throws PluginException{
45
46 String[] args = prequest.getArgs();
47 if(args == null)
48 throw new PluginException("ref plugin needs argument");
49
50 String href = getHref(args,request);
51 String label = getLabel(args,href);
52
53 Element e = null;
54 if(label.indexOf("img") != -1){
55 try{
56 URL url = new URL(href);
57
58 Image img = null;
59 if(WikiHelper.isURL(args[0])){
60 img = Image.getInstance(url);
61 }else{
62
63 Resource resource = request.getPage().getResource();
64 String file = request.getSiteName() + "/" + resource.getPath() + ".attach/" + args[0];
65 String prefix = LOCAL_WEBDAV_PATH;
66 String realpath = TgwContext.getRealPath(prefix + "/" + file + "_1.0");
67 img = Image.getInstance(realpath);
68 }
69 img.setAlignment(Image.ALIGN_MIDDLE | Image.TEXTWRAP);
70 e = (Element) img;
71 }catch(MalformedURLException mue){
72 throw new PluginException(mue);
73 }catch(BadElementException bee){
74 throw new PluginException(bee);
75 }catch(IOException ioe){
76 throw new PluginException(ioe);
77 }
78 }else{
79 Anchor a = new Anchor(label,PdfUtils.FONT_JA_MINCHO);
80 a.setReference(href);
81 e = (Element)a;
82 }
83 return e;
84
85 }
86
87 }