649 * URI part (or empty string), the local part, 650 * and the raw name, all internalized, or null 651 * if there is an undeclared prefix. 652 * @see org.xml.sax.helpers.NamespaceSupport#processName 653 */ 654 String [] processName (String qName, boolean isAttribute) 655 { 656 String name[]; 657 Map<String, String[]> table; 658 659 // Select the appropriate table. 660 if (isAttribute) { 661 table = attributeNameTable; 662 } else { 663 table = elementNameTable; 664 } 665 666 // Start by looking in the cache, and 667 // return immediately if the name 668 // is already known in this content 669 name = (String[])table.get(qName); 670 if (name != null) { 671 return name; 672 } 673 674 // We haven't seen this name in this 675 // context before. Maybe in the parent 676 // context, but we can't assume prefix 677 // bindings are the same. 678 name = new String[3]; 679 name[2] = qName.intern(); 680 int index = qName.indexOf(':'); 681 682 683 // No prefix. 684 if (index == -1) { 685 if (isAttribute) { 686 if (qName == "xmlns" && namespaceDeclUris) 687 name[0] = NSDECL; 688 else 689 name[0] = ""; 690 } else if (defaultNS == null) { 691 name[0] = ""; 692 } else { 693 name[0] = defaultNS; 694 } 695 name[1] = name[2]; 696 } 697 698 // Prefix 699 else { 700 String prefix = qName.substring(0, index); 701 String local = qName.substring(index+1); 702 String uri; 703 if ("".equals(prefix)) { 704 uri = defaultNS; 705 } else { 706 uri = (String)prefixTable.get(prefix); 707 } 708 if (uri == null 709 || (!isAttribute && "xmlns".equals (prefix))) { 710 return null; 711 } 712 name[0] = uri; 713 name[1] = local.intern(); 714 } 715 716 // Save in the cache for future use. 717 // (Could be shared with parent context...) 718 table.put(name[2], name); 719 return name; 720 } 721 722 723 /** 724 * Look up the URI associated with a prefix in this context. 725 * 726 * @param prefix The prefix to look up. 727 * @return The associated Namespace URI, or null if none is 728 * declared. 729 * @see org.xml.sax.helpers.NamespaceSupport#getURI 730 */ 731 String getURI (String prefix) 732 { 733 if ("".equals(prefix)) { 734 return defaultNS; 735 } else if (prefixTable == null) { 736 return null; 737 } else { 738 return (String)prefixTable.get(prefix); 739 } 740 } 741 742 743 /** 744 * Look up one of the prefixes associated with a URI in this context. 745 * 746 * <p>Since many prefixes may be mapped to the same URI, 747 * the return value may be unreliable.</p> 748 * 749 * @param uri The URI to look up. 750 * @return The associated prefix, or null if none is declared. 751 * @see org.xml.sax.helpers.NamespaceSupport#getPrefix 752 */ 753 String getPrefix (String uri) 754 { 755 if (uriTable == null) { 756 return null; 757 } else { 758 return (String)uriTable.get(uri); 759 } 760 } 761 762 763 /** 764 * Return an enumeration of prefixes declared in this context. 765 * 766 * @return An enumeration of prefixes (possibly empty). 767 * @see org.xml.sax.helpers.NamespaceSupport#getDeclaredPrefixes 768 */ 769 Enumeration<String> getDeclaredPrefixes () 770 { 771 if (declarations == null) { 772 return EMPTY_ENUMERATION; 773 } else { 774 return Collections.enumeration(declarations); 775 } 776 } 777 778 /** | 649 * URI part (or empty string), the local part, 650 * and the raw name, all internalized, or null 651 * if there is an undeclared prefix. 652 * @see org.xml.sax.helpers.NamespaceSupport#processName 653 */ 654 String [] processName (String qName, boolean isAttribute) 655 { 656 String name[]; 657 Map<String, String[]> table; 658 659 // Select the appropriate table. 660 if (isAttribute) { 661 table = attributeNameTable; 662 } else { 663 table = elementNameTable; 664 } 665 666 // Start by looking in the cache, and 667 // return immediately if the name 668 // is already known in this content 669 name = table.get(qName); 670 if (name != null) { 671 return name; 672 } 673 674 // We haven't seen this name in this 675 // context before. Maybe in the parent 676 // context, but we can't assume prefix 677 // bindings are the same. 678 name = new String[3]; 679 name[2] = qName.intern(); 680 int index = qName.indexOf(':'); 681 682 683 // No prefix. 684 if (index == -1) { 685 if (isAttribute) { 686 if (qName == "xmlns" && namespaceDeclUris) 687 name[0] = NSDECL; 688 else 689 name[0] = ""; 690 } else if (defaultNS == null) { 691 name[0] = ""; 692 } else { 693 name[0] = defaultNS; 694 } 695 name[1] = name[2]; 696 } 697 698 // Prefix 699 else { 700 String prefix = qName.substring(0, index); 701 String local = qName.substring(index+1); 702 String uri; 703 if ("".equals(prefix)) { 704 uri = defaultNS; 705 } else { 706 uri = prefixTable.get(prefix); 707 } 708 if (uri == null 709 || (!isAttribute && "xmlns".equals (prefix))) { 710 return null; 711 } 712 name[0] = uri; 713 name[1] = local.intern(); 714 } 715 716 // Save in the cache for future use. 717 // (Could be shared with parent context...) 718 table.put(name[2], name); 719 return name; 720 } 721 722 723 /** 724 * Look up the URI associated with a prefix in this context. 725 * 726 * @param prefix The prefix to look up. 727 * @return The associated Namespace URI, or null if none is 728 * declared. 729 * @see org.xml.sax.helpers.NamespaceSupport#getURI 730 */ 731 String getURI (String prefix) 732 { 733 if ("".equals(prefix)) { 734 return defaultNS; 735 } else if (prefixTable == null) { 736 return null; 737 } else { 738 return prefixTable.get(prefix); 739 } 740 } 741 742 743 /** 744 * Look up one of the prefixes associated with a URI in this context. 745 * 746 * <p>Since many prefixes may be mapped to the same URI, 747 * the return value may be unreliable.</p> 748 * 749 * @param uri The URI to look up. 750 * @return The associated prefix, or null if none is declared. 751 * @see org.xml.sax.helpers.NamespaceSupport#getPrefix 752 */ 753 String getPrefix (String uri) 754 { 755 if (uriTable == null) { 756 return null; 757 } else { 758 return uriTable.get(uri); 759 } 760 } 761 762 763 /** 764 * Return an enumeration of prefixes declared in this context. 765 * 766 * @return An enumeration of prefixes (possibly empty). 767 * @see org.xml.sax.helpers.NamespaceSupport#getDeclaredPrefixes 768 */ 769 Enumeration<String> getDeclaredPrefixes () 770 { 771 if (declarations == null) { 772 return EMPTY_ENUMERATION; 773 } else { 774 return Collections.enumeration(declarations); 775 } 776 } 777 778 /** |