diff --git a/src/org/openstreetmap/josm/gui/GettingStarted.java b/src/org/openstreetmap/josm/gui/GettingStarted.java
index 828b1fe..5a72523 100644
|
a
|
b
|
public class GettingStarted extends JPanel {
|
| 53 | 53 | /** |
| 54 | 54 | * Grabs current MOTD from cache or webpage and parses it. |
| 55 | 55 | */ |
| 56 | | private static class MotdContent extends CacheCustomContent { |
| | 56 | private static class MotdContent extends CacheCustomContent<RuntimeException> { |
| 57 | 57 | public MotdContent() { |
| 58 | 58 | super("motd.html", CacheCustomContent.INTERVAL_DAILY); |
| 59 | 59 | } |
diff --git a/src/org/openstreetmap/josm/io/CacheCustomContent.java b/src/org/openstreetmap/josm/io/CacheCustomContent.java
index acdcc49..9a46e97 100644
|
a
|
b
|
import org.openstreetmap.josm.Main;
|
| 16 | 16 | * Use this class if you want to cache and store a single file that gets updated regularly. |
| 17 | 17 | * Unless you flush() it will be kept in memory. If you want to cache a lot of data and/or files, |
| 18 | 18 | * use CacheFiles |
| | 19 | * @param <T> a {@link Throwable} that may be thrown during {@link #updateData()}, |
| | 20 | * use {@link RuntimeException} if no exception must be handled. |
| 19 | 21 | * @author xeen |
| 20 | 22 | * |
| 21 | 23 | */ |
| 22 | | public abstract class CacheCustomContent { |
| | 24 | public abstract class CacheCustomContent<T extends Throwable> { |
| 23 | 25 | /** |
| 24 | 26 | * Common intervals |
| 25 | 27 | */ |
| … |
… |
public abstract class CacheCustomContent {
|
| 56 | 58 | * executed in the current thread. |
| 57 | 59 | * @return the data to cache |
| 58 | 60 | */ |
| 59 | | protected abstract byte[] updateData(); |
| | 61 | protected abstract byte[] updateData() throws T; |
| 60 | 62 | |
| 61 | 63 | /** |
| 62 | 64 | * This function serves as a comfort hook to perform additional checks if the cache is valid |
| … |
… |
public abstract class CacheCustomContent {
|
| 82 | 84 | * Updates data if required |
| 83 | 85 | * @return Returns the data |
| 84 | 86 | */ |
| 85 | | public byte[] updateIfRequired() { |
| | 87 | public byte[] updateIfRequired() throws T { |
| 86 | 88 | if(Main.pref.getInteger("cache." + ident, 0) + updateInterval < new Date().getTime()/1000 |
| 87 | 89 | || !isCacheValid()) |
| 88 | 90 | return updateForce(); |
| … |
… |
public abstract class CacheCustomContent {
|
| 93 | 95 | * Updates data if required |
| 94 | 96 | * @return Returns the data as string |
| 95 | 97 | */ |
| 96 | | public String updateIfRequiredString() { |
| | 98 | public String updateIfRequiredString() throws T { |
| 97 | 99 | if(Main.pref.getInteger("cache." + ident, 0) + updateInterval < new Date().getTime()/1000 |
| 98 | 100 | || !isCacheValid()) |
| 99 | 101 | return updateForceString(); |
| … |
… |
public abstract class CacheCustomContent {
|
| 104 | 106 | * Executes an update regardless of updateInterval |
| 105 | 107 | * @return Returns the data |
| 106 | 108 | */ |
| 107 | | public byte[] updateForce() { |
| | 109 | public byte[] updateForce() throws T { |
| 108 | 110 | this.data = updateData(); |
| 109 | 111 | saveToDisk(); |
| 110 | 112 | Main.pref.putInteger("cache." + ident, (int)(new Date().getTime()/1000)); |
| … |
… |
public abstract class CacheCustomContent {
|
| 115 | 117 | * Executes an update regardless of updateInterval |
| 116 | 118 | * @return Returns the data as String |
| 117 | 119 | */ |
| 118 | | public String updateForceString() { |
| | 120 | public String updateForceString() throws T { |
| 119 | 121 | updateForce(); |
| 120 | 122 | try { |
| 121 | 123 | return new String(data,"utf-8"); |
| … |
… |
public abstract class CacheCustomContent {
|
| 129 | 131 | * Returns the data without performing any updates |
| 130 | 132 | * @return the data |
| 131 | 133 | */ |
| 132 | | public byte[] getData() { |
| | 134 | public byte[] getData() throws T { |
| 133 | 135 | if(data == null) { |
| 134 | 136 | loadFromDisk(); |
| 135 | 137 | } |
| … |
… |
public abstract class CacheCustomContent {
|
| 140 | 142 | * Returns the data without performing any updates |
| 141 | 143 | * @return the data as String |
| 142 | 144 | */ |
| 143 | | public String getDataString() { |
| | 145 | public String getDataString() throws T { |
| 144 | 146 | try { |
| 145 | 147 | return new String(getData(), "utf-8"); |
| 146 | 148 | } catch(UnsupportedEncodingException e){ |
| … |
… |
public abstract class CacheCustomContent {
|
| 152 | 154 | /** |
| 153 | 155 | * Tries to load the data using the given ident from disk. If this fails, data will be updated |
| 154 | 156 | */ |
| 155 | | private void loadFromDisk() { |
| | 157 | private void loadFromDisk() throws T { |
| 156 | 158 | if(Main.applet) |
| 157 | 159 | this.data = updateForce(); |
| 158 | 160 | else { |
diff --git a/src/org/openstreetmap/josm/io/OsmApi.java b/src/org/openstreetmap/josm/io/OsmApi.java
index 31c1055..e01d3eb 100644
|
a
|
b
|
public class OsmApi extends OsmConnection {
|
| 152 | 152 | return host; |
| 153 | 153 | } |
| 154 | 154 | |
| | 155 | private class CapabilitiesCache extends CacheCustomContent<OsmTransferException> { |
| | 156 | |
| | 157 | ProgressMonitor monitor; |
| | 158 | boolean fastFail; |
| | 159 | |
| | 160 | public CapabilitiesCache(ProgressMonitor monitor, boolean fastFail) { |
| | 161 | super("capabilities" + getBaseUrl().hashCode(), CacheCustomContent.INTERVAL_WEEKLY); |
| | 162 | this.monitor = monitor; |
| | 163 | this.fastFail = fastFail; |
| | 164 | } |
| | 165 | @Override |
| | 166 | protected byte[] updateData() throws OsmTransferException { |
| | 167 | String s = sendRequest("GET", "capabilities", null, monitor, false, fastFail); |
| | 168 | return s.getBytes(); |
| | 169 | } |
| | 170 | } |
| | 171 | |
| 155 | 172 | public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException, OsmTransferCanceledException { |
| 156 | 173 | initialize(monitor, false); |
| 157 | 174 | } |
| … |
… |
public class OsmApi extends OsmConnection {
|
| 167 | 184 | return; |
| 168 | 185 | cancel = false; |
| 169 | 186 | try { |
| 170 | | String s = sendRequest("GET", "capabilities", null, monitor, false, fastFail); |
| | 187 | String s = new CapabilitiesCache(monitor, fastFail).updateIfRequiredString(); |
| 171 | 188 | InputSource inputSource = new InputSource(new StringReader(s)); |
| 172 | 189 | SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser()); |
| 173 | 190 | if (capabilities.supportsVersion("0.6")) { |