1 package net.sf.saxon.om; 2 3 import net.sf.saxon.Err; 4 5 11 12 public abstract class Name { 13 14 17 18 private Name() { } 19 20 27 28 public static final boolean isQName(String name) { 29 int colon = name.indexOf(':'); 30 if (colon<0) return XMLChar.isValidNCName(name); 31 if (colon==0 || colon==name.length()-1) return false; 32 if (!XMLChar.isValidNCName(name.substring(0, colon))) return false; 33 if (!XMLChar.isValidNCName(name.substring(colon+1))) return false; 34 return true; 35 } 36 37 44 45 public static final String getPrefix(String qname) { 46 int colon = qname.indexOf(':'); 47 if (colon<0) { 48 return ""; 49 } 50 return qname.substring(0, colon); 51 } 52 53 54 62 63 public static final String [] getQNameParts(CharSequence qname) throws QNameException { 64 String [] parts = new String [2]; 65 int colon = -1; 66 int len = qname.length(); 67 for (int i=0; i<len; i++) { 68 if (qname.charAt(i)==':') { 69 colon = i; 70 break; 71 } 72 } 73 if (colon<0) { 74 parts[0] = ""; 75 parts[1] = qname.toString(); 76 if (!XMLChar.isValidNCName(qname)) { 77 throw new QNameException("Invalid QName " + Err.wrap(qname)); 78 } 79 } else { 80 if (colon==0) { 81 throw new QNameException("QName cannot start with colon: " + Err.wrap(qname)); 82 } 83 if (colon==len-1) { 84 throw new QNameException("QName cannot end with colon: " + Err.wrap(qname)); 85 } 86 parts[0] = qname.subSequence(0, colon).toString(); 87 parts[1] = qname.subSequence(colon+1, len).toString(); 88 if (!XMLChar.isValidNCName(parts[1])) { 94 throw new QNameException("Invalid QName local part " + Err.wrap(parts[1])); 95 } 96 } 97 return parts; 98 } 99 100 } 101 102 | Popular Tags |