KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > packtag > cache > ResourceCache


1 /**
2  * Project pack:tag >> http://packtag.sf.net
3  *
4  * This software is published under the terms of the LGPL
5  * License version 2.1, a copy of which has been included with this
6  * distribution in the 'lgpl.txt' file.
7  *
8  * Creation date: 15.04.2007 - 11:02:24
9  * Last author: $Author: danielgalan $
10  * Last modified: $Date: 2007/05/02 21:38:37 $
11  * Revision: $Revision: 1.2 $
12  *
13  * $Log: ResourceCache.java,v $
14  * Revision 1.2 2007/05/02 21:38:37 danielgalan
15  * alias to name
16  *
17  * Revision 1.1 2007/04/22 19:04:21 danielgalan
18  * pack.tag moved from subversion to good old CVS
19  *
20  */

21 package net.sf.packtag.cache;
22
23 import java.util.Hashtable JavaDoc;
24
25
26
27 /**
28  * Contains the Minifed and gzipped Resources
29  *
30  * @author Daniel Galán y Martins
31  * @version $Revision: 1.2 $
32  */

33 public class ResourceCache {
34
35     private Hashtable JavaDoc resourcesSqp = new Hashtable JavaDoc();
36     private Hashtable JavaDoc resourcesFqp = new Hashtable JavaDoc();
37
38
39     public Resource getResourceBySqp(String JavaDoc sqp) {
40         return (Resource)resourcesSqp.get(sqp);
41     }
42
43
44     public Resource getResourceByFqp(String JavaDoc fqp) {
45         return (Resource)resourcesFqp.get(fqp);
46     }
47
48
49     public boolean existResource(String JavaDoc sqp) {
50         return resourcesSqp.containsKey(sqp);
51     }
52
53
54     public void store(Resource resource, boolean clearDependingCombinedResources) {
55         resourcesSqp.put(resource.getShortQualifiedPath(), resource);
56         resourcesFqp.put(resource.getFullQualifiedPath(), resource);
57         
58         if (clearDependingCombinedResources) {
59             clearDependingCombinedResources(resource);
60         }
61     }
62
63
64     public void clearCache() {
65         resourcesSqp.clear();
66         resourcesFqp.clear();
67     }
68
69
70     private void clearDependingCombinedResources(Resource resource) {
71         String JavaDoc sqp = resource.getShortQualifiedPath();
72         Object JavaDoc[] keys = resourcesSqp.keySet().toArray();
73         for (int i = 0; i < keys.length; i++) {
74             Resource currentResource = (Resource)resourcesSqp.get(keys[i]);
75             int idx = currentResource.getShortQualifiedPath().indexOf(sqp);
76             // "> 0" because the normal resource doesn't starts with "["
77
if (idx > 0) {
78                 resourcesSqp.remove(keys[i]);
79             }
80         }
81     }
82 }
83
Popular Tags