KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/flex/CmsFlexCacheKey.java,v $
3  * Date : $Date: 2006/07/12 08:13:38 $
4  * Version: $Revision: 1.27 $
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.loader.I_CmsResourceLoader;
35 import org.opencms.main.CmsLog;
36 import org.opencms.util.CmsStringUtil;
37
38 import java.util.Arrays JavaDoc;
39 import java.util.Collections JavaDoc;
40 import java.util.HashSet JavaDoc;
41 import java.util.Iterator JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Set JavaDoc;
45
46 import javax.servlet.http.HttpSession JavaDoc;
47
48 import org.apache.commons.logging.Log;
49
50 /**
51  * Implements the CmsFlexCacheKey,
52  * which is a key used to describe the caching behaviour
53  * of a specific resource.<p>
54  *
55  * It has a lot of variables that are directly accessed (which isn't good style, I know)
56  * to avoid method calling overhead (a cache is about speed, isn't it :).<p>
57  *
58  * @author Alexander Kandzior
59  *
60  * @version $Revision: 1.27 $
61  *
62  * @since 6.0.0
63  */

64 public class CmsFlexCacheKey {
65
66     /** Flex cache keyword: always. */
67     private static final String JavaDoc CACHE_00_ALWAYS = "always";
68
69     /** Flex cache keyword: never. */
70     private static final String JavaDoc CACHE_01_NEVER = "never";
71
72     /** Flex cache keyword: uri. */
73     private static final String JavaDoc CACHE_02_URI = "uri";
74
75     /** Flex cache keyword: user. */
76     private static final String JavaDoc CACHE_03_USER = "user";
77
78     /** Flex cache keyword: params. */
79     private static final String JavaDoc CACHE_04_PARAMS = "params";
80
81     /** Flex cache keyword: no-params. */
82     private static final String JavaDoc CACHE_05_NO_PARAMS = "no-params";
83
84     /** Flex cache keyword: timeout. */
85     private static final String JavaDoc CACHE_06_TIMEOUT = "timeout";
86
87     /** Flex cache keyword: session. */
88     private static final String JavaDoc CACHE_07_SESSION = "session";
89
90     /** Flex cache keyword: schemes. */
91     private static final String JavaDoc CACHE_08_SCHEMES = "schemes";
92
93     /** Flex cache keyword: ports. */
94     private static final String JavaDoc CACHE_09_PORTS = "ports";
95
96     /** Flex cache keyword: false. */
97     private static final String JavaDoc CACHE_10_FALSE = CmsStringUtil.FALSE;
98
99     /** Flex cache keyword: parse-error. */
100     private static final String JavaDoc CACHE_11_PARSE_ERROR = "parse-error";
101
102     /** Flex cache keyword: true. */
103     private static final String JavaDoc CACHE_12_TRUE = CmsStringUtil.TRUE;
104
105     /** Flex cache keyword: ip. */
106     private static final String JavaDoc CACHE_13_IP = "ip";
107
108     /** Flex cache keyword: element. */
109     private static final String JavaDoc CACHE_14_ELEMENT = "element";
110
111     /** Flex cache keyword: locale. */
112     private static final String JavaDoc CACHE_15_LOCALE = "locale";
113
114     /** Flex cache keyword: encoding. */
115     private static final String JavaDoc CACHE_16_ENCODING = "encoding";
116
117     /** Flex cache keyword: site. */
118     private static final String JavaDoc CACHE_17_SITE = "site";
119
120     /** The list of keywords of the Flex cache language. */
121     private static final List JavaDoc CACHE_COMMANDS = Arrays.asList(new String JavaDoc[] {
122         CACHE_00_ALWAYS,
123         CACHE_01_NEVER,
124         CACHE_02_URI,
125         CACHE_03_USER,
126         CACHE_04_PARAMS,
127         CACHE_05_NO_PARAMS,
128         CACHE_06_TIMEOUT,
129         CACHE_07_SESSION,
130         CACHE_08_SCHEMES,
131         CACHE_09_PORTS,
132         CACHE_10_FALSE,
133         CACHE_11_PARSE_ERROR,
134         CACHE_12_TRUE,
135         CACHE_13_IP,
136         CACHE_14_ELEMENT,
137         CACHE_15_LOCALE,
138         CACHE_16_ENCODING,
139         CACHE_17_SITE});
140
141     /** Marker to identify use of certain String key members (uri, ip etc.). */
142     private static final String JavaDoc IS_USED = "/ /";
143
144     /** The log object for this class. */
145     private static final Log LOG = CmsLog.getLog(CmsFlexCacheKey.class);
146
147     /** Cache key variable: Determines if this resource can be cached alwys, never or under certain conditions. -1 = never, 0=check, 1=always. */
148     private int m_always;
149
150     /** Cache key variable: The requested element. */
151     private String JavaDoc m_element;
152
153     /** Cache key variable: The requested encoding. */
154     private String JavaDoc m_encoding;
155
156     /** Cache key variable: The ip address of the request. */
157     private String JavaDoc m_ip;
158
159     /** Cache key variable: The requested locale. */
160     private String JavaDoc m_locale;
161
162     /** Cache key variable: List of "blocking" parameters. */
163     private Set JavaDoc m_noparams;
164
165     /** Cache key variable: List of parameters. */
166     private Set JavaDoc m_params;
167
168     /** Flag raised in case a key parse error occured. */
169     private boolean m_parseError;
170
171     /** Cache key variable: The request TCP/IP port. */
172     private Set JavaDoc m_ports;
173
174     /** The OpenCms resource that this key is used for. */
175     private String JavaDoc m_resource;
176
177     /** Cache key variable: Distinguishes request schemes (http, https etc.). */
178     private Set JavaDoc m_schemes;
179
180     /** Cache key variable: List of session variables. */
181     private Set JavaDoc m_session;
182
183     /** Cache key variable: The current site root. */
184     private String JavaDoc m_site;
185
186     /** Cache key variable: Timeout of the resource. */
187     private long m_timeout;
188
189     /** Cache key variable: The uri of the original request. */
190     private String JavaDoc m_uri;
191
192     /** Cache key variable: The user id. */
193     private String JavaDoc m_user;
194
195     /** The cache behaviour description for the resource. */
196     private String JavaDoc m_variation;
197
198     /**
199      * This constructor is used when building a cache key from set of cache directives.<p>
200      *
201      * These directives are attached to the properties of the requested resource
202      * on a property called "cache".
203      * The value of this poperty that is passed in this constructor as "cacheDirectives"
204      * is parsed to build the keys data structure.<p>
205      *
206      * In case a parsing error occures, the value of this key is set to "cache=never",
207      * and the hadParseError() flag is set to true.
208      * This is done to ensure that a valid key is always constructed with the constructor.<p>
209      *
210      * @param resourcename the full name of the resource including site root
211      * @param cacheDirectives the cache directives of the resource (value of the property "cache")
212      * @param online must be true for an online resource, false for offline resources
213      */

214     public CmsFlexCacheKey(String JavaDoc resourcename, String JavaDoc cacheDirectives, boolean online) {
215
216         m_resource = getKeyName(resourcename, online);
217         m_variation = "never";
218         m_always = -1;
219         m_timeout = -1;
220         if (cacheDirectives != null) {
221             parseFlexKey(cacheDirectives);
222         }
223         if (LOG.isDebugEnabled()) {
224             LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_GENERATED_1, toString()));
225         }
226     }
227
228     /**
229      * Calculates the cache key name that is used as key in
230      * the first level of the FlexCache.<p>
231      *
232      * @param resourcename the full name of the resource including site root
233      * @param online must be true for an online resource, false for offline resources
234      *
235      * @return fhe FlexCache key name
236      */

