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 | * @since 8168
|
---|
14 | */
|
---|
15 | public class CacheEntryAttributes extends ElementAttributes {
|
---|
16 | private static final long serialVersionUID = 1L; //version
|
---|
17 | private final Map<String, String> attrs = new HashMap<String, String>();
|
---|
18 | private static final String NO_TILE_AT_ZOOM = "noTileAtZoom";
|
---|
19 | private static final String ETAG = "Etag";
|
---|
20 | private static final String LAST_MODIFICATION = "lastModification";
|
---|
21 | private static final String EXPIRATION_TIME = "expirationTime";
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Constructs a new {@code CacheEntryAttributes}.
|
---|
25 | */
|
---|
26 | public CacheEntryAttributes() {
|
---|
27 | super();
|
---|
28 | attrs.put(NO_TILE_AT_ZOOM, "false");
|
---|
29 | attrs.put(ETAG, null);
|
---|
30 | attrs.put(LAST_MODIFICATION, "0");
|
---|
31 | attrs.put(EXPIRATION_TIME, "0");
|
---|
32 | }
|
---|
33 |
|
---|
34 | public boolean isNoTileAtZoom() {
|
---|
35 | return Boolean.toString(true).equals(attrs.get(NO_TILE_AT_ZOOM));
|
---|
36 | }
|
---|
37 | public void setNoTileAtZoom(boolean noTileAtZoom) {
|
---|
38 | attrs.put(NO_TILE_AT_ZOOM, Boolean.toString(noTileAtZoom));
|
---|
39 | }
|
---|
40 | public String getEtag() {
|
---|
41 | return attrs.get(ETAG);
|
---|
42 | }
|
---|
43 | public void setEtag(String etag) {
|
---|
44 | attrs.put(ETAG, etag);
|
---|
45 | }
|
---|
46 |
|
---|
47 | private long getLongAttr(String key) {
|
---|
48 | try {
|
---|
49 | return Long.parseLong(attrs.get(key));
|
---|
50 | } catch (NumberFormatException e) {
|
---|
51 | attrs.put(key, "0");
|
---|
52 | return 0;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public long getLastModification() {
|
---|
57 | return getLongAttr(LAST_MODIFICATION);
|
---|
58 | }
|
---|
59 | public void setLastModification(long lastModification) {
|
---|
60 | attrs.put(LAST_MODIFICATION, Long.toString(lastModification));
|
---|
61 | }
|
---|
62 | public long getExpirationTime() {
|
---|
63 | return getLongAttr(EXPIRATION_TIME);
|
---|
64 | }
|
---|
65 | public void setExpirationTime(long expirationTime) {
|
---|
66 | attrs.put(EXPIRATION_TIME, Long.toString(expirationTime));
|
---|
67 | }
|
---|
68 |
|
---|
69 | }
|
---|