1 4 package gnu.xml; 5 import gnu.mapping.*; 6 import java.io.*; 7 8 9 10 public class XName extends Symbol implements Externalizable 11 { 12 NamespaceBinding namespaceNodes; 13 14 public XName () 15 { 16 } 17 18 public XName (Symbol symbol, NamespaceBinding namespaceNodes) 19 { 20 super(symbol.getNamespace(), symbol.getName()); 21 this.namespaceNodes = namespaceNodes; 22 } 23 24 27 public final NamespaceBinding getNamespaceNodes () { return namespaceNodes; } 28 public final void setNamespaceNodes (NamespaceBinding nodes) 29 { this.namespaceNodes = nodes; } 30 31 String lookupNamespaceURI (String prefix) 32 { 33 for (NamespaceBinding ns = namespaceNodes; ns != null; ns = ns.next) 34 { 35 if (prefix == ns.prefix) 36 return ns.uri; 37 } 38 return null; 39 } 40 41 public void writeExternal(ObjectOutput out) throws IOException 42 { 43 super.writeExternal(out); 44 out.writeObject(namespaceNodes); 45 } 46 47 public void readExternal(ObjectInput in) 48 throws IOException, ClassNotFoundException 49 { 50 super.readExternal(in); 51 namespaceNodes = (NamespaceBinding) in.readObject(); 52 } 53 54 public static boolean isNameStart(int ch) 55 { 56 57 59 return ch >= 0x10000 || Character.isLetter((char) ch) || ch == '_'; 60 61 } 62 63 public static boolean isNamePart(int ch) 64 { 65 66 68 return ch >= 0x10000 || Character.isUnicodeIdentifierPart((char) ch) 69 || ch == '-' || ch == '.'; 70 71 } 72 73 public static boolean isName (String value) 74 { 75 return isName(value, false); 76 } 77 78 public static boolean isName (String value, boolean prohibitColon) 79 { 80 int len = value.length(); 81 if (len == 0) 82 return false; 83 for (int i = 0; i < len; ) 84 { 85 boolean first = i == 0; 86 int ch = value.charAt(i++); 87 if (ch >= 0xD800 && ch < 0xDC00 && i < len) 88 ch = (ch - 0xD800) * 0x400 + (value.charAt(i++) - 0xDC00) + 0x10000; 89 if (! (first ? XName.isNameStart(ch) : XName.isNamePart(ch))) 90 return false; 91 } 92 return true; 93 } 94 } 95 | Popular Tags |