pocjenkixx 0.30.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pocjenkixx might be problematic. Click here for more details.
- package/LICENSE +19 -0
- package/Makefile +18 -0
- package/README.md +52 -0
- package/binding.gyp +81 -0
- package/index.d.ts +273 -0
- package/index.js +45 -0
- package/lib/bindings.js +1 -0
- package/lib/document.js +122 -0
- package/lib/element.js +82 -0
- package/lib/sax_parser.js +38 -0
- package/package.json +70 -0
- package/src/html_document.cc +7 -0
- package/src/html_document.h +18 -0
- package/src/libxmljs.cc +252 -0
- package/src/libxmljs.h +53 -0
- package/src/xml_attribute.cc +173 -0
- package/src/xml_attribute.h +40 -0
- package/src/xml_comment.cc +117 -0
- package/src/xml_comment.h +30 -0
- package/src/xml_document.cc +810 -0
- package/src/xml_document.h +67 -0
- package/src/xml_element.cc +565 -0
- package/src/xml_element.h +61 -0
- package/src/xml_namespace.cc +158 -0
- package/src/xml_namespace.h +39 -0
- package/src/xml_node.cc +761 -0
- package/src/xml_node.h +73 -0
- package/src/xml_pi.cc +161 -0
- package/src/xml_pi.h +34 -0
- package/src/xml_sax_parser.cc +424 -0
- package/src/xml_sax_parser.h +73 -0
- package/src/xml_syntax_error.cc +66 -0
- package/src/xml_syntax_error.h +25 -0
- package/src/xml_text.cc +320 -0
- package/src/xml_text.h +48 -0
- package/src/xml_textwriter.cc +315 -0
- package/src/xml_textwriter.h +62 -0
- package/src/xml_xpath_context.cc +70 -0
- package/src/xml_xpath_context.h +23 -0
- package/vendor/libxml/Copyright +23 -0
- package/vendor/libxml/DOCBparser.c +305 -0
- package/vendor/libxml/HTMLparser.c +7287 -0
- package/vendor/libxml/HTMLtree.c +1200 -0
- package/vendor/libxml/Makefile +2983 -0
- package/vendor/libxml/SAX.c +180 -0
- package/vendor/libxml/SAX2.c +3036 -0
- package/vendor/libxml/buf.c +1351 -0
- package/vendor/libxml/buf.h +72 -0
- package/vendor/libxml/c14n.c +2234 -0
- package/vendor/libxml/catalog.c +3828 -0
- package/vendor/libxml/chvalid.c +336 -0
- package/vendor/libxml/config.h +294 -0
- package/vendor/libxml/config.h.gch +0 -0
- package/vendor/libxml/debugXML.c +3423 -0
- package/vendor/libxml/dict.c +1298 -0
- package/vendor/libxml/elfgcchack.h +17818 -0
- package/vendor/libxml/enc.h +32 -0
- package/vendor/libxml/encoding.c +3975 -0
- package/vendor/libxml/entities.c +1163 -0
- package/vendor/libxml/error.c +998 -0
- package/vendor/libxml/globals.c +1126 -0
- package/vendor/libxml/hash.c +1146 -0
- package/vendor/libxml/include/libxml/DOCBparser.h +96 -0
- package/vendor/libxml/include/libxml/HTMLparser.h +306 -0
- package/vendor/libxml/include/libxml/HTMLtree.h +147 -0
- package/vendor/libxml/include/libxml/Makefile +725 -0
- package/vendor/libxml/include/libxml/Makefile.am +54 -0
- package/vendor/libxml/include/libxml/Makefile.in +725 -0
- package/vendor/libxml/include/libxml/SAX.h +173 -0
- package/vendor/libxml/include/libxml/SAX2.h +178 -0
- package/vendor/libxml/include/libxml/c14n.h +128 -0
- package/vendor/libxml/include/libxml/catalog.h +182 -0
- package/vendor/libxml/include/libxml/chvalid.h +230 -0
- package/vendor/libxml/include/libxml/debugXML.h +217 -0
- package/vendor/libxml/include/libxml/dict.h +79 -0
- package/vendor/libxml/include/libxml/encoding.h +245 -0
- package/vendor/libxml/include/libxml/entities.h +151 -0
- package/vendor/libxml/include/libxml/globals.h +508 -0
- package/vendor/libxml/include/libxml/hash.h +236 -0
- package/vendor/libxml/include/libxml/list.h +137 -0
- package/vendor/libxml/include/libxml/nanoftp.h +163 -0
- package/vendor/libxml/include/libxml/nanohttp.h +81 -0
- package/vendor/libxml/include/libxml/parser.h +1243 -0
- package/vendor/libxml/include/libxml/parserInternals.h +644 -0
- package/vendor/libxml/include/libxml/pattern.h +100 -0
- package/vendor/libxml/include/libxml/relaxng.h +217 -0
- package/vendor/libxml/include/libxml/schemasInternals.h +958 -0
- package/vendor/libxml/include/libxml/schematron.h +142 -0
- package/vendor/libxml/include/libxml/threads.h +89 -0
- package/vendor/libxml/include/libxml/tree.h +1311 -0
- package/vendor/libxml/include/libxml/uri.h +94 -0
- package/vendor/libxml/include/libxml/valid.h +458 -0
- package/vendor/libxml/include/libxml/xinclude.h +129 -0
- package/vendor/libxml/include/libxml/xlink.h +189 -0
- package/vendor/libxml/include/libxml/xmlIO.h +368 -0
- package/vendor/libxml/include/libxml/xmlautomata.h +146 -0
- package/vendor/libxml/include/libxml/xmlerror.h +945 -0
- package/vendor/libxml/include/libxml/xmlexports.h +77 -0
- package/vendor/libxml/include/libxml/xmlmemory.h +224 -0
- package/vendor/libxml/include/libxml/xmlmodule.h +57 -0
- package/vendor/libxml/include/libxml/xmlreader.h +428 -0
- package/vendor/libxml/include/libxml/xmlregexp.h +222 -0
- package/vendor/libxml/include/libxml/xmlsave.h +88 -0
- package/vendor/libxml/include/libxml/xmlschemas.h +246 -0
- package/vendor/libxml/include/libxml/xmlschemastypes.h +151 -0
- package/vendor/libxml/include/libxml/xmlstring.h +140 -0
- package/vendor/libxml/include/libxml/xmlunicode.h +202 -0
- package/vendor/libxml/include/libxml/xmlversion.h +484 -0
- package/vendor/libxml/include/libxml/xmlwin32version.h +239 -0
- package/vendor/libxml/include/libxml/xmlwriter.h +488 -0
- package/vendor/libxml/include/libxml/xpath.h +564 -0
- package/vendor/libxml/include/libxml/xpathInternals.h +632 -0
- package/vendor/libxml/include/libxml/xpointer.h +114 -0
- package/vendor/libxml/include/win32config.h +122 -0
- package/vendor/libxml/include/wsockcompat.h +54 -0
- package/vendor/libxml/legacy.c +1343 -0
- package/vendor/libxml/libxml.h +134 -0
- package/vendor/libxml/list.c +779 -0
- package/vendor/libxml/nanoftp.c +2118 -0
- package/vendor/libxml/nanohttp.c +1899 -0
- package/vendor/libxml/parser.c +15553 -0
- package/vendor/libxml/parserInternals.c +2164 -0
- package/vendor/libxml/pattern.c +2621 -0
- package/vendor/libxml/relaxng.c +11101 -0
- package/vendor/libxml/rngparser.c +1595 -0
- package/vendor/libxml/runsuite.c +1157 -0
- package/vendor/libxml/save.h +36 -0
- package/vendor/libxml/schematron.c +1787 -0
- package/vendor/libxml/threads.c +1049 -0
- package/vendor/libxml/timsort.h +601 -0
- package/vendor/libxml/tree.c +10183 -0
- package/vendor/libxml/trio.c +6895 -0
- package/vendor/libxml/trio.h +230 -0
- package/vendor/libxml/triodef.h +228 -0
- package/vendor/libxml/trionan.c +914 -0
- package/vendor/libxml/trionan.h +84 -0
- package/vendor/libxml/triop.h +150 -0
- package/vendor/libxml/triostr.c +2112 -0
- package/vendor/libxml/triostr.h +144 -0
- package/vendor/libxml/uri.c +2561 -0
- package/vendor/libxml/valid.c +7138 -0
- package/vendor/libxml/xinclude.c +2657 -0
- package/vendor/libxml/xlink.c +183 -0
- package/vendor/libxml/xmlIO.c +4135 -0
- package/vendor/libxml/xmlcatalog.c +624 -0
- package/vendor/libxml/xmllint.c +3796 -0
- package/vendor/libxml/xmlmemory.c +1163 -0
- package/vendor/libxml/xmlmodule.c +468 -0
- package/vendor/libxml/xmlreader.c +6033 -0
- package/vendor/libxml/xmlregexp.c +8271 -0
- package/vendor/libxml/xmlsave.c +2735 -0
- package/vendor/libxml/xmlschemas.c +29173 -0
- package/vendor/libxml/xmlschemastypes.c +6276 -0
- package/vendor/libxml/xmlstring.c +1050 -0
- package/vendor/libxml/xmlunicode.c +3179 -0
- package/vendor/libxml/xmlwriter.c +4738 -0
- package/vendor/libxml/xpath.c +14734 -0
- package/vendor/libxml/xpointer.c +2969 -0
- package/vendor/libxml/xzlib.c +815 -0
- package/vendor/libxml/xzlib.h +19 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
#ifndef SRC_XML_SAX_PARSER_H_
|
3
|
+
#define SRC_XML_SAX_PARSER_H_
|
4
|
+
|
5
|
+
#include <node.h>
|
6
|
+
|
7
|
+
namespace libxmljs {
|
8
|
+
|
9
|
+
class XmlSaxParser : public Nan::ObjectWrap {
|
10
|
+
public:
|
11
|
+
XmlSaxParser();
|
12
|
+
virtual ~XmlSaxParser();
|
13
|
+
|
14
|
+
static void Initialize(v8::Local<v8::Object> target);
|
15
|
+
|
16
|
+
static NAN_METHOD(NewParser);
|
17
|
+
|
18
|
+
static NAN_METHOD(NewPushParser);
|
19
|
+
|
20
|
+
static NAN_METHOD(ParseString);
|
21
|
+
static NAN_METHOD(Push);
|
22
|
+
|
23
|
+
void Callback(const char *what, int argc = 0,
|
24
|
+
v8::Local<v8::Value> argv[] = NULL);
|
25
|
+
|
26
|
+
void parse_string(const char *str, unsigned int size);
|
27
|
+
|
28
|
+
void initialize_push_parser();
|
29
|
+
|
30
|
+
void push(const char *str, unsigned int size, bool terminate);
|
31
|
+
|
32
|
+
/// callbacks
|
33
|
+
|
34
|
+
static void start_document(void *context);
|
35
|
+
|
36
|
+
static void end_document(void *context);
|
37
|
+
|
38
|
+
static void start_element(void *context, const xmlChar *name,
|
39
|
+
const xmlChar **p);
|
40
|
+
|
41
|
+
static void end_element(void *context, const xmlChar *name);
|
42
|
+
|
43
|
+
static void start_element_ns(void *context, const xmlChar *localname,
|
44
|
+
const xmlChar *prefix, const xmlChar *uri,
|
45
|
+
int nb_namespaces, const xmlChar **namespaces,
|
46
|
+
int nb_attributes, int nb_defaulted,
|
47
|
+
const xmlChar **attributes);
|
48
|
+
|
49
|
+
static void end_element_ns(void *context, const xmlChar *localname,
|
50
|
+
const xmlChar *prefix, const xmlChar *uri);
|
51
|
+
|
52
|
+
static void characters(void *context, const xmlChar *ch, int len);
|
53
|
+
|
54
|
+
static void comment(void *context, const xmlChar *value);
|
55
|
+
|
56
|
+
static void cdata_block(void *context, const xmlChar *value, int len);
|
57
|
+
|
58
|
+
static void warning(void *context, const char *msg, ...);
|
59
|
+
|
60
|
+
static void error(void *context, const char *msg, ...);
|
61
|
+
|
62
|
+
protected:
|
63
|
+
void initializeContext();
|
64
|
+
void releaseContext();
|
65
|
+
|
66
|
+
xmlParserCtxt *context_;
|
67
|
+
|
68
|
+
xmlSAXHandler sax_handler_;
|
69
|
+
};
|
70
|
+
|
71
|
+
} // namespace libxmljs
|
72
|
+
|
73
|
+
#endif // SRC_XML_SAX_PARSER_H_
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
|
3
|
+
#include <cstring>
|
4
|
+
|
5
|
+
#include "xml_syntax_error.h"
|
6
|
+
|
7
|
+
using namespace v8;
|
8
|
+
namespace {
|
9
|
+
|
10
|
+
void set_string_field(Local<Object> obj, const char *name, const char *value) {
|
11
|
+
Nan::HandleScope scope;
|
12
|
+
if (!value) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
Nan::Set(obj, Nan::New<String>(name).ToLocalChecked(),
|
16
|
+
Nan::New<String>(value, strlen(value)).ToLocalChecked());
|
17
|
+
}
|
18
|
+
|
19
|
+
void set_numeric_field(Local<Object> obj, const char *name, const int value) {
|
20
|
+
Nan::HandleScope scope;
|
21
|
+
Nan::Set(obj, Nan::New<String>(name).ToLocalChecked(),
|
22
|
+
Nan::New<Int32>(value));
|
23
|
+
}
|
24
|
+
|
25
|
+
} // anonymous namespace
|
26
|
+
|
27
|
+
namespace libxmljs {
|
28
|
+
|
29
|
+
Local<Value> XmlSyntaxError::BuildSyntaxError(xmlError *error) {
|
30
|
+
Nan::EscapableHandleScope scope;
|
31
|
+
|
32
|
+
Local<Value> err =
|
33
|
+
Exception::Error(Nan::New<String>(error->message).ToLocalChecked());
|
34
|
+
Local<Object> out = Local<Object>::Cast(err);
|
35
|
+
|
36
|
+
set_numeric_field(out, "domain", error->domain);
|
37
|
+
set_numeric_field(out, "code", error->code);
|
38
|
+
set_string_field(out, "message", error->message);
|
39
|
+
set_numeric_field(out, "level", error->level);
|
40
|
+
set_numeric_field(out, "column", error->int2);
|
41
|
+
set_string_field(out, "file", error->file);
|
42
|
+
set_numeric_field(out, "line", error->line);
|
43
|
+
set_string_field(out, "str1", error->str1);
|
44
|
+
set_string_field(out, "str2", error->str2);
|
45
|
+
set_string_field(out, "str3", error->str3);
|
46
|
+
|
47
|
+
// only add if we have something interesting
|
48
|
+
if (error->int1) {
|
49
|
+
set_numeric_field(out, "int1", error->int1);
|
50
|
+
}
|
51
|
+
return scope.Escape(err);
|
52
|
+
}
|
53
|
+
|
54
|
+
void XmlSyntaxError::PushToArray(void *errs, xmlError *error) {
|
55
|
+
Nan::HandleScope scope;
|
56
|
+
Local<Array> errors = *reinterpret_cast<Local<Array> *>(errs);
|
57
|
+
// push method for array
|
58
|
+
Local<Function> push = Local<Function>::Cast(
|
59
|
+
Nan::Get(errors, Nan::New<String>("push").ToLocalChecked())
|
60
|
+
.ToLocalChecked());
|
61
|
+
|
62
|
+
Local<Value> argv[1] = {XmlSyntaxError::BuildSyntaxError(error)};
|
63
|
+
Nan::Call(push, errors, 1, argv);
|
64
|
+
}
|
65
|
+
|
66
|
+
} // namespace libxmljs
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
#ifndef SRC_XML_SYNTAX_ERROR_H_
|
3
|
+
#define SRC_XML_SYNTAX_ERROR_H_
|
4
|
+
|
5
|
+
#include <libxml/xmlerror.h>
|
6
|
+
|
7
|
+
#include "libxmljs.h"
|
8
|
+
|
9
|
+
namespace libxmljs {
|
10
|
+
|
11
|
+
// basically being used like a namespace
|
12
|
+
class XmlSyntaxError {
|
13
|
+
public:
|
14
|
+
// push xmlError onto v8::Array
|
15
|
+
// helper method for xml library
|
16
|
+
static void PushToArray(void *errs, xmlError *error);
|
17
|
+
|
18
|
+
// create a v8 object for the syntax eror
|
19
|
+
// TODO make it a v8 Erorr object
|
20
|
+
static v8::Local<v8::Value> BuildSyntaxError(xmlError *error);
|
21
|
+
};
|
22
|
+
|
23
|
+
} // namespace libxmljs
|
24
|
+
|
25
|
+
#endif // SRC_XML_SYNTAX_ERROR_H_
|
package/src/xml_text.cc
ADDED
@@ -0,0 +1,320 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
|
3
|
+
#include <node.h>
|
4
|
+
|
5
|
+
#include <cstring>
|
6
|
+
|
7
|
+
#include "libxmljs.h"
|
8
|
+
|
9
|
+
#include "xml_attribute.h"
|
10
|
+
#include "xml_document.h"
|
11
|
+
#include "xml_text.h"
|
12
|
+
#include "xml_xpath_context.h"
|
13
|
+
|
14
|
+
using namespace v8;
|
15
|
+
|
16
|
+
namespace libxmljs {
|
17
|
+
|
18
|
+
Nan::Persistent<FunctionTemplate> XmlText::constructor_template;
|
19
|
+
|
20
|
+
Local<Value> XmlText::get_path() {
|
21
|
+
Nan::EscapableHandleScope scope;
|
22
|
+
xmlChar *path = xmlGetNodePath(xml_obj);
|
23
|
+
const char *return_path = path ? reinterpret_cast<char *>(path) : "";
|
24
|
+
int str_len = xmlStrlen((const xmlChar *)return_path);
|
25
|
+
Local<String> js_obj =
|
26
|
+
Nan::New<String>(return_path, str_len).ToLocalChecked();
|
27
|
+
xmlFree(path);
|
28
|
+
return scope.Escape(js_obj);
|
29
|
+
}
|
30
|
+
|
31
|
+
// doc, name, content
|
32
|
+
NAN_METHOD(XmlText::New) {
|
33
|
+
NAN_CONSTRUCTOR_CHECK(Text)
|
34
|
+
Nan::HandleScope scope;
|
35
|
+
|
36
|
+
// if we were created for an existing xml node, then we don't need
|
37
|
+
// to create a new node on the document
|
38
|
+
if (info.Length() == 0) {
|
39
|
+
return info.GetReturnValue().Set(info.Holder());
|
40
|
+
}
|
41
|
+
|
42
|
+
DOCUMENT_ARG_CHECK
|
43
|
+
if (!info[1]->IsString()) {
|
44
|
+
Nan::ThrowError("content argument must be of type string");
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
|
48
|
+
XmlDocument *document = Nan::ObjectWrap::Unwrap<XmlDocument>(doc);
|
49
|
+
assert(document);
|
50
|
+
|
51
|
+
Local<Value> contentOpt;
|
52
|
+
if (info[1]->IsString()) {
|
53
|
+
contentOpt = info[1];
|
54
|
+
}
|
55
|
+
Nan::Utf8String contentRaw(contentOpt);
|
56
|
+
const char *content = (contentRaw.length()) ? *contentRaw : NULL;
|
57
|
+
|
58
|
+
xmlNode *textNode =
|
59
|
+
xmlNewDocText(document->xml_obj, (const xmlChar *)content);
|
60
|
+
|
61
|
+
XmlText *element = new XmlText(textNode);
|
62
|
+
textNode->_private = element;
|
63
|
+
element->Wrap(info.Holder());
|
64
|
+
|
65
|
+
// this prevents the document from going away
|
66
|
+
Nan::Set(info.Holder(), Nan::New<String>("document").ToLocalChecked(),
|
67
|
+
info[0])
|
68
|
+
.Check();
|
69
|
+
|
70
|
+
return info.GetReturnValue().Set(info.Holder());
|
71
|
+
}
|
72
|
+
|
73
|
+
NAN_METHOD(XmlText::NextElement) {
|
74
|
+
Nan::HandleScope scope;
|
75
|
+
XmlText *element = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
76
|
+
assert(element);
|
77
|
+
|
78
|
+
return info.GetReturnValue().Set(element->get_next_element());
|
79
|
+
}
|
80
|
+
|
81
|
+
NAN_METHOD(XmlText::PrevElement) {
|
82
|
+
Nan::HandleScope scope;
|
83
|
+
XmlText *element = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
84
|
+
assert(element);
|
85
|
+
|
86
|
+
return info.GetReturnValue().Set(element->get_prev_element());
|
87
|
+
}
|
88
|
+
|
89
|
+
NAN_METHOD(XmlText::Text) {
|
90
|
+
Nan::HandleScope scope;
|
91
|
+
XmlText *element = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
92
|
+
assert(element);
|
93
|
+
|
94
|
+
if (info.Length() == 0) {
|
95
|
+
return info.GetReturnValue().Set(element->get_content());
|
96
|
+
} else {
|
97
|
+
element->set_content(*Nan::Utf8String(info[0]));
|
98
|
+
}
|
99
|
+
|
100
|
+
return info.GetReturnValue().Set(info.Holder());
|
101
|
+
}
|
102
|
+
|
103
|
+
NAN_METHOD(XmlText::AddPrevSibling) {
|
104
|
+
XmlText *text = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
105
|
+
assert(text);
|
106
|
+
|
107
|
+
XmlNode *new_sibling = Nan::ObjectWrap::Unwrap<XmlNode>(
|
108
|
+
Nan::To<Object>(info[0]).ToLocalChecked());
|
109
|
+
assert(new_sibling);
|
110
|
+
|
111
|
+
xmlNode *imported_sibling = text->import_node(new_sibling->xml_obj);
|
112
|
+
if (imported_sibling == NULL) {
|
113
|
+
return Nan::ThrowError(
|
114
|
+
"Could not add sibling. Failed to copy node to new Document.");
|
115
|
+
} else if ((new_sibling->xml_obj == imported_sibling) &&
|
116
|
+
text->prev_sibling_will_merge(imported_sibling)) {
|
117
|
+
imported_sibling = xmlCopyNode(imported_sibling, 0);
|
118
|
+
}
|
119
|
+
text->add_prev_sibling(imported_sibling);
|
120
|
+
|
121
|
+
return info.GetReturnValue().Set(info[0]);
|
122
|
+
}
|
123
|
+
|
124
|
+
NAN_METHOD(XmlText::AddNextSibling) {
|
125
|
+
XmlText *text = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
126
|
+
assert(text);
|
127
|
+
|
128
|
+
XmlNode *new_sibling = Nan::ObjectWrap::Unwrap<XmlNode>(
|
129
|
+
Nan::To<Object>(info[0]).ToLocalChecked());
|
130
|
+
assert(new_sibling);
|
131
|
+
|
132
|
+
xmlNode *imported_sibling = text->import_node(new_sibling->xml_obj);
|
133
|
+
if (imported_sibling == NULL) {
|
134
|
+
return Nan::ThrowError(
|
135
|
+
"Could not add sibling. Failed to copy node to new Document.");
|
136
|
+
} else if ((new_sibling->xml_obj == imported_sibling) &&
|
137
|
+
text->next_sibling_will_merge(imported_sibling)) {
|
138
|
+
imported_sibling = xmlCopyNode(imported_sibling, 0);
|
139
|
+
}
|
140
|
+
text->add_next_sibling(imported_sibling);
|
141
|
+
|
142
|
+
return info.GetReturnValue().Set(info[0]);
|
143
|
+
}
|
144
|
+
|
145
|
+
NAN_METHOD(XmlText::Replace) {
|
146
|
+
XmlText *element = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
147
|
+
assert(element);
|
148
|
+
|
149
|
+
if (info[0]->IsString()) {
|
150
|
+
element->replace_text(*Nan::Utf8String(info[0]));
|
151
|
+
} else {
|
152
|
+
XmlText *new_sibling = Nan::ObjectWrap::Unwrap<XmlText>(
|
153
|
+
Nan::To<Object>(info[0]).ToLocalChecked());
|
154
|
+
assert(new_sibling);
|
155
|
+
|
156
|
+
xmlNode *imported_sibling = element->import_node(new_sibling->xml_obj);
|
157
|
+
if (imported_sibling == NULL) {
|
158
|
+
return Nan::ThrowError(
|
159
|
+
"Could not replace. Failed to copy node to new Document.");
|
160
|
+
}
|
161
|
+
element->replace_element(imported_sibling);
|
162
|
+
}
|
163
|
+
|
164
|
+
return info.GetReturnValue().Set(info[0]);
|
165
|
+
}
|
166
|
+
|
167
|
+
NAN_METHOD(XmlText::Path) {
|
168
|
+
Nan::HandleScope scope;
|
169
|
+
XmlText *text = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
170
|
+
assert(text);
|
171
|
+
|
172
|
+
return info.GetReturnValue().Set(text->get_path());
|
173
|
+
}
|
174
|
+
|
175
|
+
NAN_METHOD(XmlText::Name) {
|
176
|
+
Nan::HandleScope scope;
|
177
|
+
XmlText *text = Nan::ObjectWrap::Unwrap<XmlText>(info.Holder());
|
178
|
+
assert(text);
|
179
|
+
|
180
|
+
if (info.Length() == 0)
|
181
|
+
return info.GetReturnValue().Set(text->get_name());
|
182
|
+
return info.GetReturnValue().Set(info.Holder());
|
183
|
+
}
|
184
|
+
|
185
|
+
void XmlText::set_content(const char *content) {
|
186
|
+
xmlChar *encoded =
|
187
|
+
xmlEncodeSpecialChars(xml_obj->doc, (const xmlChar *)content);
|
188
|
+
xmlNodeSetContent(xml_obj, encoded);
|
189
|
+
xmlFree(encoded);
|
190
|
+
}
|
191
|
+
|
192
|
+
Local<Value> XmlText::get_content() {
|
193
|
+
Nan::EscapableHandleScope scope;
|
194
|
+
xmlChar *content = xmlNodeGetContent(xml_obj);
|
195
|
+
if (content) {
|
196
|
+
Local<String> ret_content =
|
197
|
+
Nan::New<String>((const char *)content).ToLocalChecked();
|
198
|
+
xmlFree(content);
|
199
|
+
return scope.Escape(ret_content);
|
200
|
+
}
|
201
|
+
|
202
|
+
return scope.Escape(Nan::New<String>("").ToLocalChecked());
|
203
|
+
}
|
204
|
+
|
205
|
+
Local<Value> XmlText::get_name() {
|
206
|
+
Nan::EscapableHandleScope scope;
|
207
|
+
if (xml_obj->name)
|
208
|
+
return scope.Escape(
|
209
|
+
Nan::New<String>((const char *)xml_obj->name).ToLocalChecked());
|
210
|
+
else
|
211
|
+
return scope.Escape(Nan::Undefined());
|
212
|
+
}
|
213
|
+
|
214
|
+
Local<Value> XmlText::get_next_element() {
|
215
|
+
Nan::EscapableHandleScope scope;
|
216
|
+
|
217
|
+
xmlNode *sibling = xml_obj->next;
|
218
|
+
if (!sibling)
|
219
|
+
return scope.Escape(Nan::Null());
|
220
|
+
|
221
|
+
while (sibling && sibling->type != XML_ELEMENT_NODE)
|
222
|
+
sibling = sibling->next;
|
223
|
+
|
224
|
+
if (sibling) {
|
225
|
+
return scope.Escape(XmlText::New(sibling));
|
226
|
+
}
|
227
|
+
|
228
|
+
return scope.Escape(Nan::Null());
|
229
|
+
}
|
230
|
+
|
231
|
+
Local<Value> XmlText::get_prev_element() {
|
232
|
+
Nan::EscapableHandleScope scope;
|
233
|
+
|
234
|
+
xmlNode *sibling = xml_obj->prev;
|
235
|
+
if (!sibling)
|
236
|
+
return scope.Escape(Nan::Null());
|
237
|
+
|
238
|
+
while (sibling && sibling->type != XML_ELEMENT_NODE) {
|
239
|
+
sibling = sibling->prev;
|
240
|
+
}
|
241
|
+
|
242
|
+
if (sibling) {
|
243
|
+
return scope.Escape(XmlText::New(sibling));
|
244
|
+
}
|
245
|
+
|
246
|
+
return scope.Escape(Nan::Null());
|
247
|
+
}
|
248
|
+
|
249
|
+
Local<Object> XmlText::New(xmlNode *node) {
|
250
|
+
Nan::EscapableHandleScope scope;
|
251
|
+
if (node->_private) {
|
252
|
+
return scope.Escape(static_cast<XmlNode *>(node->_private)->handle());
|
253
|
+
}
|
254
|
+
|
255
|
+
XmlText *text = new XmlText(node);
|
256
|
+
Local<Object> obj =
|
257
|
+
Nan::NewInstance(
|
258
|
+
Nan::GetFunction(Nan::New(constructor_template)).ToLocalChecked())
|
259
|
+
.ToLocalChecked();
|
260
|
+
text->Wrap(obj);
|
261
|
+
return scope.Escape(obj);
|
262
|
+
}
|
263
|
+
|
264
|
+
XmlText::XmlText(xmlNode *node) : XmlNode(node) {}
|
265
|
+
|
266
|
+
void XmlText::add_prev_sibling(xmlNode *element) {
|
267
|
+
xmlAddPrevSibling(xml_obj, element);
|
268
|
+
}
|
269
|
+
|
270
|
+
void XmlText::add_next_sibling(xmlNode *element) {
|
271
|
+
xmlAddNextSibling(xml_obj, element);
|
272
|
+
}
|
273
|
+
|
274
|
+
void XmlText::replace_element(xmlNode *element) {
|
275
|
+
xmlReplaceNode(xml_obj, element);
|
276
|
+
}
|
277
|
+
|
278
|
+
void XmlText::replace_text(const char *content) {
|
279
|
+
xmlNodePtr txt = xmlNewDocText(xml_obj->doc, (const xmlChar *)content);
|
280
|
+
xmlReplaceNode(xml_obj, txt);
|
281
|
+
}
|
282
|
+
|
283
|
+
bool XmlText::next_sibling_will_merge(xmlNode *child) {
|
284
|
+
return (child->type == XML_TEXT_NODE);
|
285
|
+
}
|
286
|
+
|
287
|
+
bool XmlText::prev_sibling_will_merge(xmlNode *child) {
|
288
|
+
return (child->type == XML_TEXT_NODE);
|
289
|
+
}
|
290
|
+
|
291
|
+
void XmlText::Initialize(Local<Object> target) {
|
292
|
+
Nan::HandleScope scope;
|
293
|
+
Local<FunctionTemplate> tmpl = Nan::New<FunctionTemplate>(New);
|
294
|
+
|
295
|
+
constructor_template.Reset(tmpl);
|
296
|
+
|
297
|
+
tmpl->Inherit(Nan::New(XmlNode::constructor_template));
|
298
|
+
tmpl->InstanceTemplate()->SetInternalFieldCount(1);
|
299
|
+
|
300
|
+
Nan::SetPrototypeMethod(tmpl, "nextElement", XmlText::NextElement);
|
301
|
+
|
302
|
+
Nan::SetPrototypeMethod(tmpl, "prevElement", XmlText::PrevElement);
|
303
|
+
|
304
|
+
Nan::SetPrototypeMethod(tmpl, "text", XmlText::Text);
|
305
|
+
|
306
|
+
Nan::SetPrototypeMethod(tmpl, "replace", XmlText::Replace);
|
307
|
+
|
308
|
+
Nan::SetPrototypeMethod(tmpl, "path", XmlText::Path);
|
309
|
+
|
310
|
+
Nan::SetPrototypeMethod(tmpl, "name", XmlText::Name);
|
311
|
+
|
312
|
+
Nan::SetPrototypeMethod(tmpl, "addPrevSibling", XmlText::AddPrevSibling);
|
313
|
+
|
314
|
+
Nan::SetPrototypeMethod(tmpl, "addNextSibling", XmlText::AddNextSibling);
|
315
|
+
|
316
|
+
Nan::Set(target, Nan::New<String>("Text").ToLocalChecked(),
|
317
|
+
Nan::GetFunction(tmpl).ToLocalChecked());
|
318
|
+
}
|
319
|
+
|
320
|
+
} // namespace libxmljs
|
package/src/xml_text.h
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#ifndef SRC_XML_TEXT_H_
|
2
|
+
#define SRC_XML_TEXT_H_
|
3
|
+
|
4
|
+
#include "libxmljs.h"
|
5
|
+
#include "xml_node.h"
|
6
|
+
|
7
|
+
namespace libxmljs {
|
8
|
+
|
9
|
+
class XmlText : public XmlNode {
|
10
|
+
public:
|
11
|
+
explicit XmlText(xmlNode *node);
|
12
|
+
|
13
|
+
static void Initialize(v8::Local<v8::Object> target);
|
14
|
+
|
15
|
+
static Nan::Persistent<v8::FunctionTemplate> constructor_template;
|
16
|
+
|
17
|
+
// create new xml element to wrap the node
|
18
|
+
static v8::Local<v8::Object> New(xmlNode *node);
|
19
|
+
|
20
|
+
protected:
|
21
|
+
static NAN_METHOD(New);
|
22
|
+
static NAN_METHOD(Text);
|
23
|
+
static NAN_METHOD(Replace);
|
24
|
+
static NAN_METHOD(Path);
|
25
|
+
static NAN_METHOD(Name);
|
26
|
+
|
27
|
+
static NAN_METHOD(NextElement);
|
28
|
+
static NAN_METHOD(PrevElement);
|
29
|
+
static NAN_METHOD(AddPrevSibling);
|
30
|
+
static NAN_METHOD(AddNextSibling);
|
31
|
+
|
32
|
+
v8::Local<v8::Value> get_next_element();
|
33
|
+
v8::Local<v8::Value> get_prev_element();
|
34
|
+
v8::Local<v8::Value> get_content();
|
35
|
+
v8::Local<v8::Value> get_path();
|
36
|
+
v8::Local<v8::Value> get_name();
|
37
|
+
void set_content(const char *content);
|
38
|
+
void replace_text(const char *content);
|
39
|
+
void replace_element(xmlNode *element);
|
40
|
+
void add_prev_sibling(xmlNode *element);
|
41
|
+
void add_next_sibling(xmlNode *element);
|
42
|
+
bool prev_sibling_will_merge(xmlNode *node);
|
43
|
+
bool next_sibling_will_merge(xmlNode *node);
|
44
|
+
};
|
45
|
+
|
46
|
+
} // namespace libxmljs
|
47
|
+
|
48
|
+
#endif // SRC_XML_TEXT_H_
|