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