1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.runtag.siteplan;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import COM.FutureTense.Interfaces.ICS;
24 import COM.FutureTense.Interfaces.IList;
25 import COM.FutureTense.Util.IterableIListWrapper;
26
27 import com.fatwire.assetapi.data.AssetId;
28 import com.fatwire.gst.foundation.CSRuntimeException;
29 import com.fatwire.gst.foundation.IListUtils;
30 import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner;
31 import com.fatwire.gst.foundation.facade.runtag.asset.AssetLoadById;
32 import com.fatwire.gst.foundation.facade.runtag.asset.GetSiteNode;
33 import com.openmarket.xcelerate.asset.AssetIdImpl;
34
35
36
37
38
39
40
41
42
43 public final class ListPages extends AbstractTagRunner {
44 public ListPages() {
45 super("SITEPLAN.LISTPAGES");
46 }
47
48 public void setName(String name) {
49 set("NAME", name);
50 }
51
52 public void setPlacedList(String placedPages) {
53 set("PLACEDLIST", placedPages);
54 }
55
56 public void setLevel(int level) {
57 set("LEVEL", Integer.toString(level));
58 }
59
60
61
62
63
64
65
66
67
68
69 public static List<AssetId> getChildPages(ICS ics, long p) {
70 final String LOADED_PAGE_NAME = "__thePage";
71 final String LOADED_SITE_PLAN_NODE = "__siteplan";
72 final String CURRENT_PAGE_NODE_ID = "__nodeId";
73 final String PLACED_LIST = "__placedList";
74
75 try {
76 AssetLoadById assetLoad = new AssetLoadById();
77 assetLoad.setAssetId(p);
78 assetLoad.setAssetType("Page");
79 assetLoad.setName(LOADED_PAGE_NAME);
80 assetLoad.execute(ics);
81 if (ics.GetErrno() < 0) {
82 throw new CSRuntimeException("Failed to load page identified by Page:" + p, ics.GetErrno());
83 }
84
85 GetSiteNode getSiteNode = new GetSiteNode();
86 getSiteNode.setName(LOADED_PAGE_NAME);
87 getSiteNode.setOutput(CURRENT_PAGE_NODE_ID);
88 getSiteNode.execute(ics);
89 if (ics.GetErrno() < 0) {
90 throw new CSRuntimeException("Could not get site node for page identified by Page:" + p, ics.GetErrno());
91 }
92
93 SitePlanLoad sitePlanLoad = new SitePlanLoad();
94 sitePlanLoad.setName(LOADED_SITE_PLAN_NODE);
95 sitePlanLoad.setNodeid(ics.GetVar(CURRENT_PAGE_NODE_ID));
96 sitePlanLoad.execute(ics);
97 if (ics.GetErrno() < 0) {
98 throw new CSRuntimeException("Could not load site plan tree for page identified by Page:" + p,
99 ics.GetErrno());
100 }
101
102 ListPages listPages = new ListPages();
103 listPages.setName(LOADED_SITE_PLAN_NODE);
104 listPages.setPlacedList(PLACED_LIST);
105 listPages.setLevel(1);
106 listPages.execute(ics);
107 if (ics.GetErrno() < 0) {
108 throw new CSRuntimeException("Could not get list child pages for Page:" + p, ics.GetErrno());
109 }
110
111
112 IList placedList = ics.GetList(PLACED_LIST);
113 if (ics.GetErrno() < 0 || placedList == null || !placedList.hasData()) {
114 ics.ClearErrno();
115 return Collections.emptyList();
116 }
117 List<AssetId> list = new ArrayList<AssetId>();
118 for (IList row : new IterableIListWrapper(placedList)) {
119 AssetId id = new AssetIdImpl(IListUtils.getStringValue(row, "AssetType"), IListUtils.getLongValue(row,
120 "Id"));
121 list.add(id);
122 }
123 return list;
124 } finally {
125 ics.SetObj(LOADED_PAGE_NAME, null);
126 ics.RemoveVar(CURRENT_PAGE_NODE_ID);
127 ics.SetObj(LOADED_SITE_PLAN_NODE, null);
128 ics.RegisterList(PLACED_LIST, null);
129 }
130 }
131 }