import flash.net.*;
import org.iotashan.oauth.*;
+ import net.systemeD.halcyon.Globals;
public class XMLConnection extends Connection {
upload.appendChild(addCreated(changeset, getAllNodeIDs, getNode, serialiseNode));
upload.appendChild(addCreated(changeset, getAllWayIDs, getWay, serialiseWay));
upload.appendChild(addCreated(changeset, getAllRelationIDs, getRelation, serialiseRelation));
+ upload.appendChild(addDeleted(changeset, getAllRelationIDs, getRelation, serialiseEntityRoot));
+ upload.appendChild(addDeleted(changeset, getAllWayIDs, getWay, serialiseEntityRoot));
+ upload.appendChild(addDeleted(changeset, getAllNodeIDs, getNode, serialiseEntityRoot));
upload.appendChild(addModified(changeset, getAllNodeIDs, getNode, serialiseNode));
upload.appendChild(addModified(changeset, getAllWayIDs, getWay, serialiseWay));
upload.appendChild(addModified(changeset, getAllRelationIDs, getRelation, serialiseRelation));
return create.hasComplexContent() ? create : <!-- blank create section -->;
}
+ private function addDeleted(changeset:Changeset, getIDs:Function, get:Function, serialise:Function):XML {
+ var del:XML = <delete version="0.6"/>
+ for each( var id:Number in getIDs() ) {
+ var entity:Entity = get(id);
+ // creates are already included
+ if ( id < 0 || !entity.deleted )
+ continue;
+
+ var xml:XML = serialise(entity);
+ xml.@changeset = changeset.id;
+ del.appendChild(xml);
+ }
+ return del.hasComplexContent() ? del : <!-- blank delete section -->;
+ }
+
private function addModified(changeset:Changeset, getIDs:Function, get:Function, serialise:Function):XML {
var modify:XML = <modify version="0.6"/>
for each( var id:Number in getIDs() ) {
var entity:Entity = get(id);
- // creates are already included
- if ( id < 0 || !entity.isDirty )
+ // creates and deletes are already included
+ if ( id < 0 || entity.deleted || !entity.isDirty )
continue;
var xml:XML = serialise(entity);
}
private function serialiseNode(node:Node):XML {
- var xml:XML = <node/>
- serialiseEntity(node, xml);
+ var xml:XML = serialiseEntityRoot(node); //<node/>
+ serialiseEntityTags(node, xml);
xml.@lat = node.lat;
xml.@lon = node.lon;
return xml;
}
private function serialiseWay(way:Way):XML {
- var xml:XML = <way/>
- serialiseEntity(way, xml);
+ var xml:XML = serialiseEntityRoot(way); //<node/>
+ serialiseEntityTags(way, xml);
for ( var i:uint = 0; i < way.length; i++ ) {
var nd:XML = <nd/>
nd.@ref = way.getNode(i).id;
}
private function serialiseRelation(relation:Relation):XML {
- var xml:XML = <relation/>
- serialiseEntity(relation, xml);
+ var xml:XML = serialiseEntityRoot(Relation); //<node/>
+ serialiseEntityTags(relation, xml);
for ( var i:uint = 0; i < relation.length; i++ ) {
var relMember:RelationMember = relation.getMember(i);
var member:XML = <member/>
return xml;
}
- private function serialiseEntity(entity:Entity, xml:XML):void {
+ private function serialiseEntityRoot(entity:Object):XML {
+ var xml:XML;
+ if (entity is Way ) { xml = <way/> }
+ else if (entity is Node ) { xml = <node/> }
+ else if (entity is Relation) { xml = <relation/> }
+ xml.@id = entity.id;
+ xml.@version = entity.version;
+ return xml;
+ }
+
+ private function serialiseEntityTags(entity:Entity, xml:XML):void {
xml.@id = entity.id;
xml.@version = entity.version;
for each( var tag:Tag in entity.getTagArray() ) {
xml.appendChild(tagXML);
}
}
+
}
}