00001
00002 (function() {
00003 var XMLDTDEntity, XMLNode, isObject,
00004 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
00005 hasProp = {}.hasOwnProperty;
00006
00007 isObject = require('./Utility').isObject;
00008
00009 XMLNode = require('./XMLNode');
00010
00011 module.exports = XMLDTDEntity = (function(superClass) {
00012 extend(XMLDTDEntity, superClass);
00013
00014 function XMLDTDEntity(parent, pe, name, value) {
00015 XMLDTDEntity.__super__.constructor.call(this, parent);
00016 if (name == null) {
00017 throw new Error("Missing entity name");
00018 }
00019 if (value == null) {
00020 throw new Error("Missing entity value");
00021 }
00022 this.pe = !!pe;
00023 this.name = this.stringify.eleName(name);
00024 if (!isObject(value)) {
00025 this.value = this.stringify.dtdEntityValue(value);
00026 } else {
00027 if (!value.pubID && !value.sysID) {
00028 throw new Error("Public and/or system identifiers are required for an external entity");
00029 }
00030 if (value.pubID && !value.sysID) {
00031 throw new Error("System identifier is required for a public external entity");
00032 }
00033 if (value.pubID != null) {
00034 this.pubID = this.stringify.dtdPubID(value.pubID);
00035 }
00036 if (value.sysID != null) {
00037 this.sysID = this.stringify.dtdSysID(value.sysID);
00038 }
00039 if (value.nData != null) {
00040 this.nData = this.stringify.dtdNData(value.nData);
00041 }
00042 if (this.pe && this.nData) {
00043 throw new Error("Notation declaration is not allowed in a parameter entity");
00044 }
00045 }
00046 }
00047
00048 XMLDTDEntity.prototype.toString = function(options) {
00049 return this.options.writer.set(options).dtdEntity(this);
00050 };
00051
00052 return XMLDTDEntity;
00053
00054 })(XMLNode);
00055
00056 }).call(this);