~davidagraf/zorba/trace_without_debug_info

« back to all changes in this revision

Viewing changes to src/api/serialization/serializer.h

  • Committer: David Graf
  • Date: 2012-06-27 07:20:59 UTC
  • mfrom: (10869.1.25 zorba)
  • Revision ID: davidagraf@gmail.com-20120627072059-723duu6vsbqu60ax
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    PARAMETER_VALUE_XHTML,
70
70
    PARAMETER_VALUE_TEXT,
71
71
    PARAMETER_VALUE_BINARY,
 
72
#ifdef ZORBA_WITH_JSON
 
73
    PARAMETER_VALUE_JSON,
 
74
    PARAMETER_VALUE_JSONIQ,
 
75
    PARAMETER_VALUE_ARRAY,
 
76
    PARAMETER_VALUE_APPENDED,
 
77
#endif
72
78
 
73
79
    PARAMETER_VALUE_UTF_8,
74
80
    PARAMETER_VALUE_UTF_16,
109
115
  short int version;               // "1.0"
110
116
  zstring version_string;          // this the version as a string
111
117
  short int indent;                // "yes" or "no", implemented
 
118
#ifdef ZORBA_WITH_JSON
 
119
  short int cloudscript_multiple_items;  // "no", "array", "appended", implemented
 
120
  short int cloudscript_extensions;      // implemented
 
121
  short int cloudscript_xdm_method;  // A legal value for "method", implemented
 
122
#endif /* ZORBA_WITH_JSON */
112
123
  bool version_has_default_value;  // Used during validation to set version to
113
124
                                   // "4.0" when output method is "html"
114
125
  rchandle<emitter>    e;
181
192
 
182
193
  bool setup(std::ostream& os, bool aEmitAttributes = false);
183
194
 
 
195
  transcoder* create_transcoder(std::ostream& os);
184
196
 
185
197
  ///////////////////////////////////////////////////////////
186
198
  //                                                       //
215
227
    /**
216
228
     * Outputs the end of the serialized document.
217
229
     */
218
 
    virtual void emit_declaration_end();
219
 
 
 
230
    virtual void emit_end();
 
231
 
 
232
    /**
 
233
     * Serializes the given item, depending on its type, and its children. This
 
234
     * will be called by serializer for each top-level item in the sequence.
 
235
     *
 
236
     * @param item the item to serialize
 
237
     */
 
238
    virtual void emit_item(store::Item* item);
 
239
 
 
240
    // End of the "public" emitter API. All remaining methods are implementation
 
241
    // details and will not be called from outside.
 
242
 
 
243
  protected:
220
244
    /**
221
245
     * Outputs the doctype declaration. This function is not used by the
222
246
     * default emitter, it is intended to be defined by the XML, HTML and XHTML
225
249
    virtual void emit_doctype(const zstring& elementName);
226
250
 
227
251
    /**
228
 
     * Serializes the given item, depending on its type, and its children.
229
 
     *
230
 
     * @param item the item to serialize
231
 
     */
232
 
    virtual void emit_item(store::Item* item);
233
 
 
234
 
    /**
235
252
     * Serializes the given streamable item.
236
253
     *
237
254
     * @param item the item to serialize
287
304
     */
288
305
    void emit_indentation(int depth);
289
306
 
290
 
  protected:
291
307
    bool haveBinding(std::pair<zstring, zstring>& nsBinding) const;
292
308
 
293
309
    bool havePrefix(const zstring& pre) const;
338
354
 
339
355
    virtual void emit_declaration();
340
356
 
 
357
  protected:
341
358
    virtual void emit_doctype(const zstring& elementName);
342
359
 
343
360
  protected:
344
361
    bool theEmitAttributes;
345
362
  };
346
363
 
 
364
  ///////////////////////////////////////////////////////////
 
365
  //                                                       //
 
366
  //  class json_emitter                                   //
 
367
  //                                                       //
 
368
  ///////////////////////////////////////////////////////////
 
369
 
 
370
#ifdef ZORBA_WITH_JSON
 
371
 
 
372
  class json_emitter : public emitter
 
