001 package railo.runtime.tag; 002 003 import railo.runtime.PageContext; 004 import railo.runtime.exp.ApplicationException; 005 import railo.runtime.exp.PageException; 006 import railo.runtime.exp.SecurityException; 007 import railo.runtime.ext.tag.TagImpl; 008 import railo.runtime.functions.other.CreateObject; 009 import railo.runtime.net.proxy.ProxyData; 010 import railo.runtime.net.proxy.ProxyDataImpl; 011 import railo.runtime.security.SecurityManager; 012 013 /** 014 * Lets you call methods in COM, CORBA, and JAVA objects. 015 * 016 * 017 * 018 **/ 019 public final class ObjectTag extends TagImpl { 020 021 /* 022 * Component 023 * - name 024 * - component 025 TODO support full functonallity 026 Component 027 ------------- 028 name 029 component 030 031 Com 032 ---------- 033 type 034 action 035 class 036 name 037 context 038 server 039 040 Corba 041 -------------------- 042 type 043 context 044 class 045 name 046 locale 047 048 Java 049 -------------------- 050 type 051 action 052 class 053 name 054 055 Webservice 056 --------------------------- 057 webservice 058 name 059 060 all 061 ------------- 062 name 063 component 064 type 065 action 066 class 067 context 068 server 069 locale 070 webservice 071 */ 072 073 074 075 private String name; 076 private String component; 077 private String type=""; 078 private String action; 079 private String clazz; 080 private String context; 081 private String server; 082 private String locale; 083 private String webservice; 084 private String delimiters=","; 085 086 private String username; 087 private String password; 088 private String proxyServer; 089 private int proxyPort; 090 private String proxyUser; 091 private String proxyPassword; 092 093 /** 094 * @see javax.servlet.jsp.tagext.Tag#release() 095 */ 096 public void release() { 097 super.release(); 098 name=null; 099 component=null; 100 type=""; 101 action=null; 102 clazz=null; 103 context=null; 104 server=null; 105 locale=null; 106 webservice=null; 107 delimiters=","; 108 109 110 username=null; 111 password=null; 112 proxyServer=null; 113 proxyPort=-1; 114 proxyUser=null; 115 proxyPassword=null; 116 } 117 118 119 120 121 /** 122 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 123 */ 124 public int doStartTag() throws PageException { 125 126 if(component!=null) { 127 pageContext.setVariable(name,CreateObject.doComponent(pageContext,component)); 128 } 129 else if(type.equals("java")) { 130 checkAccess(pageContext,type); 131 checkClass(); 132 pageContext.setVariable(name,CreateObject.doJava(pageContext,clazz,context,delimiters)); 133 } 134 else if(type.equals("com")) { 135 checkAccess(pageContext,type); 136 checkClass(); 137 pageContext.setVariable(name,CreateObject.doCOM(pageContext,clazz)); 138 } 139 else if(type.equals("webservice")) { 140 checkAccess(pageContext,type); 141 checkWebservice(); 142 ProxyData proxy=null; 143 if(proxyServer!=null){ 144 proxy=new ProxyDataImpl(proxyServer,proxyPort,proxyUser,proxyPassword); 145 } 146 pageContext.setVariable(name,CreateObject.doWebService(pageContext,webservice,username,password,proxy)); 147 } 148 else { 149 if(type==null) throw new ApplicationException("to less attributes defined for tag object"); 150 throw new ApplicationException("wrong value for attribute type", 151 "types are com,java,corba and the only supported type (at the moment) are com,component,java"); 152 } 153 154 return SKIP_BODY; 155 } 156 157 private static void checkAccess(PageContext pc, String type) throws SecurityException { 158 if(pc.getConfig().getSecurityManager().getAccess(SecurityManager.TYPE_TAG_OBJECT)==SecurityManager.VALUE_NO) 159 throw new SecurityException("can't access tag [object] with type ["+type+"]", 160 "access is prohibited by security manager"); 161 162 } 163 164 /** 165 * check if attribute class is defined 166 * @throws ApplicationException 167 */ 168 private void checkClass() throws ApplicationException { 169 if(clazz==null)throw new ApplicationException("attribute class must be defined"); 170 } 171 172 /** 173 * check if attribute webservice is defined 174 * @throws ApplicationException 175 */ 176 private void checkWebservice() throws ApplicationException { 177 if(webservice==null)throw new ApplicationException("attribute webservice must be defined"); 178 } 179 180 181 /** 182 * @see javax.servlet.jsp.tagext.Tag#doEndTag() 183 */ 184 public int doEndTag() { 185 return EVAL_PAGE; 186 } 187 /** 188 * @param locale The locale to set. 189 */ 190 public void setLocale(String locale) { 191 this.locale = locale; 192 } 193 /** 194 * @param name The name to set. 195 */ 196 public void setName(String name) { 197 this.name = name; 198 } 199 /** 200 * @param server The server to set. 201 */ 202 public void setServer(String server) { 203 this.server = server; 204 } 205 /** 206 * @param type The type to set. 207 */ 208 public void setType(String type) { 209 this.type = type.toLowerCase().trim(); 210 } 211 /** 212 * @param webservice The webservice to set. 213 */ 214 public void setWebservice(String webservice) { 215 this.type="webservice"; 216 this.webservice = webservice; 217 } 218 /** 219 * @param action The action to set. 220 */ 221 public void setAction(String action) { 222 this.action = action; 223 } 224 /** 225 * @param clazz The clazz to set. 226 */ 227 public void setClass(String clazz) { 228 this.clazz = clazz; 229 } 230 /** 231 * @param component The component to set. 232 */ 233 public void setComponent(String component) { 234 this.component = component; 235 } 236 /** 237 * @param context The context to set. 238 */ 239 public void setContext(String context) { 240 this.context = context; 241 } 242 243 public void setPassword(String password) { 244 this.password = password; 245 } 246 247 public void setUsername(String username) { 248 this.username = username; 249 } 250 251 /** 252 * @param proxyServer the proxyServer to set 253 */ 254 public void setProxyServer(String proxyServer) { 255 this.proxyServer = proxyServer; 256 } 257 258 /** 259 * @param proxyPort the proxyPort to set 260 */ 261 public void setProxyPort(double proxyPort) { 262 this.proxyPort = (int)proxyPort; 263 } 264 265 /** 266 * @param proxyUser the proxyUser to set 267 */ 268 public void setProxyUser(String proxyUser) { 269 this.proxyUser = proxyUser; 270 } 271 272 /** 273 * @param proxyPassword the proxyPassword to set 274 */ 275 public void setProxyPassword(String proxyPassword) { 276 this.proxyPassword = proxyPassword; 277 } 278 279 /** 280 * @param delimiters the delimiters to set 281 */ 282 public void setDelimiters(String delimiters) { 283 this.delimiters = delimiters; 284 } 285 286 }