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