KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > arooa > handlers > AttributeHelper


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.arooa.handlers;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import org.xml.sax.Attributes JavaDoc;
11
12 /**
13  *
14  */

15 public class AttributeHelper {
16
17     private Map JavaDoc attributes = new HashMap JavaDoc();
18     
19     public AttributeHelper(String JavaDoc uri, Attributes JavaDoc attrs) {
20         for (int i = 0; i < attrs.getLength(); i++) {
21             String JavaDoc attrUri = attrs.getURI(i);
22             if (attrUri != null
23                 && !attrUri.equals("")
24                 && !attrUri.equals(uri)) {
25                 continue; // Ignore attributes from unknown uris
26
}
27             String JavaDoc key = attrs.getLocalName(i);
28             String JavaDoc value = attrs.getValue(i);
29
30             attributes.put(key, value);
31         }
32     }
33     
34     public String JavaDoc remove(String JavaDoc name) {
35         return (String JavaDoc) attributes.remove(name);
36     }
37     
38     public interface Processor {
39         public void process(String JavaDoc name, String JavaDoc value);
40     }
41     
42     public void process(Processor processor) {
43         for (Iterator JavaDoc it = attributes.entrySet().iterator(); it.hasNext(); ) {
44             Map.Entry JavaDoc es = (Map.Entry JavaDoc) it.next();
45             processor.process((String JavaDoc) es.getKey(), (String JavaDoc) es.getValue());
46         }
47     }
48 }
49
Popular Tags