Example #1
0
    element: function(def, indentation) {
        var attr = null,
            children = [],
            attrs = [];

        if (typeof def !== 'object') return;

        if (def.attributes && typeof def.attributes === 'object') {
            for (var name in def.attributes) {
                attr = def.attributes[name];

                if (attr instanceof Array) attr = attr.join(' ');
                attrs.push(name + '="' + encode(attr) + '"');
            }
        }

        if (def.children && def.children instanceof Array) {
            for (var i = 0; i < def.children.length; i++) {
                children.push(HTML.element(def.children[i], INDENT));
            }

            def.html = '\n' + children.join('\n') + '\n';
        }

        return indent(toHTML(def.tagName,
            encode(def.text || '') + (def.html || ''), attrs), indentation);
    },
Example #2
0
				errors.forEach(function (error) {
					var encodedError = clone(error),
						evidence = error.evidence,
						reason = error.reason;

					encodedError.evidence = evidence ? entities.encode(evidence, 0) : evidence;
					encodedError.reason = reason ? entities.encode(reason, 0) : reason;
					encodedErrors.push(encodedError);
				});
Example #3
0
        encode: function (test) {
            test.expect(2);

            var ampersandsText = entities.encode('dude with a red hat && beard'),
                quotesText = entities.encode('dudette with a white rock & "so" long hair');

            test.equal(ampersandsText, 'dude with a red hat &amp;&amp; beard', 'should correct encode ampersands for XML output');
            test.equal(quotesText, 'dudette with a white rock &amp; &quot;so&quot; long hair', 'should correct encode quotes and ampersands for XML output');

            test.done();
        }
BrokerUtilsXML.makeMessage = function( message )
{
	var xmlMessage;

	xmlMessage = ''
	+ '<BrokerMessage>'
	+ '<DestinationName>'+ message.destinationName +'</DestinationName>'
	+ '<TextPayload>'+ entities.encode( message.payload ) +'</TextPayload>';

	if ( object.priority != null ) {
		xmlMessage += ''
		+ '<Priority>'+ message.priority +'</Priority>';
	}

	if ( object.messageid != null ) {
		xmlMessage += ''
		+ '<MessageId>'+ message.messageId +'</MessageId>';
	}

	if ( object.timestamp != null ) {
		xmlMessage += ''
		+ '<Timestamp>'+ message.timestamp +'</Timestamp>';
	}

	if ( object.expiration != null ) {
		xmlMessage += ''
		+ '<Expiration>'+ message.expiration +'</Expiration>';
	}

	if ( object.correlationid != null ) {
		xmlMessage += ''
		+ '<CorrelationId>'+ message.correlationId +'</CorrelationId>';
	}

	xmlMessage += ''
    + '</BrokerMessage>';

    return xmlMessage;
};
encodeXml = function ( string ) {
	return entities.encode(string, 0 /* xml entities */);
};
Example #6
0
exports.encode = function(str) { return entities.encode(String(str), 0); };
Example #7
0
module.exports = function(options, callback) {
  if (!options.url) {
    callback(new Error('options.url is a required arguemnt'));
  }
  if (!options.query) {
    callback(new Error('options.query is a required argument'));
  } else {
    // XML encode the query
    options.query = entities.encode(options.query);
  }
  if (!options.sortby) {
    options.sortby = 'rlv';
  }
  if (options.sortby !== 'rlv' && options.sortby !== 'tm') {
    callback(new Error('options.sortBy must be "rlv" or "tm"'));
  }
  if (!options.maxpassages) {
    options.maxpassages = 4;
  }
  if (options.maxpassages > 5 || options.maxpassages < 1) {
    callback(new Error('options.maxpassages must be 1-5'));
  }
  if (!options.page) {
    options.page =  0;
  }
  if (!options.groupby) {
    options.groupby = {
                        mode: 'deep',
                        attr: 'd',
                        groupsOnPage: 10,
                        docsInGroup: 1
                      };

  } else {
    if (!options.groupby.mode) {
      options.groupby.mode = 'deep';
      options.groupby.attr = 'd';
    } else if (options.groupby.mode !== 'deep' && options.groupby.mode !== 'flat') {
      return callback(new Error('options.groupby.mode must be "deep" or "flat"'));
    } else if (options.groupby.mode === 'deep') {
      options.groupby.attr = 'd';
    } else {
      options.groupby.attr = ' ';
    }
    if (!options.groupby.groupsOnPage) {
      options.groupby.groupsOnPage = 10;
    }
    if (isNaN(options.groupby.groupsOnPage) ||
              options.groupby.groupsOnPage > 100 ||
              options.groupby.groupsOnPage < 1) {
      return callback(new Error('options.groupby.groupsOnPage must be 1-100'));
    }
    if (!options.groupby.docsInGroup) {
      options.groupby.docsInGroup = 1;
    }
    if (isNaN(options.groupby.docsInGroup) ||
        options.groupby.docsInGroup > 3 ||
        options.groupby.docsInGroup < 1) {
      return callback(new Error('options.groupby.docsInGroup must be 1-3'));
    }
  }

  var requestBody = util.format(xmlString, options.query, options.sortby,
                                 options.maxpassages, options.page,
                                 options.groupby.attr, options.groupby.mode,
                                 options.groupby.groupsOnPage,
                                 options.groupby.docsInGroup);
  var requestOptions = { url: options.url, body: requestBody };
  request.post(requestOptions, function(err, response) {
    if (err) {
      return callback(err);
    } else if (response.statusCode !== 200) {
      return callback(new Error('received non 200 status code'));
    } else {
      return callback(null, response.body);
    }
  });
}
Example #8
0
var encode = exports.encode = function(str) { return entities.encode(str, 0); };