Package org.olat.commons.servlets.util

Examples of org.olat.commons.servlets.util.ResourceDescriptor


            response.sendError(HttpServletResponse.SC_NOT_FOUND, request
                    .getRequestURI());
            return false;
        }

        ResourceDescriptor rd = handler.getResourceDescriptor(request, relPath);
        if (rd == null) {
            // no handler found or relPath incomplete
            response.sendError(HttpServletResponse.SC_NOT_FOUND, request
                    .getRequestURI());
            return false;
        }

        setHeaders(response, rd);
        // check if modified since
        long ifModifiedSince = request.getDateHeader("If-Modified-Since");
        long lastMod = rd.getLastModified();
        if (lastMod != -1L && ifModifiedSince >= lastMod) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            return false;
        }

        // server the resource
        if (copyContent) {
            InputStream is = handler.getInputStream(request, rd);
            if (is == null) {
                // resource not found or access denied
                response.sendError(HttpServletResponse.SC_NOT_FOUND, request
                        .getRequestURI());
                return false;
            }
            copyContent(response, is);
            if (logDebug) {
                long stop = System.currentTimeMillis()
                Tracing.logDebug("Serving resource '" + relPath + "' ("+rd.getSize()+" bytes) in "+ (stop-start) +"ms with handler '" + handlerName + "'.", StaticsLegacyDispatcher.class);

            }
        }
        return true;
    }
View Full Code Here


        i ++;
      }
      //FIXME:fj: handle appropriately
      Locale loc = UserSession.getUserSession(request).getLocale();
     
      ResourceDescriptor rd = new ResourceDescriptor(relPath);
      rd.setLastModified(f.lastModified());
      rd.setSize(f.length());
      String mimeType = WebappHelper.getMimeType(relPath);
      if (mimeType == null) mimeType = "application/octet-stream";
      rd.setContentType(mimeType);
      return rd;
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

  public ResourceDescriptor getResourceDescriptor(HttpServletRequest request, String relPath) {
    if (root == null) return null;
    try {
      File f = new File(root + relPath);
      if (!f.exists() || f.isDirectory()) return null;
      ResourceDescriptor rd = new ResourceDescriptor(relPath);
      rd.setLastModified(f.lastModified());
      rd.setSize(f.length());
      String mimeType = WebappHelper.getMimeType(relPath);
      if (mimeType == null) mimeType = "application/octet-stream";
      if (mimeType.equals("text/html")) {
        mimeType = "text/html; charset=utf-8";
      }
      rd.setContentType(mimeType);
      return rd;
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

  /**
   * @see org.olat.commons.servlets.pathhandlers.PathHandler#getResourceDescriptor(javax.servlet.http.HttpServletRequest, java.lang.String)
   */
  public ResourceDescriptor getResourceDescriptor(HttpServletRequest request, String relPath) {
    try {
      ResourceDescriptor rd = new ResourceDescriptor(relPath);
      File f = new File(QTIEditorPackage.getTmpBaseDir() + relPath);
      rd.setLastModified(f.lastModified());
      rd.setSize(f.length());
      String mimeType = WebappHelper.getMimeType(relPath);
      if (mimeType == null) mimeType = "application/octet-stream";
      rd.setContentType(mimeType);
      return rd;
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.olat.commons.servlets.util.ResourceDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.