1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.url;
17
18 import java.util.Map;
19
20 import COM.FutureTense.Export.ReferenceException;
21 import COM.FutureTense.Interfaces.ICS;
22 import COM.FutureTense.Util.ftMessage;
23
24 import com.fatwire.assetapi.data.AssetId;
25 import com.fatwire.gst.foundation.vwebroot.AssetApiVirtualWebrootDao;
26 import com.fatwire.gst.foundation.vwebroot.VirtualWebroot;
27 import com.fatwire.gst.foundation.wra.AssetApiWraCoreFieldDao;
28 import com.fatwire.gst.foundation.wra.VanityAsset;
29 import com.fatwire.gst.foundation.wra.WraCoreFieldDao;
30 import com.openmarket.xcelerate.asset.AssetIdImpl;
31 import com.openmarket.xcelerate.publish.PageRef;
32 import com.openmarket.xcelerate.publish.PubConstants;
33
34 import org.apache.commons.lang.StringUtils;
35
36 import static COM.FutureTense.Interfaces.Utilities.goodString;
37
38 public class WraPagePreviewReference extends PageRef {
39
40 public static final String GST_DISPATCHER = "GST/Dispatcher";
41
42
43 @SuppressWarnings({ "rawtypes", "unchecked" })
44 @Override
45 public void setParameters(Map args, ICS ics) throws ReferenceException {
46
47
48 if (shouldModify(args, ics)) {
49 AssetId id = new AssetIdImpl((String) args.get("c"), Long.parseLong((String) args.get("cid")));
50 AssetApiVirtualWebrootDao vwDao = new AssetApiVirtualWebrootDao(ics);
51 WraCoreFieldDao wraDao = new AssetApiWraCoreFieldDao(ics);
52 String currentEnvironment = vwDao.getVirtualWebrootEnvironment();
53
54 if (currentEnvironment != null && wraDao.isVanityAsset(id)) {
55 VanityAsset wra = wraDao.getVanityWra(id);
56
57 VirtualWebroot vw = vwDao.lookupVirtualWebrootForAsset(wra);
58 if (vw != null) {
59
60 args.put("virtual-webroot", vw.getEnvironmentVirtualWebroot());
61 args.put("url-path", wra.getPath().substring(vw.getMasterVirtualWebroot().length()));
62
63 String pagename = ics.GetProperty(WraPathAssembler.DISPATCHER_PROPNAME,
64 "ServletRequest.properties", true);
65 if (!goodString(pagename)) {
66 pagename = GST_DISPATCHER;
67 }
68
69
70 if (args.get(PubConstants.WRAPPERPAGE) != null)
71 args.put(PubConstants.WRAPPERPAGE, pagename);
72 else
73 args.put("pagename", pagename);
74 } else {
75 if (log.isDebugEnabled()) {
76 log.debug("Not adding WRAPathAssembler args because no matching virtual webroot found for path "
77 + wra.getPath() + " and environemnt " + currentEnvironment);
78 }
79 }
80 } else {
81 if (log.isDebugEnabled()) {
82 if (currentEnvironment == null) {
83 log.debug("Not adding WraPathAssembler args because virtual webroot environment is not configured");
84 } else {
85 log.debug("Not adding WraPathAssembler args because asset " + id + " is not web referenceable.");
86 }
87 }
88 }
89 } else {
90 if (log.isDebugEnabled()) {
91 log.debug("Not adding WRAPathAssembler args because context is not satellite server (it is "
92 + getSatelliteContext() + "). Args: " + args);
93 }
94 }
95 super.setParameters(args, ics);
96 }
97
98 protected boolean shouldModify(Map<String, String> args, ICS ics) {
99 return isRendermodeLive(ics) && getSatelliteContext() == SatelliteContext.SATELLITE_SERVER
100 && isGetTemplateUrl(args);
101 }
102
103 protected boolean isRendermodeLive(ICS ics) {
104 String rendermode = ics.GetVar(PubConstants.RENDERMODE);
105 return StringUtils.isBlank(rendermode) || "live".equals(rendermode);
106 }
107
108
109
110
111
112
113
114
115
116 private boolean isGetTemplateUrl(Map<String, String> args) {
117 if (args.get("c") == null)
118 return false;
119 if (args.get("cid") == null)
120 return false;
121 String pagename = args.get(ftMessage.PageName);
122 if (pagename == null)
123 return false;
124 if (pagename.split("/").length < 2)
125 return false;
126
127 if (args.get(PubConstants.WRAPPERPAGE) != null)
128 return true;
129 else {
130
131 }
132 return true;
133 }
134 }