KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > flex > CmsFlexRequestContextInfo


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/flex/CmsFlexRequestContextInfo.java,v $
3  * Date : $Date: 2005/06/23 11:11:33 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.flex;
33
34 import org.opencms.file.CmsResource;
35
36 /**
37  * Contains information about the OpenCms request context required by the
38  * Flex implementation.<p>
39  *
40  * An instance of this class is attached to every <code>CmsRequestContext</code> as
41  * an attribute as soon as the request context is wrapped in a flex response.
42  * Information about the "last modified" and "expire" times of VFS resources are
43  * stored in this Object.<p>
44  *
45  * @author Alexander Kandzior
46  *
47  * @version $Revision: 1.9 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsFlexRequestContextInfo {
52
53     /** The currently calculated "expires" date for this request context .*/
54     private long m_dateExpires;
55
56     /** The currently calculated "last modified" date for this request context. */
57     private long m_dateLastModified;
58
59     /**
60      * Public constructor.<p>
61      */

62     public CmsFlexRequestContextInfo() {
63
64         // by default the expiration date is the max long value
65
m_dateExpires = CmsResource.DATE_EXPIRED_DEFAULT;
66     }
67
68     /**
69      * Returns the "expires" date for this context.<p>
70      *
71      * @return the "expires" date for this context
72      */

73     public long getDateExpires() {
74
75         return m_dateExpires;
76     }
77
78     /**
79      * Returns the "last modified" date for this context.<p>
80      *
81      * @return the "last modified" date for this context
82      */

83     public long getDateLastModified() {
84
85         return m_dateLastModified;
86     }
87
88     /**
89      * Merges this context info with the values from the other context info.<p>
90      *
91      * @param other the context info to merge with
92      */

93     public void merge(CmsFlexRequestContextInfo other) {
94
95         updateDateLastModified(other.getDateLastModified());
96         updateDateExpires(other.getDateExpires());
97     }
98
99     /**
100      * Updates the "expires" date for this context with the given value.<p>
101      *
102      * @param dateExpires the value to update the "expires" date with
103      */

104     public void updateDateExpires(long dateExpires) {
105
106         if (dateExpires > System.currentTimeMillis()) {
107             if (dateExpires < m_dateExpires) {
108                 m_dateExpires = dateExpires;
109             }
110         } else {
111             updateDateLastModified(dateExpires);
112         }
113     }
114
115     /**
116      * Updates the "last modified" date for this context with the given value.<p>
117      *
118      * The currently stored value is only updated with the new value if
119      * the new value is either larger (i.e. newer) then the stored value,
120      * or if the new value is less then zero, which indicates that the "last modified"
121      * optimization can not be used because the element is dynamic.<p>
122      *
123      * @param dateLastModified the value to update the "last modified" date with
124      */

125     public void updateDateLastModified(long dateLastModified) {
126
127         if ((m_dateLastModified > -1) && ((dateLastModified > m_dateLastModified) || (dateLastModified < 0))) {
128             m_dateLastModified = dateLastModified;
129         }
130     }
131
132     /**
133      * Updates both the "last modified" and the "expires" date
134      * for this context with the given values.<p>
135      *
136      * @param dateLastModified the value to update the "last modified" date with
137      * @param dateExpires the value to update the "expires" date with
138      */

139     public void updateDates(long dateLastModified, long dateExpires) {
140
141         updateDateLastModified(dateLastModified);
142         updateDateExpires(dateExpires);
143     }
144
145     /**
146      * Updates the "last modified" date for this context as well as the
147      * "expires" date with the values from a given resource.<p>
148      *
149      * The "expires" date is the calculated from the given date values
150      * of resource release and expiration and also the current time.<p>
151      *
152      * @param resource the resource to use for updating the context values
153      */

154     public void updateFromResource(CmsResource resource) {
155
156         // first set the last modification date
157
updateDateLastModified(resource.getDateLastModified());
158         // now use both release and expiration date from the resource to update the expires info
159
updateDateExpires(resource.getDateReleased());
160         updateDateExpires(resource.getDateExpired());
161     }
162 }
163
Popular Tags