001 package railo.runtime.tag; 002 003 import javax.servlet.jsp.tagext.Tag; 004 005 import railo.commons.io.res.Resource; 006 import railo.commons.io.res.util.ResourceUtil; 007 import railo.commons.io.res.util.WildcardPatternFilter; 008 import railo.runtime.exp.ApplicationException; 009 import railo.runtime.exp.PageException; 010 import railo.runtime.ext.tag.TagImpl; 011 import railo.runtime.op.Caster; 012 013 public final class ZipParam extends TagImpl { 014 015 private String charset; 016 private Object content; 017 private String entryPath; 018 private String filter; 019 private String prefix; 020 private railo.commons.io.res.Resource source; 021 private Boolean recurse=null; 022 private Zip zip; 023 024 025 026 @Override 027 public void release() { 028 super.release(); 029 charset=null; 030 content=null; 031 entryPath=null; 032 filter=null; 033 prefix=null; 034 source=null; 035 recurse=null; 036 zip=null; 037 } 038 039 040 /** 041 * @param charset the charset to set 042 */ 043 public void setCharset(String charset) { 044 this.charset=charset; 045 } 046 047 /** 048 * @param content the content to set 049 */ 050 public void setContent(Object content) { 051 this.content=content; 052 } 053 054 /** 055 * @param entryPath the entryPath to set 056 */ 057 public void setEntrypath(String entryPath) { 058 this.entryPath=entryPath; 059 } 060 061 /** 062 * @param filter the filter to set 063 */ 064 public void setFilter(String filter) { 065 this.filter=filter; 066 } 067 068 /** 069 * @param prefix the prefix to set 070 */ 071 public void setPrefix(String prefix) { 072 this.prefix=prefix; 073 } 074 075 /** 076 * @param strSource the source to set 077 * @throws PageException 078 */ 079 public void setSource(String strSource) throws PageException { 080 Resource zipSrc = getZip().getSource(); 081 if(zipSrc!=null)source=zipSrc.getRealResource(strSource); 082 if(source==null || !source.exists()) 083 source=ResourceUtil.toResourceExisting(pageContext, strSource); 084 } 085 086 /** 087 * @param recurse the recurse to set 088 */ 089 public void setRecurse(boolean recurse) { 090 this.recurse=Caster.toBoolean(recurse); 091 } 092 093 @Override 094 public int doStartTag() throws PageException { 095 096 if(source!=null) { 097 notAllowed("source","charset", charset); 098 notAllowed("source","content", content); 099 100 WildcardPatternFilter f = ( filter == null ? null : new WildcardPatternFilter( filter ) ); 101 getZip().setParam( new ZipParamSource( source, entryPath, f, prefix, recurse() ) ); 102 } 103 else if(content!=null) { 104 required("content","entrypath",entryPath); 105 notAllowed("content,entrypath","filter", filter); 106 notAllowed("content,entrypath","prefix", prefix); 107 notAllowed("content,entrypath","source", source); 108 notAllowed("content,entrypath","recurse", recurse); 109 110 getZip().setParam(new ZipParamContent(content,entryPath,charset)); 111 } 112 /*else if(filter!=null) { 113 notAllowed("filter","charset", charset); 114 notAllowed("filter","content", content); 115 notAllowed("filter","prefix", prefix); 116 notAllowed("filter","source", source); 117 getZip().setParam(new ZipParamFilter(filter,entryPath,recurse())); 118 } 119 else if(entryPath!=null) { 120 notAllowed("entryPath","charset", charset); 121 notAllowed("entryPath","content", content); 122 notAllowed("entryPath","prefix", prefix); 123 notAllowed("entryPath","source", source); 124 getZip().setParam(new ZipParamFilter(filter,entryPath,recurse())); 125 }*/ 126 else 127 throw new ApplicationException("invalid attribute combination"); 128 129 130 131 132 return SKIP_BODY; 133 } 134 135 private boolean recurse() { 136 return recurse==null?true:recurse.booleanValue(); 137 } 138 139 140 private Zip getZip() throws ApplicationException { 141 if(zip!=null) return zip; 142 Tag parent=getParent(); 143 while(parent!=null && !(parent instanceof Zip)) { 144 parent=parent.getParent(); 145 } 146 147 if(parent instanceof Zip) { 148 return zip=(Zip)parent; 149 } 150 throw new ApplicationException("Wrong Context, tag ZipParam must be inside a Zip tag"); 151 } 152 153 154 private void notAllowed(String combi, String name, Object value) throws ApplicationException { 155 if(value!=null) 156 throw new ApplicationException("attribute ["+name+"] is not allowed in combination with attribute(s) ["+combi+"]"); 157 } 158 public void required(String combi, String name, Object value) throws ApplicationException { 159 if(value==null) 160 throw new ApplicationException("attribute ["+name+"] is required in combination with attribute(s) ["+combi+"]"); 161 } 162 163 @Override 164 public int doEndTag() { 165 return EVAL_PAGE; 166 } 167 }