1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.fsii;
18
19 import COM.FutureTense.Interfaces.ICS;
20
21 import com.fatwire.assetapi.data.AssetData;
22 import com.fatwire.assetapi.data.AssetId;
23 import com.fatwire.gst.foundation.CSRuntimeException;
24 import com.fatwire.gst.foundation.facade.assetapi.AssetDataUtils;
25 import com.fatwire.gst.foundation.facade.assetapi.AssetIdUtils;
26 import com.fatwire.gst.foundation.facade.assetapi.AttributeDataUtils;
27 import com.fatwire.gst.foundation.facade.runtag.TagRunnerRuntimeException;
28 import com.fatwire.gst.foundation.facade.runtag.asset.AssetList;
29 import com.fatwire.gst.foundation.facade.runtag.asset.Children;
30 import com.fatwire.gst.foundation.facade.runtag.asset.GetSubtype;
31 import com.fatwire.gst.foundation.facade.runtag.render.GetTemplateUrl;
32 import com.fatwire.gst.foundation.facade.runtag.siteplan.ListPages;
33 import com.openmarket.xcelerate.asset.AssetIdImpl;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public final class SitePlanUtils {
53 private static Log LOG = LogFactory.getLog(SitePlanUtils.class);
54
55 private SitePlanUtils() {
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69 public static String getPageDetailTemplateForPage(ICS ics, String p, String assocname) {
70 AssetId kid = Children.getSingleAssociation(ics, "Page", resolvePageAlias(ics, p), assocname);
71 return AssetList.getRequiredSingleField(ics, kid.getType(), Long.toString(kid.getId()), "template");
72 }
73
74
75
76
77
78
79
80
81 public static String getTemplateForPage(ICS ics, String p) {
82 return AssetList.getRequiredSingleField(ics, "Page", p, "template");
83 }
84
85
86
87
88
89
90
91
92
93 public static AssetId getPageDetailForPage(ICS ics, String p, String assocname) {
94 return Children.getSingleAssociation(ics, "Page", resolvePageAlias(ics, p), assocname);
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 public static HeadTagData getStandardHeadData(ICS ics, String c, String cid, String metaKeywordAttribute,
115 String metaDescriptionAttribute, String titleAttribute) {
116 HeadTagData result = new HeadTagData();
117
118 AssetData data = AssetDataUtils.getAssetData(ics, AssetIdUtils.createAssetId(cid, c), cid,
119 metaKeywordAttribute, metaDescriptionAttribute, titleAttribute, "description", "name");
120 result.setTitle(AttributeDataUtils.getWithFallback(data, titleAttribute, "description", "name"));
121 result.setDescription(AttributeDataUtils.getWithFallback(data, metaDescriptionAttribute, titleAttribute,
122 "description", "name"));
123 String kw = AttributeDataUtils.getMultivaluedAsCommaSepString(data.getAttributeData(metaKeywordAttribute));
124 if (kw == null || kw.length() == 0) {
125 kw = AttributeDataUtils.getWithFallback(data, "name");
126 }
127 result.setKeywords(kw);
128 return result;
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 public static PageLinkData getSitePlanAsLinks(ICS ics, final String p, String assocname, String linktextAttr,
157 String tname, String wrapper, boolean withChildren) {
158 PageLinkData pageLinkData = new PageLinkData();
159
160 pageLinkData.setPageId(new AssetIdImpl("Page", Long.valueOf(p)));
161
162
163 pageLinkData.setSubtype(GetSubtype.getSubtype(ics, pageLinkData.getPageId()));
164
165
166 final boolean isNavigationPlaceholder = PAGE_SUBTYPE_NAVIGATION_PLACEHOLDER.equals(pageLinkData.getSubtype());
167 if (assocname == null) {
168 AssetData data = AssetDataUtils.getAssetData(ics,
169 AssetIdUtils.createAssetId("Page", resolvePageAlias(ics, p)), linktextAttr);
170 pageLinkData.setLinktext(AttributeDataUtils.getWithFallback(data, linktextAttr));
171 } else {
172 LOG.debug("About to load " + assocname + " for Page:" + p);
173 try {
174 AssetId kid = Children.getSingleAssociation(ics, "Page", resolvePageAlias(ics, p), assocname);
175 AssetData data = AssetDataUtils.getAssetData(ics, kid, linktextAttr);
176 pageLinkData.setLinktext(AttributeDataUtils.getWithFallback(data, linktextAttr));
177 } catch (TagRunnerRuntimeException e) {
178 if (e.getErrno() == -111) {
179
180 if (!isNavigationPlaceholder) {
181 throw new CSRuntimeException("Missing required association: " + assocname + " for Page:"
182 + resolvePageAlias(ics, p), -111);
183 }
184
185 } else {
186 throw e;
187 }
188 }
189
190 }
191
192
193 if (!isNavigationPlaceholder && tname != null) {
194
195 if (tname != null) {
196
197 GetTemplateUrl gtu = new GetTemplateUrl(ics, "Page", p, tname, wrapper, "SitePlanUtils");
198 gtu.setArgument("p", p);
199
200 ics.RemoveVar("gspal-url");
201 gtu.setOutstr("gspal-url");
202 gtu.execute(ics);
203 pageLinkData.setUrl(ics.GetVar("gspal-url"));
204 ics.RemoveVar("gspal-url");
205 }
206 }
207
208
209 if (withChildren) {
210 for (AssetId kid : ListPages.getChildPages(ics, pageLinkData.getPageId().getId())) {
211
212 PageLinkData kidData = getSitePlanAsLinks(ics, Long.toString(kid.getId()), assocname, linktextAttr,
213 tname, wrapper, withChildren);
214 pageLinkData.addImmediateChild(kidData);
215 }
216 }
217
218 return pageLinkData;
219 }
220
221
222
223
224
225
226 public static final String PAGE_SUBTYPE_NAVIGATION_PLACEHOLDER = "NavigationPlaceholder";
227
228
229
230
231
232 public static final String PAGE_SUBTYPE_ALIAS = "Alias";
233
234
235
236
237 public static final String PAGE_SUBTYPE_ASSOCIATION_NAME = "TargetPage";
238
239
240
241
242
243
244
245
246
247
248 public static String resolvePageAlias(ICS ics, final String p) {
249 String subtype = GetSubtype.getSubtype(ics, "Page", p);
250 if (PAGE_SUBTYPE_ALIAS.equals(subtype)) {
251 AssetId target = Children.getSingleAssociation(ics, "Page", p, PAGE_SUBTYPE_ASSOCIATION_NAME);
252 return Long.toString(target.getId());
253 }
254 return p;
255 }
256 }