1 /*
2 * Copyright 2008 FatWire Corporation. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package tools.gsf.facade.assetapi.asset;
18
19 import COM.FutureTense.Interfaces.ICS;
20 import COM.FutureTense.Util.ftMessage;
21 import com.fatwire.cs.core.db.Util;
22
23 import java.util.Date;
24
25 /**
26 * @author Dolf.Dijkstra
27 * @since Apr 21, 2011
28 */
29 public class PreviewContext {
30
31 /**
32 * Returns the value of the preview date based on the session variable and
33 * the setting for the xcelerate property <tt>cs.sitepreview</tt>.
34 *
35 * @param ics Content Server context object
36 * @param ssvarName server session variable name
37 * @return the preview date
38 */
39 public static Date getPreviewDateFromSession(final ICS ics, final String ssvarName) {
40 final Date cutoff = ics.GetSSVar(ssvarName) != null ? Util.parseJdbcDate(ics.GetSSVar(ssvarName)) : null;
41 return getPreviewDate(ics, cutoff);
42 }
43
44 /**
45 * Returns the value of the preview date based on the cs variable and the
46 * setting for the xcelerate property <tt>cs.sitepreview</tt>.
47 *
48 * @param ics Content Server context object
49 * @param varName variable name
50 * @return the date to preview
51 */
52 public static Date getPreviewDateFromCSVar(final ICS ics, final String varName) {
53 final Date cutoff = ics.GetVar(varName) != null ? Util.parseJdbcDate(ics.GetVar(varName)) : null;
54 return getPreviewDate(ics, cutoff);
55 }
56
57 /**
58 * Returns the value of the preview date based on the provided date and the
59 * setting for the xcelerate property <tt>cs.sitepreview</tt>.
60 *
61 * @param ics Content Server context object
62 * @param cutoff cut-off date
63 * @return the date to preview
64 */
65 public static Date getPreviewDate(final ICS ics, final Date cutoff) {
66 if (ics.LoadProperty("futuretense.ini;futuretense_xcel.ini")) {
67 if (ftMessage.cm.equals(ics.GetProperty(ftMessage.cssitepreview))) {
68 // We disable caching if and ONLY if cs.sitepreview is
69 // contentmanagement. Check for that property in the ini files
70 ics.DisableFragmentCache();
71
72 // Insite Editing is enabled
73 if (null == cutoff) {
74 return new Date();
75 } else {
76 return cutoff;
77 }
78
79 } else if (ftMessage.disabled.equals(ics.GetProperty(ftMessage.cssitepreview))) {
80 return null;
81 } else {
82 return new Date(); // site preview disabled or delivery,
83 }
84 // implies production install, use
85 // server date
86
87 } else
88 // Cannot read from property file, use server date
89 // TODO: isn't ignoring cutoff a better option when prop can't be
90 // read??
91 {
92 return new Date();
93 }
94 }
95
96 /**
97 * Checks if start/enddate checking is enabled.
98 *
99 * @param ics Content Server context object
100 * @return true if 'cs.sitepreview' xcelerate property is either
101 * 'contentmanagement' or 'delivery', false if set to 'disabled'.
102 */
103 public static boolean isSitePreviewEnabled(final ICS ics) {
104 boolean ret = false;
105 if (ics.LoadProperty("futuretense.ini;futuretense_xcel.ini")) {
106
107 if (!ftMessage.disabled.equals(ics.GetProperty(ftMessage.cssitepreview))) {
108 ret = true;
109 }
110
111 }
112 return ret;
113
114 }
115
116 /**
117 * @param ics Content Server context object
118 * @return true if 'cs.sitepreview' xcelerate property is set to delivery
119 */
120 public static boolean isSitePreviewDelivery(final ICS ics) {
121 boolean ret = false;
122
123 if (ics.LoadProperty("futuretense.ini;futuretense_xcel.ini")) {
124
125 if (ftMessage.delivery.equals(ics.GetProperty(ftMessage.cssitepreview))) {
126 ret = true;
127 }
128 }
129 return ret;
130
131 }
132 }