Package com.baidu.ueditor.define

Examples of com.baidu.ueditor.define.BaseState


    String callbackName = this.request.getParameter("callback");
   
    if ( callbackName != null ) {

      if ( !validCallbackName( callbackName ) ) {
        return new BaseState( false, AppInfo.ILLEGAL ).toJSONString();
      }
     
      return callbackName+"("+this.invoke()+");";
     
    } else {
View Full Code Here


  }
 
  public String invoke() {
   
    if ( actionType == null || !ActionMap.mapping.containsKey( actionType ) ) {
      return new BaseState( false, AppInfo.INVALID_ACTION ).toJSONString();
    }
   
    if ( this.configManager == null || !this.configManager.valid() ) {
      return new BaseState( false, AppInfo.CONFIG_ERROR ).toJSONString();
    }
   
    State state = null;
   
    int actionCode = ActionMap.getType( this.actionType );
View Full Code Here

      Map<String, Object> conf) {
    FileItemStream fileStream = null;
    boolean isAjaxUpload = request.getHeader( "X_Requested_With" ) != null;

    if (!ServletFileUpload.isMultipartContent(request)) {
      return new BaseState(false, AppInfo.NOT_MULTIPART_CONTENT);
    }

    ServletFileUpload upload = new ServletFileUpload(
        new DiskFileItemFactory());

        if ( isAjaxUpload ) {
            upload.setHeaderEncoding( "UTF-8" );
        }

    try {
      FileItemIterator iterator = upload.getItemIterator(request);

      while (iterator.hasNext()) {
        fileStream = iterator.next();

        if (!fileStream.isFormField())
          break;
        fileStream = null;
      }

      if (fileStream == null) {
        return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
      }

      String savePath = (String) conf.get("savePath");
      String originFileName = fileStream.getName();
      String suffix = FileType.getSuffixByFilename(originFileName);

      originFileName = originFileName.substring(0,
          originFileName.length() - suffix.length());
      savePath = savePath + suffix;

      long maxSize = ((Long) conf.get("maxSize")).longValue();

      if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
        return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
      }

      savePath = PathFormat.parse(savePath, originFileName);

      String physicalPath = (String) conf.get("rootPath") + savePath;

      InputStream is = fileStream.openStream();
      State storageState = StorageManager.saveFileByInputStream(is,
          physicalPath, maxSize);
      is.close();

      if (storageState.isSuccess()) {
        storageState.putInfo("url", PathFormat.format(savePath));
        storageState.putInfo("type", suffix);
        storageState.putInfo("original", originFileName + suffix);
      }

      return storageState;
    } catch (FileUploadException e) {
      return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
    } catch (IOException e) {
    }
    return new BaseState(false, AppInfo.IO_ERROR);
  }
View Full Code Here

    byte[] data = decode(content);

    long maxSize = ((Long) conf.get("maxSize")).longValue();

    if (!validSize(data, maxSize)) {
      return new BaseState(false, AppInfo.MAX_SIZE);
    }

    String suffix = FileType.getSuffix("JPG");

    String savePath = PathFormat.parse((String) conf.get("savePath"),
View Full Code Here

          new FileOutputStream(file));
      bos.write(data);
      bos.flush();
      bos.close();
    } catch (IOException ioe) {
      return new BaseState(false, AppInfo.IO_ERROR);
    }

    state = new BaseState(true, file.getAbsolutePath());
    state.putInfo( "size", data.length );
    state.putInfo( "title", file.getName() );
    return state;
  }
View Full Code Here

      bos.flush();
      bos.close();

      if (tmpFile.length() > maxSize) {
        tmpFile.delete();
        return new BaseState(false, AppInfo.MAX_SIZE);
      }

      state = saveTmpFile(tmpFile, path);

      if (!state.isSuccess()) {
        tmpFile.delete();
      }

      return state;
     
    } catch (IOException e) {
    }
    return new BaseState(false, AppInfo.IO_ERROR);
  }
View Full Code Here

      }

      return state;
    } catch (IOException e) {
    }
    return new BaseState(false, AppInfo.IO_ERROR);
  }
View Full Code Here

  private static State saveTmpFile(File tmpFile, String path) {
    State state = null;
    File targetFile = new File(path);

    if (targetFile.canWrite()) {
      return new BaseState(false, AppInfo.PERMISSION_DENIED);
    }
    try {
      FileUtils.moveFile(tmpFile, targetFile);
    } catch (IOException e) {
      return new BaseState(false, AppInfo.IO_ERROR);
    }

    state = new BaseState(true);
    state.putInfo( "size", targetFile.length() );
    state.putInfo( "title", targetFile.getName() );
   
    return state;
  }
View Full Code Here

  private static State valid(File file) {
    File parentPath = file.getParentFile();

    if ((!parentPath.exists()) && (!parentPath.mkdirs())) {
      return new BaseState(false, AppInfo.FAILED_CREATE_FILE);
    }

    if (!parentPath.canWrite()) {
      return new BaseState(false, AppInfo.PERMISSION_DENIED);
    }

    return new BaseState(true);
  }
View Full Code Here

   
    File dir = new File( this.dir );
    State state = null;

    if ( !dir.exists() ) {
      return new BaseState( false, AppInfo.NOT_EXIST );
    }
   
    if ( !dir.isDirectory() ) {
      return new BaseState( false, AppInfo.NOT_DIRECTORY );
    }
   
    Collection<File> list = FileUtils.listFiles( dir, this.allowFiles, true );
   
    if ( index < 0 || index > list.size() ) {
View Full Code Here

TOP

Related Classes of com.baidu.ueditor.define.BaseState

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.