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.JavaGenerator; 34 import com.caucho.xsl.XslParseException; 35 36 39 public class XslElementNode extends XslNode { 40 private static final QName _useAttributeSets = 41 new QName("xsl", "use-attribute-sets", JavaGenerator.XSLNS); 42 43 private QName _name; 44 45 public XslElementNode(QName name) 46 { 47 _name = name; 48 } 49 50 53 public String getTagName() 54 { 55 return _name.getName(); 56 } 57 58 61 public void addAttribute(QName name, String value) 62 throws XslParseException 63 { 64 if (_useAttributeSets.equals(name)) { 65 XslUseAttributeSets attr = new XslUseAttributeSets(value); 66 67 attr.setGenerator(_gen); 68 69 addChild(attr); 70 } 71 else if (name.getName().startsWith("xmlns")) { 72 super.addAttribute(name, value); 73 74 if (! JavaGenerator.XSLNS.equals(value) && 75 ! JavaGenerator.XTPNS.equals(value)) { 76 XslNamespaceNode attr = new XslNamespaceNode(name, value); 77 78 attr.setParent(this); 79 attr.setGenerator(_gen); 80 81 addChild(attr); 82 } 83 } 84 else if (JavaGenerator.XSLNS.equals(name.getNamespaceURI())) { 85 } 86 else if (JavaGenerator.XTPNS.equals(name.getNamespaceURI())) { 87 } 88 else { 89 XslAttributeNode attr = new XslAttributeNode(name, value); 90 91 attr.setParent(this); 92 attr.setGenerator(_gen); 93 94 addChild(attr); 95 } 96 } 97 98 103 public void generate(JavaWriter out) 104 throws Exception 105 { 106 String namespace = _name.getNamespaceURI(); 107 String prefix = _name.getPrefix(); 108 String local = _name.getLocalName(); 109 String name = _name.getName(); 110 111 _gen.printLocation(_systemId, _filename, _startLine); 112 113 String []postPrefix = _gen.getNamespaceAlias(namespace); 114 115 if (postPrefix != null) { 116 prefix = postPrefix[0]; 117 namespace = postPrefix[1]; 118 if (prefix == null || prefix.equals("")) 119 name = local; 120 else 121 name = prefix + ":" + local; 122 } 123 127 128 out.print("out.pushElement("); 130 out.print(namespace == null ? "\"\"" : ("\"" + namespace + "\"")); 131 out.print(prefix == null ? ", null" : (", \"" + prefix + "\"")); 132 out.print(local == null ? ", null" : (", \"" + local + "\"")); 133 out.print(name == null ? ", null" : (", \"" + name + "\"")); 134 out.println(");"); 135 143 144 generateChildren(out); 145 146 out.println("out.popElement();"); 147 } 148 } 149 | Popular Tags |