Beispiel #1
0
  /**
   * Inserts a plugin to expose parts of the teaservlet via the EngineAccess interface.
   *
   * <p>private void createEngineAccessPlugin(PluginContext context) {
   *
   * <p>Plugin engineAccess = new EngineAccessPlugin(this); context.addPlugin(engineAccess);
   * context.addPluginListener(engineAccess); }
   */
  private boolean processResource(ApplicationRequest appRequest, ApplicationResponse appResponse)
      throws IOException {

    // get the associated system path
    String requestURI = null;
    if ((requestURI = appRequest.getPathInfo()) == null) {
      String context = appRequest.getContextPath();

      requestURI = appRequest.getRequestURI();
      if (requestURI.startsWith(context)) {
        requestURI = requestURI.substring(context.length());
      }
    }

    // check for valid asset
    Asset asset = getEngine().getAssetEngine().getAsset(requestURI);
    if (asset == null) {
      return false;
    }

    // set mime type
    appResponse.setContentType(asset.getMimeType());

    // write contents
    int read = -1;
    byte[] contents = new byte[1024];
    InputStream input = asset.getInputStream();
    ServletOutputStream output = appResponse.getOutputStream();
    while ((read = input.read(contents)) >= 0) {
      output.write(contents, 0, read);
    }

    // complete response
    appResponse.finish();

    // success
    return true;
  }