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 XslTemplate extends XslNode implements XslTopNode { 39 private String _match; 40 private String _name; 41 private String _mode; 42 private double _priority = 0.0/0.0; 43 private String _as; 44 45 private String _macroName; 46 47 50 public void addAttribute(QName name, String value) 51 throws XslParseException 52 { 53 if (name.getName().equals("match")) 54 _match = value; 55 else if (name.getName().equals("name")) 56 _name = value; 57 else if (name.getName().equals("mode")) 58 _mode = value; 59 else if (name.getName().equals("priority")) 60 _priority = Double.parseDouble(value); 61 else if (name.getName().equals("as")) 62 _as = value; 63 else 64 super.addAttribute(name, value); 65 } 66 67 70 public void endAttributes() 71 throws XslParseException 72 { 73 if (_match == null && _name == null) 74 throw error(L.l("xsl:template needs a 'match' or a 'name' attribute.")); 75 76 if (_name != null) { 77 _macroName = ("_xsl_macro_" + _gen.toJavaIdentifier(_name) + "__" + 78 _gen.uniqueId()); 79 80 _gen.addMacro(_name, _macroName); 81 } 82 } 83 84 89 public void generate(JavaWriter out) 90 throws Exception 91 { 92 String fun = null; 93 94 if (_match != null) { 95 fun = _gen.createTemplatePattern(_name, parseMatch(_match), 96 _mode, _priority); 97 98 out.println(); 99 out.print("// '" + _match.replace('\n', ' ') + "'"); 100 101 if (_mode != null) { 102 _gen.addMode(_mode); 103 out.println(" mode '" + _mode + "'"); 104 } 105 else 106 out.println(); 107 108 out.printJavaString("// " + getFilename() + ":" + getStartLine()); 109 out.println(); 110 111 out.println("private void " + fun + 112 "(XslWriter out, Node inputNode, Env env)"); 113 out.println(" throws Exception"); 114 out.println("{"); 115 out.pushDepth(); 116 117 out.println("Object _xsl_tmp;"); 118 out.println("Node node = inputNode;"); 119 out.println("int _xsl_top = env.getTop();"); 120 121 boolean isRawText = _gen.getDisableOutputEscaping(); 122 if (isRawText) 123 out.println("boolean oldEscaping = out.disableEscaping(true);"); 124 else 125 out.println("boolean oldEscaping = out.disableEscaping(false);"); 126 127 String filename = getBaseURI(); 128 if (filename != null) { 129 int pos = _gen.addStylesheet(filename); 130 131 out.println("env.setStylesheetEnv(stylesheets[" + pos + "]);"); 132 } 133 134 _gen.setSelectDepth(0); 135 _gen.clearUnique(); 136 137 generateChildren(out); 138 145 146 150 151 out.println("out.disableEscaping(oldEscaping);"); 152 out.println("env.popToTop(_xsl_top);"); 153 out.popDepth(); 154 out.println("}"); 155 out.println(); 156 } 157 158 if (_name != null) { 159 out.println("void " + _macroName + 160 "(XslWriter out, Node inputNode, Env env)"); 161 out.println(" throws Exception"); 162 out.println("{"); 163 out.pushDepth(); 164 165 if (_match == null) { 166 out.println("Object _xsl_tmp;"); 167 out.println("Node node = inputNode;"); 168 generateChildren(out); 169 } 170 else { 171 out.println(fun + "(out, inputNode, env);"); 172 } 173 174 out.popDepth(); 175 out.println("}"); 176 } 177 } 178 } 179 | Popular Tags |