View Javadoc
1   /**
2    *
3    */
4   package fr.paris.lutece.plugins.dila.utils;
5   
6   import fr.paris.lutece.plugins.dila.utils.constants.DilaConstants;
7   
8   import org.apache.commons.lang.StringUtils;
9   
10  
11  /**
12   * Class used to generate and decode cache key
13   *
14   */
15  public final class CacheKeyUtils
16  {
17      /**
18       * Private constructor
19       */
20      private CacheKeyUtils(  )
21      {
22      }
23  
24      /**
25       * Generate cache key
26       * @param lCategoryId the category id
27       * @param strCardId the card id
28       * @return the generated key
29       */
30      public static String generateCacheKey( Long lCategoryId, String strCardId )
31      {
32          StringBuilder sbKey = new StringBuilder(  );
33          sbKey.append( lCategoryId ).append( DilaConstants.CACHE_KEY_SEPARATOR ).append( strCardId );
34  
35          return sbKey.toString(  );
36      }
37  
38      /**
39       * Get category part of cache key
40       * @param strKey the key to split
41       * @return the category id of cache key
42       */
43      public static Long getCategoryFromCacheKey( String strKey )
44      {
45          Long catId = null;
46  
47          if ( StringUtils.isNotBlank( strKey ) )
48          {
49              String[] splitKey = strKey.split( DilaConstants.CACHE_KEY_SEPARATOR );
50  
51              if ( ( splitKey.length >= 1 ) && StringUtils.isNumeric( splitKey[0] ) )
52              {
53                  catId = Long.valueOf( splitKey[0] );
54              }
55          }
56  
57          return catId;
58      }
59  
60      /**
61       * Get card id part of cache key
62       * @param strKey the key to split
63       * @return the card id of cache key
64       */
65      public static String getCardIdFromCacheKey( String strKey )
66      {
67          String cardId = null;
68  
69          if ( StringUtils.isNotBlank( strKey ) )
70          {
71              String[] splitKey = strKey.split( DilaConstants.CACHE_KEY_SEPARATOR );
72  
73              if ( splitKey.length == 2 )
74              {
75                  cardId = splitKey[1];
76              }
77          }
78  
79          return cardId;
80      }
81  }