237     public static String JavaDoc getKeyName(String JavaDoc resourcename, boolean online) {
238
239         return resourcename.concat(online ? CmsFlexCache.CACHE_ONLINESUFFIX : CmsFlexCache.CACHE_OFFLINESUFFIX);
240     }
241
242     /**
243      * Appends a flex cache key value to the given buffer.<p>
244      *
245      * @param str the buffer to append to
246      * @param key the key to append
247      * @param value the value to append
248      */

249     private static void appendKeyValue(StringBuffer JavaDoc str, String JavaDoc key, String JavaDoc value) {
250
251         str.append(key);
252         if (value == IS_USED) {
253             str.append(";");
254         } else {
255             str.append("=(");
256             str.append(value);
257             str.append(");");
258         }
259     }
260
261     /**
262      * This flag is used to indicate that a parse error had
263      * occured, which can happen if the cache directives String
264      * passed to the constructor using the response is
265      * not build according to the Flex cache language syntax.<p>
266      *
267      * @return true if a parse error did occur, false otherwise
268      */

269     public boolean hadParseError() {
270
271         return m_parseError;
272     }
273
274     /**
275      * Compares this key to the other key passed as parameter,
276      * from comparing the two keys, a variation String is constructed.<p>
277      *
278      * This method is the "heart" of the key matching process.<p>
279      *
280      * The assumtion is that this key should be the one constructed for the response,
281      * while the parameter key should have been constructed from the request.<p>
282      *
283      * A short example how this works:
284      * If the cache key is "cache=user" and the request is done from a guest user
285      * the constructed variation will be "user=(guest)".<p>
286      *
287      * @param key the key to match this key with
288      * @return null if not cachable, or the Variation String if cachable
289      */

