1 /*
2 * Copyright 2002 - 2006 JEuclid, http://jeuclid.sf.net
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* $Id: SAXAttributeMap.java 310 2007-05-18 20:26:36Z maxberger $ */
18
19 package net.sourceforge.jeuclid.elements.support.attributes;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.xml.sax.Attributes;
25
26 /**
27 * Attributes derived from SAX.
28 *
29 * @author Max Berger
30 * @version $Revision: 310 $
31 */
32 public class SAXAttributeMap extends AbstractAttributeMap {
33
34 private final Attributes attributes;
35
36 /**
37 * Creates a new AttributeMap based on SAX attributes.
38 *
39 * @param attr
40 * the SAX attributes.
41 */
42 public SAXAttributeMap(final Attributes attr) {
43 this.attributes = attr;
44 }
45
46 /** {@inheritDoc} */
47 @Override
48 protected String getAttribute(final String attrName) {
49 return this.attributes.getValue(attrName);
50 }
51
52 /** {@inheritDoc} */
53 @Override
54 protected String getAttributeNS(final String namespace,
55 final String attrName) {
56 return this.attributes.getValue(namespace, attrName);
57 }
58
59 /** {@inheritDoc} */
60 public Map<String, String> getAsMap() {
61 final Map<String, String> m = new HashMap<String, String>();
62 for (int i = 0; i < this.attributes.getLength(); i++) {
63 m.put(this.attributes.getLocalName(i), this.attributes
64 .getValue(i));
65 }
66 return m;
67 }
68
69 }