1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.util;
  58. import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
  59. import org.xml.sax.AttributeList;
  60. import org.xml.sax.Attributes;
  61. /**
  62. * Wraps {@link XMLAttributes} and makes it look like
  63. * {@link AttributeList} and {@link Attributes}.
  64. *
  65. * @author Arnaud Le Hors, IBM
  66. * @author Andy Clark, IBM
  67. *
  68. * @version $Id: AttributesProxy.java,v 1.2 2004/01/27 00:31:58 kk122374 Exp $
  69. */
  70. public final class AttributesProxy
  71. implements AttributeList, Attributes {
  72. //
  73. // Data
  74. //
  75. /** XML attributes. */
  76. private XMLAttributes fAttributes;
  77. //
  78. // Public methods
  79. //
  80. /** Sets the XML attributes to be wrapped. */
  81. public void setAttributes(XMLAttributes attributes) {
  82. fAttributes = attributes;
  83. } // setAttributes(XMLAttributes)
  84. public XMLAttributes getAttributes() {
  85. return fAttributes;
  86. }
  87. public int getLength() {
  88. return fAttributes.getLength();
  89. }
  90. public String getName(int i) {
  91. return fAttributes.getQName(i);
  92. }
  93. public String getQName(int index) {
  94. return fAttributes.getQName(index);
  95. }
  96. public String getURI(int index) {
  97. // REVISIT: this hides the fact that internally we use
  98. // null instead of empty string
  99. // SAX requires URI to be a string or an empty string
  100. String uri= fAttributes.getURI(index);
  101. return uri != null ? uri : "";
  102. }
  103. public String getLocalName(int index) {
  104. return fAttributes.getLocalName(index);
  105. }
  106. public String getType(int i) {
  107. return fAttributes.getType(i);
  108. }
  109. public String getType(String name) {
  110. return fAttributes.getType(name);
  111. }
  112. public String getType(String uri, String localName) {
  113. return uri.equals("") ? fAttributes.getType(null, localName) :
  114. fAttributes.getType(uri, localName);
  115. }
  116. public String getValue(int i) {
  117. return fAttributes.getValue(i);
  118. }
  119. public String getValue(String name) {
  120. return fAttributes.getValue(name);
  121. }
  122. public String getValue(String uri, String localName) {
  123. return uri.equals("") ? fAttributes.getValue(null, localName) :
  124. fAttributes.getValue(uri, localName);
  125. }
  126. public int getIndex(String qName) {
  127. return fAttributes.getIndex(qName);
  128. }
  129. public int getIndex(String uri, String localPart) {
  130. return uri.equals("") ? fAttributes.getIndex(null, localPart) :
  131. fAttributes.getIndex(uri, localPart);
  132. }
  133. }