The Resource registry for FreeDOM.  Used to look up requested Resources,
and provide lookup and migration of resources.
@Class Resource
@param {Debug} debug The logger to use for debugging.
@constructor
171495
function (debug) {
  this.debug = debug;
  this.files = {};
  this.resolvers = [this.httpResolver, this.nullResolver];
  this.contentRetrievers = {
    'http': this.xhrRetriever,
    'https': this.xhrRetriever,
    'chrome-extension': this.xhrRetriever,
    'resource': this.xhrRetriever,
    'chrome': this.xhrRetriever,
    'app': this.xhrRetriever,
    'gopher': this.xhrRetriever,  // For Cordova; see http://crbug.com/513352 .
    'manifest': this.manifestRetriever
  };
}
1204796
function(provider, name, path, data, dbg) {
    dbg = dbg || debug

    this._provider = provider

    this._name = name
    this._path = path

    this._err = null
    this._data = data

    this._lock = null
    this._queue = []

    this._ready = false

    Object.defineProperty(this, 'legend', {
        get: function() {
            return this._path
        }
    })
}
1065299
function Resource(data) {
	var self = this;
	ARRAY(Object.keys(data)).forEach(function(key) {
		self[key] = data[key];
	});
}
744369
function registerResource( $res )
    {
        if ( is_object( $res ) )
            $this->Resources[$res->resourceName()] =& $res;
        else
            $this->warning( "registerResource()", "Supplied argument is not a resource object" );
    }
1173675
function (res, cfg) {
                var providerInstance = providerInstances[cfg.provider];
                providerInstance.load({
                    fn : this._retrieveMapInstance,
                    scope : this,
                    args : cfg
                });
            }
597804
function addResources (statebox, options) {
  options.messages.info('Adding resources...')
  const stateResources = options.pluginComponents.stateResources
  if (!_.isObject(stateResources)) {
    return
  }

  const resourceClasses = {}
  for (const [name, resource] of Object.entries(stateResources)) {
    options.messages.detail(`Adding ${name}`)
    resourceClasses[name] = resource.componentModule
  } // for ...

  statebox.createModuleResources(resourceClasses)

  statebox.registerResourceResolver('function', functionResolver)
}
1271411
function Resource ( config, vault ) {
  if ( !config || !vault ) throw new Error('config and vault are required')
  this.config = _init( config, vault )
  this.vault = vault
  return this
}
47564
function init (state, namespace) {
  namespace = namespace || 'deftly'
  const logger = { namespace: namespace }
  attach(state, logger, namespace)
  return logger
}
733664
function debugLog(browserWindow, message) {
  // need the timeout as it takes time for the preload javascript to be loaded in the window
  setTimeout(() => {
    browserWindow.webContents.send('debug', message);
  }, 3000);
  log.info(message);
}
83029
function (module) {
        "use strict";
    
        var getResource = function (hostType, resource) {
    
            var host;
            var modulePath, filePath;
    
            if (resource.substr(0, 1) === '/') {
                resource = resource.substr(1);
            }
    
            if (hostType === 'module') {
    
                if (module.library) {
                    host = beyond.hosts.libraries[module.library.name].js;
                    library = module.library.name;
                }
                else {
                    host = beyond.hosts.application.js;
                    library = undefined;
                }
    
                modulePath = module.path;
                filePath = resource;
    
            }
            else if (hostType === 'application') {
    
                host = beyond.hosts.application.js;
                return host + resource;
    
            }
            else {
    
                var library = hostType;
                host = beyond.hosts.libraries[library];
    
                if (!host) {
                    console.warn('invalid css host on module "' + module.ID + '", resource "' + resource + '"' +
                        ', library "' + library + '" is not defined');
                    return;
                }
    
                if (resource.substr(0, 7) === 'static/') {
                    modulePath = 'main';
                    filePath = resource.substr(7);
                }
                else {
                    var overwrite = resource.split('/static/');
                    modulePath = overwrite[0];
                    filePath = overwrite[1];
                }
    
            }
    
            var overwrites = beyond.overwrites;
            var overwrited;
            if (library) {
                overwrited = overwrites[library];
            }
    
            if (!overwrited || !overwrited[modulePath] ||
                overwrited[modulePath].indexOf(filePath) === -1) {
    
                return host + modulePath + '/static/' + filePath;
            }
    
            return beyond.hosts.application.js +
                'custom/' + library + '/' +
                modulePath + '/static/' + filePath;
    
        };
    
        var setHosts = function (styles) {
    
            // find variables
            var variable;
    
            var replace = {};
    
            var regexp = /#host\.(.*?)#(.*?)[\)\s]/g;
            variable = regexp.exec(styles);
    
            var resource;
            while (variable) {
    
                // hostType can be 'application', 'module', libraryName
                var hostType = variable[1];
                resource = variable[2];
                resource = getResource(hostType, resource);
    
                var original = variable[0];
                if (original.substr(original.length - 1) === ')')
                    original = original.substr(0, original.length - 1);
    
                replace[original] = resource;
                variable = regexp.exec(styles);
    
            }
    
            // replace #host.* variables with their values
            for (var original in replace) {
    
                resource = replace[original];
    
                while (styles.indexOf(original) !== -1)
                    styles = styles.replace(original, resource);
    
            }
    
            return styles;
    
        };
    
        this.process = function (styles) {
    
            // find and replace #host...
            styles = setHosts(styles);
            return styles;
    
        };
    
    }
