1 package org.sapia.util.xml.idefix; 2 3 4 import org.sapia.util.xml.Attribute; 7 import org.sapia.util.xml.Namespace; 8 9 import java.util.ArrayList ; 12 import java.util.List ; 13 14 15 26 public class BufferState { 27 31 32 private BufferState _theParent; 33 34 35 private Namespace _theElementNamespace; 36 37 38 private String _theElementName; 39 40 41 private List _theAttributes; 42 43 44 private boolean _isGettingMoreAttribute; 45 46 47 private StringBuffer _theContent; 48 49 50 private List _theDeclaredNamespaces; 51 52 53 private StringBuffer _theNestedXmlString; 54 55 56 private boolean _isStartElementGenerated; 57 58 62 68 public BufferState(BufferState aParent, Namespace aNamespace, 69 String anElementName) { 70 _theParent = aParent; 71 _theElementNamespace = aNamespace; 72 _theElementName = anElementName; 73 _theAttributes = new ArrayList (); 74 _isGettingMoreAttribute = true; 75 _theDeclaredNamespaces = new ArrayList (); 76 _isStartElementGenerated = false; 77 } 78 79 84 public BufferState getParent() { 85 return _theParent; 86 } 87 88 93 public Namespace getElementNamespace() { 94 return _theElementNamespace; 95 } 96 97 102 public String getElementName() { 103 return _theElementName; 104 } 105 106 112 public List getAttributes() { 113 return _theAttributes; 114 } 115 116 121 public boolean isGettingMoreAttribute() { 122 return _isGettingMoreAttribute; 123 } 124 125 130 public boolean isElementEmpty() { 131 return ((_theContent == null) || (_theContent.length() == 0)) && 132 ((_theNestedXmlString == null) || (_theNestedXmlString.length() == 0)); 133 } 134 135 140 public boolean isNestedXMLEmpty() { 141 return (_theNestedXmlString == null) || 142 (_theNestedXmlString.length() == 0); 143 } 144 145 150 public boolean isContentEmpty() { 151 return (_theContent == null) || (_theContent.length() == 0); 152 } 153 154 159 public StringBuffer getContent() { 160 if (_theContent == null) { 161 _theContent = new StringBuffer (); 162 } 163 164 return _theContent; 165 } 166 167 173 public List getDeclaredNamespaces() { 174 return _theDeclaredNamespaces; 175 } 176 177 182 public StringBuffer getNestedXmlString() { 183 if (_theNestedXmlString == null) { 184 _theNestedXmlString = new StringBuffer (); 185 } 186 187 return _theNestedXmlString; 188 } 189 190 195 public boolean isStartElementGenerated() { 196 return _isStartElementGenerated; 197 } 198 199 203 208 public void addAttribute(Attribute anAttribute) { 209 _theAttributes.add(anAttribute); 210 } 211 212 218 public void addAttribute(int anIndex, Attribute anAttribute) { 219 _theAttributes.add(anIndex, anAttribute); 220 } 221 222 227 public void removeAttribute(Attribute anAttribute) { 228 _theAttributes.remove(anAttribute); 229 } 230 231 234 public void clearAttributes() { 235 _theAttributes.clear(); 236 } 237 238 243 public void setIsGettingMoreAttribute(boolean isGettingMoreAttribute) { 244 _isGettingMoreAttribute = isGettingMoreAttribute; 245 } 246 247 252 public void addDeclaredNamespace(Namespace aNamespace) { 253 if (!isNamespaceDeclared(aNamespace)) { 254 _theDeclaredNamespaces.add(aNamespace); 255 } 256 } 257 258 265 protected boolean isNamespaceDeclared(Namespace aNamespace) { 266 if (_theDeclaredNamespaces.contains(aNamespace)) { 267 return true; 268 } else if (_theParent != null) { 269 return _theParent.isNamespaceDeclared(aNamespace); 270 } else { 271 return false; 272 } 273 } 274 275 280 public void removeDeclaredNamespace(Namespace aNamespace) { 281 _theDeclaredNamespaces.remove(aNamespace); 282 } 283 284 287 public void clearDelcaredNamespaces() { 288 _theDeclaredNamespaces.clear(); 289 } 290 291 297 public void setNestedXmlString(StringBuffer aBuffer) { 298 if ((_theNestedXmlString != null) && (aBuffer != _theNestedXmlString)) { 299 throw new IllegalStateException ( 300 "Could not overwrite the buffer of the nested XML"); 301 } 302 303 _theNestedXmlString = aBuffer; 304 } 305 306 311 public void setIsStartElementGenerated(boolean isStartElementGenerated) { 312 _isStartElementGenerated = isStartElementGenerated; 313 } 314 } 315 | Popular Tags |