00001
00002 (function() {
00003 var XMLDTDEntity, create, isObject;
00004
00005 create = require('lodash/create');
00006
00007 isObject = require('lodash/isObject');
00008
00009 module.exports = XMLDTDEntity = (function() {
00010 function XMLDTDEntity(parent, pe, name, value) {
00011 this.stringify = parent.stringify;
00012 if (name == null) {
00013 throw new Error("Missing entity name");
00014 }
00015 if (value == null) {
00016 throw new Error("Missing entity value");
00017 }
00018 this.pe = !!pe;
00019 this.name = this.stringify.eleName(name);
00020 if (!isObject(value)) {
00021 this.value = this.stringify.dtdEntityValue(value);
00022 } else {
00023 if (!value.pubID && !value.sysID) {
00024 throw new Error("Public and/or system identifiers are required for an external entity");
00025 }
00026 if (value.pubID && !value.sysID) {
00027 throw new Error("System identifier is required for a public external entity");
00028 }
00029 if (value.pubID != null) {
00030 this.pubID = this.stringify.dtdPubID(value.pubID);
00031 }
00032 if (value.sysID != null) {
00033 this.sysID = this.stringify.dtdSysID(value.sysID);
00034 }
00035 if (value.nData != null) {
00036 this.nData = this.stringify.dtdNData(value.nData);
00037 }
00038 if (this.pe && this.nData) {
00039 throw new Error("Notation declaration is not allowed in a parameter entity");
00040 }
00041 }
00042 }
00043
00044 XMLDTDEntity.prototype.toString = function(options, level) {
00045 var indent, newline, offset, pretty, r, ref, ref1, ref2, space;
00046 pretty = (options != null ? options.pretty : void 0) || false;
00047 indent = (ref = options != null ? options.indent : void 0) != null ? ref : ' ';
00048 offset = (ref1 = options != null ? options.offset : void 0) != null ? ref1 : 0;
00049 newline = (ref2 = options != null ? options.newline : void 0) != null ? ref2 : '\n';
00050 level || (level = 0);
00051 space = new Array(level + offset + 1).join(indent);
00052 r = '';
00053 if (pretty) {
00054 r += space;
00055 }
00056 r += '<!ENTITY';
00057 if (this.pe) {
00058 r += ' %';
00059 }
00060 r += ' ' + this.name;
00061 if (this.value) {
00062 r += ' "' + this.value + '"';
00063 } else {
00064 if (this.pubID && this.sysID) {
00065 r += ' PUBLIC "' + this.pubID + '" "' + this.sysID + '"';
00066 } else if (this.sysID) {
00067 r += ' SYSTEM "' + this.sysID + '"';
00068 }
00069 if (this.nData) {
00070 r += ' NDATA ' + this.nData;
00071 }
00072 }
00073 r += '>';
00074 if (pretty) {
00075 r += newline;
00076 }
00077 return r;
00078 };
00079
00080 return XMLDTDEntity;
00081
00082 })();
00083
00084 }).call(this);