Changeset 333
- Timestamp:
- 08/15/08 18:11:14 (3 months ago)
- Location:
- trunk/geowebcache/src/main
- Files:
-
- 1 added
- 5 modified
-
java/org/geowebcache/layer/TileLayerResource.java (modified) (3 diffs)
-
java/org/geowebcache/seeder/SeedResource.java (modified) (2 diffs)
-
java/org/geowebcache/util/XMLConfiguration.java (modified) (2 diffs)
-
resources/geowebcache.xml (modified) (1 diff)
-
resources/layerTest.json (added)
-
resources/layerTest.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/geowebcache/src/main/java/org/geowebcache/layer/TileLayerResource.java
r330 r333 6 6 import java.io.Reader; 7 7 import java.io.CharArrayReader; 8 import java.io.StringReader; 9 import java.io.StringWriter; 8 10 9 11 import org.restlet.Context; … … 22 24 23 25 import com.thoughtworks.xstream.*; 26 import com.thoughtworks.xstream.io.HierarchicalStreamDriver; 27 import com.thoughtworks.xstream.io.HierarchicalStreamReader; 24 28 import com.thoughtworks.xstream.io.xml.DomDriver; 29 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter; 30 import com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier; 31 import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; 25 32 import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; 26 33 … … 226 233 + getRequest().getHostRef().getHostIdentifier()); 227 234 try{ 228 String xmlText = entity.getText(); 235 String xmlText = entity.getText(); 229 236 XStream xs = RESTDispatcher.getConfig().getConfiguredXStream(new XStream(new DomDriver())); 230 TileLayer tileLayer = (WMSLayer) xs.fromXML(xmlText); 237 TileLayer tileLayer = null; 238 if(entity.getMediaType().equals(MediaType.APPLICATION_XML)){ 239 tileLayer = (WMSLayer) xs.fromXML(xmlText); 240 } 241 242 /** 243 * deserializing a json string is more complicated. XStream does not natively 244 * support it. Rather it uses a JettisonMappedXmlDriver to convert to intermediate xml 245 * and then deserializes that into the desired object. At this time, there is a known issue 246 * with the Jettison driver involving elements that come after an array in the json string. 247 * 248 * http://jira.codehaus.org/browse/JETTISON-48 249 * 250 * The code below is a hack: it treats the json string as text, then converts it to the intermediate 251 * xml and then deserializes that into the tileLayer object. 252 * 253 * 254 */ 255 else if(entity.getMediaType().equals(MediaType.APPLICATION_JSON)){ 256 HierarchicalStreamDriver driver = new JettisonMappedXmlDriver(); 257 StringReader reader = new StringReader(xmlText); 258 HierarchicalStreamReader hsr = driver.createReader(reader); 259 StringWriter writer = new StringWriter(); 260 new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer)); 261 writer.close(); 262 263 XStream x = new XStream(new DomDriver()); 264 x.alias("wmslayer", WMSLayer.class); 265 x.aliasField("layer-name", TileLayer.class, "name"); 266 x.alias("grid", Grid.class); 267 268 269 tileLayer = (WMSLayer) x.fromXML(writer.toString()); 270 } 271 231 272 //the layer we are posting to is null, so we need to create a new one 232 273 if(currentLayer == null){ -
trunk/geowebcache/src/main/java/org/geowebcache/seeder/SeedResource.java
r331 r333 99 99 try { 100 100 String text = entity.getText(); 101 101 102 XStream xs = new XStream(new DomDriver()); 102 103 xs.alias("seedRequest", SeedRequest.class); … … 106 107 xs.alias("zoomstart", Integer.class); 107 108 xs.alias("zoomstop", Integer.class); 109 108 110 SeedRequest rq = null; 111 109 112 if(entity.getMediaType().equals(MediaType.APPLICATION_XML)){ 110 113 rq = (SeedRequest) xs.fromXML(text); 111 114 } 115 116 /** 117 * deserializing a json string is more complicated. XStream does not natively 118 * support it. Rather it uses a JettisonMappedXmlDriver to convert to intermediate xml 119 * and then deserializes that into the desired object. At this time, there is a known issue 120 * with the Jettison driver involving elements that come after an array in the json string. 121 * 122 * http://jira.codehaus.org/browse/JETTISON-48 123 * 124 * The code below is a hack: it treats the json string as text, then converts it to the intermediate 125 * xml and then deserializes that into the SeedRequest object. 126 * 127 * 128 */ 129 112 130 else if(entity.getMediaType().equals(MediaType.APPLICATION_JSON)){ 113 131 HierarchicalStreamDriver driver = new JettisonMappedXmlDriver(); -
trunk/geowebcache/src/main/java/org/geowebcache/util/XMLConfiguration.java
r331 r333 35 35 import org.geowebcache.layer.wms.WMSLayer; 36 36 import org.geowebcache.GeoWebCacheException; 37 import org.geowebcache.cache.CacheFactory;38 37 import org.geowebcache.cache.*; 39 38 import org.geowebcache.layer.Grid; … … 133 132 public XStream getConfiguredXStream(XStream xstream) { 134 133 XStream xs = xstream; 135 134 xs.setMode(XStream.NO_REFERENCES); 135 136 136 xs.alias("layer", TileLayer.class); 137 137 xs.alias("wmslayer", WMSLayer.class); 138 138 xs.aliasField("layer-name", TileLayer.class, "name"); 139 xs.alias("grids", new ArrayList<Grid>().getClass()); 139 140 xs.alias("grid", Grid.class); 140 xs.alias("format", String.class); 141 141 xs.aliasType("format", String.class); 142 xs.alias("mimeFormats", new ArrayList<String>().getClass()); 143 xs.aliasType("WMSurl", String.class); 144 xs.aliasType("errormime", String.class); 145 xs.alias("metaWidthHeight", new int[1].getClass()); 146 xs.alias("width", Integer.class); 147 xs.alias("height", Integer.class); 148 xs.aliasType("version", String.class); 149 xs.alias("tiled", boolean.class); 150 xs.alias("transparent", boolean.class); 151 xs.alias("debugheaders", boolean.class); 152 153 142 154 return xs; 143 155 } -
trunk/geowebcache/src/main/resources/geowebcache.xml
r330 r333 3 3 <layer-name>topp:states</layer-name> 4 4 <mimeFormats> 5 < format>image/png</format>6 < format>image/jpeg</format>5 <string>image/png</string> 6 <string>image/jpeg</string> 7 7 </mimeFormats> 8 8 <grids> -
trunk/geowebcache/src/main/resources/layerTest.xml
r319 r333 3 3 <layer-name>my:newTest</layer-name> 4 4 <mimeFormats> 5 < format>image/jpeg</format>5 <string>image/jpeg</string> 6 6 </mimeFormats> 7 7 <grids>
