Ejemplo n.º 1
0
  @Override
  public synchronized void start() throws Exception {
    // restlet servlet engine will pass parameters from web.xml via the context parameters
    Series<Parameter> parameters = getContext().getParameters();
    dataSource = PSCPDataSource.createDataSource(parameters);
    daoFactory = PGDaoFactory.createPGDaoFactory(dataSource);
    lookupCache = new LookupCache(daoFactory);
    secretResolver = new SecretResolver();
    adminPage = parameters.getFirstValue("pscp.web.admin");
    urls = new URLS(adminPage);
    // links out to website
    urls.putStatic(
        new Template(getSlashedURL(parameters, "pscp.web.products")), URLS.Name.PRODUCT_LOCATION);
    urls.putStatic(
        new Template(getSlashedURL(parameters, "pscp.web.root")), URLS.Name.STATIC_MEDIA);

    // @todo how to deal with this?
    baseURIs = new ArrayList<String>(Arrays.asList("localhost:8080"));

    Map<String, Object> contextAttributes = getContext().getAttributes();
    contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_DAO_FACTORY, daoFactory);
    contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_URL_MAPPER, urls);
    contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_LOOKUP_CACHE, lookupCache);
    contextAttributes.put(
        BaseResource.CONTEXT_ATTRIBUTE_PRODUCT_ROOT,
        getRootDir(BaseResource.CONTEXT_ATTRIBUTE_PRODUCT_ROOT, "pscp-products"));
    contextAttributes.put(
        BaseResource.CONTEXT_ATTRIBUTE_UPLOAD_ROOT,
        getRootDir(BaseResource.CONTEXT_ATTRIBUTE_UPLOAD_ROOT, "pscp-uploads"));

    super.start();
  }