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 XslNamespaceNode extends XslNode { 38 private QName _name; 39 private String _value; 40 41 public XslNamespaceNode(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 if (name.equals("xmlns")) { 63 out.print("out.bindNamespace(null, \""); 64 out.printJavaString(_value); 65 out.println("\");"); 66 } 67 else if (name.startsWith("xmlns:")) { 68 out.print("out.bindNamespace(\"" + name.substring(6) + "\", \""); 69 out.printJavaString(_value); 70 out.println("\");"); 71 } 72 else if (namespace != null && _value.indexOf('{') < 0) { 73 out.print("out.attribute("); 74 out.print(namespace == null ? "null" : ("\"" + namespace + "\"")); 75 out.print(prefix == null ? ", null" : (", \"" + prefix + "\"")); 76 out.print(local == null ? ", null" : (", \"" + local + "\"")); 77 out.print(name == null ? ", null" : (", \"" + name + "\"")); 78 out.print(", "); 79 if (_value == null) 80 out.print("null"); 81 else { 82 out.print("\""); 83 out.printJavaString(_value); 84 out.print("\""); 85 } 86 out.println(");"); 87 } 88 else if (namespace != null) { 89 out.print("out.pushAttribute("); 90 out.print(namespace == null ? "null" : ("\"" + namespace + "\"")); 91 out.print(prefix == null ? ", null" : (", \"" + prefix + "\"")); 92 out.print(local == null ? ", null" : (", \"" + local + "\"")); 93 out.print(name == null ? ", null" : (", \"" + name + "\"")); 94 out.println(");"); 95 printAttributeValue(out, _value); 96 out.println("out.popAttribute();"); 97 } 98 else if (_value.indexOf('{') < 0) { 99 out.print("out.attribute("); 100 out.print(name == null ? "null" : ("\"" + name + "\"")); 101 out.print(", "); 102 if (_value == null) 103 out.print("null"); 104 else { 105 out.print("\""); 106 out.printJavaString(_value); 107 out.print("\""); 108 } 109 out.println(");"); 110 } 111 else { 112 out.print("out.pushAttribute("); 113 out.print(name == null ? "null" : ("\"" + name + "\"")); 114 out.println(");"); 115 printAttributeValue(out, _value); 116 out.println("out.popAttribute();"); 117 } 118 } 119 } 120 | Popular Tags |