3 var XMLDTDEntity, create, isObject;
5 create = require(
'lodash/create');
7 isObject = require(
'lodash/isObject');
9 module.exports = XMLDTDEntity = (
function() {
10 function XMLDTDEntity(parent, pe, name, value) {
11 this.stringify = parent.stringify;
13 throw new Error(
"Missing entity name");
16 throw new Error(
"Missing entity value");
19 this.name = this.stringify.eleName(name);
20 if (!isObject(value)) {
21 this.value = this.stringify.dtdEntityValue(value);
23 if (!value.pubID && !value.sysID) {
24 throw new Error(
"Public and/or system identifiers are required for an external entity");
26 if (value.pubID && !value.sysID) {
27 throw new Error(
"System identifier is required for a public external entity");
29 if (value.pubID != null) {
30 this.pubID = this.stringify.dtdPubID(value.pubID);
32 if (value.sysID != null) {
33 this.sysID = this.stringify.dtdSysID(value.sysID);
35 if (value.nData != null) {
36 this.nData = this.stringify.dtdNData(value.nData);
38 if (this.pe && this.nData) {
39 throw new Error(
"Notation declaration is not allowed in a parameter entity");
44 XMLDTDEntity.prototype.toString =
function(options, level) {
45 var indent, newline, offset, pretty, r, ref, ref1, ref2, space;
46 pretty = (options != null ? options.pretty :
void 0) ||
false;
47 indent = (ref = options != null ? options.indent :
void 0) != null ? ref :
' ';
48 offset = (ref1 = options != null ? options.offset :
void 0) != null ? ref1 : 0;
49 newline = (ref2 = options != null ? options.newline :
void 0) != null ? ref2 :
'\n';
51 space =
new Array(level + offset + 1).join(indent);
62 r +=
' "' + this.value +
'"';
64 if (this.pubID && this.sysID) {
65 r +=
' PUBLIC "' + this.pubID +
'" "' + this.sysID +
'"';
66 }
else if (this.sysID) {
67 r +=
' SYSTEM "' + this.sysID +
'"';
70 r +=
' NDATA ' + this.nData;