1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.taglibs;
35
36 import info.magnolia.cms.core.Content;
37
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41
42
43
44
45
46
47
48
49 public class Set extends BaseContentTag {
50
51 public static final String SCOPE_GLOBAL = "global";
52
53 public static final String SCOPE_LOCAL = "local";
54
55 public static final String SCOPE_PARAGRAPH = "paragraph";
56
57 public static final String SCOPE_CURRENT = "current";
58
59 public static final String SCOPE_PAGE = "page";
60
61 private String scope = SCOPE_GLOBAL;
62
63
64
65
66 private boolean forBodyOnly = false;
67
68
69
70
71 private Content previousNode;
72
73
74
75
76
77 public void setContainer(Content contentNode) {
78 this.setContentNode(contentNode);
79 }
80
81
82
83
84
85 public void setContainerName(String name) {
86 this.setContentNodeName(name);
87 }
88
89
90
91
92 public void setNodeDataName(String name) {
93 throw new UnsupportedOperationException("nodeDataName not supported in this tag");
94 }
95
96 public int doStartTag() {
97 Content node = getFirstMatchingNode();
98
99 if(isForBodyOnly()){
100 saveCurrentNode();
101 }
102
103 setNode(node);
104
105 return EVAL_BODY_INCLUDE;
106 }
107
108 protected void saveCurrentNode() {
109 if(SCOPE_GLOBAL.equals(this.getScope())){
110 previousNode = Resource.getGlobalContentNode();
111 }
112 else if (SCOPE_LOCAL.equals(this.getScope()) || SCOPE_PARAGRAPH.equals(this.getScope())){
113 previousNode = Resource.getLocalContentNode();
114 }
115 else if (SCOPE_CURRENT.equals(this.getScope()) || SCOPE_PAGE.equals(this.getScope())){
116 previousNode = Resource.getCurrentActivePage();
117 }
118 }
119
120 protected void setNode(Content node) {
121 if(SCOPE_GLOBAL.equals(this.getScope())){
122 Resource.setGlobalContentNode(node);
123 }
124 else if (SCOPE_LOCAL.equals(this.getScope()) || SCOPE_PARAGRAPH.equals(this.getScope())){
125 Resource.setLocalContentNode(node);
126 }
127 else if (SCOPE_CURRENT.equals(this.getScope()) || SCOPE_PAGE.equals(this.getScope())){
128 Resource.setCurrentActivePage(node);
129 }
130 }
131
132 public int doEndTag() {
133 if(isForBodyOnly()){
134 setNode(previousNode);
135 }
136 return EVAL_PAGE;
137 }
138
139 public void release() {
140 super.release();
141 this.scope = SCOPE_GLOBAL;
142 this.forBodyOnly = false;
143 this.previousNode = null;
144 }
145
146 public String getScope() {
147 return this.scope;
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161 public void setScope(String scope) {
162 this.scope = scope;
163 }
164
165 public boolean isForBodyOnly() {
166 return this.forBodyOnly;
167 }
168
169
170
171
172
173 public void setForBodyOnly(boolean forBodyOnly) {
174 this.forBodyOnly = forBodyOnly;
175 }
176 }