KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > utils > MutableAttrListImpl


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: MutableAttrListImpl.java,v 1.7 2004/02/17 04:21:14 minchau Exp $
18  */

19 package com.sun.org.apache.xml.internal.utils;
20
21 import java.io.Serializable JavaDoc;
22
23 import org.xml.sax.Attributes JavaDoc;
24 import org.xml.sax.helpers.AttributesImpl JavaDoc;
25
26 /**
27  * Mutable version of AttributesImpl.
28  * @xsl.usage advanced
29  */

30 public class MutableAttrListImpl extends AttributesImpl JavaDoc
31         implements Serializable JavaDoc
32 {
33
34 /**
35  * Construct a new, empty AttributesImpl object.
36  */

37
38 public MutableAttrListImpl()
39   {
40     super();
41   }
42
43   /**
44    * Copy an existing Attributes object.
45    *
46    * <p>This constructor is especially useful inside a start
47    * element event.</p>
48    *
49    * @param atts The existing Attributes object.
50    */

51   public MutableAttrListImpl(Attributes JavaDoc atts)
52   {
53     super(atts);
54   }
55
56   /**
57    * Add an attribute to the end of the list.
58    *
59    * <p>For the sake of speed, this method does no checking
60    * to see if the attribute is already in the list: that is
61    * the responsibility of the application.</p>
62    *
63    * @param uri The Namespace URI, or the empty string if
64    * none is available or Namespace processing is not
65    * being performed.
66    * @param localName The local name, or the empty string if
67    * Namespace processing is not being performed.
68    * @param qName The qualified (prefixed) name, or the empty string
69    * if qualified names are not available.
70    * @param type The attribute type as a string.
71    * @param value The attribute value.
72    */

73   public void addAttribute(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName,
74                            String JavaDoc type, String JavaDoc value)
75   {
76
77     if (null == uri)
78       uri = "";
79
80     // getIndex(qName) seems to be more reliable than getIndex(uri, localName),
81
// in the case of the xmlns attribute anyway.
82
int index = this.getIndex(qName);
83     // int index = this.getIndex(uri, localName);
84

85     // System.out.println("MutableAttrListImpl#addAttribute: "+uri+":"+localName+", "+index+", "+qName+", "+this);
86

87     if (index >= 0)
88       this.setAttribute(index, uri, localName, qName, type, value);
89     else
90       super.addAttribute(uri, localName, qName, type, value);
91   }
92
93   /**
94    * Add the contents of the attribute list to this list.
95    *
96    * @param atts List of attributes to add to this list
97    */

98   public void addAttributes(Attributes JavaDoc atts)
99   {
100
101     int nAtts = atts.getLength();
102
103     for (int i = 0; i < nAtts; i++)
104     {
105       String JavaDoc uri = atts.getURI(i);
106
107       if (null == uri)
108         uri = "";
109
110       String JavaDoc localName = atts.getLocalName(i);
111       String JavaDoc qname = atts.getQName(i);
112       int index = this.getIndex(uri, localName);
113       // System.out.println("MutableAttrListImpl#addAttributes: "+uri+":"+localName+", "+index+", "+atts.getQName(i)+", "+this);
114
if (index >= 0)
115         this.setAttribute(index, uri, localName, qname, atts.getType(i),
116                           atts.getValue(i));
117       else
118         addAttribute(uri, localName, qname, atts.getType(i),
119                      atts.getValue(i));
120     }
121   }
122
123   /**
124    * Return true if list contains the given (raw) attribute name.
125    *
126    * @param name Raw name of attribute to look for
127    *
128    * @return true if an attribute is found with this name
129    */

130   public boolean contains(String JavaDoc name)
131   {
132     return getValue(name) != null;
133   }
134 }
135
136 // end of MutableAttrListImpl.java
137
Popular Tags