1 28 29 package com.caucho.xml; 30 31 import com.caucho.util.CharBuffer; 32 33 import org.xml.sax.Attributes ; 34 35 class QAttributes implements Attributes { 36 QName []names = new QName[32]; 37 String []values = new String [32]; 38 int size; 39 40 void clear() 41 { 42 size = 0; 43 } 44 45 void add(QName name, String value) 46 { 47 if (size == names.length) { 48 QName []newNames = new QName[2 * names.length]; 49 String []newValues = new String [2 * names.length]; 50 System.arraycopy(names, 0, newNames, 0, names.length); 51 System.arraycopy(values, 0, newValues, 0, names.length); 52 names = newNames; 53 values = newValues; 54 } 55 56 names[size] = name; 57 values[size] = value; 58 size++; 59 } 60 61 public int getLength() 62 { 63 return size; 64 } 65 66 public QName getName(int i) 67 { 68 return names[i]; 69 } 70 71 public String getQName(int i) 72 { 73 return names[i].getName(); 74 } 75 76 public String getURI(int i) 77 { 78 String uri = names[i].getNamespaceURI(); 79 80 if (uri != null) 81 return uri; 82 else 83 return ""; 84 } 85 86 public String getLocalName(int i) 87 { 88 String name = names[i].getLocalName(); 89 90 if (name != null) 91 return name; 92 else 93 return ""; 94 } 95 96 public String getValue(int i) 97 { 98 return values[i]; 99 } 100 101 public String getValue(String qName) 102 { 103 for (int i = 0; i < size; i++) { 104 if (qName.equals(names[i].getName())) 105 return values[i]; 106 } 107 108 return null; 109 } 110 111 public String getValue(String uri, String localName) 112 { 113 for (int i = 0; i < size; i++) { 114 String testURI = names[i].getNamespaceURI(); 115 116 if (testURI == null) 117 testURI = ""; 118 119 if (uri.equals(testURI) && localName.equals(names[i].getLocalName())) 120 return values[i]; 121 } 122 123 return null; 124 } 125 126 public int getIndex(String qName) 127 { 128 for (int i = 0; i < size; i++) { 129 if (qName.equals(names[i].getName())) 130 return i; 131 } 132 133 return -1; 134 } 135 136 public int getIndex(String uri, String localName) 137 { 138 for (int i = 0; i < size; i++) { 139 if (uri.equals(names[i].getNamespaceURI()) && 140 localName.equals(names[i].getLocalName())) 141 return i; 142 } 143 144 return -1; 145 } 146 147 public String getType(int i) 148 { 149 return "CDATA"; 150 } 151 152 public String getType(String uri, String localName) 153 { 154 return "CDATA"; 155 } 156 157 public String getType(String qName) 158 { 159 return "CDATA"; 160 } 161 162 public String toString() 163 { 164 CharBuffer cb = CharBuffer.allocate(); 165 cb.append("[QAttributes"); 166 for (int i = 0; i < size; i++) { 167 cb.append(" "); 168 cb.append(names[i]); 169 cb.append("=\""); 170 cb.append(values[i]); 171 cb.append("\""); 172 } 173 cb.append("]"); 174 return cb.close(); 175 } 176 } 177 | Popular Tags |