@@ -1618,6 +1618,19 @@ Jsonix.XML.Output = Jsonix.Class({
1618
1618
return node ;
1619
1619
1620
1620
} ,
1621
+ writeCDATA : function ( text ) {
1622
+ var node ;
1623
+ if ( Jsonix . Util . Type . isFunction ( this . document . createCDATASection ) ) {
1624
+ node = this . document . createCDATASection ( text ) ;
1625
+ }
1626
+ else if ( this . xmldom ) {
1627
+ node = this . xmldom . createCDATASection ( text ) ;
1628
+ } else {
1629
+ throw new Error ( "Could not create a CDATA section node." ) ;
1630
+ }
1631
+ this . peek ( ) . appendChild ( node ) ;
1632
+ return node ;
1633
+ } ,
1621
1634
writeAttribute : function ( name , value ) {
1622
1635
Jsonix . Util . Ensure . ensureString ( value ) ;
1623
1636
Jsonix . Util . Ensure . ensureObject ( name ) ;
@@ -1655,7 +1668,7 @@ Jsonix.XML.Output = Jsonix.Class({
1655
1668
}
1656
1669
this . declareNamespace ( namespaceURI , prefix ) ;
1657
1670
}
1658
-
1671
+
1659
1672
} ,
1660
1673
writeNode : function ( node ) {
1661
1674
var importedNode ;
@@ -1764,7 +1777,7 @@ Jsonix.XML.Output = Jsonix.Class({
1764
1777
if ( Jsonix . Util . Type . isString ( p ) )
1765
1778
{
1766
1779
var oldp = nspItem [ ns ] ;
1767
- // If prefix is already declared and equals the proposed prefix
1780
+ // If prefix is already declared and equals the proposed prefix
1768
1781
if ( p === oldp )
1769
1782
{
1770
1783
// Nothing to do
@@ -1804,6 +1817,7 @@ Jsonix.XML.Output = Jsonix.Class({
1804
1817
} ,
1805
1818
CLASS_NAME : "Jsonix.XML.Output"
1806
1819
} ) ;
1820
+
1807
1821
Jsonix . Mapping = { } ;
1808
1822
Jsonix . Mapping . Style = Jsonix . Class ( {
1809
1823
marshaller : null ,
@@ -1866,6 +1880,7 @@ Jsonix.Binding.Marshalls.Element = Jsonix.Class({
1866
1880
}
1867
1881
}
1868
1882
var typeInfo = actualTypeInfo || declaredTypeInfo ;
1883
+
1869
1884
if ( typeInfo ) {
1870
1885
output . writeStartElement ( elementValue . name ) ;
1871
1886
if ( actualTypeInfo && declaredTypeInfo !== actualTypeInfo ) {
@@ -2145,32 +2160,32 @@ Jsonix.Model.ClassInfo = Jsonix
2145
2160
var n = mapping . name || mapping . n || undefined ;
2146
2161
Jsonix . Util . Ensure . ensureString ( n ) ;
2147
2162
this . name = n ;
2148
-
2163
+
2149
2164
var ln = mapping . localName || mapping . ln || null ;
2150
2165
this . localName = ln ;
2151
2166
2152
2167
var dens = mapping . defaultElementNamespaceURI || mapping . dens || mapping . targetNamespace || mapping . tns || '' ;
2153
2168
this . defaultElementNamespaceURI = dens ;
2154
-
2169
+
2155
2170
var tns = mapping . targetNamespace || mapping . tns || mapping . defaultElementNamespaceURI || mapping . dens || this . defaultElementNamespaceURI ;
2156
2171
this . targetNamespace = tns ;
2157
2172
2158
2173
var dans = mapping . defaultAttributeNamespaceURI || mapping . dans || '' ;
2159
2174
this . defaultAttributeNamespaceURI = dans ;
2160
-
2175
+
2161
2176
var bti = mapping . baseTypeInfo || mapping . bti || null ;
2162
2177
this . baseTypeInfo = bti ;
2163
-
2178
+
2164
2179
var inF = mapping . instanceFactory || mapping . inF || undefined ;
2165
2180
if ( Jsonix . Util . Type . exists ( inF ) ) {
2166
2181
// TODO: should we support instanceFactory as functions?
2167
2182
// For the pure JSON configuration?
2168
2183
Jsonix . Util . Ensure . ensureFunction ( inF ) ;
2169
2184
this . instanceFactory = inF ;
2170
2185
}
2171
-
2186
+
2172
2187
var tn = mapping . typeName || mapping . tn || undefined ;
2173
-
2188
+
2174
2189
if ( Jsonix . Util . Type . exists ( tn ) )
2175
2190
{
2176
2191
if ( Jsonix . Util . Type . isString ( tn ) )
@@ -2185,14 +2200,14 @@ Jsonix.Model.ClassInfo = Jsonix
2185
2200
{
2186
2201
this . typeName = new Jsonix . XML . QName ( tns , ln ) ;
2187
2202
}
2188
-
2203
+
2189
2204
this . properties = [ ] ;
2190
2205
this . propertiesMap = { } ;
2191
2206
var ps = mapping . propertyInfos || mapping . ps || [ ] ;
2192
2207
Jsonix . Util . Ensure . ensureArray ( ps ) ;
2193
2208
for ( var index = 0 ; index < ps . length ; index ++ ) {
2194
2209
this . p ( ps [ index ] ) ;
2195
- }
2210
+ }
2196
2211
} ,
2197
2212
getPropertyInfoByName : function ( name ) {
2198
2213
return this . propertiesMap [ name ] ;
@@ -2237,15 +2252,15 @@ Jsonix.Model.ClassInfo = Jsonix
2237
2252
unmarshal : function ( context , input ) {
2238
2253
this . build ( context ) ;
2239
2254
var result ;
2240
-
2255
+
2241
2256
if ( this . instanceFactory ) {
2242
2257
result = new this . instanceFactory ( ) ;
2243
2258
}
2244
2259
else
2245
2260
{
2246
- result = { TYPE_NAME : this . name } ;
2261
+ result = { TYPE_NAME : this . name } ;
2247
2262
}
2248
-
2263
+
2249
2264
if ( input . eventType !== 1 ) {
2250
2265
throw new Error ( "Parser must be on START_ELEMENT to read a class info." ) ;
2251
2266
}
@@ -2526,6 +2541,7 @@ Jsonix.Model.ClassInfo.prototype.propertyInfoCreators = {
2526
2541
"v" : Jsonix . Model . ClassInfo . prototype . v ,
2527
2542
"value" : Jsonix . Model . ClassInfo . prototype . v
2528
2543
} ;
2544
+
2529
2545
Jsonix . Model . EnumLeafInfo = Jsonix . Class ( Jsonix . Model . TypeInfo , {
2530
2546
name : null ,
2531
2547
baseTypeInfo : 'String' ,
@@ -2948,6 +2964,9 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
2948
2964
initialize : function ( mapping ) {
2949
2965
Jsonix . Util . Ensure . ensureObject ( mapping ) ;
2950
2966
Jsonix . Model . SingleTypePropertyInfo . prototype . initialize . apply ( this , [ mapping ] ) ;
2967
+
2968
+ var c = mapping . asCDATA || mapping . c || false ;
2969
+ this . asCDATA = c ;
2951
2970
} ,
2952
2971
unmarshal : function ( context , input , scope ) {
2953
2972
var text = input . getElementText ( ) ;
@@ -2957,7 +2976,12 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
2957
2976
if ( ! Jsonix . Util . Type . exists ( value ) ) {
2958
2977
return ;
2959
2978
}
2960
- output . writeCharacters ( this . print ( value , context , output , scope ) ) ;
2979
+
2980
+ if ( this . asCDATA ) {
2981
+ output . writeCDATA ( this . print ( value , context , output , scope ) ) ;
2982
+ } else {
2983
+ output . writeCharacters ( this . print ( value , context , output , scope ) ) ;
2984
+ }
2961
2985
} ,
2962
2986
buildStructure : function ( context , structure ) {
2963
2987
Jsonix . Util . Ensure . ensureObject ( structure ) ;
@@ -5820,15 +5844,15 @@ Jsonix.Context = Jsonix
5820
5844
Jsonix . Util . Ensure . ensureObject ( options ) ;
5821
5845
if ( Jsonix . Util . Type
5822
5846
. isObject ( options . namespacePrefixes ) ) {
5823
- this . namespacePrefixes =
5847
+ this . namespacePrefixes =
5824
5848
Jsonix . Util . Type . cloneObject ( options . namespacePrefixes , { } ) ;
5825
5849
}
5826
5850
if ( Jsonix . Util . Type
5827
5851
. isBoolean ( options . supportXsiType ) ) {
5828
- this . supportXsiType = options . supportXsiType ;
5852
+ this . supportXsiType = options . supportXsiType ;
5829
5853
}
5830
5854
}
5831
-
5855
+
5832
5856
// Initialize prefix/namespace mapping
5833
5857
for ( var ns in this . namespacePrefixes )
5834
5858
{
@@ -5857,7 +5881,7 @@ Jsonix.Context = Jsonix
5857
5881
module = mapping ;
5858
5882
} else {
5859
5883
mapping = Jsonix . Util . Type . cloneObject ( mapping ) ;
5860
- module = new this . mappingStyle . module ( mapping ,
5884
+ module = new this . mappingStyle . module ( mapping ,
5861
5885
{
5862
5886
mappingStyle : this . mappingStyle
5863
5887
} ) ;
@@ -6098,6 +6122,7 @@ Jsonix.Context = Jsonix
6098
6122
Jsonix . Schema . XSD . UnsignedShort . INSTANCE ] ,
6099
6123
CLASS_NAME : 'Jsonix.Context'
6100
6124
} ) ;
6125
+
6101
6126
// Complete Jsonix script is included above
6102
6127
return { Jsonix : Jsonix } ;
6103
6128
} ;
0 commit comments