KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > util > core > CacheUtil


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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 package com.blandware.atleap.webapp.util.core;
17
18 import com.blandware.atleap.webapp.menu.MenuComponent;
19 import com.opensymphony.oscache.base.Cache;
20 import com.opensymphony.oscache.base.NeedsRefreshException;
21 import com.opensymphony.oscache.web.ServletCacheAdministrator;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 import javax.servlet.ServletContext JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.jsp.PageContext JavaDoc;
28 import java.io.Serializable JavaDoc;
29 import java.util.Date JavaDoc;
30
31 /**
32  * <p>This is a helper to use OSCache</p>
33  * <p><a HREF="CacheUtil.java.htm"><i>View Source</i></a></p>
34  * <p/>
35  *
36  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
37  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
38  * @version $Revision: 1.22 $ $Date: 2005/11/26 14:51:26 $
39  */

40 public class CacheUtil {
41     protected transient final Log log = LogFactory.getLog(CacheUtil.class);
42
43     public static final String JavaDoc PAGE_SUFFIX = "_page";
44     public static final String JavaDoc LAYOUT_SUFFIX = "_layout";
45     public static final String JavaDoc LOCALIZABLE_SUFFIX = "_localizable";
46     public static final String JavaDoc RESOURCE_SUFFIX = "_resource";
47     public static final String JavaDoc CONTENT_PAGE_SUFFIX = "_contentPage";
48     public static final String JavaDoc MENU_SUFFIX = "_menu";
49     public static final String JavaDoc FIELD_INDICES_SUFFIX = "_fieldIndices";
50
51     public static final String JavaDoc FIELD_VALUE_GROUP = "fieldValueGroup";
52     public static final String JavaDoc FIELD_INDEXES_GROUP = "fieldIndexesGroup";
53     public static final String JavaDoc RESOURCE_GROUP = "resourceGroup";
54     public static final String JavaDoc CONTENT_PAGE_GROUP = "contentPageGroup";
55     public static final String JavaDoc MENU_GROUP = "menuGroup";
56
57     public static final String JavaDoc INSTANCE_KEY = "com.blandware.atleap.util.CacheUtil.INSTANCE";
58
59     protected static final String JavaDoc TIME_KEY = "cache.web.time";
60     protected static final String JavaDoc RESOURCE_MAXSIZE_KEY = "cache.web.resource.maxsize";
61
62     protected ServletCacheAdministrator admin = null;
63     protected HttpServletRequest JavaDoc request = null;
64     protected ServletContext JavaDoc servletContext = null;
65     protected int refreshPeriod = -1;
66     protected int resourceMaxSize = 50000;
67
68     /**
69      * Returns instance of CacheUtil
70      *
71      * @param request Http request from which to obtain instance
72      * @return Instance of CacheUtil
73      */

74     public static CacheUtil getInstance(HttpServletRequest JavaDoc request) {
75         CacheUtil ourInstance = (CacheUtil) request.getAttribute(INSTANCE_KEY);
76         if ( ourInstance == null ) {
77             ourInstance = new CacheUtil(request);
78             request.setAttribute(INSTANCE_KEY, ourInstance);
79         }
80         return ourInstance;
81     }
82
83     /**
84      * Constructs a new instance of CacheUtil
85      *
86      * @param request Http request to which this instance will be tied
87      */

88     protected CacheUtil(HttpServletRequest JavaDoc request) {
89         this.request = request;
90         this.servletContext = request.getSession().getServletContext();
91
92         //cache administrator
93
admin = ServletCacheAdministrator.getInstance(servletContext);
94         if ( admin == null ) {
95             String JavaDoc error = "Cannot get cache administrator";
96             if ( log.isErrorEnabled() ) {
97                 log.error(error);
98             }
99             throw new RuntimeException JavaDoc(error);
100         }
101
102         //refresh period
103
Integer JavaDoc rp = GlobalProperties.getInstance(servletContext).getInteger(TIME_KEY);
104         if ( rp != null ) {
105             refreshPeriod = rp.intValue();
106         } else {
107             if ( log.isWarnEnabled() ) {
108                 log.warn("Cache refresh period is not specified in key '" + TIME_KEY + "' using default " + String.valueOf(refreshPeriod));
109             }
110         }
111
112         //resource max size
113
Integer JavaDoc ms = GlobalProperties.getInstance(servletContext).getInteger(RESOURCE_MAXSIZE_KEY);
114         if ( ms != null ) {
115             resourceMaxSize = ms.intValue();
116         } else {
117             if ( log.isWarnEnabled() ) {
118                 log.warn("Maxsize of resource in cache is not specified in key '" + RESOURCE_MAXSIZE_KEY + "' using default " + String.valueOf(resourceMaxSize));
119             }
120         }
121
122     }
123
124     // P A G E F I E L D V A L U E
125

126     /**
127      * Gets content from the cache for Page from Application Scope
128      *
129      * @param pageUri Uri of the Page
130      * @param identifier Identifier of the ContentField
131      * @param locale Locale string
132      * @return Data object with content or <code>null</code> if content is not found or stale.
133      */

134     public CFVData getPageFieldValueFromCache(String JavaDoc pageUri, String JavaDoc identifier, String JavaDoc locale) {
135         return (CFVData) getFromCache(pageUri + "_" + identifier, locale, PAGE_SUFFIX, PageContext.APPLICATION_SCOPE);
136     }
137
138     /**
139      * Puts into cache into Application Scope for Page
140      *
141      * @param data Data to put into cache
142      * @param pageUri Uri of the page
143      * @param identifier Identifier of the content field
144      * @param locale Locale string
145      */

146     public void putPageFieldValueInCache(CFVData data, String JavaDoc pageUri, String JavaDoc identifier, String JavaDoc locale) {
147         putInCache(data, pageUri + "_" + identifier, locale, PAGE_SUFFIX, new String JavaDoc[]{pageUri, FIELD_VALUE_GROUP}, PageContext.APPLICATION_SCOPE);
148     }
149
150     /**
151      * Flushes content from the cache for Page from Application Scope
152      *
153      * @param pageUri Uri of the Page
154      * @param identifier Identifier of the ContentField
155      * @param locale Locale string
156      */

157     public void flushPageFieldValueCache(String JavaDoc pageUri, String JavaDoc identifier, String JavaDoc locale) {
158         flushCache(pageUri + "_" + identifier, locale, PAGE_SUFFIX, PageContext.APPLICATION_SCOPE);
159     }
160
161     /**
162      * Flushes content from the cache for all fields of page
163      *
164      * @param pageUri Uri of the Page
165      */

166     public void flushPageFieldValueCache(String JavaDoc pageUri) {
167         flushCacheGroup(pageUri, PageContext.APPLICATION_SCOPE);
168     }
169
170
171     // L A Y O U T F I E L D V A L U E
172

173     /**
174      * Puts into cache into Application Scope for layout. This is different from
175      * <code>putPageFieldValueInCache()</code> because this method also adds
176      * the given data to group corresponding to layout definition, not only
177      * to group for page URI.
178      *
179      * @param data Data to put into cache
180      * @param layoutDefinition Definition name of layout
181      * @param pageUri Uri of the page
182      * @param identifier Identifier of the content field
183      * @param locale Locale string
184      */

185     public void putLayoutFieldValueInCache(CFVData data, String JavaDoc layoutDefinition, String JavaDoc pageUri, String JavaDoc identifier, String JavaDoc locale) {
186         putInCache(data, pageUri + "_" + identifier, locale, PAGE_SUFFIX, new String JavaDoc[]{pageUri, layoutDefinition, FIELD_VALUE_GROUP}, PageContext.APPLICATION_SCOPE);
187     }
188
189     /**
190      * Flushes content from the cache for all fields of layout
191      *
192      * @param layoutDefinition definition of the Layout
193      */

194     public void flushLayoutFieldValueCache(String JavaDoc layoutDefinition) {
195         flushCacheGroup(layoutDefinition, PageContext.APPLICATION_SCOPE);
196     }
197
198     // L O C A L I Z A B L E F I E L D V A L U E
199

200     /**
201      * Gets content from the cache for undefined localizable from Application Scope
202      *
203      * @param localizableId ID of localizable
204      * @param identifier Identifier of the content field
205      * @param locale Locale string
206      * @return Data object with content or <code>null</code> if content is not found or stale.
207      */

208     public CFVData getLocalizableFieldValueFromCache(Long JavaDoc localizableId, String JavaDoc identifier, String JavaDoc locale) {
209         return (CFVData) getFromCache(localizableId + "_" + identifier, locale, LOCALIZABLE_SUFFIX, PageContext.APPLICATION_SCOPE);
210     }
211
212     /**
213      * Puts into cache into Application Scope for localizable
214      *
215      * @param data data to put into cache
216      * @param localizableId ID of localizable
217      * @param identifier Identifier of the content field
218      * @param locale locale string
219      */

220     public void putLocalizableFieldValueInCache(CFVData data, Long JavaDoc localizableId, String JavaDoc identifier, String JavaDoc locale) {
221         putInCache(data, localizableId + "_" + identifier, locale, LOCALIZABLE_SUFFIX, new String JavaDoc[]{localizableId.toString(), FIELD_VALUE_GROUP}, PageContext.APPLICATION_SCOPE);
222     }
223
224     /**
225      * Flushes content from the cache for localizable from Application Scope
226      *
227      * @param localizableId ID of localizable
228      * @param identifier Identifier of the content field
229      * @param locale Locale string
230      */

231     public void flushLocalizableFieldValueCache(Long JavaDoc localizableId, String JavaDoc identifier, String JavaDoc locale) {
232         flushCache(localizableId + "_" + identifier, locale, LOCALIZABLE_SUFFIX, PageContext.APPLICATION_SCOPE);
233     }
234
235     /**
236      * Flushes content from the cache for all fields of localizable
237      *
238      * @param localizableId ID of localizable
239      */

240     public void flushLocalizableFieldValueCache(Long JavaDoc localizableId) {
241         flushCacheGroup(localizableId.toString(), PageContext.APPLICATION_SCOPE);
242     }
243
244     // R E S O U R C E
245

246     /**
247      * Gets resource data from cache
248      *
249      * @param uri The uri of resource to get from cache
250      * @return data of resource and its mime type
251      */

252     public ResourceData getResourceFromCache(String JavaDoc uri) {
253         return (ResourceData) getFromCache(uri, null, RESOURCE_SUFFIX, PageContext.APPLICATION_SCOPE);
254     }
255
256     /**
257      * Puts the resource into cache
258      *
259      * @param resourceData Data of resource
260      * @param uri The uri of resource
261      */

262     public void putResourceInCache(ResourceData resourceData, String JavaDoc uri) {
263         if ( resourceData.getData().length <= resourceMaxSize ) {
264             putInCache(resourceData, uri, null, RESOURCE_SUFFIX, new String JavaDoc[]{RESOURCE_GROUP}, PageContext.APPLICATION_SCOPE);
265         } else {
266             //put without data
267
resourceData.setData(null);
268             putInCache(resourceData, uri, null, RESOURCE_SUFFIX, new String JavaDoc[]{RESOURCE_GROUP}, PageContext.APPLICATION_SCOPE);
269         }
270     }
271
272     /**
273      * Update roles of resource in cache
274      * @param uri uri of resource
275      * @param roles new roles
276      */

277     public void updateResourceRolesInCache(String JavaDoc uri, String JavaDoc roles) {
278         ResourceData resourceData = getResourceFromCache(uri);
279         if (resourceData != null) {
280             resourceData.setRoles(roles);
281             putResourceInCache(resourceData, uri);
282         }
283     }
284
285     /**
286      * Flushes resource from the cache
287      *
288      * @param uri The uri of resource to flush
289      */

290     public void flushResourceCache(String JavaDoc uri) {
291         flushCache(uri, null, RESOURCE_SUFFIX, PageContext.APPLICATION_SCOPE);
292     }
293
294     /**
295      * Flushes all resources from cache
296      */

297     public void flushResourceCache() {
298         flushCacheGroup(RESOURCE_GROUP, PageContext.APPLICATION_SCOPE);
299     }
300
301     // M E N U
302

303     /**
304      * Gets menu component from cache.
305      *
306      * @param menuName Name of menu component
307      * @param locale Locale string
308      * @param layoutDefinition Definition of layout to which this menu component
309      * belongs
310      * @param pageUri Uri of page to which this menu component belongs
311      * @return MenuComponent or <code>null</code> if nothing has been found or cache is stale.
312      */

313     public MenuComponent getMenuFromCache(String JavaDoc menuName, String JavaDoc locale, String JavaDoc layoutDefinition, String JavaDoc pageUri) {
314         return (MenuComponent) getFromCache(menuName + "_" + layoutDefinition + "_" + pageUri, locale, MENU_SUFFIX, PageContext.APPLICATION_SCOPE);
315     }
316
317     /**
318      * Puts menu component into cache.
319      *
320      * @param menuComponent Menu component to put into cache
321      * @param menuName Name of menu component
322      * @param locale Locale string
323      * @param layoutDefinition Definition of layout to which this menu component
324      * belongs
325      * @param pageUri Uri of page to which this menu component
326      * belongs
327      */

328     public void putMenuInCache(MenuComponent menuComponent, String JavaDoc menuName, String JavaDoc locale, String JavaDoc layoutDefinition, String JavaDoc pageUri) {
329         putInCache(menuComponent, menuName + "_" + layoutDefinition + "_" + pageUri, locale, MENU_SUFFIX, new String JavaDoc[]{MENU_GROUP}, PageContext.APPLICATION_SCOPE);
330     }
331
332     /**
333      * Flushes all menus from a cache
334      */

335     public void flushMenuCache() {
336         flushCacheGroup(MENU_GROUP, PageContext.APPLICATION_SCOPE);
337     }
338
339
340     // F I E L D I N D I C E S
341

342     /**
343      * Gets an array of content field indices for indexed field
344      *
345      * @param fieldIdentifier Identifier of indexed field
346      * @param locale Locale string
347      * @param layoutDefinition Definition of layout to which a field belongs
348      * @param pageUri Uri of page to which a field belongs
349      * @return Array of indices or <code>null</code> if not found or stale.
350      */

351     public String JavaDoc[] getFieldIndices(String JavaDoc fieldIdentifier, String JavaDoc locale, String JavaDoc layoutDefinition, String JavaDoc pageUri) {
352         return (String JavaDoc[]) getFromCache(fieldIdentifier + "_" + layoutDefinition + "_" + pageUri, locale, FIELD_INDICES_SUFFIX, PageContext.APPLICATION_SCOPE);
353     }
354
355     /**
356      * Puts array of field indices into cache
357      *
358      * @param fieldIndices Array of field indices
359      * @param fieldIdentifier Identifier of field
360      * @param locale Locale string
361      * @param layoutDefinition Definition of layout to which a field belongs
362      * @param pageUri Uri of page to which a field belongs
363      */

364     public void putFieldIndicesInCache(String JavaDoc[] fieldIndices, String JavaDoc fieldIdentifier, String JavaDoc locale, String JavaDoc layoutDefinition, String JavaDoc pageUri) {
365         putInCache(fieldIndices, fieldIdentifier + "_" + layoutDefinition + "_" + pageUri, locale, FIELD_INDICES_SUFFIX, new String JavaDoc[]{FIELD_INDEXES_GROUP}, PageContext.APPLICATION_SCOPE);
366     }
367
368     /**
369      * Flushes field indices from cache
370      */

371     public void flushFieldIndices() {
372         flushCacheGroup(FIELD_INDEXES_GROUP, PageContext.APPLICATION_SCOPE);
373     }
374
375     // C O N T E N T P A G E
376

377     /**
378      * Gets content page data from cache
379      *
380      * @param uri Uri of page to get
381      * @return Data of content page
382      */

383     public ContentPageData getContentPageFromCache(String JavaDoc uri) {
384         return (ContentPageData) getFromCache(uri, null, CONTENT_PAGE_SUFFIX, PageContext.APPLICATION_SCOPE);
385     }
386
387     /**
388      * Puts the content page into cache
389      *
390      * @param contentPageData Data of content page
391      * @param uri Uri of page to get
392      */

393     public void putContentPageInCache(ContentPageData contentPageData, String JavaDoc uri) {
394         putInCache(contentPageData, uri, null, CONTENT_PAGE_SUFFIX, new String JavaDoc[]{CONTENT_PAGE_GROUP}, PageContext.APPLICATION_SCOPE);
395     }
396
397     /**
398      * Updates last modified time in cache for specified content page uri
399      *
400      * @param uri Uri of page to update its modification time
401      */

402     public void updateContentPageLastModifiedInCache(String JavaDoc uri) {
403         ContentPageData cpd = getContentPageFromCache(uri);
404         if ( cpd != null ) {
405             cpd.setLastModified(new Date JavaDoc().getTime());
406             putContentPageInCache(cpd, uri);
407         }
408     }
409
410     /**
411      * Update roles of content page in cache
412      * @param uri uri of page
413      * @param roles new roles
414      */

415     public void updateContentPageRolesInCache(String JavaDoc uri, String JavaDoc roles) {
416         ContentPageData cpd = getContentPageFromCache(uri);
417         if ( cpd != null ) {
418             cpd.setRoles(roles);
419             putContentPageInCache(cpd, uri);
420         }
421     }
422
423     /**
424      * Flushes content page from the cache
425      *
426      * @param uri Uri of the content page to flush
427      */

428     public void flushContentPageCache(String JavaDoc uri) {
429         flushCache(uri, null, CONTENT_PAGE_SUFFIX, PageContext.APPLICATION_SCOPE);
430     }
431
432     /**
433      * Flushes all content pages from cache
434      */

435     public void flushContentPageCache() {
436         flushCacheGroup(CONTENT_PAGE_GROUP, PageContext.APPLICATION_SCOPE);
437     }
438
439
440     // C O M M O N
441

442     /**
443      * Gets content from cache from Application Scope
444      *
445      * @param compositeKey Key in the cache storage. The format is </code>pageUri_identifier</code> or </code>definitionName_identifier</code>
446      * (other formats can be used too)
447      * @param locale Locale string
448      * @param suffix Used to determine scope of key: page, layout, ...
449      * @param scope PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE
450      * @return Serializable object with content or <code>null</code> if content is not found or stale.
451      */

452     public Object JavaDoc getFromCache(String JavaDoc compositeKey, String JavaDoc locale, String JavaDoc suffix, int scope) {
453         if ( log.isDebugEnabled() ) {
454             log.debug("Get from cache compositeKey: " + compositeKey + ", locale: " + locale + ", suffix: " + suffix);
455         }
456
457         String JavaDoc fullKey = admin.generateEntryKey(compositeKey, request, scope, locale, suffix);
458
459         if ( log.isDebugEnabled() ) {
460             log.debug("Get from cache, full cache key: " + fullKey);
461         }
462
463         Cache cache = admin.getCache(request, scope);
464         Object JavaDoc content = null;
465         try {
466             content = cache.getFromCache(fullKey, refreshPeriod);
467             if ( log.isDebugEnabled() ) {
468                 log.debug("Using cached entry for key :" + fullKey);
469             }
470         } catch ( NeedsRefreshException nre ) {
471             if ( log.isDebugEnabled() ) {
472                 log.debug("Cache stale or cache scope flushed for key :" + fullKey);
473             }
474             cache.cancelUpdate(fullKey);
475             return null;
476         }
477         return content;
478     }
479
480     /**
481      * Puts into cache in Application or Session scope
482      *
483      * @param content Serializable object with content
484      * @param key Key in the cache storage.
485      * The format is </code>pageUri_identifier</code> or </code>definitionName_identifier</code> or </code>id_identifier</code>.
486      * (Other formats can be used too)
487      * @param locale Locale string
488      * @param suffix Used to determine scope of key: page, layout, ...
489      * @param groups The array of names of groups to which this cached object
490      * will participate
491      * @param scope PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE
492      */

493     public void putInCache(Object JavaDoc content, String JavaDoc key, String JavaDoc locale, String JavaDoc suffix, String JavaDoc[] groups, int scope) {
494         if ( log.isDebugEnabled() ) {
495             log.debug("Put into cache compositeKey: " + key + ", locale: " + locale + ", suffix: " + suffix);
496         }
497         Cache cache = admin.getCache(request, scope);
498         String JavaDoc fullKey = admin.generateEntryKey(key, request, scope, locale, suffix);
499         if ( log.isDebugEnabled() ) {
500             log.debug("Put into cache, full cache key: " + fullKey);
501         }
502         cache.putInCache(fullKey, content, groups);
503     }
504
505     /**
506      * Flushes the entry of the cache
507      *
508      * @param key Key in the cache storage.
509      * The format is </code>pageUri_identifier</code> or </code>definitionName_identifier</code> or </code>id_identifier</code>.
510      * (Other formats can be used too)
511      * @param locale Locale string
512      * @param suffix Used to determine scope of key: page, layout, ...
513      * @param scope PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE
514      */

515     public void flushCache(String JavaDoc key, String JavaDoc locale, String JavaDoc suffix, int scope) {
516         Cache cache = admin.getCache(request, scope);
517         key = admin.generateEntryKey(key, request, scope, locale, suffix);
518         cache.flushEntry(key);
519     }
520
521     /**
522      * Flushes the group
523      *
524      * @param group Cache group
525      * @param scope PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE
526      */

527     public void flushCacheGroup(String JavaDoc group, int scope) {
528         Cache cache = admin.getCache(request, scope);
529         cache.flushGroup(group);
530     }
531
532     /**
533      * Flushes the scope
534      *
535      * @param scope PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE
536      */

537     public void flushCacheScope(int scope) {
538         admin.setFlushTime(scope);
539     }
540
541     /**
542      * Flushes all cache
543      */

544     public void flushAllCache() {
545         admin.flushAll();
546         if (log.isInfoEnabled()) {
547             log.info("All cache of web layer flushed");
548         }
549     }
550
551     /**
552      * A struct to store content resource contents
553      */

554     public static class ResourceData implements Serializable JavaDoc {
555         private byte[] data;
556         private String JavaDoc mimeType = null;
557         private String JavaDoc charset = null;
558         private String JavaDoc roles = "";
559         private long lastModified = -1;
560
561         /**
562          * Constructs a new ResourceData with specified properties and no charset
563          *
564          * @param array Binary data
565          * @param mimeType Mime-type of the resource
566          * @param roles Comma-separated list of roles that are assigned
567          * to this resource
568          * @param lastModified Last modification date/time
569          */

570         public ResourceData(byte[] array, String JavaDoc mimeType, String JavaDoc roles, long lastModified) {
571             this(array, mimeType, null, roles, lastModified);
572         }
573
574         /**
575          * Constructs a new ResourceData with specified properties and no charset
576          *
577          * @param array Binary data
578          * @param mimeType Mime-type of the resource
579          * @param charset Charset that corresponds to this resource
580          * @param roles Comma-separated list of roles that are assigned
581          * to this resource
582          * @param lastModified Last modification date/time
583          */

584         public ResourceData(byte[] array, String JavaDoc mimeType, String JavaDoc charset, String JavaDoc roles, long lastModified) {
585             setData(array);
586             setMimeType(mimeType);
587             setRoles(roles);
588             setCharset(charset);
589             setLastModified(lastModified);
590         }
591
592         /**
593          * Gets the binary data that is content of this resource
594          *
595          * @return Binary data
596          */

597         public byte[] getData() {
598             return data;
599         }
600
601         /**
602          * Sets the binary data that is content of this resource
603          *
604          * @param data Binary data
605          */

606         public void setData(byte[] data) {
607             this.data = data;
608         }
609
610         /**
611          * Gets mime-type of this resource
612          *
613          * @return Mime-type
614          */

615         public String JavaDoc getMimeType() {
616             return mimeType;
617         }
618
619         /**
620          * Sets mime-type of this resource
621          *
622          * @param mimeType Mime-type to set
623          */

624         public void setMimeType(String JavaDoc mimeType) {
625             this.mimeType = mimeType;
626         }
627
628         /**
629          * Gets charset that corresponds to this resource
630          *
631          * @return Charset
632          */

633         public String JavaDoc getCharset() {
634             return charset;
635         }
636
637         /**
638          * Sets charset that corresponds to this resource
639          *
640          * @param charset Charset to set
641          */

642         public void setCharset(String JavaDoc charset) {
643             this.charset = charset;
644         }
645
646         /**
647          * Gets comma-separated list of roles that are assigned to this resource
648          *
649          * @return Comma-separated list of roles
650          */

651         public String JavaDoc getRoles() {
652             return roles;
653         }
654
655         /**
656          * Sets comma-separated list of roles
657          *
658          * @param roles Comma-separated list of roles
659          */

660         public void setRoles(String JavaDoc roles) {
661             this.roles = roles;
662         }
663
664         /**
665          * Gets last modification date/time
666          *
667          * @return Last modification date/time
668          */

669         public long getLastModified() {
670             return lastModified;
671         }
672
673         /**
674          * Sets last modification date/time
675          *
676          * @param lastModified Last modification date/time
677          */

678         public void setLastModified(long lastModified) {
679             this.lastModified = lastModified;
680         }
681     }
682
683     /**
684      * A struct to store content page contents
685      */

686     public static class ContentPageData implements Serializable JavaDoc {
687         private String JavaDoc cpDefinition = null;
688         private String JavaDoc roles = "";
689         private long lastModified = -1;
690         private Long JavaDoc cacheMaxAge = new Long JavaDoc(-1);
691
692         /**
693          * Constructs a new ContentPageData with specified properties
694          *
695          * @param cpDefinition Additional tiles definition name
696          * @param roles Comma-separated list of roles that are assigned
697          * to this content page
698          * @param cacheMaxAge Maximum age that page needs to be cached at client
699          */

700         public ContentPageData(String JavaDoc cpDefinition, String JavaDoc roles, Long JavaDoc cacheMaxAge) {
701             setCpDefinition(cpDefinition);
702             setRoles(roles);
703             setCacheMaxAge(cacheMaxAge);
704             setLastModified(new Date JavaDoc().getTime());
705         }
706
707         /**
708          * Sets content page tiles definition name
709          *
710          * @return additional definition name
711          */

712         public String JavaDoc getCpDefinition() {
713             return cpDefinition;
714         }
715
716         /**
717          * Gets content page tiles definition name
718          *
719          * @param cpDefinition additional definition name
720          */

721         public void setCpDefinition(String JavaDoc cpDefinition) {
722             this.cpDefinition = cpDefinition;
723         }
724
725         /**
726          * Gets comma-separated list of roles that are assigned to this page
727          *
728          * @return Comma-separated list of roles
729          */

730         public String JavaDoc getRoles() {
731             return roles;
732         }
733
734         /**
735          * Sets comma-separated list of roles that are assigned to this page
736          *
737          * @param roles Comma-separated list of roles
738          */

739         public void setRoles(String JavaDoc roles) {
740             this.roles = roles;
741         }
742
743         /**
744          * Gets last modification date/time
745          *
746          * @return Last modification date/time
747          */

748         public long getLastModified() {
749             return lastModified;
750         }
751
752         /**
753          * Sets last modification date/time
754          *
755          * @param lastModified Last modification date/time
756          */

757         public void setLastModified(long lastModified) {
758             this.lastModified = lastModified;
759         }
760
761         /**
762          * Gets maximum age that page needs to be cached at client
763          *
764          * @return Max cache age
765          */

766         public Long JavaDoc getCacheMaxAge() {
767             return cacheMaxAge;
768         }
769
770         /**
771          * Sets maximum age that page needs to be cached at client
772          *
773          * @param cacheMaxAge Max cache age
774          */

775         public void setCacheMaxAge(Long JavaDoc cacheMaxAge) {
776             this.cacheMaxAge = cacheMaxAge;
777         }
778     }
779
780     /**
781      * A struct to store CFV contents
782      */

783     public static class CFVData implements Serializable JavaDoc {
784         private String JavaDoc data = null;
785         private Long JavaDoc contentFieldId = null;
786         private Long JavaDoc contentFieldValueId = null;
787         private byte contentFieldType = 0;
788
789         /**
790          * Constructs a new CFVData with specified properties
791          *
792          * @param data Data that is stored in this CTF
793          * @param contentFieldId ID of the content field
794          * @param contentFieldType Type of the content field
795          * @param contentFieldValueId ID of this CTF
796          */

797         public CFVData(String JavaDoc data, Long JavaDoc contentFieldId, byte contentFieldType, Long JavaDoc contentFieldValueId) {
798             setData(data);
799             setContentFieldType(contentFieldType);
800             setContentFieldId(contentFieldId);
801             setContentFieldValueId(contentFieldValueId);
802         }
803
804         /**
805          * Gets data of this CTF
806          *
807          * @return Data
808          */

809         public String JavaDoc getData() {
810             return data;
811         }
812
813         /**
814          * Sets data of this CTF
815          *
816          * @param data Data to set
817          */

818         public void setData(String JavaDoc data) {
819             this.data = data;
820         }
821
822         /**
823          * Gets content field ID
824          *
825          * @return Content field ID
826          */

827         public Long JavaDoc getContentFieldId() {
828             return contentFieldId;
829         }
830
831         /**
832          * Sets content field ID
833          *
834          * @param contentFieldId Content field ID to set
835          */

836         public void setContentFieldId(Long JavaDoc contentFieldId) {
837             this.contentFieldId = contentFieldId;
838         }
839
840         /**
841          * Gets ID of this CFV
842          *
843          * @return CFV ID
844          */

845         public Long JavaDoc getContentFieldValueId() {
846             return contentFieldValueId;
847         }
848
849         /**
850          * Sets ID of this CFV
851          *
852          * @param contentFieldValueId CFV ID to set
853          */

854         public void setContentFieldValueId(Long JavaDoc contentFieldValueId) {
855             this.contentFieldValueId = contentFieldValueId;
856         }
857
858         /**
859          * Gets content field type
860          *
861          * @return Content field type
862          */

863         public byte getContentFieldType() {
864             return contentFieldType;
865         }
866
867         /**
868          * Sets content field type
869          *
870          * @param contentFieldType Content field type to set
871          */

872         public void setContentFieldType(byte contentFieldType) {
873             this.contentFieldType = contentFieldType;
874         }
875
876     }
877
878
879 }
880
Popular Tags