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