1 28 29 package com.caucho.xsl.java; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.xml.QName; 33 import com.caucho.xsl.XslParseException; 34 35 38 public class XslParam extends XslNode implements XslTopNode { 39 private String _name; 40 private String _select; 41 private String _as; 42 private String _require; 43 44 private boolean _isGlobal; 45 46 49 public String getTagName() 50 { 51 return "xsl:param"; 52 } 53 54 57 public String getName() 58 { 59 return _name; 60 } 61 62 65 public void setParent(XslNode parent) 66 { 67 super.setParent(parent); 68 69 if (parent instanceof XslStylesheet) 70 _isGlobal = true; 71 } 72 73 76 public void setGlobal(boolean isGlobal) 77 { 78 _isGlobal = true; 79 } 80 81 84 public void addAttribute(QName name, String value) 85 throws XslParseException 86 { 87 if (name.getName().equals("name")) 88 _name = value; 89 else if (name.getName().equals("select")) 90 _select = value; 91 else if (name.getName().equals("as")) 92 _as = value; 93 else if (name.getName().equals("require")) 94 _require = value; 95 else 96 super.addAttribute(name, value); 97 } 98 99 102 public void endAttributes() 103 throws XslParseException 104 { 105 if (_name == null) 106 throw error(L.l("xsl:param needs a 'name' attribute.")); 107 108 if (_isGlobal) 109 _gen.addGlobalParameter(_name); 110 } 111 112 117 public void generate(JavaWriter out) 118 throws Exception 119 { 120 125 126 if (_isGlobal) { 127 out.println("if (out.getParameter(\"" + _name + "\") != null)"); 128 out.println(" env.setGlobal(\"" + _name + "\", out.getParameter(\"" + _name + "\"));"); 129 out.println("else {"); 130 out.pushDepth(); 131 } 132 133 if (_select != null) { 134 if (_isGlobal) { 135 out.print("env.setGlobal(\"" + _name + "\", "); 136 out.println("_exprs[" + addExpr(_select) + "].evalObject(node, env));"); 137 } 138 else { 139 out.print("_exprs[" + addExpr(_select) + "]"); 140 out.println(".addParam(env, \"" + _name + "\", " + 141 "node, env);"); 142 } 143 } 144 else if (hasChildren()) { 145 out.println("if (env.getVar(\"" + _name + "\") == null) {"); 146 out.pushDepth(); 147 148 String id = "frag" + _gen.generateId(); 149 150 out.println("XMLWriter " + id + " = out.pushFragment();"); 151 152 generateChildren(out); 153 154 if (_isGlobal) 155 out.print("env.setGlobal(\""); 156 else 157 out.print("env.addVar(\""); 158 159 out.printJavaString(_name); 160 out.println("\", out.popFragment(" + id + "));"); 161 162 out.popDepth(); 163 out.println("}"); 164 } 165 166 if (_isGlobal) { 167 out.popDepth(); 168 out.println("}"); 169 } 170 } 171 } 172 | Popular Tags |