1 38 39 package com.sun.xml.fastinfoset.stax.events; 40 41 import javax.xml.stream.events.Namespace; 42 import javax.xml.stream.events.XMLEvent; 43 import javax.xml.namespace.QName ; 44 import com.sun.xml.fastinfoset.util.Util; 45 46 public class NamespaceBase extends AttributeBase implements Namespace{ 47 static final String DEFAULT_NS_PREFIX = ""; 49 static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace"; 50 static final String XML_NS_PREFIX = "xml"; 51 static final String XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/"; 52 static final String XMLNS_ATTRIBUTE = "xmlns"; 53 static final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema"; 54 static final String W3C_XML_SCHEMA_INSTANCE_NS_URI = "http://www.w3.org/2001/XMLSchema-instance"; 55 56 private boolean defaultDeclaration = false; 58 59 60 public NamespaceBase(String namespaceURI) { 61 super(XMLNS_ATTRIBUTE, "", namespaceURI); 62 setEventType(NAMESPACE); 63 } 64 65 71 public NamespaceBase(String prefix, String namespaceURI){ 72 super(XMLNS_ATTRIBUTE, prefix, namespaceURI); 73 setEventType(NAMESPACE); 74 if (Util.isEmptyString(prefix)) { 75 defaultDeclaration=true; 76 } 77 } 78 79 void setPrefix(String prefix){ 80 if(prefix == null) 81 setName(new QName (XMLNS_ATTRIBUTE_NS_URI,DEFAULT_NS_PREFIX,XMLNS_ATTRIBUTE)); 82 else setName(new QName (XMLNS_ATTRIBUTE_NS_URI,prefix,XMLNS_ATTRIBUTE)); 84 } 85 86 public String getPrefix() { 87 if (defaultDeclaration) return ""; 88 return super.getLocalName(); 89 } 90 91 92 96 void setNamespaceURI(String uri) { 97 setValue(uri); 98 } 99 public String getNamespaceURI() { 100 return getValue(); 101 } 102 103 104 public boolean isNamespace(){ 105 return true; 106 } 107 108 public boolean isDefaultNamespaceDeclaration() { 109 return defaultDeclaration; 110 } 111 112 113 } 114 | Popular Tags |