Changeset 29384 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/SimpleOffsetQueryTask.java
- Timestamp:
- 2013-03-22T22:18:26+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/SimpleOffsetQueryTask.java
r29380 r29384 9 9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 11 import org.openstreetmap.josm.io.OsmTransferException;12 import org.xml.sax.SAXException;13 11 import static org.openstreetmap.josm.tools.I18n.tr; 14 12 15 13 /** 14 * A task to query the imagery offset server and process the response. 16 15 * 17 * @author zverik 16 * @author Zverik 17 * @license WTFPL 18 18 */ 19 19 class SimpleOffsetQueryTask extends PleaseWaitRunnable { … … 24 24 private QuerySuccessListener listener; 25 25 26 /** 27 * Initialize the task. 28 * @param query A query string, usually starting with an action word and a question mark. 29 * @param title A title for the progress monitor. 30 */ 26 31 public SimpleOffsetQueryTask( String query, String title ) { 27 32 super(tr("Uploading")); … … 31 36 } 32 37 38 /** 39 * In case a query was not specified when the object was constructed, 40 * it can be set with this method. 41 * @see #SimpleOffsetQueryTask(java.lang.String, java.lang.String) 42 */ 33 43 public void setQuery( String query ) { 34 44 this.query = query; 35 45 } 36 46 47 /** 48 * Install a listener for successful responses. There can be only one. 49 */ 37 50 public void setListener( QuerySuccessListener listener ) { 38 51 this.listener = listener; 39 52 } 40 53 54 /** 55 * Remove a listener for successful responses. 56 */ 41 57 public void removeListener() { 42 58 this.listener = null; 43 59 } 44 60 61 /** 62 * The main method: calls {@link #doQuery(java.lang.String)} and processes exceptions. 63 */ 45 64 @Override 46 protected void realRun() throws SAXException, IOException, OsmTransferException{65 protected void realRun() { 47 66 getProgressMonitor().indeterminateSubTask(title); 48 67 try { … … 56 75 } 57 76 77 /** 78 * Sends a request to the imagery offset server. Processes exceptions and 79 * return codes, calls {@link #processResponse(java.io.InputStream)} on success. 80 * @param query 81 * @throws iodb.SimpleOffsetQueryTask.UploadException 82 * @throws IOException 83 */ 58 84 private void doQuery( String query ) throws UploadException, IOException { 59 85 try { 60 URL url = new URL(ImageryOffsetTools.getServerURL() + query); 61 System.out.println("url=" + url); // todo: remove in release 86 String serverURL = Main.pref.get("iodb.server.url", "http://offsets.textual.ru/"); 87 URL url = new URL(serverURL + query); 88 Main.info("IODB URL = " + url); // todo: remove in release 62 89 HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 63 90 connection.connect(); … … 79 106 } 80 107 108 /** 109 * Doesn't actually cancel, just raises a flag. 110 */ 81 111 @Override 82 112 protected void cancel() { … … 84 114 } 85 115 116 /** 117 * Is called after {@link #realRun()}. Either displays an error message 118 * or notifies a listener of success. 119 */ 86 120 @Override 87 121 protected void finish() { … … 93 127 } 94 128 129 /** 130 * Parse the response input stream and determine whether an operation 131 * was successful or not. 132 * @throws iodb.SimpleOffsetQueryTask.UploadException Thrown if an error message was found. 133 */ 95 134 protected void processResponse( InputStream inp ) throws UploadException { 96 135 String response = ""; … … 110 149 } 111 150 151 /** 152 * A placeholder exception for error messages. 153 */ 112 154 public static class UploadException extends Exception { 113 155 public UploadException( String message ) {
Note:
See TracChangeset
for help on using the changeset viewer.