| Home >> All >> org >> milligan >> eccles >> tags >> [ web Javadoc ] |
Source code: org/milligan/eccles/tags/web/OpenUrlTag.java
1 package org.milligan.eccles.tags.web; 2 3 import org.milligan.eccles.*; 4 import com.meterware.httpunit.WebConversation; 5 import com.meterware.httpunit.WebResponse; 6 import com.meterware.httpunit.WebRequest; 7 import com.meterware.httpunit.GetMethodWebRequest; 8 import org.xml.sax.SAXException; 9 import org.milligan.eccles.httpunit.ResponseWrapper; 10 11 12 /** 13 * Opens a Url on a web conversation 14 * @author Ian Tomey 15 * 16 */ 17 18 public class OpenUrlTag extends Tag { 19 20 public static final String RESPONSE_PROPERTY="response"; 21 22 public OpenUrlTag() { 23 } 24 25 private String url; 26 private String conversation=WebConversationTag.CONVERSATION_PROPERTY; 27 private String property=RESPONSE_PROPERTY; 28 29 public String getTagName() { 30 return "open-url"; 31 } 32 public void setUrl(String url) { 33 this.url = url; 34 } 35 public String getUrl() { 36 return url; 37 } 38 public void setConversation(String conversation) { 39 this.conversation = conversation; 40 } 41 public String getConversation() { 42 return conversation; 43 } 44 public void setProperty(String property) { 45 this.property = property; 46 } 47 public String getProperty() { 48 return property; 49 } 50 51 /** 52 * 53 * @param state 54 * @return 55 * @throws EcclesException 56 */ 57 public EcclesReturnValue doStartTag(RunState state) throws org.milligan.eccles.EcclesException { 58 59 // get the conversation 60 String evalConversation = (String) state.evaluate(conversation,String.class); 61 WebConversation wc = (WebConversation) state.getProperty( evalConversation ); 62 if (wc==null) 63 throw new EcclesException( state, "Unable to find the web-conversation named: "+evalConversation ); 64 65 String evalUrl = (String) state.evaluate(url,String.class); 66 WebRequest req = new GetMethodWebRequest( evalUrl ); 67 68 try { 69 WebResponse wr = wc.getResponse(req); 70 state.setParentProperty(property, new ResponseWrapper(wr) ); 71 } catch ( SAXException e ) { 72 throw new EcclesException( state,"Error parsing page from URL: " + evalUrl, e ); 73 } catch ( Exception e ) { 74 throw new EcclesException( state,"Error opening URL: " + evalUrl, e ); 75 } 76 77 return SKIP_CHILDREN; 78 } 79 80 }