update dev300-m58
[ooovba.git] / xmlsecurity / tools / uno / AttributeListHelper.java
blobecf77949d694f15fd060baaea13613935fc7e6d1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AttributeListHelper.java,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.xml.security.uno;
33 import java.util.Vector;
34 import com.sun.star.xml.sax.XAttributeList;
36 /**
37 * Class to construct an attribute list, and provide a XAttributeList
38 * interface.
40 * @author Michael Mi
41 * @version %I%, %G%
43 public class AttributeListHelper implements com.sun.star.xml.sax.XAttributeList
45 private Vector m_AttributeList;
47 public AttributeListHelper()
49 m_AttributeList = new Vector();
52 public void clear()
54 m_AttributeList.removeAllElements();
57 public void setAttribute(String name, String type, String value)
59 int nLength = m_AttributeList.size();
60 boolean bFound = false;
62 for (int i=0; i<nLength; ++i)
64 if (getNameByIndex((short)i).equals(name))
66 Vector attribute = (Vector)m_AttributeList.get(i);
67 attribute.setElementAt(type,1);
68 attribute.setElementAt(value,2);
69 bFound = true;
70 break;
74 if (!bFound)
76 Vector attribute = new Vector();
77 attribute.addElement(name);
78 attribute.addElement(type);
79 attribute.addElement(value);
80 m_AttributeList.addElement(attribute);
84 public String getAttributeItem(short index, int itemIndex)
86 String item = null;
88 if (index>=0 && index<getLength())
90 Vector attribute = (Vector)m_AttributeList.get(index);
91 item = (String)(attribute.get(itemIndex));
94 return item;
97 /* XAttributeList */
98 public short getLength()
100 return (short)m_AttributeList.size();
103 public String getNameByIndex(short i)
105 return getAttributeItem(i, 0);
108 public String getTypeByIndex(short i)
110 return getAttributeItem(i, 1);
113 public String getValueByIndex(short i)
115 return getAttributeItem(i, 2);
118 public String getTypeByName(String aName)
120 int nLength = m_AttributeList.size();
121 String type = null;
123 for (int i=0; i<nLength; ++i)
125 if (getNameByIndex((short)i).equals(aName))
127 type = getTypeByIndex((short)i);
128 break;
132 return type;
135 public String getValueByName(String aName)
137 int nLength = m_AttributeList.size();
138 String value = null;
140 for (int i=0; i<nLength; ++i)
142 if (getNameByIndex((short)i).equals(aName))
144 value = getValueByIndex((short)i);
145 break;
148 return value;