File: pa_vxdoc.h

package info (click to toggle)
parser 3.4.5-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,552 kB
  • sloc: cpp: 32,375; sh: 11,487; ansic: 10,849; yacc: 1,361; makefile: 248; awk: 5
file content (123 lines) | stat: -rw-r--r-- 2,840 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/** @file
	Parser: @b xdoc parser class decl.

	Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
	Author: Alexandr Petrosian <[email protected]> (http://paf.design.ru)
*/

#ifndef PA_VXDOC_H
#define PA_VXDOC_H

#define IDENT_PA_VXDOC_H "$Id: pa_vxdoc.h,v 1.58 2017/02/07 22:00:52 moko Exp $"

#include "classes.h"
#include "pa_common.h"
#include "pa_vstateless_object.h"
#include "pa_vxnode.h"
#include "pa_vhash.h"

// defines

#define VXDOC_TYPE "xdoc"

// externals

extern Methoded* xdoc_class;

struct XDocOutputOptions {
	const String* method;       /* the output method */
	const String* encoding;     /* encoding string */
	const String* mediaType;    /* media-type string */
	int indent;                 /* should output being indented */
	const String* version;      /* version string */
	int standalone;             /* standalone = "yes" | "no" */
	int omitXmlDeclaration;     /* omit-xml-declaration = "yes" | "no" */
	const String* filename;     /* Parser3 option: filename */

	XDocOutputOptions() {
		memset(this, 0, sizeof(*this));
		indent=standalone=omitXmlDeclaration=-1;
	};

	void append(Request& r, HashStringValue* options, bool with_filename=false);
};

typedef struct _xsltStylesheet xsltStylesheet;

/// value of type 'xdoc'. implemented with libxml & co
class VXdoc: public VXnode {
public: // Value

	override const char* type() const { return VXDOC_TYPE; }
	override Value* as(const char* atype);

	override VStateless_class* get_class() { return xdoc_class; }

	/// VXdoc: true
	override bool as_bool() const { return true; }

	/// VXdoc: true	 
	override Value& as_expr_result();

	/// VFile: json-string
	override const String* get_json_string(Json_options& options);

	/// VXdoc: $method, fields
	override Value* get_element(const String& aname);

public: // VXNode

	override xmlNode& get_xmlnode() {
		return *reinterpret_cast<xmlNode*>(&get_xmldoc());
	}

	override VXdoc& get_vxdoc() {
		return *this;
	}

public: // usage

	VXdoc() : VXnode(*this), stylesheet(0), fcharsets(0), fdocument(0) {}

	VXdoc(Request_charsets& acharsets, xmlDoc& adocument) : VXnode(*this) {
		set_xmldoc(acharsets, adocument);
	}

public: // VXdoc

	void set_xmldoc(Request_charsets& acharsets, xmlDoc& adocument) { 
		fcharsets=&acharsets;
		fdocument=&adocument;
		fdocument->_private=this;
		stylesheet=0;
	}

	xmlDoc& get_xmldoc() {
		if(!fdocument)
			throw Exception(PARSER_RUNTIME, 0, "using uninitialized xdoc object");
		return *fdocument;
	}

	Request_charsets& charsets() {
		if(!fcharsets)
			throw Exception(PARSER_RUNTIME, 0, "using uninitialized xdoc object");
		return *fcharsets;
	}

	VXnode& wrap(xmlNode& anode);

public:

	VHash search_namespaces;

	XDocOutputOptions output_options;

	xsltStylesheet *stylesheet;

private:

	Request_charsets* fcharsets;
	xmlDoc* fdocument;
};

#endif