Index: applications/editors/josm/plugins/imagery-xml-bounds/build.xml
===================================================================
--- applications/editors/josm/plugins/imagery-xml-bounds/build.xml	(revision 26781)
+++ applications/editors/josm/plugins/imagery-xml-bounds/build.xml	(revision 26808)
@@ -32,5 +32,5 @@
     <property name="commit.message" value="Commit message"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
-    <property name="plugin.main.version" value="4488"/>
+    <property name="plugin.main.version" value="4506"/>
     <!-- should not be necessary to change the following properties -->
     <property name="josm" location="../../core/dist/josm-custom.jar"/>
Index: applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java
===================================================================
--- applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java	(revision 26781)
+++ applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java	(revision 26808)
@@ -27,9 +27,10 @@
 
 /**
- * Main class of Imagery XLM bounds plugin.
+ * Main class of Imagery XML bounds plugin.
  * @author Don-vip
- * @version 1.0
+ * @version 1.1
  * History:
- * 2.0 03-Oct-2011 first version
+ * 1.1 08-Oct-2011 Update for #6934 and JOSM 4506, code refactorisation, removing debug code
+ * 1.0 03-Oct-2011 first version
  */
 public class ImageryXmlBoundsPlugin extends Plugin {
Index: applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java
===================================================================
--- applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java	(revision 26781)
+++ applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java	(revision 26808)
@@ -33,5 +33,5 @@
 	 * Plugin version.
 	 */
-	public static final String PLUGIN_VERSION = "1.0";
+	public static final String PLUGIN_VERSION = "1.1";
 	
 	/**
@@ -45,24 +45,46 @@
 	public static final String XML_SCHEMA = "resource://data/maps.xsd";
 	
-	/**
-	 * Prefix used in front of OSM keys.
-	 */
-	public static final String PREFIX = "imagery:";
-	
+    /**
+     * XML tags
+     */
+    public static final String XML_NAME = "name";
+    public static final String XML_TYPE = "type";
+    public static final String XML_URL = "url";
+    public static final String XML_DEFAULT = "default";
+    public static final String XML_EULA = "eula";
+    public static final String XML_ATTR_TEXT = "attribution-text";
+    public static final String XML_ATTR_URL = "attribution-url";
+    public static final String XML_TERMS_TEXT = "terms-of-use-text";
+    public static final String XML_TERMS_URL = "terms-of-use-url";
+    public static final String XML_PROJECTIONS = "projections";
+    public static final String XML_MAX_ZOOM = "max-zoom";
+    public static final String XML_MIN_ZOOM = "min-zoom";
+    public static final String XML_COUNTRY_CODE = "country-code";
+    public static final String XML_LOGO_IMAGE = "logo-image";// TODO
+    public static final String XML_LOGO_URL = "logo-url";
+
+    /**
+     * Prefix used in front of OSM keys.
+     */
+    public static final String PREFIX = "imagery:";
+
 	/**
 	 * OSM keys, equivalent to those used in XML schema, but prefixed (except for name).
 	 */
-	public static final String KEY_NAME = "name";
-	public static final String KEY_TYPE = PREFIX + "type";
-	public static final String KEY_URL = PREFIX + "url";
-	public static final String KEY_DEFAULT = PREFIX + "default";
-	public static final String KEY_EULA = PREFIX + "eula";
-	public static final String KEY_ATTR_TEXT = PREFIX + "attribution-text";
-	public static final String KEY_ATTR_URL = PREFIX + "attribution-url";
-	public static final String KEY_TERMS_URL = PREFIX + "terms-of-use-url";
-	public static final String KEY_PROJECTIONS = PREFIX + "projections";
-	public static final String KEY_MAX_ZOOM = PREFIX + "max-zoom";
-	public static final String KEY_MIN_ZOOM = PREFIX + "min-zoom";
-	public static final String KEY_COUNTRY_CODE = PREFIX + "country-code";
+	public static final String KEY_NAME = XML_NAME;
+	public static final String KEY_TYPE = PREFIX + XML_TYPE;
+	public static final String KEY_URL = PREFIX + XML_URL;
+	public static final String KEY_DEFAULT = PREFIX + XML_DEFAULT;
+	public static final String KEY_EULA = PREFIX + XML_EULA;
+	public static final String KEY_ATTR_TEXT = PREFIX + XML_ATTR_TEXT;
+	public static final String KEY_ATTR_URL = PREFIX + XML_ATTR_URL;
+    public static final String KEY_TERMS_TEXT = PREFIX + XML_TERMS_TEXT;
+	public static final String KEY_TERMS_URL = PREFIX + XML_TERMS_URL;
+	public static final String KEY_PROJECTIONS = PREFIX + XML_PROJECTIONS;
+	public static final String KEY_MAX_ZOOM = PREFIX + XML_MAX_ZOOM;
+	public static final String KEY_MIN_ZOOM = PREFIX + XML_MIN_ZOOM;
+	public static final String KEY_COUNTRY_CODE = PREFIX + XML_COUNTRY_CODE;
+    public static final String KEY_LOGO_IMAGE = PREFIX + XML_LOGO_IMAGE;// TODO
+    public static final String KEY_LOGO_URL = PREFIX + XML_LOGO_URL;
 	
 	/**
Index: applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsImporter.java
===================================================================
--- applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsImporter.java	(revision 26781)
+++ applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsImporter.java	(revision 26808)
@@ -148,8 +148,10 @@
 		safePut(osmImagery, KEY_PROJECTIONS, imagery.getServerProjections());
 		safePut(osmImagery, KEY_EULA, imagery.getEulaAcceptanceRequired());
-		safePut(osmImagery, KEY_ATTR_TEXT, imagery.getAttributionText());
+		safePut(osmImagery, KEY_ATTR_TEXT, imagery.getAttributionText(0, null, null));
 		safePut(osmImagery, KEY_ATTR_URL, imagery.getAttributionLinkURL());
+        safePut(osmImagery, KEY_TERMS_TEXT, imagery.getTermsOfUseText());
 		safePut(osmImagery, KEY_TERMS_URL, imagery.getTermsOfUseURL());
 		safePut(osmImagery, KEY_COUNTRY_CODE, imagery.getCountryCode());
+		safePut(osmImagery, KEY_LOGO_URL, imagery.getAttributionImageURL());
 
 		if (imagery.getImageryType().equals(ImageryType.TMS)) {
Index: applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ComputeBoundsAction.java
===================================================================
--- applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ComputeBoundsAction.java	(revision 26781)
+++ applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ComputeBoundsAction.java	(revision 26808)
@@ -120,4 +120,47 @@
 	}
 	
+    protected static final String startTag(String tag) {
+        return "<" + tag + ">";
+    }
+
+    protected static final String startMandatoryTag(String tag) {
+        return "<" + tag + " mandatory='true'>";
+    }
+
+    protected static final String endTag(String tag) {
+        return "</" + tag + ">";
+    }
+
+    protected static final String simpleTag(String tag, String content) {
+        return simpleTag(tag, content, "");
+    }
+
+    protected static final String simpleTag(String tag, String content, boolean escape) {
+        return simpleTag(tag, content, "", escape);
+    }
+
+    protected static final String simpleTag(String tag, String content, String def) {
+        return simpleTag(tag, content, def, true);
+    }
+
+    protected static final String simpleTag(String tag, String content, String def, boolean escape) {
+        return startTag(tag) + (content != null 
+                ? (escape ? escapeReservedCharacters(content) : content) 
+                : def
+                ) + endTag(tag);
+    }
+
+    protected static final String mandatoryTag(String tag, String content) {
+        return mandatoryTag(tag, content, true);
+    }
+
+    protected static final String mandatoryTag(String tag, String content, boolean escape) {
+        return startMandatoryTag(tag) + (escape ? escapeReservedCharacters(content) : content) + endTag(tag);
+    }
+
+    public static String escapeReservedCharacters(String s) {
+        return s == null ? "" : s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
+    }
+    
 	protected static final String getXml(OsmPrimitive ... primitives) {
 		List<String> entries = new ArrayList<String>();
@@ -144,16 +187,22 @@
 	
 	protected static final String getEntry(OsmPrimitive p, String bounds) {
-		return getEntry(p.get(KEY_NAME), p.get(KEY_TYPE), p.get(KEY_URL), bounds, p.get(KEY_PROJECTIONS), p.get(KEY_EULA), p.get(KEY_ATTR_TEXT), p.get(KEY_ATTR_URL), p.get(KEY_COUNTRY_CODE));
-	}
-	
-	protected static final String getEntry(String name, String type, String url, String bounds, String projections, String eula, String attributionText, String attributionUrl, String countryCode) {
+		return getEntry(p.get(KEY_NAME), p.get(KEY_TYPE), p.get(KEY_DEFAULT), p.get(KEY_URL), bounds, p.get(KEY_PROJECTIONS), p.get(KEY_LOGO_URL),
+		        p.get(KEY_EULA), p.get(KEY_ATTR_TEXT), p.get(KEY_ATTR_URL),  p.get(KEY_TERMS_TEXT), p.get(KEY_TERMS_URL), p.get(KEY_COUNTRY_CODE), p.get(KEY_MAX_ZOOM), p.get(KEY_MIN_ZOOM));
+	}
+	
+	protected static final boolean isSet(String tag) {
+	    return tag != null && !tag.isEmpty();
+	}
+	
+	protected static final String getEntry(String name, String type, String def, String url, String bounds, String projections, String logoURL,
+	        String eula, String attributionText, String attributionUrl, String termsText, String termsUrl, String countryCode, String maxZoom, String minZoom) {
 		String result =
 	    "    <entry>\n"+
-	    "        <name>"+ (name != null ? name : "") +"</name>\n"+
-	    "        <type>"+ (type != null ? type : "wms") +"</type>\n"+
-	    "        <url>" + (url != null ? encodeUrl(url) : "") +"</url>\n"+
+        "        " + simpleTag(XML_NAME, name) + "\n"+
+        "        " + simpleTag(XML_TYPE, type, "wms") + "\n"+
+        "        " + simpleTag(XML_URL, url != null ? encodeUrl(url) : "") + "\n"+
 	             bounds+"\n";
 		if (projections != null && !projections.isEmpty()) {
-			result += "        <projections>\n";
+			result += "        "+startTag(XML_PROJECTIONS)+"\n";
 			int i = 0;
 			String[] codes = projections.split(";");
@@ -162,5 +211,5 @@
 					result += "            ";
 				}
-				result += "<code>"+code.trim()+"</code>";
+				result += simpleTag("code", code.trim());
 				if (i%6 == 5 || i == codes.length-1 ) {
 					result += "\n";
@@ -168,17 +217,37 @@
 				i++;
 			}
-			result += "        </projections>\n";
-		}
-		if (eula != null && !eula.isEmpty()) {
-			result += "        <eula mandatory='true'>"+encodeUrl(eula)+"></eula>\n";
-		}
-		if (attributionText != null && !attributionText.isEmpty()) {
-			result += "        <attribution-text mandatory='true'>"+attributionText+"</attribution-text>\n";
-		}
-		if (attributionUrl != null && !attributionUrl.isEmpty()) {
-			result += "        <attribution-url>"+encodeUrl(attributionUrl)+"</attribution-url>\n";
-		}
-		if (countryCode != null && !countryCode.isEmpty()) {
-			result += "        <country-code>"+countryCode+"</country-code>\n";
+			result += "        "+endTag(XML_PROJECTIONS)+"\n";
+		}
+        if (isSet(def) && def.equals("true")) {
+            result += "        " + simpleTag(XML_DEFAULT, def) + "\n";
+        }
+		if (isSet(eula)) {
+			result += "        " + mandatoryTag(XML_EULA, encodeUrl(eula), false) + "\n";
+		}
+		if (isSet(attributionText)) {
+            result += "        " + mandatoryTag(XML_ATTR_TEXT, attributionText) + "\n";
+		}
+		if (isSet(attributionUrl)) {
+            result += "        " + simpleTag(XML_ATTR_URL, encodeUrl(attributionUrl), false) + "\n";
+		}
+        if (isSet(termsText)) {
+            result += "        " + simpleTag(XML_TERMS_TEXT, termsText) + "\n";
+        }
+        if (isSet(termsUrl)) {
+            result += "        " + simpleTag(XML_TERMS_URL, encodeUrl(termsUrl), false) + "\n";
+        }
+        if (isSet(logoURL)) {
+            result += "        " + simpleTag(XML_LOGO_URL, encodeUrl(logoURL), false) + "\n";
+        }
+		if (isSet(countryCode)) {
+            result += "        " + simpleTag(XML_COUNTRY_CODE, countryCode) + "\n";
+		}
+		if ("tms".equals(type)) {
+		    if (isSet(maxZoom)) {
+		        result += "        " + simpleTag(XML_MAX_ZOOM, maxZoom) + "\n";
+		    }
+            if (isSet(minZoom)) {
+                result += "        " + simpleTag(XML_MIN_ZOOM, minZoom) + "\n";
+            }
 		}
 	    result += "    </entry>";
@@ -253,9 +322,7 @@
 			}
 			
-			boolean result = latMap.size() == 2 && lonMap.size() == 2 
+			return latMap.size() == 2 && lonMap.size() == 2 
 					&& latMap.containsKey(bBox.getBottomRight().lat()) && latMap.containsKey(bBox.getTopLeft().lat())
 					&& lonMap.containsKey(bBox.getBottomRight().lon()) && lonMap.containsKey(bBox.getTopLeft().lon());
-			System.out.println(result);
-			return result;
 		}
 		return false;
