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 @Override 094 public void release() { 095 super.release(); 096 name=null; 097 component=null; 098 type=""; 099 action=null; 100 clazz=null; 101 context=null; 102 server=null; 103 locale=null; 104 webservice=null; 105 delimiters=","; 106 107 108 username=null; 109 password=null; 110 proxyServer=null; 111 proxyPort=-1; 112 proxyUser=null; 113 proxyPassword=null; 114 } 115 116 117 118 119 @Override 120 public int doStartTag() throws PageException { 121 122 if(component!=null) { 123 pageContext.setVariable(name,CreateObject.doComponent(pageContext,component)); 124 } 125 else if(type.equals("java")) { 126 checkAccess(pageContext,type); 127 checkClass(); 128 pageContext.setVariable(name,CreateObject.doJava(pageContext,clazz,context,delimiters)); 129 } 130 else if(type.equals("com")) { 131 checkAccess(pageContext,type); 132 checkClass(); 133 pageContext.setVariable(name,CreateObject.doCOM(pageContext,clazz)); 134 } 135 else if(type.equals("webservice")) { 136 checkAccess(pageContext,type); 137 checkWebservice(); 138 ProxyData proxy=null; 139 if(proxyServer!=null){ 140 proxy=new ProxyDataImpl(proxyServer,proxyPort,proxyUser,proxyPassword); 141 } 142 pageContext.setVariable(name,CreateObject.doWebService(pageContext,webservice,username,password,proxy)); 143 } 144 else { 145 if(type==null) throw new ApplicationException("to less attributes defined for tag object"); 146 throw new ApplicationException("wrong value for attribute type", 147 "types are com,java,corba and the only supported type (at the moment) are com,component,java"); 148 } 149 150 return SKIP_BODY; 151 } 152 153 private static void checkAccess(PageContext pc, String type) throws SecurityException { 154 if(pc.getConfig().getSecurityManager().getAccess(SecurityManager.TYPE_TAG_OBJECT)==SecurityManager.VALUE_NO) 155 throw new SecurityException("can't access tag [object] with type ["+type+"]", 156 "access is prohibited by security manager"); 157 158 } 159 160 /** 161 * check if attribute class is defined 162 * @throws ApplicationException 163 */ 164 private void checkClass() throws ApplicationException { 165 if(clazz==null)throw new ApplicationException("attribute class must be defined"); 166 } 167 168 /** 169 * check if attribute webservice is defined 170 * @throws ApplicationException 171 */ 172 private void checkWebservice() throws ApplicationException { 173 if(webservice==null)throw new ApplicationException("attribute webservice must be defined"); 174 } 175 176 177 @Override 178 public int doEndTag() { 179 return EVAL_PAGE; 180 } 181 /** 182 * @param locale The locale to set. 183 */ 184 public void setLocale(String locale) { 185 this.locale = locale; 186 } 187 /** 188 * @param name The name to set. 189 */ 190 public void setName(String name) { 191 this.name = name; 192 } 193 /** 194 * @param server The server to set. 195 */ 196 public void setServer(String server) { 197 this.server = server; 198 } 199 /** 200 * @param type The type to set. 201 */ 202 public void setType(String type) { 203 this.type = type.toLowerCase().trim(); 204 } 205 /** 206 * @param webservice The webservice to set. 207 */ 208 public void setWebservice(String webservice) { 209 this.type="webservice"; 210 this.webservice = webservice; 211 } 212 /** 213 * @param action The action to set. 214 */ 215 public void setAction(String action) { 216 this.action = action; 217 } 218 /** 219 * @param clazz The clazz to set. 220 */ 221 public void setClass(String clazz) { 222 this.clazz = clazz; 223 } 224 /** 225 * @param component The component to set. 226 */ 227 public void setComponent(String component) { 228 this.component = component; 229 } 230 /** 231 * @param context The context to set. 232 */ 233 public void setContext(String context) { 234 this.context = context; 235 } 236 237 public void setPassword(String password) { 238 this.password = password; 239 } 240 241 public void setUsername(String username) { 242 this.username = username; 243 } 244 245 /** 246 * @param proxyServer the proxyServer to set 247 */ 248 public void setProxyServer(String proxyServer) { 249 this.proxyServer = proxyServer; 250 } 251 252 /** 253 * @param proxyPort the proxyPort to set 254 */ 255 public void setProxyPort(double proxyPort) { 256 this.proxyPort = (int)proxyPort; 257 } 258 259 /** 260 * @param proxyUser the proxyUser to set 261 */ 262 public void setProxyUser(String proxyUser) { 263 this.proxyUser = proxyUser; 264 } 265 266 /** 267 * @param proxyPassword the proxyPassword to set 268 */ 269 public void setProxyPassword(String proxyPassword) { 270 this.proxyPassword = proxyPassword; 271 } 272 273 /** 274 * @param delimiters the delimiters to set 275 */ 276 public void setDelimiters(String delimiters) { 277 this.delimiters = delimiters; 278 } 279 280 }