001    package railo.runtime.tag;
002    
003    
004    import javax.servlet.jsp.tagext.Tag;
005    
006    import railo.commons.io.res.Resource;
007    import railo.commons.io.res.util.ResourceUtil;
008    import railo.commons.pdf.PDFDocument;
009    import railo.commons.pdf.PDFException;
010    import railo.commons.pdf.PDFPageMark;
011    import railo.runtime.exp.ApplicationException;
012    import railo.runtime.exp.PageException;
013    import railo.runtime.ext.tag.BodyTagImpl;
014    
015    public final class DocumentSection extends BodyTagImpl {
016    
017            
018            private PDFDocument _document; 
019            
020    
021    
022            public DocumentSection() {
023                    this._document=null;
024            }
025            
026            private PDFDocument getPDFDocument() {
027                    //SerialNumber sn = pageContext.getConfig().getSerialNumber();
028                    if(_document==null)_document=new PDFDocument();
029                    return _document;
030            }
031            
032            @Override
033            public void release() {
034                    super.release();
035                    _document=null;
036            }
037            
038            
039    
040            /** set the value proxyserver
041            *  Host name or IP address of a proxy server.
042            * @param proxyserver value to set
043            **/
044            public void setProxyserver(String proxyserver)  {
045                    getPDFDocument().setProxyserver(proxyserver);
046            }
047            
048            /** set the value proxyport
049            *  The port number on the proxy server from which the object is requested. Default is 80. When 
050            *       used with resolveURL, the URLs of retrieved documents that specify a port number are automatically 
051            *       resolved to preserve links in the retrieved document.
052            * @param proxyport value to set
053            **/
054            public void setProxyport(double proxyport)      {
055                    getPDFDocument().setProxyport((int)proxyport);
056            }
057    
058            /** set the value username
059            *  When required by a proxy server, a valid username.
060            * @param proxyuser value to set
061            **/
062            public void setProxyuser(String proxyuser)      {
063                    getPDFDocument().setProxyuser(proxyuser);
064            }
065    
066            /** set the value password
067            *  When required by a proxy server, a valid password.
068            * @param proxypassword value to set
069            **/
070            public void setProxypassword(String proxypassword)      {
071                    getPDFDocument().setProxypassword(proxypassword);
072            }
073    
074            /**
075             * @param marginbottom the marginbottom to set
076             */
077            public void setMarginbottom(double marginbottom) {
078                    getPDFDocument().setMarginbottom(marginbottom);
079            }
080    
081            /**
082             * @param marginleft the marginleft to set
083             */
084            public void setMarginleft(double marginleft) {
085                    getPDFDocument().setMarginleft(marginleft);
086            }
087    
088            /**
089             * @param marginright the marginright to set
090             */
091            public void setMarginright(double marginright) {
092                    getPDFDocument().setMarginright(marginright);
093            }
094    
095            /**
096             * @param margintop the margintop to set
097             */
098            public void setMargintop(double margintop) {
099                    getPDFDocument().setMargintop(margintop);
100            }
101    
102            /**
103             * @param src the src to set
104             * @throws ApplicationException 
105             */
106            public void setSrc(String src) throws ApplicationException {
107                    try {
108                            getPDFDocument().setSrc(src);
109                    } catch (PDFException e) {
110                            throw new ApplicationException(e.getMessage());
111                    }
112            }
113    
114            /**
115             * @param srcfile the srcfile to set
116             * @throws PageException 
117             * @throws  
118             */
119            public void setSrcfile(String strSrcfile) throws PageException {
120                    Resource srcfile = ResourceUtil.toResourceExisting(pageContext, strSrcfile);
121                    pageContext.getConfig().getSecurityManager().checkFileLocation(srcfile);
122                    try {
123                            getPDFDocument().setSrcfile(srcfile);
124                    } catch (PDFException e) {
125                            throw new ApplicationException(e.getMessage());
126                    }
127            }
128    
129            /**
130             * @param mimetype the mimetype to set
131             */
132            public void setMimetype(String strMimetype) {
133                    getPDFDocument().setMimetype(strMimetype);
134                    strMimetype = strMimetype.toLowerCase().trim();
135            }
136            
137    
138            public void setHeader(PDFPageMark header) {
139                    getPDFDocument().setHeader(header);
140            }
141    
142            public void setFooter(PDFPageMark footer) {
143                    getPDFDocument().setFooter(footer);
144            }
145            
146            
147            /**
148             * @param name the name to set
149             */
150            public void setName(String name) {
151                    getPDFDocument().setName(name);
152            }
153    
154            /**
155             * @param authUser the authUser to set
156             */
157            public void setAuthuser(String authUser) {
158                    getPDFDocument().setAuthUser(authUser);
159            }
160    
161            /**
162             * @param authPassword the authPassword to set
163             */
164            public void setAuthpassword(String authPassword) {
165                    getPDFDocument().setAuthPassword(authPassword);
166            }
167    
168            /**
169             * @param userAgent the userAgent to set
170             */
171            public void setUseragent(String userAgent) {
172                    getPDFDocument().setUserAgent(userAgent);
173            }
174    
175        @Override
176            public int doStartTag() {
177                    return EVAL_BODY_BUFFERED;
178            }
179    
180            @Override
181            public void doInitBody()        {
182                    
183            }
184            
185            @Override
186            public int doAfterBody()        {
187                    getPDFDocument().setBody(bodyContent.getString());
188                    return SKIP_BODY;
189            }
190            
191            @Override
192            public int doEndTag() {
193                    Document doc = getDocument();// TODO write evaluator for documentitem and section
194                    if(doc!=null)doc.addPDFDocument(getPDFDocument());
195                    return EVAL_PAGE;
196            }
197    
198            private Document getDocument()  {
199                    // get Mail Tag
200                    Tag parent=getParent();
201                    while(parent!=null && !(parent instanceof Document)) {
202                            parent=parent.getParent();
203                    }
204                    
205                    if(parent instanceof Document) {
206                            return  (Document)parent;
207                    }
208                    return null;
209            }
210            /**
211             * sets if has body or not
212             * @param hasBody
213             */
214            public void hasBody(boolean hasBody) {
215                
216            }
217    
218    
219    }
220            
221