1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.portals.bridges.util;
18
19 import java.util.Enumeration;
20 import java.util.NoSuchElementException;
21
22 /***
23 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
24 * @version $Id: NamespacedNamesEnumeration.java 549659 2007-06-22 01:21:29Z ate $
25 */
26 public class NamespacedNamesEnumeration implements Enumeration
27 {
28 private Enumeration namesEnumeration;
29 private String namespace;
30
31 private String nextName;
32 private boolean done;
33
34 public NamespacedNamesEnumeration(Enumeration namesEnumeration, String namespace)
35 {
36 this.namesEnumeration = namesEnumeration;
37 this.namespace = namespace;
38 hasMoreElements();
39 }
40
41 public boolean hasMoreElements()
42 {
43 if (!done)
44 {
45 if (nextName == null)
46 {
47 while (namesEnumeration.hasMoreElements())
48 {
49 String name = (String)namesEnumeration.nextElement();
50 if ( name.startsWith(namespace))
51 {
52 nextName = name.substring(namespace.length());
53 break;
54 }
55 }
56 done = nextName == null;
57 }
58 }
59 return !done;
60 }
61
62 public Object nextElement()
63 {
64 if (done)
65 {
66 throw new NoSuchElementException();
67 }
68 String name = nextName;
69 nextName = null;
70 return name;
71 }
72 }