373
  {
 
374
  public:
 
375
    json_emitter(serializer* the_serializer, transcoder& the_transcoder);
 
376
 
 
377
    virtual ~json_emitter();
 
378
 
 
379
    virtual void emit_declaration();
 
380
 
 
381
    virtual void emit_item(store::Item *item);
 
382
 
 
383
    virtual void emit_end();
 
384
 
 
385
  private:
 
386
 
 
387
    /**
 
388
     * Outputs a JSON item. This method is called both for top-level JSON
 
389
     * items as well as any items within a JSON object or array, so it may
 
390
     * output simple typed values differently than standard XML serialization.
 
391
     */
 
392
    void emit_json_item(store::Item* item, int depth);
 
393
 
 
394
    void emit_json_object(store::Item* object, int depth);
 
395
 
 
396
    void emit_json_array(store::Item* array, int depth);
 
397
 
 
398
    void emit_json_pair(store::Item* pair, int depth);
 
399
 
 
400
    void emit_json_value(store::Item* value, int depth);
 
401
 
 
402
    void emit_cloudscript_value(zstring type, zstring value, int depth);
 
403
 
 
404
    void emit_cloudscript_xdm_node(store::Item *item, int depth);
 
405
 
 
406
    void emit_json_string(zstring string);
 
407
 
 
408
    store::Item_t theCloudScriptValueName;
 
409
    store::Item_t theTypeName;
 
410
    store::Item_t theValueName;
 
411
    store::Item_t theCloudScriptXDMNodeName;
 
412
 
 
413
    rchandle<emitter> theXMLEmitter;
 
414
    rchandle<transcoder> theXMLTranscoder;
 
415
    std::stringstream* theXMLStringStream;
 
416
    bool theMultipleItems;
 
417
  };
 
418
 
 
419
 
 
420
  ///////////////////////////////////////////////////////////
 
421
  //                                                       //
 
422
  //  class jsoniq_emitter (auto-detects JSON or XML)      //
 
423
  //                                                       //
 
424
  ///////////////////////////////////////////////////////////
 
425
 
 
426
  class jsoniq_emitter : public emitter
 
427
  {
 
428
  public:
 
429
    jsoniq_emitter(serializer* the_serializer, transcoder& the_transcoder);
 
430
 
 
431
    virtual ~jsoniq_emitter();
 
432
 
 
433
    virtual void emit_declaration();
 
434
 
 
435
    virtual void emit_item(store::Item *item);
 
436
 
 
437
    virtual void emit_end();
 
438
 
 
439
  private:
 
440
    enum JSONiqEmitterState {
 
441
      JESTATE_UNDETERMINED,
 
442
      JESTATE_JDM,
 
443
      JESTATE_XDM
 
444
    }                           theEmitterState;
 
445
 
 
446
    serializer::emitter*        theEmitter;
 
447
  };
 
448
 
 
449
#endif /* ZORBA_WITH_JSON */
 
450
 
 
451
 
347
452
 
348
453
  ///////////////////////////////////////////////////////////
349
454
  //                                                       //
356
461
  public:
357
462
    xhtml_emitter(serializer* the_serializer, transcoder& the_transcoder);
358
463
 
 
464
  protected:
359
465
    virtual void emit_node(const store::Item* item, int depth);
360
466
  };
361
467
 
372
478
    html_emitter(serializer* the_serializer, transcoder& the_transcoder);
373
479
 
374
480
    virtual void emit_declaration();
375
 
    virtual void emit_declaration_end();
 
481
    virtual void emit_end();
 
482
 
 
483
  protected:
376
484
    virtual void emit_doctype(const zstring& elementName);
377
485
    virtual void emit_node(const store::Item* item, int depth);
378
486
  };
391
499
 
392
500
    virtual void emit_declaration();
393
501
 
 
502
    virtual void emit_item(store::Item* item);
 
503
 
 
504
  protected:
394
505
    virtual void emit_node(const store::Item* item, int depth);
395
506
 
396
507
    virtual int emit_node_children(
398
509
        int depth,
399
510
        bool perform_escaping = true);
400
511
 
401
 
    virtual void emit_item(store::Item* item);
402
 
 
403
512
    virtual void emit_streamable_item(store::Item* item);
404
513
  };
405
514
 
425
534
          std::stringstream& aSStream,
426
535
          SAX2_ContentHandler* aSAX2ContentHandler);
427
536
 
 
537
    void emit_declaration();
 
538
    void emit_item(store::Item* item );
 
539
    void emit_end();
 
540
 
 
541
  protected:
428
542
    void emit_startPrefixMapping(
429
543
          const store::Item* item,
430
544
          store::NsBindings& nsBindings );
431
545
 
432
546
    void emit_endPrefixMapping(store::NsBindings& nsBindings );
433
547
 
434
 
    void emit_declaration();
435
 
 
436
 
    void emit_declaration_end();
437
 
 
438
548
    void emit_node(const store::Item* item, int depth);
439
549
 
440
550
    void emit_node(const store::Item* item);
452
562
    void emit_node_children(const store::Item* item);
453
563
 
454
564
    bool emit_bindings(const store::Item* item, int depth);
455
 
 
456
 
    void emit_item(store::Item* item );
457
565
  };
458
566
 
459
567