1*db859879SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*db859879SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*db859879SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*db859879SAndrew Rist  * distributed with this work for additional information
6*db859879SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*db859879SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*db859879SAndrew Rist  * "License"); you may not use this file except in compliance
9*db859879SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*db859879SAndrew Rist  *
11*db859879SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*db859879SAndrew Rist  *
13*db859879SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*db859879SAndrew Rist  * software distributed under the License is distributed on an
15*db859879SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*db859879SAndrew Rist  * KIND, either express or implied.  See the License for the
17*db859879SAndrew Rist  * specific language governing permissions and limitations
18*db859879SAndrew Rist  * under the License.
19*db859879SAndrew Rist  *
20*db859879SAndrew Rist  *************************************************************/
21*db859879SAndrew Rist 
22*db859879SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.xml.security.uno;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.util.Vector;
27cdf0e10cSrcweir import com.sun.star.xml.sax.XAttributeList;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /**
30cdf0e10cSrcweir  * Class to construct an attribute list, and provide a XAttributeList
31cdf0e10cSrcweir  * interface.
32cdf0e10cSrcweir  *
33cdf0e10cSrcweir  * @author      Michael Mi
34cdf0e10cSrcweir  * @version     %I%, %G%
35cdf0e10cSrcweir  */
36cdf0e10cSrcweir public class AttributeListHelper implements com.sun.star.xml.sax.XAttributeList
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	private Vector m_AttributeList;
39cdf0e10cSrcweir 
AttributeListHelper()40cdf0e10cSrcweir 	public AttributeListHelper()
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		m_AttributeList = new Vector();
43cdf0e10cSrcweir 	}
44cdf0e10cSrcweir 
clear()45cdf0e10cSrcweir 	public void clear()
46cdf0e10cSrcweir 	{
47cdf0e10cSrcweir 		m_AttributeList.removeAllElements();
48cdf0e10cSrcweir 	}
49cdf0e10cSrcweir 
setAttribute(String name, String type, String value)50cdf0e10cSrcweir 	public void setAttribute(String name, String type, String value)
51cdf0e10cSrcweir 	{
52cdf0e10cSrcweir 		int nLength = m_AttributeList.size();
53cdf0e10cSrcweir 		boolean bFound = false;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 		for (int i=0; i<nLength; ++i)
56cdf0e10cSrcweir 		{
57cdf0e10cSrcweir 			if (getNameByIndex((short)i).equals(name))
58cdf0e10cSrcweir 			{
59cdf0e10cSrcweir 				Vector attribute = (Vector)m_AttributeList.get(i);
60cdf0e10cSrcweir 				attribute.setElementAt(type,1);
61cdf0e10cSrcweir 				attribute.setElementAt(value,2);
62cdf0e10cSrcweir 				bFound = true;
63cdf0e10cSrcweir 				break;
64cdf0e10cSrcweir 			}
65cdf0e10cSrcweir 		}
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 		if (!bFound)
68cdf0e10cSrcweir 		{
69cdf0e10cSrcweir 			Vector attribute = new Vector();
70cdf0e10cSrcweir 			attribute.addElement(name);
71cdf0e10cSrcweir 			attribute.addElement(type);
72cdf0e10cSrcweir 			attribute.addElement(value);
73cdf0e10cSrcweir 			m_AttributeList.addElement(attribute);
74cdf0e10cSrcweir 		}
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 
getAttributeItem(short index, int itemIndex)77cdf0e10cSrcweir 	public String getAttributeItem(short index, int itemIndex)
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		String item = null;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		if (index>=0 && index<getLength())
82cdf0e10cSrcweir 		{
83cdf0e10cSrcweir 			Vector attribute = (Vector)m_AttributeList.get(index);
84cdf0e10cSrcweir 			item = (String)(attribute.get(itemIndex));
85cdf0e10cSrcweir 		}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		return item;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	/* XAttributeList */
getLength()91cdf0e10cSrcweir 	public short getLength()
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir 		return (short)m_AttributeList.size();
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir 
getNameByIndex(short i)96cdf0e10cSrcweir 	public String getNameByIndex(short i)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		return getAttributeItem(i, 0);
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 
getTypeByIndex(short i)101cdf0e10cSrcweir 	public String getTypeByIndex(short i)
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		return getAttributeItem(i, 1);
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
getValueByIndex(short i)106cdf0e10cSrcweir 	public String getValueByIndex(short i)
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		return getAttributeItem(i, 2);
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 
getTypeByName(String aName)111cdf0e10cSrcweir 	public String getTypeByName(String aName)
112cdf0e10cSrcweir 	{
113cdf0e10cSrcweir 		int nLength = m_AttributeList.size();
114cdf0e10cSrcweir 		String type = null;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		for (int i=0; i<nLength; ++i)
117cdf0e10cSrcweir 		{
118cdf0e10cSrcweir 			if (getNameByIndex((short)i).equals(aName))
119cdf0e10cSrcweir 			{
120cdf0e10cSrcweir 				type = getTypeByIndex((short)i);
121cdf0e10cSrcweir 				break;
122cdf0e10cSrcweir 			}
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		return type;
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 
getValueByName(String aName)128cdf0e10cSrcweir 	public String getValueByName(String aName)
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		int nLength = m_AttributeList.size();
131cdf0e10cSrcweir 		String value = null;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		for (int i=0; i<nLength; ++i)
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			if (getNameByIndex((short)i).equals(aName))
136cdf0e10cSrcweir 			{
137cdf0e10cSrcweir 				value = getValueByIndex((short)i);
138cdf0e10cSrcweir 				break;
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 		return value;
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145