source: josm/trunk/src/org/openstreetmap/josm/io/XmlWriter.java@ 4701

Last change on this file since 4701 was 4645, checked in by framm, 12 years ago

Added three new hooks for plugins, allowing plugins to mess with JOSM's server I/O. Plugins can now add postprocessors to server reading (so they may change what JOSM receives from the OSM server), and they can add postprocessors to server writing (so they can react to an upload action *after* it happened and after IDs for new objects have been assigned - this is in addition to the existing UploadHook which is a server writing preprocessor). Thirdly, plugins can now substitute their own version of OsmWriter. Taken together, these changes make it possible for a plugin to introduce extra information from a non-OSM source into the JOSM editing process, and upon upload split away that extra information and send it to another destination. - Also made minor changes to CredentialDialog to allow plugins to subclass the dialog in case they need their own authentication.

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.io;
3
4import java.io.PrintWriter;
5import java.util.HashMap;
6
7/**
8 * Helper class to use for xml outputting classes.
9 *
10 * @author imi
11 */
12public class XmlWriter {
13
14 protected PrintWriter out;
15
16 public XmlWriter(PrintWriter out) {
17 this.out = out;
18 }
19
20 public void flush() {
21 out.flush();
22 }
23
24 /**
25 * Encode the given string in XML1.0 format.
26 * Optimized to fast pass strings that don't need encoding (normal case).
27 */
28 public static String encode(String unencoded) {
29 StringBuilder buffer = null;
30 for (int i = 0; i < unencoded.length(); ++i) {
31 String encS = XmlWriter.encoding.get(unencoded.charAt(i));
32 if (encS != null) {
33 if (buffer == null) {
34 buffer = new StringBuilder(unencoded.substring(0,i));
35 }
36 buffer.append(encS);
37 } else if (buffer != null) {
38 buffer.append(unencoded.charAt(i));
39 }
40 }
41 return (buffer == null) ? unencoded : buffer.toString();
42 }
43
44 /**
45 * The output writer to save the values to.
46 */
47 final private static HashMap<Character, String> encoding = new HashMap<Character, String>();
48 static {
49 encoding.put('<', "&lt;");
50 encoding.put('>', "&gt;");
51 encoding.put('"', "&quot;");
52 encoding.put('\'', "&apos;");
53 encoding.put('&', "&amp;");
54 encoding.put('\n', "&#xA;");
55 encoding.put('\r', "&#xD;");
56 encoding.put('\t', "&#x9;");
57 }
58}
Note: See TracBrowser for help on using the repository browser.