290     public String JavaDoc matchRequestKey(CmsFlexRequestKey key) {
291
292         StringBuffer JavaDoc str = new StringBuffer JavaDoc(100);
293         if (m_always < 0) {
294             if (LOG.isDebugEnabled()) {
295                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_KEYMATCH_CACHE_NEVER_0));
296             }
297             return null;
298         }
299
300         if (LOG.isDebugEnabled()) {
301             LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_KEYMATCH_CHECK_NO_PARAMS_0));
302         }
303         if ((m_noparams != null) && (key.getParams() != null)) {
304             if ((m_noparams.size() == 0) && (key.getParams().size() > 0)) {
305                 return null;
306             }
307             Iterator JavaDoc i = key.getParams().keySet().iterator();
308             while (i.hasNext()) {
309                 if (m_noparams.contains(i.next())) {
310                     return null;
311                 }
312             }
313         }
314
315         if (m_always > 0) {
316             if (LOG.isDebugEnabled()) {
317                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_KEYMATCH_CACHE_ALWAYS_0));
318             }
319             str.append(CACHE_00_ALWAYS);
320             return str.toString();
321         }
322
323         if (m_uri != null) {
324             appendKeyValue(str, CACHE_02_URI, key.getUri());
325         }
326
327         if (m_site != null) {
328             appendKeyValue(str, CACHE_17_SITE, key.getSite());
329         }
330
331         if (m_element != null) {
332             appendKeyValue(str, CACHE_14_ELEMENT, key.getElement());
333         }
334
335         if (m_locale != null) {
336             appendKeyValue(str, CACHE_15_LOCALE, key.getLocale());
337         }
338
339         if (m_encoding != null) {
340             appendKeyValue(str, CACHE_16_ENCODING, key.getEncoding());
341         }
342
343         if (m_ip != null) {
344             appendKeyValue(str, CACHE_13_IP, key.getIp());
345         }
346
347         if (m_user != null) {
348             appendKeyValue(str, CACHE_03_USER, key.getUser());
349         }
350
351         if (m_params != null) {
352             str.append(CACHE_04_PARAMS);
353             str.append("=(");
354             Map JavaDoc keyParams = key.getParams();
355             if (keyParams != null) {
356                 if (m_params.size() > 0) {
357                     // match only params listed in cache directives
358
Iterator JavaDoc i = m_params.iterator();
359                     while (i.hasNext()) {
360                         Object JavaDoc o = i.next();
361                         if (keyParams.containsKey(o)) {
362                             str.append(o);
363                             str.append("=");
364                             // TODO: handle multiple occurances of the same parameter value
365
String JavaDoc[] values = (String JavaDoc[])keyParams.get(o);
366                             str.append(values[0]);
367                             if (i.hasNext()) {
368                                 str.append(",");
369                             }
370                         }
371                     }
372                 } else {
373                     // match all request params
374
Iterator JavaDoc i = keyParams.keySet().iterator();
375                     while (i.hasNext()) {
376                         Object JavaDoc o = i.next();
377                         str.append(o);
378                         str.append("=");
379                         // TODO: handle multiple occurances of the same parameter value
380
String JavaDoc[] values = (String JavaDoc[])keyParams.get(o);
381                         str.append(values[0]);
382                         if (i.hasNext()) {
383                             str.append(",");
384                         }
385                     }
386                 }
387             }
388             str.append(");");
389         }
390
391         if (m_session != null) {
392             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(32);
393             boolean found = false;
394             buf.append(CACHE_07_SESSION);
395             buf.append("=(");
396             HttpSession JavaDoc keySession = key.getSession();
397             if (keySession != null) {
398                 // match only session attributes listed in cache directives
399
Iterator JavaDoc i = m_session.iterator();
400                 while (i.hasNext()) {
401                     String JavaDoc name = (String JavaDoc)i.next();
402                     Object JavaDoc val = keySession.getAttribute(name);
403                     if (val != null) {
404                         found = true;
405                         buf.append(name);
406                         buf.append("=");
407                         buf.append(val);
408                         if (i.hasNext()) {
409                             buf.append(",");
410                         }
411                     }
412                 }
413             }
414             if (found) {
415                 buf.append(");");
416                 str.append(buf);
417             }
418         }
419
420         if (m_schemes != null) {
421             String JavaDoc s = key.getScheme();
422             if ((m_schemes.size() > 0) && (!m_schemes.contains(s))) {
423                 return null;
424             }
425             appendKeyValue(str, CACHE_08_SCHEMES, s);
426         }
427
428         if (m_ports != null) {
429             Integer JavaDoc i = key.getPort();
430             if ((m_ports.size() > 0) && (!m_ports.contains(i))) {
431                 return null;
432             }
433             str.append(CACHE_09_PORTS);
434             str.append("=(");
435             str.append(i);
436             str.append(");");
437         }
438
439         if (m_timeout > 0) {
440             str.append(CACHE_06_TIMEOUT);
441             str.append("=(");
442             str.append(m_timeout);
443             str.append(");");
444         }
445
446         if (str.length() > 0) {
447             return str.toString();
448         } else {
449             return null;
450         }
451     }
452
453     /**
454      * @see java.lang.Object#toString()
455      *
456      * @return a complete String representation for this key
457      */

