Skip to content

Commit bac7f82

Browse files
committed
Issue #173.
1 parent f868cf1 commit bac7f82

File tree

8 files changed

+63
-36
lines changed

8 files changed

+63
-36
lines changed

dist/Jsonix-all.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ Jsonix.XML.Output = Jsonix.Class({
16181618
return node;
16191619

16201620
},
1621-
writeCDATA : function(text) {
1621+
writeCdata : function(text) {
16221622
var node;
16231623
if (Jsonix.Util.Type.isFunction(this.document.createCDATASection)) {
16241624
node = this.document.createCDATASection(text);
@@ -2978,7 +2978,7 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
29782978
}
29792979

29802980
if (this.asCDATA) {
2981-
output.writeCDATA(this.print(value, context, output, scope));
2981+
output.writeCdata(this.print(value, context, output, scope));
29822982
} else {
29832983
output.writeCharacters(this.print(value, context, output, scope));
29842984
}

dist/Jsonix-min.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ if(Jsonix.Util.Type.isFunction(this.document.createTextNode)){d=this.document.cr
650650
}else{throw new Error("Could not create a text node.")
651651
}}this.peek().appendChild(d);
652652
return d
653-
},writeCDATA:function(c){var d;
653+
},writeCdata:function(c){var d;
654654
if(Jsonix.Util.Type.isFunction(this.document.createCDATASection)){d=this.document.createCDATASection(c)
655655
}else{if(this.xmldom){d=this.xmldom.createCDATASection(c)
656656
}else{throw new Error("Could not create a CDATA section node.")
@@ -1162,7 +1162,7 @@ this.asCDATA=c
11621162
},unmarshal:function(e,f,h){var g=f.getElementText();
11631163
return this.unmarshalValue(g,e,f,h)
11641164
},marshal:function(g,e,f,h){if(!Jsonix.Util.Type.exists(g)){return
1165-
}if(this.asCDATA){f.writeCDATA(this.print(g,e,f,h))
1165+
}if(this.asCDATA){f.writeCdata(this.print(g,e,f,h))
11661166
}else{f.writeCharacters(this.print(g,e,f,h))
11671167
}},buildStructure:function(c,d){Jsonix.Util.Ensure.ensureObject(d);
11681168
if(Jsonix.Util.Type.exists(d.elements)){throw new Error("The structure already defines element mappings, it cannot define a value property.")

nodejs/scripts/jsonix.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,21 @@ Jsonix.XML.Output = Jsonix.Class({
16181618
return node;
16191619

16201620
},
1621-
writeCDATA : function(text) {
1621+
writeCdata : function(text) {
1622+
var parts = text.split(']]>');
1623+
for (var index = 0; index < parts.length; index++) {
1624+
if (index + 1 < parts.length) {
1625+
parts[index] = parts[index] + ']]';
1626+
parts[index + 1] = '>' + parts[index + 1];
1627+
}
1628+
}
1629+
var node;
1630+
for (var jndex = 0; jndex < parts.length; jndex ++) {
1631+
node = this.writeCdataWithoutCdend(parts[jndex]);
1632+
}
1633+
return node;
1634+
},
1635+
writeCdataWithoutCdend : function(text) {
16221636
var node;
16231637
if (Jsonix.Util.Type.isFunction(this.document.createCDATASection)) {
16241638
node = this.document.createCDATASection(text);
@@ -1880,7 +1894,6 @@ Jsonix.Binding.Marshalls.Element = Jsonix.Class({
18801894
}
18811895
}
18821896
var typeInfo = actualTypeInfo || declaredTypeInfo;
1883-
18841897
if (typeInfo) {
18851898
output.writeStartElement(elementValue.name);
18861899
if (actualTypeInfo && declaredTypeInfo !== actualTypeInfo) {
@@ -2160,32 +2173,32 @@ Jsonix.Model.ClassInfo = Jsonix
21602173
var n = mapping.name||mapping.n||undefined;
21612174
Jsonix.Util.Ensure.ensureString(n);
21622175
this.name = n;
2163-
2176+
21642177
var ln = mapping.localName||mapping.ln||null;
21652178
this.localName = ln;
21662179

21672180
var dens = mapping.defaultElementNamespaceURI||mapping.dens||mapping.targetNamespace||mapping.tns||'';
21682181
this.defaultElementNamespaceURI = dens;
2169-
2182+
21702183
var tns = mapping.targetNamespace||mapping.tns||mapping.defaultElementNamespaceURI||mapping.dens||this.defaultElementNamespaceURI;
21712184
this.targetNamespace = tns;
21722185

21732186
var dans = mapping.defaultAttributeNamespaceURI||mapping.dans||'';
21742187
this.defaultAttributeNamespaceURI = dans;
2175-
2188+
21762189
var bti = mapping.baseTypeInfo||mapping.bti||null;
21772190
this.baseTypeInfo = bti;
2178-
2191+
21792192
var inF = mapping.instanceFactory||mapping.inF||undefined;
21802193
if (Jsonix.Util.Type.exists(inF)) {
21812194
// TODO: should we support instanceFactory as functions?
21822195
// For the pure JSON configuration?
21832196
Jsonix.Util.Ensure.ensureFunction(inF);
21842197
this.instanceFactory = inF;
21852198
}
2186-
2199+
21872200
var tn = mapping.typeName||mapping.tn||undefined;
2188-
2201+
21892202
if (Jsonix.Util.Type.exists(tn))
21902203
{
21912204
if (Jsonix.Util.Type.isString(tn))
@@ -2200,14 +2213,14 @@ Jsonix.Model.ClassInfo = Jsonix
22002213
{
22012214
this.typeName = new Jsonix.XML.QName(tns, ln);
22022215
}
2203-
2216+
22042217
this.properties = [];
22052218
this.propertiesMap = {};
22062219
var ps = mapping.propertyInfos||mapping.ps||[];
22072220
Jsonix.Util.Ensure.ensureArray(ps);
22082221
for ( var index = 0; index < ps.length; index++) {
22092222
this.p(ps[index]);
2210-
}
2223+
}
22112224
},
22122225
getPropertyInfoByName : function(name) {
22132226
return this.propertiesMap[name];
@@ -2252,15 +2265,15 @@ Jsonix.Model.ClassInfo = Jsonix
22522265
unmarshal : function(context, input) {
22532266
this.build(context);
22542267
var result;
2255-
2268+
22562269
if (this.instanceFactory) {
22572270
result = new this.instanceFactory();
22582271
}
22592272
else
22602273
{
2261-
result = { TYPE_NAME : this.name };
2274+
result = { TYPE_NAME : this.name };
22622275
}
2263-
2276+
22642277
if (input.eventType !== 1) {
22652278
throw new Error("Parser must be on START_ELEMENT to read a class info.");
22662279
}
@@ -2541,7 +2554,6 @@ Jsonix.Model.ClassInfo.prototype.propertyInfoCreators = {
25412554
"v" : Jsonix.Model.ClassInfo.prototype.v,
25422555
"value" : Jsonix.Model.ClassInfo.prototype.v
25432556
};
2544-
25452557
Jsonix.Model.EnumLeafInfo = Jsonix.Class(Jsonix.Model.TypeInfo, {
25462558
name : null,
25472559
baseTypeInfo : 'String',
@@ -2965,8 +2977,8 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
29652977
Jsonix.Util.Ensure.ensureObject(mapping);
29662978
Jsonix.Model.SingleTypePropertyInfo.prototype.initialize.apply(this, [ mapping ]);
29672979

2968-
var c = mapping.asCDATA || mapping.c || false;
2969-
this.asCDATA = c;
2980+
var cdata = mapping.asCDATA || mapping.cdata || false;
2981+
this.asCDATA = cdata;
29702982
},
29712983
unmarshal : function(context, input, scope) {
29722984
var text = input.getElementText();
@@ -2978,7 +2990,7 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
29782990
}
29792991

29802992
if (this.asCDATA) {
2981-
output.writeCDATA(this.print(value, context, output, scope));
2993+
output.writeCdata(this.print(value, context, output, scope));
29822994
} else {
29832995
output.writeCharacters(this.print(value, context, output, scope));
29842996
}
@@ -5844,15 +5856,15 @@ Jsonix.Context = Jsonix
58445856
Jsonix.Util.Ensure.ensureObject(options);
58455857
if (Jsonix.Util.Type
58465858
.isObject(options.namespacePrefixes)) {
5847-
this.namespacePrefixes =
5859+
this.namespacePrefixes =
58485860
Jsonix.Util.Type.cloneObject(options.namespacePrefixes, {});
58495861
}
58505862
if (Jsonix.Util.Type
58515863
.isBoolean(options.supportXsiType)) {
5852-
this.supportXsiType = options.supportXsiType;
5864+
this.supportXsiType = options.supportXsiType;
58535865
}
58545866
}
5855-
5867+
58565868
// Initialize prefix/namespace mapping
58575869
for (var ns in this.namespacePrefixes)
58585870
{
@@ -5881,7 +5893,7 @@ Jsonix.Context = Jsonix
58815893
module = mapping;
58825894
} else {
58835895
mapping = Jsonix.Util.Type.cloneObject(mapping);
5884-
module = new this.mappingStyle.module(mapping,
5896+
module = new this.mappingStyle.module(mapping,
58855897
{
58865898
mappingStyle : this.mappingStyle
58875899
});
@@ -6122,7 +6134,6 @@ Jsonix.Context = Jsonix
61226134
Jsonix.Schema.XSD.UnsignedShort.INSTANCE ],
61236135
CLASS_NAME : 'Jsonix.Context'
61246136
});
6125-
61266137
// Complete Jsonix script is included above
61276138
return { Jsonix: Jsonix };
61286139
};

nodejs/scripts/tests/xml.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ module.exports =
4444
output.writeStartElement(new Jsonix.XML.QName("test"));
4545
output.writeAttribute(new Jsonix.XML.QName("test"), 'test');
4646
output.writeCharacters('test');
47-
47+
output.writeCdata(']]>');
48+
output.writeCdata('a]]>');
49+
output.writeCdata('b]]>c');
50+
output.writeCdata(']]>d');
4851
output.writeEndElement();
4952
output.writeEndDocument();
5053
test.notEqual(null, doc.documentElement);
5154
var serializedDocument = Jsonix.DOM.serialize(doc);
52-
console.log(serializedDocument);
55+
test.equal('<test test="test">test<![CDATA[]]]]><![CDATA[>]]><![CDATA[a]]]]><![CDATA[>]]><![CDATA[b]]]]><![CDATA[>c]]><![CDATA[]]]]><![CDATA[>d]]></test>', serializedDocument);
5356
test.done();
5457
},
5558
"OutputNS": function(test) {

nodejs/tests/basic/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"main": "jsonix-tests-basic.js",
88
"dependencies": {
9-
"jsonix": "2.x.x"
109
},
1110
"devDependencies" : {
1211
"nodeunit" : "0.x.x",

nodejs/tests/basic/tests/one.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ module.exports =
742742
};
743743
var result = marshaller.marshalString(value);
744744
console.log(result);
745-
test.ok(result === '<valueAsCDATA><![CDATA[test<>?\'"&]]></valueAsCDATA>');
745+
test.equal(result, '<valueAsCDATA><![CDATA[test<>?\'"&]]></valueAsCDATA>');
746746
test.done();
747747
},
748748
"UnmarshalCDATAValueType": function (test)
@@ -751,8 +751,8 @@ module.exports =
751751
var unmarshaller = context.createUnmarshaller();
752752
var text = '<valueAsCDATA><![CDATA[test<>?\'"&]]></valueAsCDATA>';
753753
var result = unmarshaller.unmarshalString(text);
754-
test.equal('string', result.name.localPart);
755-
test.equal('text', result.value);
754+
test.equal('valueAsCDATA', result.name.localPart);
755+
test.equal('test<>?\'"&', result.value.value);
756756
test.done();
757757
}
758758
};

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Model/ValuePropertyInfo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
33
Jsonix.Util.Ensure.ensureObject(mapping);
44
Jsonix.Model.SingleTypePropertyInfo.prototype.initialize.apply(this, [ mapping ]);
55

6-
var c = mapping.asCDATA || mapping.c || false;
7-
this.asCDATA = c;
6+
var cdata = mapping.asCDATA || mapping.cdata || false;
7+
this.asCDATA = cdata;
88
},
99
unmarshal : function(context, input, scope) {
1010
var text = input.getElementText();
@@ -16,7 +16,7 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
1616
}
1717

1818
if (this.asCDATA) {
19-
output.writeCDATA(this.print(value, context, output, scope));
19+
output.writeCdata(this.print(value, context, output, scope));
2020
} else {
2121
output.writeCharacters(this.print(value, context, output, scope));
2222
}

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/XML/Output.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,21 @@ Jsonix.XML.Output = Jsonix.Class({
9595
return node;
9696

9797
},
98-
writeCDATA : function(text) {
98+
writeCdata : function(text) {
99+
var parts = text.split(']]>');
100+
for (var index = 0; index < parts.length; index++) {
101+
if (index + 1 < parts.length) {
102+
parts[index] = parts[index] + ']]';
103+
parts[index + 1] = '>' + parts[index + 1];
104+
}
105+
}
106+
var node;
107+
for (var jndex = 0; jndex < parts.length; jndex ++) {
108+
node = this.writeCdataWithoutCdend(parts[jndex]);
109+
}
110+
return node;
111+
},
112+
writeCdataWithoutCdend : function(text) {
99113
var node;
100114
if (Jsonix.Util.Type.isFunction(this.document.createCDATASection)) {
101115
node = this.document.createCDATASection(text);

0 commit comments

Comments
 (0)