1 38 package com.gargoylesoftware.htmlunit.jelly; 39 40 import org.apache.commons.jelly.JellyTagException; 41 import org.apache.commons.jelly.MissingAttributeException; 42 import org.apache.commons.jelly.XMLOutput; 43 import org.apache.commons.jelly.TagSupport; 44 45 import org.jaxen.JaxenException; 46 import org.jaxen.VariableContext; 47 import org.jaxen.UnresolvableException; 48 49 import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath; 50 51 65 public class SelectTag extends TagSupport implements VariableContext { 66 67 68 private String var_; 69 70 71 private String xpath_; 72 73 74 public SelectTag() { 75 } 76 77 83 public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException { 84 if (var_ == null) { 85 throw new MissingAttributeException( "var" ); 86 } 87 if (xpath_ == null) { 88 throw new MissingAttributeException( "xpath" ); 89 } 90 91 Object value = null; 92 try { 93 final HtmlUnitXPath xpath = new HtmlUnitXPath(xpath_); 94 xpath.setVariableContext(this); 95 value = xpath.evaluate(null); 96 } 97 catch (final JaxenException e) { 98 throw new JellyTagException(e); 99 } 100 101 context.setVariable(var_, value); 102 } 103 104 107 public void setVar(final String var) { 108 var_ = var; 109 } 110 111 114 public void setXpath(final String xpath) { 115 xpath_ = xpath; 116 } 117 118 126 public Object getVariableValue(final String namespaceURI, final String prefix, final String localName) 127 throws UnresolvableException { 128 129 final Object var = context.getVariable(localName); 130 if(var == null) { 131 throw new UnresolvableException(localName); 132 } 133 return var; 134 } 135 } 136 | Popular Tags |