lib/sf.js
function transferSingleFile(sfXML, dir, callback){
  var xmlParser; 
  var groups;
  var responders = [];
  var fileList = [];
  var entry;
  var responder;
  var stat;

  if(typeof sfXML === 'undefined'){
    throw new Error('No input file specified');
  }

  if(!/\.xml$/.test(sfXML)){
    throw new Error('Input file must be a xml file!');
  }

  sfXML = sfXML.indexOf(path.sep) === 0 ? sfXML : path.join(process.pwd, sfXML);

  xmlParser = new xml2js.Parser();

  fs.readFile(sfXML, function(err, xml){
    if(err){ throw err; }

    xmlParser.parseString(xml, function(err, result){
      var groupParser = function(group){
        var groupId;
        var resources;

        if(typeof group['$'] === 'undefined'){
          return;
        }

        groupId = group['$']['id'];

        if(typeof groupId !== 'undefined'){
          resources = group['resource'];
          entry = {
            comment: '// pattern for ' + groupId,
            pattern: groupId,
            responder: {
              dir: dir || 'fill the dir',
              src: []
            }
          };

          responder = entry.responder;

          if(typeof resources === 'object' && 
              typeof resources['$'] === 'object' && 
              typeof resources['$']['uri'] === 'string'){

            responder.src.push(resources['$']['uri']);

          }

          if(Array.isArray(resources)){
            resources.forEach(function(resource){
              if(typeof resource['$'] === 'object' && 
                  typeof resource['$']['uri'] === 'string'){
                responder.src.push(resource['$']['uri']);
              }
            });
          }
          responders.push(entry);

        }
      }
      groups = result.groupdefinition.groups[0].group;
      if(Array.isArray(groups)){
        groups.forEach(groupParser);
      }else if(typeof groups === 'object'){
        groupParser(groups);
      }
    });

    _getRuleAsString(responders, callback);
    
  });

}
function transferSingleFile(sfXML, dir, callback){
  var xmlParser; 
  var groups;
  var responders = [];
  var fileList = [];
  var entry;
  var responder;
  var stat;

  if(typeof sfXML === 'undefined'){
    throw new Error('No input file specified');
  }

  if(!/\.xml$/.test(sfXML)){
    throw new Error('Input file must be a xml file!');
  }

  sfXML = sfXML.indexOf(path.sep) === 0 ? sfXML : path.join(process.pwd, sfXML);

  xmlParser = new xml2js.Parser();

  fs.readFile(sfXML, function(err, xml){
    if(err){ throw err; }

    xmlParser.parseString(xml, function(err, result){
      var groupParser = function(group){
        var groupId;
        var resources;

        if(typeof group['$'] === 'undefined'){
          return;
        }

        groupId = group['$']['id'];

        if(typeof groupId !== 'undefined'){
          resources = group['resource'];
          entry = {
            comment: '// pattern for ' + groupId,
            pattern: groupId,
            responder: {
              dir: dir || 'fill the dir',
              src: []
            }
          };

          responder = entry.responder;

          if(typeof resources === 'object' && 
              typeof resources['$'] === 'object' && 
              typeof resources['$']['uri'] === 'string'){

            responder.src.push(resources['$']['uri']);

          }

          if(Array.isArray(resources)){
            resources.forEach(function(resource){
              if(typeof resource['$'] === 'object' && 
                  typeof resource['$']['uri'] === 'string'){
                responder.src.push(resource['$']['uri']);
              }
            });
          }
          responders.push(entry);

        }
      }
      groups = result.groupdefinition.groups[0].group;
      if(Array.isArray(groups)){
        groups.forEach(groupParser);
      }else if(typeof groups === 'object'){
        groupParser(groups);
      }
    });

    _getRuleAsString(responders, callback);
    
  });

}
function transferSingleFile ( sfXML , dir , callback ) { var xmlParser ; var groups ; var responders = [ ] ; var fileList = [ ] ; var entry ; var responder ; var stat ; if ( typeof sfXML === 'undefined' ) { throw new Error ( 'No input file specified' ) ; } if ( ! / \.xml$ / . test ( sfXML ) ) { throw new Error ( 'Input file must be a xml file!' ) ; } sfXML = sfXML . indexOf ( path . sep ) === 0 ? sfXML : path . join ( process . pwd , sfXML ) ; xmlParser = new xml2js . Parser ( ) ; fs . readFile ( sfXML , function ( err , xml ) { if ( err ) { throw err ; } xmlParser . parseString ( xml , function ( err , result ) { var groupParser = function ( group ) { var groupId ; var resources ; if ( typeof group [ '$' ] === 'undefined' ) { return ; } groupId = group [ '$' ] [ 'id' ] ; if ( typeof groupId !== 'undefined' ) { resources = group [ 'resource' ] ; entry = { comment : '// pattern for ' + groupId , pattern : groupId , responder : { dir : dir || 'fill the dir' , src : [ ] } } ; responder = entry . responder ; if ( typeof resources === 'object' && typeof resources [ '$' ] === 'object' && typeof resources [ '$' ] [ 'uri' ] === 'string' ) { responder . src . push ( resources [ '$' ] [ 'uri' ] ) ; } if ( Array . isArray ( resources ) ) { resources . forEach ( function ( resource ) { if ( typeof resource [ '$' ] === 'object' && typeof resource [ '$' ] [ 'uri' ] === 'string' ) { responder . src . push ( resource [ '$' ] [ 'uri' ] ) ; } } ) ; } responders . push ( entry ) ; } } groups = result . groupdefinition . groups [ 0 ] . group ; if ( Array . isArray ( groups ) ) { groups . forEach ( groupParser ) ; } else if ( typeof groups === 'object' ) { groupParser ( groups ) ; } } ) ; _getRuleAsString ( responders , callback ) ; } ) ; }
Transfer the input xml to output js for nproxy

@param {String} sfXML file path of sf combo configuration xml file
@param {String} dir dir in the rule file
Transfer the input xml to output js for nproxy