- Timestamp:
- 2011-12-25T15:03:43+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/GettingStarted.java
r4364 r4709 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); -
trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java
r3947 r4709 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 … … 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 /** … … 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()) … … 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()) … … 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(); … … 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 { … … 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(); … … 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"); … … 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(); -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r4690 r4709 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); … … 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());
Note:
See TracChangeset
for help on using the changeset viewer.