1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.cache;
|
---|
3 |
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Map;
|
---|
6 |
|
---|
7 | import org.apache.commons.jcs.engine.ElementAttributes;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Class that contains attirubtes for JCS cache entries. Parameters are used to properly handle HTTP caching
|
---|
11 | *
|
---|
12 | * @author Wiktor Niesiobędzki
|
---|
13 | *
|
---|
14 | */
|
---|
15 | public class CacheEntryAttributes extends ElementAttributes {
|
---|
16 | private static final long serialVersionUID = 1L; //version
|
---|
17 | private transient Map<String, String> attrs = new HashMap<String, String>();
|
---|
18 | private final static String NO_TILE_AT_ZOOM = "noTileAtZoom";
|
---|
19 | private final static String ETAG = "Etag";
|
---|
20 | private final static String LAST_MODIFICATION = "lastModification";
|
---|
21 | private final static String EXPIRATION_TIME = "expirationTime";
|
---|
22 |
|
---|
23 | public CacheEntryAttributes() {
|
---|
24 | super();
|
---|
25 | attrs.put(NO_TILE_AT_ZOOM, "false");
|
---|
26 | attrs.put(ETAG, null);
|
---|
27 | attrs.put(LAST_MODIFICATION, "0");
|
---|
28 | attrs.put(EXPIRATION_TIME, "0");
|
---|
29 | }
|
---|
30 |
|
---|
31 | public boolean isNoTileAtZoom() {
|
---|
32 | return Boolean.toString(true).equals(attrs.get(NO_TILE_AT_ZOOM));
|
---|
33 | }
|
---|
34 | public void setNoTileAtZoom(boolean noTileAtZoom) {
|
---|
35 | attrs.put(NO_TILE_AT_ZOOM, Boolean.toString(noTileAtZoom));
|
---|
36 | }
|
---|
37 | public String getEtag() {
|
---|
38 | return attrs.get(ETAG);
|
---|
39 | }
|
---|
40 | public void setEtag(String etag) {
|
---|
41 | attrs.put(ETAG, etag);
|
---|
42 | }
|
---|
43 |
|
---|
44 | private long getLongAttr(String key) {
|
---|
45 | try {
|
---|
46 | return Long.parseLong(attrs.get(key));
|
---|
47 | } catch (NumberFormatException e) {
|
---|
48 | attrs.put(key, "0");
|
---|
49 | return 0;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public long getLastModification() {
|
---|
54 | return getLongAttr(LAST_MODIFICATION);
|
---|
55 | }
|
---|
56 | public void setLastModification(long lastModification) {
|
---|
57 | attrs.put(LAST_MODIFICATION, Long.toString(lastModification));
|
---|
58 | }
|
---|
59 | public long getExpirationTime() {
|
---|
60 | return getLongAttr(EXPIRATION_TIME);
|
---|
61 | }
|
---|
62 | public void setExpirationTime(long expirationTime) {
|
---|
63 | attrs.put(EXPIRATION_TIME, Long.toString(expirationTime));
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|