832956
def dispatch(req)
      debug_log(req)

      response = Response.new
      @request = req

      if ! @request.valid?
        response.body = handle_invalid_request
        response.code = :error
      else
        begin
          debug_log("do lookup for #{@request.selector}")
          @params, block = lookup(@request.selector)

          #
          # call the block that handles this lookup
          #
          response.body = block.bind(self).call
          response.code = :success
        rescue Gopher::NotFoundError => e
          debug_log("#{@request.selector} -- not found")
          response.body = handle_not_found
          response.code = :missing
        rescue Exception => e
          debug_log("#{@request.selector} -- error")
          debug_log(e.inspect)
          debug_log(e.backtrace)

          response.body = handle_error(e)
          response.code = :error
        end
      end

      access_log(req, response)
      response
    end
1216154
function Resource(uri, context) {
      // This constructor does not use the automatically created object but instantiate from a subclass instead

      // Intermediate prototype to add profile-specific properties to
      var prototype = Object.create(Object.getPrototypeOf(this));

      // Current profile(s)
      var profile = null;

      // Instantiated object
      return Object.create(prototype, {

        /**
         * The resource URI.
         *
         * @property {string}
         */
        $uri: {value: uri},

        /**
         * The resource context. Can be used to get related resources.
         *
         * @property {ResourceContext}
         */
        $context: {value: context},

        /**
         * Links to other resources.
         *
         * @property {object}
         */
        $links: {value: {
          self: {
            href: uri
          }
        }, writable: true},

        /**
         * The timestamp of the last successful GET or PUT request.
         *
         * @property {number} Resource.syncTime
         * @see ResourceContext#markSynced
         */
        $syncTime: {value: null, writable: true},

        /**
         * The resource profile URI(s). If profile properties have been registered for this URI (using
         * HalContextProvider.registerProfile or ResourceContext.registerProfile), the properties will be defined on the
         * resource.
         *
         * Setting the profile to 'undefined' or 'null' will remove the profile.
         *
         * @property {string|string[]}
         */
        $profile: {
          get: function () {
            return profile;
          },
          set: function (value) {
            // Remove old profile properties
            if (profile) {
              var oldProfiles = angular.isArray(profile) ? profile : [profile];
              oldProfiles.forEach(function (profile) {
                var properties = registeredProfiles[profile] || {};
                Object.keys(properties).forEach(function (key) {
                  delete prototype[key];
                });
              });
            }

            // Apply new profile properties
            if (value) {
              var newProfiles = angular.isArray(value) ? value : [value];
              newProfiles.forEach(function (profile) {
                var properties = registeredProfiles[profile] || {};
                Object.defineProperties(prototype, properties);
              });
            }

            profile = value;
          }
        }
      });
    }
986504
function psnGETRequestDEBUG (url, callback) {
	var 
		options = {
			url: url
			,method : 'GET'
			,headers: {
				'Authorization': 'Bearer ' + accessToken
			}
		}
	;
	console.log('GET '+ url)
	request.get(options, function(error, response, body) {
		callback(body)
	})
}
822989
function debug(name) {
  function disabled(){}
  disabled.enabled = false;

  var match = skips.some(function(re){
    return re.test(name);
  });

  if (match) return disabled;

  match = names.some(function(re){
    return re.test(name);
  });

  if (!match) return disabled;

  function logger(msg) {
    msg = (msg instanceof Error) ? (msg.stack || msg.message) : msg;
    Function.prototype.apply.call(logger.log, this, arguments);
  }

  logger.log = exports.log;
  logger.enabled = true;

  return logger;
}
1136959
function toInstance(properties) {
        //TODO maybe fail if instance of Resource

        var resource = Object.create(DefinedResource.prototype);

        //TODO trasfer properties to resource
        mergeProperties(resource, properties);

        return resource;
    }
1289570
private LogRecord createLogRecord(Level level, String msg, Object[] params, String sourceClassName, String sourceMethodName, String resourceBundleName, Throwable thrown) {

        ResourceBundle resourceBundle = null;
        if (level.intValue() >= this.ivMinimumLocalizationLevelIntValue) {
            if (null == this.ivCachedResourceBundle) {
                this.ivCachedResourceBundle = super.getResourceBundle();
                this.ivCachedResourceBundleName = super.getResourceBundleName();
            }
            // if resourceBundleName not set by caller, look it up from logger
            // (and logger's parents if needed).
            if (resourceBundleName == null) {
                resourceBundleName = computeResourceBundleName();
            }

            // get the resourceBundle
            if (resourceBundleName != null) {
                if (resourceBundleName.equals(this.ivCachedResourceBundleName)) {
                    resourceBundle = this.ivCachedResourceBundle;
                } else {
                    resourceBundle = getResourceBundle(resourceBundleName);
                }
            }
            if (null == resourceBundle && null != sourceClassName) {
                try {
                    Class<?> source = Class.forName(sourceClassName);
                    resourceBundle = ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), source.getClassLoader());
                } catch (Throwable t) {
                    // unable to find the resource bundle
                }
            }
        }

        return createWsLogRecord(level, msg, params, sourceClassName, sourceMethodName, resourceBundleName, resourceBundle, thrown);
    }
313068
function createResource (req) {
  let resource = new Resource(req.path);

  if (!_.isEmpty(req.files)) {
    // Save file data too
    resource.data = _.extend({}, req.body, req.files);
  }
  else {
    resource.data = req.body;
  }

  return resource;
}