1 /* 2 * (C) Copyright Keith Visco 1998, 1999 All rights reserved. 3 * 4 * The contents of this file are released under an Open Source Definition (OSD) compliant license; 5 * you may not use this file execpt in compliance with the license. Please see license.txt, 6 * distributed with this file. You may also obtain a copy of the license at 7 * http://www.clc-marketing.com/xslp/license.txt 8 * 9 * The program is provided "as is" without any warranty express or implied, including the warranty 10 * of non-infringement and the implied warranties of merchantibility and fitness for a particular 11 * purpose. The Copyright owner will not be liable for any damages suffered by you as a result of 12 * using the Program. In no event will the Copyright owner be liable for any special, indirect or 13 * consequential damages or lost profits even if the Copyright owner has been advised of the 14 * possibility of their occurrence. 15 * 16 * The orginal source for this file is XSL:P 17 * 18 * $Id$ 19 */ 20 package org.exolab.castor.xml.util; 21 22 import org.w3c.dom.Attr; 23 import org.w3c.dom.NamedNodeMap; 24 import org.xml.sax.AttributeList; 25 26 /** 27 * A class which implements AttributeList by "wrapping" a DOM NamedNodeMap. XSLReader when reading 28 * an XSLT stylsheet. 29 * 30 * @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a> 31 * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $ 32 */ 33 public class AttributeListWrapper implements AttributeList { 34 35 NamedNodeMap _map = null; 36 37 public AttributeListWrapper(NamedNodeMap namedNodeMap) { 38 _map = namedNodeMap; 39 } // -- AtrributeListWrapper 40 41 // -----------------------------/ 42 // - org.xml.sax.AttributeList -/ 43 // -----------------------------/ 44 45 /** 46 * Returns the number of attributes in the list. 47 * 48 * @return The number of attributes in the list. 49 */ 50 public int getLength() { 51 if (_map == null) { 52 return 0; 53 } 54 return _map.getLength(); 55 } // -- getLength 56 57 /** 58 * Returns the name of the attribute at the given index. 59 * 60 * @param i The position of the attribute in the list. 61 * @return The attribute name as a string, or null if there is no attribute at that position. 62 */ 63 public String getName(final int i) { 64 if (_map != null) { 65 Attr attr = (Attr) _map.item(i); 66 return attr.getName(); 67 } 68 return null; 69 } // -- getName 70 71 /** 72 * Returns the type of the attribute at the specified index. 73 * 74 * @param i The position of the attribute in the list. 75 * @return The attribute type as a string ("NMTOKEN" for an enumeration, and "CDATA" if no 76 * declaration was read), or null if there is no attribute at that position. <br/> 77 * <b>Note:</b> Not supported, will simply return null. 78 */ 79 public String getType(final int i) { 80 return null; 81 } // -- getType 82 83 /** 84 * Return the value of the attribute at the specified index 85 * 86 * @param i The position of the attribute in the list. 87 * @return The attribute value as a string, or null if there is no attribute at that position. 88 */ 89 public String getValue(final int i) { 90 if (_map != null) { 91 Attr attr = (Attr) _map.item(i); 92 return attr.getValue(); 93 } 94 return null; 95 } // -- getValue 96 97 /** 98 * Return the type of the attribute with the given name. 99 * 100 * @param name The attribute name. 101 * @return The attribute type as a string ("NMTOKEN" for an enumeration, and "CDATA" if no 102 * declaration was read). <br/> 103 * <b>Note:</b> Not supported, will simply return null. 104 */ 105 public String getType(final String name) { 106 return null; 107 } // -- getType 108 109 /** 110 * Get the value of an attribute (by name). 111 * 112 * @param name The attribute name. 113 * @see org.xml.sax.AttributeList#getValue(java.lang.String) 114 */ 115 public String getValue(final String name) { 116 if (_map != null) { 117 Attr attr = (Attr) _map.getNamedItem(name); 118 if (attr != null) { 119 return attr.getValue(); 120 } 121 } 122 return null; 123 } // -- getValue 124 125 } // -- AttributeListWrapper