1 28 29 package com.caucho.xsl.java; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.xml.QName; 33 34 37 public class XslAttributeNode extends XslNode { 38 private QName _name; 39 private String _value; 40 41 public XslAttributeNode(QName name, String value) 42 { 43 _name = name; 44 _value = value; 45 } 46 47 52 public void generate(JavaWriter out) 53 throws Exception 54 { 55 57 String namespace = _name.getNamespaceURI(); 58 String prefix = _name.getPrefix(); 59 String local = _name.getLocalName(); 60 String name = _name.getName(); 61 62 String []postPrefix = _gen.getNamespaceAlias(namespace); 63 64 if (postPrefix != null) { 65 prefix = postPrefix[0]; 66 namespace = postPrefix[1]; 67 if (prefix == null || prefix.equals("")) 68 name = local; 69 else 70 name = prefix + ":" + local; 71 } 72 76 77 if (name.equals("xmlns")) { 78 out.print("out.bindNamespace(null, \""); 79 out.printJavaString(_value); 80 out.println("\");"); 81 } 82 else if (name.startsWith("xmlns:")) { 83 out.print("out.bindNamespace(\"" + name.substring(6) + "\", \""); 84 out.printJavaString(_value); 85 out.println("\");"); 86 } 87 else if (namespace != null && _value.indexOf('{') < 0) { 88 out.print("out.attribute("); 89 out.print(namespace == null ? "null" : ("\"" + namespace + "\"")); 90 out.print(prefix == null ? ", null" : (", \"" + prefix + "\"")); 91 out.print(local == null ? ", null" : (", \"" + local + "\"")); 92 out.print(name == null ? ", null" : (", \"" + name + "\"")); 93 out.print(", "); 94 if (_value == null) 95 out.print("null"); 96 else { 97 out.print("\""); 98 out.printJavaString(_value); 99 out.print("\""); 100 } 101 out.println(");"); 102 } 103 else if (namespace != null) { 104 out.print("out.attribute("); 105 out.print(namespace == null ? "null" : ("\"" + namespace + "\"")); 106 out.print(prefix == null ? ", null" : (", \"" + prefix + "\"")); 107 out.print(local == null ? ", null" : (", \"" + local + "\"")); 108 out.print(name == null ? ", null" : (", \"" + name + "\"")); 109 out.print(","); 110 generateString(out, _value, '+'); 111 out.println(");"); 112 } 113 else if (_value.indexOf('{') < 0) { 114 out.print("out.attribute("); 115 out.print(name == null ? "null" : ("\"" + name + "\"")); 116 out.print(", "); 117 if (_value == null) 118 out.print("null"); 119 else { 120 out.print("\""); 121 out.printJavaString(_value); 122 out.print("\""); 123 } 124 out.println(");"); 125 } 126 else { 127 out.print("out.attribute("); 128 out.print(name == null ? "null" : ("\"" + name + "\"")); 129 out.print(", "); 130 generateString(out, _value, '+'); 131 out.println(");"); 132 } 133 } 134 135 public String toString() 136 { 137 return "XslAttributeNode[" + _name + "," + _value + "]"; 138 } 139 } 140 | Popular Tags |