458     public String JavaDoc toString() {
459
460         StringBuffer JavaDoc str = new StringBuffer JavaDoc(100);
461
462         if (m_always < 0) {
463             str.append(CACHE_01_NEVER);
464             if (m_parseError) {
465                 str.append(";");
466                 str.append(CACHE_11_PARSE_ERROR);
467             }
468             return str.toString();
469         }
470         if (m_noparams != null) {
471             // add "no-cachable" parameters
472
str.append(CACHE_05_NO_PARAMS);
473             if (m_noparams.size() == 0) {
474                 str.append(";");
475             } else {
476                 str.append("=(");
477                 Iterator JavaDoc i = m_noparams.iterator();
478                 while (i.hasNext()) {
479                     Object JavaDoc o = i.next();
480                     str.append(o);
481                     if (i.hasNext()) {
482                         str.append(",");
483                     }
484                 }
485                 str.append(");");
486             }
487         }
488         if (m_always > 0) {
489             str.append(CACHE_00_ALWAYS);
490             if (m_parseError) {
491                 str.append(";");
492                 str.append(CACHE_11_PARSE_ERROR);
493             }
494             return str.toString();
495         }
496         if (m_uri != null) {
497             // add uri
498
appendKeyValue(str, CACHE_02_URI, m_uri);
499         }
500         if (m_site != null) {
501             // add site
502
appendKeyValue(str, CACHE_17_SITE, m_site);
503         }
504         if (m_element != null) {
505             // add element
506
appendKeyValue(str, CACHE_14_ELEMENT, m_element);
507         }
508         if (m_locale != null) {
509             // add locale
510
appendKeyValue(str, CACHE_15_LOCALE, m_locale);
511         }
512         if (m_encoding != null) {
513             // add encoding
514
appendKeyValue(str, CACHE_16_ENCODING, m_encoding);
515         }
516         if (m_ip != null) {
517             // add ip
518
appendKeyValue(str, CACHE_13_IP, m_ip);
519         }
520         if (m_user != null) {
521             // add user
522
appendKeyValue(str, CACHE_03_USER, m_user);
523         }
524         if (m_params != null) {
525             // add parameters
526
str.append(CACHE_04_PARAMS);
527             if (m_params.size() == 0) {
528                 str.append(";");
529             } else {
530                 str.append("=(");
531                 Iterator JavaDoc i = m_params.iterator();
532                 while (i.hasNext()) {
533                     Object JavaDoc o = i.next();
534                     if (I_CmsResourceLoader.PARAMETER_ELEMENT.equals(o)) {
535                         continue;
536                     }
537                     str.append(o);
538                     if (i.hasNext()) {
539                         str.append(",");
540                     }
541                 }
542                 str.append(");");
543             }
544         }
545         if (m_session != null) {
546             // add session variables
547
str.append(CACHE_07_SESSION);
548             str.append("=(");
549             Iterator JavaDoc i = m_session.iterator();
550             while (i.hasNext()) {
551                 Object JavaDoc o = i.next();
552                 str.append(o);
553                 if (i.hasNext()) {
554                     str.append(",");
555                 }
556             }
557             str.append(");");
558         }
559         if (m_timeout >= 0) {
560             // add timeout
561
str.append(CACHE_06_TIMEOUT);
562             str.append("=(");
563             str.append(m_timeout);
564             str.append(");");
565         }
566         if (m_schemes != null) {
567             // add schemes
568
str.append(CACHE_08_SCHEMES);
569             if (m_schemes.size() == 0) {
570                 str.append(";");
571             } else {
572                 str.append("=(");
573                 Iterator JavaDoc i = m_schemes.iterator();
574                 while (i.hasNext()) {
575                     str.append(i.next());
576                     if (i.hasNext()) {
577                         str.append(",");
578                     }
579                 }
580                 str.append(");");
581             }
582         }
583         if (m_ports != null) {
584             // add ports
585
str.append(CACHE_09_PORTS);
586             if (m_ports.size() == 0) {
587                 str.append(";");
588             } else {
589                 str.append("=(");
590                 Iterator JavaDoc i = m_ports.iterator();
591                 while (i.hasNext()) {
592                     str.append(i.next());
593                     if (i.hasNext()) {
594                         str.append(",");
595                     }
596                 }
597                 str.append(");");
598             }
599         }
600
601         if (m_parseError) {
602             str.append(CACHE_11_PARSE_ERROR);
603         }
604         return str.toString();
605     }
606
607     /**
608      * Returns the resource.<p>
609      *
610      * @return the resource
611      */

