001 /*
002 * Copyright 2002 - 2006 JEuclid, http://jeuclid.sf.net
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 /* $Id: SAXAttributeMap.java 310 2007-05-18 20:26:36Z maxberger $ */
018
019 package net.sourceforge.jeuclid.elements.support.attributes;
020
021 import java.util.HashMap;
022 import java.util.Map;
023
024 import org.xml.sax.Attributes;
025
026 /**
027 * Attributes derived from SAX.
028 *
029 * @author Max Berger
030 * @version $Revision: 310 $
031 */
032 public class SAXAttributeMap extends AbstractAttributeMap {
033
034 private final Attributes attributes;
035
036 /**
037 * Creates a new AttributeMap based on SAX attributes.
038 *
039 * @param attr
040 * the SAX attributes.
041 */
042 public SAXAttributeMap(final Attributes attr) {
043 this.attributes = attr;
044 }
045
046 /** {@inheritDoc} */
047 @Override
048 protected String getAttribute(final String attrName) {
049 return this.attributes.getValue(attrName);
050 }
051
052 /** {@inheritDoc} */
053 @Override
054 protected String getAttributeNS(final String namespace,
055 final String attrName) {
056 return this.attributes.getValue(namespace, attrName);
057 }
058
059 /** {@inheritDoc} */
060 public Map<String, String> getAsMap() {
061 final Map<String, String> m = new HashMap<String, String>();
062 for (int i = 0; i < this.attributes.getLength(); i++) {
063 m.put(this.attributes.getLocalName(i), this.attributes
064 .getValue(i));
065 }
066 return m;
067 }
068
069 }