Changeset 12778 in osm for applications/editors/josm/plugins/openlayers
- Timestamp:
- 2009-01-01T18:28:53+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/Browser.java
r8748 r12778 21 21 static 22 22 { 23 23 Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING); 24 24 } 25 25 … … 29 29 30 30 public Browser(String uri) { 31 31 super(); 32 32 33 34 35 33 UserAgentContext ucontext = new CacheableUserAgentContext(); 34 rcontext = new SimpleHtmlRendererContext(this, ucontext); 35 addNotify(); 36 36 37 37 process( uri ); 38 38 } 39 39 40 40 private void process(String uri) { 41 try { 42 URL url; 43 try { 44 url = new URL(uri); 45 } catch (java.net.MalformedURLException mfu) { 46 int idx = uri.indexOf(':'); 47 if (idx == -1 || idx == 1) { 48 // try file 49 url = new URL("file:" + uri); 50 } else { 51 throw mfu; 52 } 53 } 54 // Call SimpleHtmlRendererContext.navigate() 55 // which implements incremental rendering. 56 this.rcontext.navigate(url, null); 57 } catch (Exception err) { 58 err.printStackTrace(); 59 } 41 try { 42 URL url; 43 try { 44 url = new URL(uri); 45 } catch (java.net.MalformedURLException mfu) { 46 int idx = uri.indexOf(':'); 47 if (idx == -1 || idx == 1) { 48 // try file 49 url = new URL("file:" + uri); 50 } else { 51 throw mfu; 52 } 53 } 54 // Call SimpleHtmlRendererContext.navigate() 55 // which implements incremental rendering. 56 this.rcontext.navigate(url, null); 57 } catch (Exception err) { 58 err.printStackTrace(); 60 59 } 61 60 } 61 62 62 @Override 63 63 public void setSize(final Dimension newSize) 64 64 { 65 66 67 68 65 if (!newSize.equals(oldSize)) { 66 oldSize = newSize; 67 super.setSize(newSize); 68 validate(); 69 69 70 71 70 executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");"); 71 } 72 72 } 73 73 74 74 public void executeAsyncScript(final String script) 75 75 { 76 77 78 79 80 76 EventQueue.invokeLater(new Runnable() { 77 public void run() { 78 executeScript(script); 79 } 80 }); 81 81 } 82 82 83 83 public Object executeScript(String script) 84 84 { 85 86 87 88 89 85 System.out.println("Executing script " + script); 86 try { 87 Window window = Window.getWindow(rcontext); 88 if( window.getDocumentNode() == null ) 89 return null; // Document not loaded yet 90 90 91 return window.eval(script); 92 } catch (EcmaError ecmaError) { 93 logger.log(Level.WARNING, "Javascript error at " + ecmaError.sourceName() + ":" + ecmaError.lineNumber() + ": " + ecmaError.getMessage()); 94 } catch (Throwable err) { 95 logger.log(Level.WARNING, "Unable to evaluate Javascript code", err); 96 } 97 98 return null; 91 return window.eval(script); 92 } catch (EcmaError ecmaError) { 93 logger.log(Level.WARNING, "Javascript error at " + ecmaError.sourceName() + ":" + ecmaError.lineNumber() + ": " + ecmaError.getMessage()); 94 } catch (Throwable err) { 95 logger.log(Level.WARNING, "Unable to evaluate Javascript code", err); 99 96 } 100 101 97 98 return null; 99 } 100 101 102 102 /** 103 103 * Overrided to hide hardcoded scrollbars and insets … … 105 105 @Override 106 106 protected HtmlBlockPanel createHtmlBlockPanel(UserAgentContext ucontext, HtmlRendererContext rcontext) { 107 107 return new MyHtmlBlockPanel(java.awt.Color.WHITE, true, ucontext, rcontext, this); 108 108 } 109 109 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableHttpRequest.java
r8748 r12778 44 44 45 45 public CacheableHttpRequest(UserAgentContext context, Proxy proxy) { 46 47 46 this.context = context; 47 this.proxy = proxy; 48 48 } 49 49 50 50 public synchronized int getReadyState() { 51 51 return this.readyState; 52 52 } 53 53 54 54 public synchronized String getResponseText() { 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 55 if( response == null ) return null; 56 57 byte[] bytes = this.response.responseBytes; 58 String encoding = this.response.encoding; 59 60 try { 61 return bytes == null ? null : new String(bytes, encoding); 62 } catch (UnsupportedEncodingException uee) { 63 logger.log(Level.WARNING, "getResponseText(): Charset '" + encoding + "' did not work. Retrying with ISO-8859-1.", uee); 64 try { 65 return new String(bytes, "ISO-8859-1"); 66 } catch (UnsupportedEncodingException uee2) { 67 // Ignore this time 68 return null; 69 } 70 } 71 71 } 72 72 73 73 public synchronized Document getResponseXML() { 74 75 76 77 78 79 80 81 82 83 84 85 74 if( response == null ) return null; 75 76 byte[] bytes = this.response.responseBytes; 77 if (bytes == null) return null; 78 79 InputStream in = new ByteArrayInputStream(bytes); 80 try { 81 return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in); 82 } catch (Exception err) { 83 logger.log(Level.WARNING, "Unable to parse response as XML.", err); 84 return null; 85 } 86 86 } 87 87 88 88 public synchronized byte[] getResponseBytes() { 89 90 89 if( response == null ) return null; 90 return this.response.responseBytes; 91 91 } 92 92 93 93 public synchronized Image getResponseImage() { 94 95 96 97 98 99 94 if( response == null ) return null; 95 96 byte[] bytes = this.response.responseBytes; 97 if (bytes == null) return null; 98 99 return Toolkit.getDefaultToolkit().createImage(bytes); 100 100 } 101 101 102 102 public synchronized int getStatus() { 103 104 103 if( response == null ) return 0; 104 return this.response.status; 105 105 } 106 106 107 107 public synchronized String getStatusText() { 108 109 108 if( response == null ) return null; 109 return this.response.statusText; 110 110 } 111 111 112 112 public synchronized String getAllResponseHeaders() { 113 114 113 if( response == null ) return null; 114 return this.response.responseHeaders; 115 115 } 116 116 117 117 public synchronized String getResponseHeader(String headerName) { 118 119 120 118 if( response == null ) return null; 119 Map headers = this.response.responseHeadersMap; 120 return headers == null ? null : (String) headers.get(headerName); 121 121 } 122 122 123 123 public void open(String method, String url) throws IOException { 124 124 this.open(method, url, true); 125 125 } 126 126 127 127 public void open(String method, URL url) throws IOException { 128 128 this.open(method, url, true, null, null); 129 129 } 130 130 131 131 public void open(String method, URL url, boolean asyncFlag) throws IOException { 132 132 this.open(method, url, asyncFlag, null, null); 133 133 } 134 134 135 135 public void open(String method, String url, boolean asyncFlag) throws IOException { 136 137 136 URL urlObj = Urls.createURL(null, url); 137 this.open(method, urlObj, asyncFlag, null); 138 138 } 139 139 140 140 public void open(String method, URL url, boolean asyncFlag, String userName) throws IOException { 141 141 this.open(method, url, asyncFlag, userName, null); 142 142 } 143 143 144 144 public void abort() { 145 146 147 148 149 150 151 152 153 154 155 156 157 158 145 URLConnection c; 146 synchronized (this) { 147 c = this.connection; 148 response = null; 149 } 150 if (c instanceof HttpURLConnection) { 151 ((HttpURLConnection) c).disconnect(); 152 } else if (c != null) { 153 try { 154 c.getInputStream().close(); 155 } catch (IOException ioe) { 156 ioe.printStackTrace(); 157 } 158 } 159 159 } 160 160 161 161 /** 162 162 * Opens the request. Call {@link #send(String)} to complete it. 163 * 163 * 164 164 * @param method The request method. 165 165 * @param url The request URL. … … 170 170 */ 171 171 public void open(final String method, final URL url, boolean asyncFlag, final String userName, final String password) throws IOException { 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 172 this.abort(); 173 174 HttpResponse response = HttpResponse.lookup(url); 175 URLConnection c = null; 176 177 if( response == null ) 178 { 179 c = proxy == null || proxy == Proxy.NO_PROXY ? url.openConnection() : url.openConnection(proxy); 180 response = new HttpResponse(); 181 } 182 183 synchronized (this) { 184 this.connection = c; 185 this.isAsync = asyncFlag; 186 this.requestMethod = method; 187 this.requestUserName = userName; 188 this.requestPassword = password; 189 this.requestURL = url; 190 this.response = response; 191 192 if( response.loaded ) 193 changeState(HttpRequest.STATE_LOADING); 194 else 195 changeState(HttpRequest.STATE_LOADING, 0, null, null); 196 } 197 197 } 198 198 … … 201 201 * <p> 202 202 * In the case of asynchronous requests, a new thread is created. 203 * 203 * 204 204 * @param content POST content or <code>null</code> if there's no such 205 205 * content. 206 206 */ 207 207 public void send(final String content) throws IOException { 208 209 210 211 212 213 214 215 208 final URL url = this.requestURL; 209 if (url == null) { 210 throw new IOException("No URL has been provided."); 211 } 212 if (this.isAsync) { 213 // Should use a thread pool instead 214 new Thread("SimpleHttpRequest-" + url.getHost()) { 215 @Override 216 216 public void run() { 217 218 219 220 221 222 223 224 225 226 217 try { 218 sendSync(content); 219 } catch (Throwable thrown) { 220 logger.log(Level.WARNING,"send(): Error in asynchronous request on " + url, thrown); 221 } 222 } 223 }.start(); 224 } else { 225 sendSync(content); 226 } 227 227 } 228 228 … … 232 232 */ 233 233 protected String getPostCharset() { 234 234 return "UTF-8"; 235 235 } 236 236 … … 238 238 * This is a synchronous implementation of {@link #send(String)} method 239 239 * functionality. It may be overridden to change the behavior of the class. 240 * 240 * 241 241 * @param content POST content if any. It may be <code>null</code>. 242 242 * @throws IOException 243 243 */ 244 244 protected void sendSync(String content) throws IOException { 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 245 if( response.loaded ) 246 { 247 // Response from cache 248 changeState(HttpRequest.STATE_LOADED); 249 changeState(HttpRequest.STATE_INTERACTIVE); 250 changeState(HttpRequest.STATE_COMPLETE); 251 return; 252 } 253 254 try { 255 URLConnection c; 256 synchronized (this) { 257 c = this.connection; 258 } 259 c.setRequestProperty("User-Agent", this.context.getUserAgent()); 260 int istatus = 0; 261 String istatusText = ""; 262 InputStream err = null; 263 264 if (c instanceof HttpURLConnection) { 265 HttpURLConnection hc = (HttpURLConnection) c; 266 String method = requestMethod.toUpperCase(); 267 hc.setRequestMethod(method); 268 if ("POST".equals(method) && content != null) { 269 hc.setDoOutput(true); 270 byte[] contentBytes = content.getBytes(this.getPostCharset()); 271 hc.setFixedLengthStreamingMode(contentBytes.length); 272 OutputStream out = hc.getOutputStream(); 273 try { 274 out.write(contentBytes); 275 } finally { 276 out.flush(); 277 } 278 } 279 istatus = hc.getResponseCode(); 280 istatusText = hc.getResponseMessage(); 281 err = hc.getErrorStream(); 282 } 283 284 response.setConnectionInfo(c); 285 changeState(HttpRequest.STATE_LOADED, istatus, istatusText, null); 286 InputStream in = err == null ? c.getInputStream() : err; 287 int contentLength = c.getContentLength(); 288 changeState(HttpRequest.STATE_INTERACTIVE, istatus, istatusText, null); 289 byte[] bytes = IORoutines.load(in, contentLength == -1 ? 4096 : contentLength); 290 changeState(HttpRequest.STATE_COMPLETE, istatus, istatusText, bytes); 291 response.store(requestURL); 292 } finally { 293 synchronized (this) { 294 this.connection = null; 295 } 296 } 297 297 } 298 298 … … 300 300 301 301 public void addReadyStateChangeListener( final ReadyStateChangeListener listener) { 302 303 304 305 306 307 } 308 302 readyEvent.addListener(new GenericEventListener() { 303 public void processEvent(EventObject event) { 304 listener.readyStateChanged(); 305 } 306 }); 307 } 308 309 309 protected void changeState(int readyState, int status, String statusMessage, byte[] bytes) { 310 310 synchronized (this) { -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableUserAgentContext.java
r8748 r12778 9 9 public class CacheableUserAgentContext extends SimpleUserAgentContext { 10 10 11 /** 11 /** 12 12 * Returns a cache aware HttpRequest 13 13 */ 14 14 @Override 15 15 public HttpRequest createHttpRequest() { 16 16 return new CacheableHttpRequest(this, this.getProxy()); 17 17 } 18 18 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/HttpResponse.java
r8748 r12778 1 1 /** 2 * 2 * 3 3 */ 4 4 package org.openstreetmap.josm.plugins.openLayers; … … 16 16 public class HttpResponse implements Serializable { 17 17 private static final long serialVersionUID = -8605486951415515445L; 18 18 19 19 /** The status of the response */ 20 20 protected int status; … … 27 27 /** Whether this response has been already loaded */ 28 28 protected boolean loaded = false; 29 29 30 30 /** Response headers are set in this map after a response is received. */ 31 31 protected Map<String, List<String>> responseHeadersMap; … … 33 33 /** Response headers are set in this string after a response is received. */ 34 34 protected String responseHeaders; 35 35 36 36 /** 37 37 * Sets the information about this response: headers and encoding … … 43 43 if (encoding == null) 44 44 encoding = "ISO-8859-1"; 45 45 46 46 responseHeaders = getAllResponseHeaders(c); 47 47 responseHeadersMap = c.getHeaderFields(); … … 50 50 /** 51 51 * Sets the state of this response 52 * 52 * 53 53 * @param status The response status 54 54 * @param statusMessage The status message … … 56 56 */ 57 57 public synchronized void changeState(int status, String statusMessage, byte[] bytes) { 58 58 this.status = status; 59 59 this.statusText = statusMessage; 60 60 this.responseBytes = bytes; 61 61 } 62 62 63 63 /** 64 64 * Returns the headers of the connection as a String … … 68 68 private String getAllResponseHeaders(URLConnection c) { 69 69 int idx = 0; 70 71 72 73 74 75 76 77 78 79 80 81 82 83 70 String value; 71 StringBuffer buf = new StringBuffer(); 72 while((value = c.getHeaderField(idx)) != null) { 73 String key = c.getHeaderFieldKey(idx); 74 if( key != null ) 75 { 76 buf.append(key); 77 buf.append("="); 78 } 79 buf.append(value); 80 buf.append("\n"); 81 idx++; 82 } 83 return buf.toString(); 84 84 } 85 85 … … 89 89 */ 90 90 public void store(URL requestURL) { 91 92 91 loaded = true; 92 StorageManager.getInstance().put(requestURL, this); 93 93 } 94 94 95 95 /** 96 96 * Looks up the requested URL in the cache 97 * @param requestURL The requested URL 97 * @param requestURL The requested URL 98 98 * @return The response, if available 99 99 */ 100 100 public static HttpResponse lookup(URL requestURL) { 101 101 return StorageManager.getInstance().get(requestURL); 102 102 } 103 103 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/MyHtmlBlockPanel.java
r8748 r12778 43 43 this.rblock = null; 44 44 } 45 45 46 46 this.invalidate(); 47 47 this.validateAll(); -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java
r8748 r12778 21 21 /** 22 22 * Class that displays a OpenLayers layer. 23 * 23 * 24 24 * @author Francisco R. Santos <frsantos@gmail.com> 25 * 25 * 26 26 */ 27 27 public class OpenLayersLayer extends Layer implements PreferenceChangedListener, PropertyChangeListener { … … 33 33 */ 34 34 public OpenLayersLayer() { 35 36 37 38 39 40 41 42 43 44 35 super("OpenLayers"); 36 37 this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html"); 38 39 if( Main.map != null ) 40 { 41 LatLon bottomLeft = Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight()); 42 LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0); 43 browser.executeAsyncScript("zoomMapToExtent(" + bottomLeft.lon() + "," + bottomLeft.lat() + "," + topRight.lon() + "," + topRight.lat() + ")"); 44 } 45 45 } 46 46 … … 50 50 @Override 51 51 public void paint(Graphics g, MapView mv) { 52 53 52 setSize(Main.map.mapView.getSize()); 53 browser.paint(g); 54 54 } 55 55 … … 58 58 */ 59 59 public void setSize(Dimension dim) { 60 60 browser.setSize(dim); 61 61 } 62 62 63 63 @Override 64 64 public Icon getIcon() { 65 65 return ImageProvider.get("OpenLayers.png"); 66 66 } 67 67 68 68 @Override 69 69 public Object getInfoComponent() { 70 70 return null; 71 71 } 72 72 73 73 @Override 74 74 public Component[] getMenuEntries() { 75 76 77 78 79 80 81 82 75 return new Component[] { 76 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 77 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 78 new JSeparator(), 79 // color, 80 new JMenuItem(new RenameLayerAction(associatedFile, this)), 81 new JSeparator(), 82 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 83 83 } 84 84 85 85 @Override 86 86 public String getToolTipText() { 87 87 return null; 88 88 } 89 89 90 90 @Override 91 91 public boolean isMergable(Layer other) { 92 92 return false; 93 93 } 94 94 … … 103 103 @Override 104 104 public void destroy() { 105 105 Main.pref.listener.remove(this); 106 106 107 108 109 110 111 107 if( Main.map != null ) 108 Main.map.mapView.removePropertyChangeListener(this); 109 110 OpenLayersPlugin.layer = null; 111 StorageManager.flush(); 112 112 } 113 113 … … 116 116 117 117 public void propertyChange(PropertyChangeEvent evt) { 118 119 120 118 if( !visible ) 119 return; 120 121 121 String prop = evt.getPropertyName(); 122 if ("center".equals(prop) || "scale".equals(prop)) { 123 zoomToMapView(); 124 } 122 if ("center".equals(prop) || "scale".equals(prop)) { 123 zoomToMapView(); 125 124 } 126 125 } 126 127 127 public void zoomToMapView() 128 128 { … … 133 133 { 134 134 // TODO wrong calculations 135 135 136 136 // Get actual extent from browser 137 137 NativeArray array = (NativeArray)value; … … 140 140 double right = ((Double)array.get(2, null)).doubleValue(); 141 141 double top = ((Double)array.get(3, null)).doubleValue(); 142 143 144 145 146 147 148 149 142 bottomLeft = new LatLon( bottom, left ); 143 topRight = new LatLon( top, right); 144 145 BoundingXYVisitor v = new BoundingXYVisitor(); 146 v.visit(Main.proj.latlon2eastNorth(bottomLeft)); 147 v.visit(Main.proj.latlon2eastNorth(topRight)); 148 System.out.println("Recalculating position (" + left + "," + bottom + "," + right + "," + top + ")"); 149 Main.map.mapView.recalculateCenterScale(v); 150 150 } 151 151 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersPlugin.java
r8748 r12778 14 14 /** 15 15 * Main class for the OpenLayers plugin. 16 * 16 * 17 17 * @author Francisco R. Santos <frsantos@gmail.com> 18 * 18 * 19 19 */ 20 20 public class OpenLayersPlugin extends Plugin { … … 25 25 26 26 public OpenLayersPlugin() { 27 pluginDir = getPluginDir(); 28 try { 29 copy("/resources/yahoo.html", "yahoo.html"); 30 } catch (FileNotFoundException e) { 31 // TODO Auto-generated catch block 32 e.printStackTrace(); 33 } catch (IOException e) { 34 // TODO Auto-generated catch block 35 e.printStackTrace(); 36 } 37 StorageManager.initStorage( pluginDir ); 38 refreshMenu(); 27 pluginDir = getPluginDir(); 28 try { 29 copy("/resources/yahoo.html", "yahoo.html"); 30 } catch (FileNotFoundException e) { 31 // TODO Auto-generated catch block 32 e.printStackTrace(); 33 } catch (IOException e) { 34 // TODO Auto-generated catch block 35 e.printStackTrace(); 39 36 } 40 37 StorageManager.initStorage( pluginDir ); 38 refreshMenu(); 39 } 40 41 41 public static void refreshMenu() { 42 43 44 45 46 47 48 49 50 42 JMenuBar menuBar = Main.main.menu; 43 if (menu == null) { 44 menu = new JMenu(tr("OpenLayers")); 45 menuBar.add(menu, 5); 46 } else { 47 menu.removeAll(); 48 } 49 50 menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo"))); 51 51 } 52 52 53 53 /* 54 54 * (non-Javadoc) 55 * 55 * 56 56 * @see org.openstreetmap.josm.plugins.Plugin#getPreferenceSetting() 57 57 */ 58 58 @Override 59 59 public PreferenceSetting getPreferenceSetting() { 60 60 return null; 61 61 } 62 62 -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java
r8748 r12778 10 10 11 11 public ShowOpenLayersAction(String name) { 12 12 super(name, "OpenLayers", "Show layer" + name, 0, 0, false); 13 13 } 14 14 15 15 public void actionPerformed(ActionEvent e) { 16 17 18 19 20 21 22 23 24 25 26 27 28 29 16 final OpenLayersLayer layer = OpenLayersPlugin.layer != null ? OpenLayersPlugin.layer : new OpenLayersLayer(); 17 OpenLayersPlugin.layer = layer; 18 Main.main.addLayer(layer); 19 20 EventQueue.invokeLater(new Runnable() { 21 public void run() { 22 layer.setSize(Main.map.mapView.getSize()); 23 } 24 }); 25 26 // Get notifications of scale and position 27 Main.map.mapView.addPropertyChangeListener("scale", layer); 28 Main.map.mapView.addPropertyChangeListener("center", layer); 29 30 30 } 31 31 }; -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/StorageManager.java
r8748 r12778 10 10 * too big, with many jars, it should be replaced for a hand-made storage to 11 11 * disk. 12 * 12 * 13 13 * @author frsantos 14 * 14 * 15 15 */ 16 16 public class StorageManager { 17 17 18 18 private Cache cache; 19 19 20 20 private static StorageManager storage; 21 21 22 22 public static void initStorage(String basedir) 23 23 { 24 25 26 24 if( storage != null ) storage.dispose(); 25 26 storage = new StorageManager(basedir); 27 27 } 28 28 29 29 protected StorageManager(String basedir) 30 30 { 31 32 33 31 System.setProperty("net.sf.ehcache.enableShutdownHook", "true"); 32 cache = new Cache("OpenLayers", 500, MemoryStoreEvictionPolicy.LRU, true, basedir + "cache", false, 300*24*7, 300, true, 3600*24*7, null); 33 CacheManager.getInstance().addCache(cache); 34 34 } 35 35 36 36 protected void dispose() 37 37 { 38 39 38 if( cache != null ) 39 cache.dispose(); 40 40 } 41 41 42 42 public static StorageManager getInstance() 43 43 { 44 44 return storage; 45 45 } 46 46 47 47 public HttpResponse get(URL key) 48 48 { 49 50 51 52 53 49 Element element = cache.get(key); 50 if( element != null ) 51 return (HttpResponse)element.getObjectValue(); 52 53 return null; 54 54 } 55 55 56 56 public void put(URL key, HttpResponse value) 57 57 { 58 59 58 Element element = new Element(key, value); 59 cache.put(element); 60 60 } 61 61 … … 64 64 */ 65 65 public static void flush() { 66 67 66 if( storage != null ) 67 storage.cache.flush(); 68 68 } 69 69 }
Note:
See TracChangeset
for help on using the changeset viewer.