Package cn.jhc.um.generator

Examples of cn.jhc.um.generator.PathGenerator


    computeHumanReadableSizeLimit(properties);
    //for test
    properties.list(System.err);
    context.setAttribute(SC_UM_CONFIG, properties);
    checkUploadDirectories(properties);
    PathGenerator pathGenerator = loadPathGenerator(properties);
    context.setAttribute(SC_PATH_GENERATOR, pathGenerator);
   
    ConstraintChecker checker = new ConstraintChecker(properties);
    context.setAttribute(SC_CONSTRAINT_CHECKER, checker);
   
View Full Code Here


      }
    }
    if(!foundInterface)
      throw new RuntimeException("Cann't assign to PathGenerator interface, "
          + "the " + PATH_GENERATOR + " in configure file is wrong.");
    PathGenerator pathGenerator = null;
    try {
      pathGenerator = (PathGenerator)clazz.newInstance();
    } catch (InstantiationException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
View Full Code Here

    ConstraintChecker checker = (ConstraintChecker)servletContext.getAttribute(SC_CONSTRAINT_CHECKER);

    String destUrl = config.getProperty(DEST_URL_PREFIX);

    PathGenerator pathGenerator = (PathGenerator) servletContext.getAttribute(SC_PATH_GENERATOR);
   
    ResourceBundle bundle = ResourceBundle.getBundle("messages", request.getLocale());
   
      String type = request.getParameter("type");

      String editorId = request.getParameter("editorid");
   
    Collection<Part> parts = null;
    try {
      parts = request.getParts();
    } catch (IllegalStateException e) {
      String pattern = bundle.getString(MSG_UPLOAD_EXCEEDED);
      out.println(buildResponseScript(editorId, destUrl,
          MessageFormat.format(pattern,
              config.getProperty(HUMAN_UPLOAD_FILE_SIZE_LIMIT),
              config.getProperty(HUMAN_REQUEST_SIZE_LIMIT))));
      return;
    } catch (ServletException e) {
      out.println(buildResponseScript(editorId, destUrl, bundle.getString(MSG_WRONG_ENCTYPE)));
      return;
    } catch (IOException e) {
      out.println(buildResponseScript(editorId, destUrl, bundle.getString(MSG_IO_ERROR)));
      return;
    }
    for (Part part : parts) {
      String fileName = extractFileName(part);
      if(fileName == null) continue;
      // 检查扩展名
      String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1)
          .toLowerCase();
      if( !checker.checkFileExtension(fileExt) ) {
        out.println(buildResponseScript(editorId, destUrl, bundle.getString(MSG_EXT_VIOLATED)));
        return;
      }

      String path = pathGenerator.generate(request, fileName);
      int last = path.lastIndexOf(File.separator);
      if(last > 0) {
        File lastDir = new File(uploadRoot, path.substring(0, last));
        if(!lastDir.exists())
          lastDir.mkdirs();
View Full Code Here

TOP

Related Classes of cn.jhc.um.generator.PathGenerator

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.