View Javadoc
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 com.fatwire.gst.foundation.facade.assetapi.asset;
18  
19  import java.util.Date;
20  
21  import COM.FutureTense.Interfaces.ICS;
22  import COM.FutureTense.Util.ftMessage;
23  
24  import com.fatwire.cs.core.db.Util;
25  
26  /**
27   * @author Dolf.Dijkstra
28   * @since Apr 21, 2011
29   */
30  public class PreviewContext {
31  
32      /**
33       * Returns the value of the preview date based on the session variable and
34       * the setting for the xcelerate property <tt>cs.sitepreview</tt>.
35       * 
36       * @param ics
37       * @param ssvarName
38       * @return the preview date
39       */
40      public static Date getPreviewDateFromSession(final ICS ics, final String ssvarName) {
41          final Date cutoff = ics.GetSSVar(ssvarName) != null ? Util.parseJdbcDate(ics.GetSSVar(ssvarName)) : null;
42          return getPreviewDate(ics, cutoff);
43      }
44  
45      /**
46       * Returns the value of the preview date based on the cs variable and the
47       * setting for the xcelerate property <tt>cs.sitepreview</tt>.
48       * 
49       * @param ics
50       * @param varName
51       * @return the date to preview
52       */
53      public static Date getPreviewDateFromCSVar(final ICS ics, final String varName) {
54          final Date cutoff = ics.GetVar(varName) != null ? Util.parseJdbcDate(ics.GetVar(varName)) : null;
55          return getPreviewDate(ics, cutoff);
56      }
57  
58      /**
59       * Returns the value of the preview date based on the provided date and the
60       * setting for the xcelerate property <tt>cs.sitepreview</tt>.
61       * 
62       * @param ics
63       * @param cutoff
64       * @return the date to preview
65       */
66      public static Date getPreviewDate(final ICS ics, final Date cutoff) {
67          if (ics.LoadProperty("futuretense.ini;futuretense_xcel.ini")) {
68              if (ftMessage.cm.equals(ics.GetProperty(ftMessage.cssitepreview))) {
69                  // We disable caching if and ONLY if cs.sitepreview is
70                  // contentmanagement. Check for that property in the ini files
71                  ics.DisableFragmentCache();
72  
73                  // Insite Editing is enabled
74                  if (null == cutoff)
75                      return new Date();
76                  else
77                      return cutoff;
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              // implies production install, use
84              // server date
85  
86          } else
87              // Cannot read from property file, use server date
88              // TODO: isn't ignoring cutoff a better option when prop can't be
89              // read??
90              return new Date();
91      }
92  
93      /**
94       * Checks if start/enddate checking is enabled.
95       * 
96       * @param ics
97       * @return true if 'cs.sitepreview' xcelerate property is either
98       *         'contentmanagement' or 'delivery', false if set to 'disabled'.
99       */
100     public static boolean isSitePreviewEnabled(final ICS ics) {
101         boolean ret = false;
102         if (ics.LoadProperty("futuretense.ini;futuretense_xcel.ini")) {
103 
104             if (!ftMessage.disabled.equals(ics.GetProperty(ftMessage.cssitepreview))) {
105                 ret = true;
106             }
107 
108         }
109         return ret;
110 
111     }
112 
113     /**
114      * @param ics
115      * @return true if 'cs.sitepreview' xcelerate property is set to delivery
116      */
117     public static boolean isSitePreviewDelivery(final ICS ics) {
118         boolean ret = false;
119 
120         if (ics.LoadProperty("futuretense.ini;futuretense_xcel.ini")) {
121 
122             if (ftMessage.delivery.equals(ics.GetProperty(ftMessage.cssitepreview))) {
123                 ret = true;
124             }
125         }
126         return ret;
127 
128     }
129 }