1 package org.ejen; 22 23 import java.util.Properties ; 24 import javax.xml.transform.dom.DOMSource ; 25 import org.apache.xpath.XPathAPI; 26 import org.apache.xalan.transformer.TransformerImpl; 27 28 73 public class EjenParamNode extends EjenChildNode { 74 protected String _name = null; 75 protected String _select = null; 76 protected String _literal = null; 77 78 82 public String nodeName() { 83 return "param"; 84 } 85 86 90 public Properties getAttributes() { 91 Properties attrs = super.getAttributes(); 92 93 if (_name != null) { 94 attrs.setProperty("name", _name); 95 } 96 if (_select != null) { 97 attrs.setProperty("select", _select); 98 } 99 if (_literal != null) { 100 attrs.setProperty("literal", _literal); 101 } 102 return attrs; 103 } 104 105 109 public void setName(String name) { 110 _name = name; 111 } 112 113 118 public void setSelect(String select) { 119 _select = select; 120 } 121 122 127 public void setLiteral(String literal) { 128 _literal = literal; 129 } 130 131 136 public void check() { 137 super.check(); 138 if (_name == null) { 139 throw new EjenException(this, "No 'name' attribute"); 140 } 141 if (_select == null && _literal == null) { 142 throw new EjenException(this, 143 "Neither 'select' nor 'literal' attribute"); 144 } 145 if (_select != null && _literal != null) { 146 throw new EjenException(this, 147 "Cannot choose between 'select' and 'literal' attributes"); 148 } 149 } 150 151 155 public void process() { 156 super.process(); 157 try { 158 TransformerImpl ti = (TransformerImpl) (getFromContext(CTX_TRANSFORMER_IMPL)); 159 160 if (ti == null) { 161 throw new EjenException(this, 162 "no '" + CTX_TRANSFORMER_IMPL + "' in context"); 163 } 164 String name = evaluateAVT(_name); 165 166 if (_select != null) { 167 DOMSource src = (DOMSource ) (getFromGlobalContext(CTX_DOM_SOURCE)); 168 169 if (src == null) { 170 throw new EjenException(this, 171 "no '" + CTX_DOM_SOURCE + "' in global context"); 172 } 173 ti.setParameter(name, 174 XPathAPI.selectNodeList(src.getNode(), 175 evaluateAVT(ti, _select))); 176 } else { 177 ti.setParameter(name, _literal); 178 } 179 } catch (EjenException e) { 180 throw e; 181 } catch (Exception e) { 182 throw new EjenException(this, "bad param", e); 183 } 184 } 185 } 186 | Popular Tags |