612     protected String JavaDoc getResource() {
613
614         return m_resource;
615     }
616
617     /**
618      * Returns the timeout.<p>
619      *
620      * @return the timeout
621      */

622     protected long getTimeout() {
623
624         return m_timeout;
625     }
626
627     /**
628      * Returns the variation.<p>
629      *
630      * @return the variation
631      */

632     protected String JavaDoc getVariation() {
633
634         return m_variation;
635     }
636
637     /**
638      * Sets the variation.<p>
639      *
640      * @param variation the variation to set
641      */

642     protected void setVariation(String JavaDoc variation) {
643
644         m_variation = variation;
645     }
646
647     /**
648      * Parse a String in the Flex cache language and construct
649      * the key data structure from this.<p>
650      *
651      * @param key the String to parse (usually read from the file property "cache")
652      */

653     private void parseFlexKey(String JavaDoc key) {
654
655         List JavaDoc tokens = CmsStringUtil.splitAsList(key, ';', false);
656         Iterator JavaDoc i = tokens.iterator();
657         try {
658             while (i.hasNext()) {
659                 String JavaDoc t = (String JavaDoc)i.next();
660                 String JavaDoc k = null;
661                 String JavaDoc v = null;
662                 int idx = t.indexOf('=');
663                 if (idx >= 0) {
664                     k = t.substring(0, idx).trim();
665                     if (t.length() > idx) {
666                         v = t.substring(idx + 1).trim();
667                     }
668                 } else {
669                     k = t.trim();
670                 }
671                 m_always = 0;
672                 if (LOG.isDebugEnabled()) {
673                     LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_PARSE_FLEXKEY_3, t, k, v));
674                 }
675                 switch (CACHE_COMMANDS.indexOf(k)) {
676                     case 0: // always
677
case 12: // true
678
m_always = 1;
679                         // continue processing (make sure we find a "never" behind "always")
680
break;
681                     case 1: // never
682
case 10: // false
683
m_always = -1;
684                         // no need for any further processing
685
return;
686                     case 2: // uri
687
m_uri = IS_USED; // marks m_uri as being used
688
break;
689                     case 3: // user
690
m_user = IS_USED; // marks m_user as being used
691
break;
692                     case 4: // params
693
if (v!= null) {
694                             m_params = parseValueList(v);
695                         } else {
696                             m_params = Collections.EMPTY_SET;
697                         }
698                         
699                         if (m_params.contains(I_CmsResourceLoader.PARAMETER_ELEMENT)) {
700                             // workaround for element setting by parameter in OpenCms < 6.0
701
m_element = IS_USED;
702                             m_params.remove(I_CmsResourceLoader.PARAMETER_ELEMENT);
703                             if (m_params.size() == 0) {
704                                 m_params = null;
705                             }
706                         }
707                         break;
708                     case 5: // no-params
709
if (v != null) {
710                             // no-params are present
711
m_noparams = parseValueList(v);
712                         } else {
713                             // never cache with parameters
714
m_noparams = Collections.EMPTY_SET;
715                         }
716                         break;
717                     case 6: // timeout
718
m_timeout = Integer.parseInt(v);
719                         break;
720                     case 7: // session
721
m_session = parseValueList(v);
722                         if (m_session.size() <= 0) {
723                             // session must have at last one variable set
724
m_parseError = true;
725                         }
726                         break;
727                     case 8: // schemes
728
m_schemes = parseValueList(v);
729                         break;
730                     case 9: // ports
731
m_ports = parseValueList(v);
732                         break;
733                     case 11: // previous parse error - ignore
734
break;
735                     case 13: // ip
736
m_ip = IS_USED; // marks ip as being used
737
break;
738                     case 14: // element
739
m_element = IS_USED;
740                         break;
741                     case 15: // locale
742
m_locale = IS_USED;
743                         break;
744                     case 16: // encoding
745
m_encoding = IS_USED;
746                         break;
747                     case 17: // site
748
m_site = IS_USED;
749                         break;
750                     default: // unknown directive, throw error
751
m_parseError = true;
752                 }
753             }
754         } catch (Exception JavaDoc e) {
755             // any Exception here indicates a parsing error
756
if (LOG.isDebugEnabled()) {
757                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_PARSE_ERROR_1, e.toString()));
758             }
759             m_parseError = true;
760         }
761         if (m_parseError) {
762             // If string is invalid set cache to "never"
763
m_always = -1;
764         }
765     }
766
767     /**
768      * A helper method for the parsing process which parses
769      * Strings like groups=(a, b, c).<p>
770      *
771      * @param value the String to parse
772      * @return a Map that contains of the parsed values, only the keyset of the Map is needed later
773      */

774     private Set JavaDoc parseValueList(String JavaDoc value) {
775
776         if (value.charAt(0) == '(') {
777             value = value.substring(1);
778         }
779         int len = value.length() - 1;
780         if (value.charAt(len) == ')') {
781             value = value.substring(0, len);
782         }
783         if (value.charAt(len - 1) == ',') {
784             value = value.substring(0, len - 1);
785         }
786         if (LOG.isDebugEnabled()) {
787             LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_PARSE_VALUES_1, value));
788         }
789         List JavaDoc tokens = CmsStringUtil.splitAsList(value, ',', true);
790         Set JavaDoc result = new HashSet JavaDoc();
791         result.addAll(tokens);
792         return result;
793     }
794 }
Popular Tags