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 | 0 | { |
41 | 0 | this.prefix = prefix; |
42 | 0 | this.namespace = ns; |
43 | 0 | } |
44 | |
} |
45 | |
|
46 | |
private final List<NS> namespaces; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public NamespaceManager() |
52 | 0 | { |
53 | 0 | this.namespaces = new ArrayList<NS>(); |
54 | 0 | } |
55 | |
|
56 | |
public void reset() |
57 | |
{ |
58 | 0 | this.namespaces.clear(); |
59 | 0 | } |
60 | |
|
61 | |
public void pushNamespace(String prefix, String namespace) |
62 | |
{ |
63 | 0 | NS ns = new NS(prefix, namespace); |
64 | 0 | this.namespaces.add(0, ns); |
65 | 0 | } |
66 | |
|
67 | |
public String getNamespace(String prefix) |
68 | |
{ |
69 | 0 | NS ns = null; |
70 | 0 | for (int i = 0; i < this.namespaces.size(); i++) |
71 | |
{ |
72 | 0 | ns = (NS) this.namespaces.get(i); |
73 | 0 | if (ns.prefix.equals(prefix)) |
74 | |
{ |
75 | 0 | return ns.namespace; |
76 | |
} |
77 | |
} |
78 | 0 | return null; |
79 | |
} |
80 | |
|
81 | |
public void popNamespace(String prefix) |
82 | |
{ |
83 | 0 | NS ns = null; |
84 | 0 | for (int i = 0; i < this.namespaces.size(); i++) |
85 | |
{ |
86 | 0 | ns = (NS) this.namespaces.get(i); |
87 | 0 | if (ns.prefix.equals(prefix)) |
88 | |
{ |
89 | 0 | this.namespaces.remove(i); |
90 | 0 | return; |
91 | |
} |
92 | |
} |
93 | 0 | } |
94 | |
|
95 | |
public NamespaceUnit toNamespaceUnit(TagLibrary library) |
96 | |
{ |
97 | 0 | NamespaceUnit unit = new NamespaceUnit(library); |
98 | 0 | if (this.namespaces.size() > 0) |
99 | |
{ |
100 | 0 | NS ns = null; |
101 | 0 | for (int i = this.namespaces.size() - 1; i >= 0; i--) |
102 | |
{ |
103 | 0 | ns = this.namespaces.get(i); |
104 | 0 | unit.setNamespace(ns.prefix, ns.namespace); |
105 | |
} |
106 | |
} |
107 | 0 | return unit; |
108 | |
} |
109 | |
|
110 | |
} |