- Timestamp:
- 2006-03-27T08:24:41+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/coor/EastNorth.java
r71 r72 21 21 return y; 22 22 } 23 24 @Override 25 public String toString() { 26 return "(EastNorth e="+x+", n="+y+")"; 27 } 23 28 } -
src/org/openstreetmap/josm/gui/NavigatableComponent.java
r71 r72 75 75 center.east() + (x - getWidth()/2.0)*scale, 76 76 center.north() - (y - getHeight()/2.0)*scale); 77 return Main.pref.getProjection().eastNorth2latlon(eastNorth);77 return getProjection().eastNorth2latlon(eastNorth); 78 78 } 79 79 -
src/org/openstreetmap/josm/io/OsmReader.java
r71 r72 113 113 114 114 @Override 115 public void endElement(String namespaceURI, String localName, String qName) throws SAXException{115 public void endElement(String namespaceURI, String localName, String qName) { 116 116 if (qName.equals("node") || qName.equals("segment") || qName.equals("way") || qName.equals("area")) { 117 117 current.visit(adder); -
src/org/openstreetmap/josm/io/OsmWriter.java
r71 r72 12 12 import org.openstreetmap.josm.data.osm.Way; 13 13 import org.openstreetmap.josm.data.osm.visitor.Visitor; 14 import org. xml.sax.SAXException;14 import org.openstreetmap.josm.tools.XmlWriter; 15 15 16 16 /** … … 20 20 */ 21 21 public class OsmWriter implements Visitor { 22 23 private class RuntimeEncodingException extends RuntimeException {24 public RuntimeEncodingException(Throwable t) {25 super(t);26 }27 public RuntimeEncodingException() {28 }29 }30 22 31 23 /** … … 46 38 private final boolean osmConform; 47 39 48 private final static HashMap<Character, String> encoding = new HashMap<Character, String>();49 static {50 encoding.put('<', "<");51 encoding.put('>', ">");52 encoding.put('"', """);53 encoding.put('\'', "'");54 encoding.put('&', "&");55 encoding.put('\n', "
");56 encoding.put('\r', "
");57 encoding.put('\t', "	");58 }59 60 40 /** 61 41 * Output the data to the stream … … 77 57 } 78 58 79 public static void outputSingle(Writer out, OsmPrimitive osm, boolean osmConform) throws SAXException { 80 try { 81 OsmWriter writer = new OsmWriter(out, osmConform); 82 writer.out.println("<?xml version='1.0' encoding='UTF-8'?>"); 83 writer.out.println("<osm version='0.3' generator='JOSM'>"); 84 osm.visit(writer); 85 writer.out.println("</osm>"); 86 } catch (RuntimeEncodingException e) { 87 throw new SAXException("Your Java installation does not support the required UTF-8 encoding", (Exception)e.getCause()); 88 } 59 public static void outputSingle(Writer out, OsmPrimitive osm, boolean osmConform) { 60 OsmWriter writer = new OsmWriter(out, osmConform); 61 writer.out.println(XmlWriter.header()); 62 writer.out.println("<osm version='0.3' generator='JOSM'>"); 63 osm.visit(writer); 64 writer.out.println("</osm>"); 89 65 } 90 66 … … 105 81 public void visit(LineSegment ls) { 106 82 if (ls.incomplete) 107 throw new IllegalArgumentException("Cannot write an incomplete LineSegment.");83 return; // Do not write an incomplete line segment 108 84 addCommon(ls, "segment"); 109 85 out.print(" from='"+getUsedId(ls.from)+"' to='"+getUsedId(ls.to)+"'"); … … 137 113 out.println(">"); 138 114 for (Entry<String, String> e : osm.keys.entrySet()) 139 out.println(" <tag k='"+ encode(e.getKey()) +140 "' v='"+ encode(e.getValue())+ "' />");115 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 116 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 141 117 out.println(" </" + tagname + ">"); 142 118 } else if (tagOpen) … … 145 121 out.println(" </" + tagname + ">"); 146 122 } 147 148 /**149 * Encode the given string in XML1.0 format.150 * Optimized to fast pass strings that don't need encoding (normal case).151 */152 public String encode(String unencoded) {153 StringBuilder buffer = null;154 for (int i = 0; i < unencoded.length(); ++i) {155 String encS = encoding.get(unencoded.charAt(i));156 if (encS != null) {157 if (buffer == null)158 buffer = new StringBuilder(unencoded.substring(0,i));159 buffer.append(encS);160 } else if (buffer != null)161 buffer.append(unencoded.charAt(i));162 }163 return (buffer == null) ? unencoded : buffer.toString();164 }165 166 123 167 124 /**
Note:
See TracChangeset
for help on using the changeset viewer.