1 // (c) BenoƮt PIN 2006-2007
6 this.domDoc
= Sarissa
.getDomDocument('http://plinn.org/namespaces/plinn_document/1.0', 'plinn');
7 this.rootNode
= this.domDoc
.documentElement
;
10 XMLExport
.prototype.getXML = function() {
11 this.exportDocument();
12 var s
= new XMLSerializer();
13 XML_OUTPUT
.value
= s
.serializeToString(this.domDoc
);
17 XMLExport
.prototype.exportDocument = function() {
18 this.exportRectangles(LAYER_MANAGER
.space
, this.rootNode
);
21 XMLExport
.prototype.exportRectangles = function(baseObj
, baseNode
) {
22 var doc
= this.domDoc
;
23 var childs
= baseObj
.childNodes
;
25 for(var i
= 0 ; i
< childs
.length
; i
++) {
26 rectObj
= childs
[i
].rectangle
;
31 var rectEl
= doc
.createElement("rectangle");
32 rectEl
.setAttribute("width", rectObj
.width
);
33 rectEl
.setAttribute("height", rectObj
.height
);
34 rectEl
.setAttribute("elementKey", rectObj
.elementKey
);
35 rectEl
.setAttribute("ddOptions", rectObj
.ddOptions
);
36 rectEl
.setAttribute("ratio", rectObj
.ratio
);
37 rectEl
.setAttribute("visibility", rectObj
.style
.visibility
);
40 var ulc
= doc
.createElement("upperLeftCorner");
41 var point
= doc
.createElement("point");
42 point
.setAttribute("x", rectObj
.upperLeftCorner
.x
);
43 point
.setAttribute("y", rectObj
.upperLeftCorner
.y
);
44 ulc
.appendChild(point
);
45 rectEl
.appendChild(ulc
);
48 var rdata
= doc
.createElement("rawData");
49 if (rectObj
.getRawData
) {
50 var rawEl
= doc
.createTextNode(rectObj
.getRawData());
51 rdata
.appendChild(rawEl
);
53 rectEl
.appendChild(rdata
);
55 baseNode
.appendChild(rectEl
);
57 this.exportRectangles(rectObj
.node
, rectEl
);
61 function XMLImport(url
, root_container
) {
62 this.root_container
= root_container
;
63 var thisImporter
= this;
64 var req
= new XMLHttpRequest();
66 req
.onreadystatechange = function() {
67 if(req
.readyState
== 4)
68 thisImporter
.constructDocument(req
);
70 req
.open("GET", url
, true);
74 XMLImport
.prototype.constructDocument = function(req
) {
75 var rootNode
= req
.responseXML
.documentElement
;
76 var layerElements
= rootNode
.childNodes
;
77 initLayerManager(this.root_container
, true);
79 for (var i
= 0 ; i
< layerElements
.length
; i
++) {
80 layerElement
= layerElements
[i
];
81 if (i
==0) { // initialize LAYER_MANAGER from first layer data
82 LAYER_MANAGER
.defaultLayerWidth
= parseInt(layerElement
.getAttribute("width"));
83 LAYER_MANAGER
.defaultLayerHeight
= parseInt(layerElement
.getAttribute("height"));
84 LAYER_MANAGER
.addLayer("relative");
87 LAYER_MANAGER
.addLayer();
90 if (layerElement
.getAttribute("visibility") == "hidden")
91 LAYER_MANAGER
.toggleLayerVisibility();
93 this.constructRectangles(CURRENT_LAYER
, layerElement
)
97 XMLImport
.prototype.constructRectangles = function(baseObj
, baseNode
) {
98 var rectangleElements
= baseNode
.childNodes
;
99 var rectE
, rect
, ulcE
, ulc
, rawDataE
, rawData
, putFunc
;
101 for (var i
= 0 ; i
< rectangleElements
.length
; i
++) {
102 rectE
= rectangleElements
[i
];
103 if (rectE
.nodeName
!= "rectangle")
105 ulcE
= rectE
.childNodes
[0].childNodes
[0];
106 rawDataE
= rectE
.childNodes
[1]
108 ulc
= new Point( parseInt(ulcE
.getAttribute("x")), parseInt(ulcE
.getAttribute("y")) )
109 rect
= new Rectangle(ulc
,
110 parseInt(rectE
.getAttribute("width")),
111 parseInt(rectE
.getAttribute("height")),
112 rectE
.getAttribute("elementKey"),
113 parseInt(rectE
.getAttribute("ddOptions")),
114 parseFloat(rectE
.getAttribute("ratio")));
116 putFunc
= ELEMENTS_POOL
[rectE
.getAttribute("elementKey")]["putData"]
118 putFunc
.apply(rect
, [rawDataE
.childNodes
[0].nodeValue
]);
125 function _plinnDocumentBeforeSubmit() {
126 with (GLOBAL_DD_CONTROLER
.ddEventCaptureElmt
) {
131 new XMLExport().getXML();