Changeset 12778 in osm for applications/editors/josm/plugins/DirectUpload
- Timestamp:
- 2009-01-01T18:28:53+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload
- Files:
-
- 2 edited
-
UploadDataGui.java (modified) (16 diffs)
-
UploadDataGuiPlugin.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java
r12707 r12778 40 40 */ 41 41 public class UploadDataGui extends javax.swing.JFrame { 42 43 String tagging; 44 String Descriptionfield; 42 43 String tagging; 44 String Descriptionfield; 45 45 String urlDescription; 46 46 String urlTags; … … 48 48 String PassWord; 49 49 //GpxData gpxData; 50 50 51 51 public static final String API_VERSION = "0.5"; 52 52 private static final String BASE64_ENC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 53 53 private static final String BOUNDARY = "----------------------------d10f7aa230e8"; 54 54 private static final String LINE_END = "\r\n"; 55 55 56 56 boolean dfield; 57 57 boolean taggy; … … 60 60 boolean pass; 61 61 boolean publicheck; 62 62 63 63 DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss"); 64 Date date = new Date(); 64 Date date = new Date(); 65 65 String datename = dateFormat.format(date); 66 66 67 67 /** Creates new form UploadDataGui */ 68 68 public UploadDataGui() { … … 70 70 } 71 71 72 72 73 73 /** This method is called from within the constructor to 74 74 * initialize the form. … … 142 142 143 143 144 145 Container contentPane = getContentPane();146 contentPane.setLayout(new GridBagLayout());147 GridBagConstraints c = new GridBagConstraints();148 149 c.gridx = 0;150 c.gridy = 0;151 c.gridwidth = 2;152 c.fill = 1;153 contentPane.add(OutputDisplay, c);154 155 c.gridwidth = 1;156 c.gridy = 1;157 contentPane.add(jLabel3, c);158 c.gridx = 1;159 contentPane.add(tagfield, c);160 161 c.gridy = 2; c.gridx = 0;162 contentPane.add(jLabel1, c);163 c.gridx = 1;164 contentPane.add(descriptionfield, c);165 166 c.gridy = 3; c.gridx = 0;167 contentPane.add(jLabel2, c);168 c.gridx = 1;169 contentPane.add(PublicTrace, c);170 171 c.gridy = 4; c.gridx = 0;172 contentPane.add(CancelButton, c);173 c.gridx = 1;174 contentPane.add(OkButton, c);144 145 Container contentPane = getContentPane(); 146 contentPane.setLayout(new GridBagLayout()); 147 GridBagConstraints c = new GridBagConstraints(); 148 149 c.gridx = 0; 150 c.gridy = 0; 151 c.gridwidth = 2; 152 c.fill = 1; 153 contentPane.add(OutputDisplay, c); 154 155 c.gridwidth = 1; 156 c.gridy = 1; 157 contentPane.add(jLabel3, c); 158 c.gridx = 1; 159 contentPane.add(tagfield, c); 160 161 c.gridy = 2; c.gridx = 0; 162 contentPane.add(jLabel1, c); 163 c.gridx = 1; 164 contentPane.add(descriptionfield, c); 165 166 c.gridy = 3; c.gridx = 0; 167 contentPane.add(jLabel2, c); 168 c.gridx = 1; 169 contentPane.add(PublicTrace, c); 170 171 c.gridy = 4; c.gridx = 0; 172 contentPane.add(CancelButton, c); 173 c.gridx = 1; 174 contentPane.add(OkButton, c); 175 175 176 176 pack(); … … 181 181 public void upload(String username, String password, String Descriptionfield, String tagging , GpxData gpxData ) throws IOException { 182 182 OutputDisplay.setText("Starting to upload selected file to openstreetmap.org"); 183 183 184 184 try { 185 185 186 186 urlDescription = Descriptionfield.replaceAll("\\.;&?,/","_"); 187 187 if (urlDescription == null || urlDescription.length() == 0) { 188 188 OutputDisplay.setText("No description provided .Please provide some description . For the time being ignore the exception error "); 189 189 190 190 } 191 191 urlTags = tagging.replaceAll("\\\\.;&?,/","_"); 192 193 192 193 194 194 URL url = new URL("http://www.openstreetmap.org/api/" + API_VERSION + "/gpx/create"); 195 195 System.err.println("url: " + url); … … 212 212 writeContentDisposition(out, "public", "1"); 213 213 } else { 214 writeContentDisposition(out, "public", "0"); 214 writeContentDisposition(out, "public", "0"); 215 215 } 216 216 out.writeBytes("--" + BOUNDARY + "--" + LINE_END); 217 217 out.flush(); 218 218 219 219 int returnCode = connect.getResponseCode(); 220 220 String returnMsg = connect.getResponseMessage(); 221 221 System.err.println(returnCode); 222 222 OutputDisplay.setText(returnMsg); 223 if (returnCode != 200) { 223 if (returnCode != 200) { 224 224 if (connect.getHeaderField("Error") != null) 225 225 returnMsg += "\n" + connect.getHeaderField("Error"); … … 228 228 out.close(); 229 229 connect.disconnect(); 230 231 } catch(UnsupportedEncodingException ignore) { 230 231 } catch(UnsupportedEncodingException ignore) { 232 232 } catch (MalformedURLException e) { 233 233 OutputDisplay.setText("Cant Upload ."); 234 234 e.printStackTrace(); 235 235 } 236 236 237 237 } 238 238 … … 246 246 247 247 private void OkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OkButtonActionPerformed 248 GpxData gpxData; 249 250 UserName = Main.pref.get("osm-server.username"); 248 GpxData gpxData; 249 250 UserName = Main.pref.get("osm-server.username"); 251 251 PassWord = Main.pref.get("osm-server.password"); 252 252 253 253 if(Main.map == null || Main.map.mapView == null ||Main.map.mapView.getActiveLayer() == null || 254 254 !(Main.map.mapView.getActiveLayer() instanceof GpxLayer)){ … … 260 260 gpxData = ((GpxLayer)Main.map.mapView.getActiveLayer()).data; 261 261 System.out.println(Descriptionfield); 262 try { 262 try { 263 263 upload(UserName,PassWord,Descriptionfield ,tagging ,gpxData) ; 264 264 } catch (IOException ex) { 265 265 Logger.getLogger(UploadDataGui.class.getName()).log(Level.SEVERE, null, ex); 266 } 267 266 } 267 268 268 }//GEN-LAST:event_OkButtonActionPerformed 269 269 … … 276 276 if (evt.getStateChange() == ItemEvent.SELECTED) { 277 277 publicheck = true; 278 278 279 279 } 280 280 }//GEN-LAST:event_PublicTraceItemStateChanged … … 284 284 JTextField Descsel = (JTextField)evt.getSource(); 285 285 Descriptionfield = Descsel.getText(); 286 286 287 287 }//GEN-LAST:event_descriptionfieldFocusLost 288 288 … … 291 291 JTextField Tagsel = (JTextField)evt.getSource(); 292 292 tagging = Tagsel.getText(); 293 293 294 294 }//GEN-LAST:event_tagfieldFocusLost 295 295 … … 300 300 out.writeBytes(LINE_END); 301 301 out.writeBytes(value + LINE_END); 302 302 303 303 } 304 304 305 305 private void writeContentDispositionGpxData(DataOutputStream out, String name, GpxData gpxData ) throws IOException { 306 306 307 307 out.writeBytes("--" + BOUNDARY + LINE_END); 308 308 out.writeBytes("Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + datename +".gpx" + "\"" + LINE_END); … … 310 310 out.writeBytes("Content-Type: application/octet-stream" + LINE_END); 311 311 out.writeBytes(LINE_END); 312 312 313 313 OutputDisplay.setText("Transferring data to server"); 314 314 new GpxWriter(out).write(gpxData); 315 315 out.flush(); 316 out.writeBytes(LINE_END); 317 318 } 319 320 // Taken from Christof Dallermassal java class : 316 out.writeBytes(LINE_END); 317 318 } 319 320 // Taken from Christof Dallermassal java class : 321 321 public String encodeBase64(String s) { 322 322 StringBuilder out = new StringBuilder(); … … 328 328 out.append(l>1 ? BASE64_ENC.charAt((buf.charAt(1) & 0x0f) << 2 | (l==2 ? 0 : (buf.charAt(2) & 0xc0) >> 6)) : '='); 329 329 out.append(l>2 ? BASE64_ENC.charAt(buf.charAt(2) & 0x3f) : '='); 330 330 331 331 } 332 332 return out.toString(); 333 } 333 } 334 334 335 335 // Variables declaration - do not modify//GEN-BEGIN:variables -
applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGuiPlugin.java
r12588 r12778 2 2 * Copyright by Subhodip Biswas 3 3 * This program is free software and licensed under GPL. 4 * 4 * 5 5 */ 6 6
Note:
See TracChangeset
for help on using the changeset viewer.
