1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.compiler;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.myfaces.view.facelets.tag.TagLibrary;
25
26
27
28
29
30 final class NamespaceManager
31 {
32
33 private final static class NS
34 {
35 public final String prefix;
36
37 public final String namespace;
38
39 public NS(String prefix, String ns)
40 {
41 this.prefix = prefix;
42 this.namespace = ns;
43 }
44 }
45
46 private final List<NS> namespaces;
47
48
49
50
51 public NamespaceManager()
52 {
53 this.namespaces = new ArrayList<NS>();
54 }
55
56 public void reset()
57 {
58 this.namespaces.clear();
59 }
60
61 public void pushNamespace(String prefix, String namespace)
62 {
63 NS ns = new NS(prefix, namespace);
64 this.namespaces.add(0, ns);
65 }
66
67 public String getNamespace(String prefix)
68 {
69 NS ns = null;
70 for (int i = 0; i < this.namespaces.size(); i++)
71 {
72 ns = (NS) this.namespaces.get(i);
73 if (ns.prefix.equals(prefix))
74 {
75 return ns.namespace;
76 }
77 }
78 return null;
79 }
80
81 public void popNamespace(String prefix)
82 {
83 NS ns = null;
84 for (int i = 0; i < this.namespaces.size(); i++)
85 {
86 ns = (NS) this.namespaces.get(i);
87 if (ns.prefix.equals(prefix))
88 {
89 this.namespaces.remove(i);
90 return;
91 }
92 }
93 }
94
95 public NamespaceUnit toNamespaceUnit(TagLibrary library)
96 {
97 NamespaceUnit unit = new NamespaceUnit(library);
98 if (this.namespaces.size() > 0)
99 {
100 NS ns = null;
101 for (int i = this.namespaces.size() - 1; i >= 0; i--)
102 {
103 ns = this.namespaces.get(i);
104 unit.setNamespace(ns.prefix, ns.namespace);
105 }
106 }
107 return unit;
108 }
109
110 }