Package com.baidu.ueditor.define

Examples of com.baidu.ueditor.define.State


   
    if ( this.configManager == null || !this.configManager.valid() ) {
      return new BaseState( false, AppInfo.CONFIG_ERROR ).toJSONString();
    }
   
    State state = null;
   
    int actionCode = ActionMap.getType( this.actionType );
   
    Map<String, Object> conf = null;
   
    switch ( actionCode ) {
   
      case ActionMap.CONFIG:
        return this.configManager.getAllConfig().toString();
       
      case ActionMap.UPLOAD_IMAGE:
      case ActionMap.UPLOAD_SCRAWL:
      case ActionMap.UPLOAD_VIDEO:
      case ActionMap.UPLOAD_FILE:
        conf = this.configManager.getConfig( actionCode );
        state = new Uploader( request, conf ).doExec();
        break;
       
      case ActionMap.CATCH_IMAGE:
        conf = configManager.getConfig( actionCode );
        String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) );
        state = new ImageHunter( conf ).capture( list );
        break;
       
      case ActionMap.LIST_IMAGE:
      case ActionMap.LIST_FILE:
        conf = configManager.getConfig( actionCode );
        int start = this.getStartIndex();
        state = new FileManager( conf ).listFile( start );
        break;
       
    }
   
    return state.toJSONString();
   
  }
View Full Code Here


      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);
View Full Code Here

    this.conf = conf;
  }

  public final State doExec() {
    String filedName = (String) this.conf.get("fieldName");
    State state = null;

    if ("true".equals(this.conf.get("isBase64"))) {
      state = Base64Uploader.save(this.request.getParameter(filedName),
          this.conf);
    } else {
View Full Code Here

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

    State storageState = StorageManager.saveBinaryFile(data, physicalPath);

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

    return storageState;
  }
View Full Code Here

  }

  public static State saveBinaryFile(byte[] data, String path) {
    File file = new File(path);

    State state = valid(file);

    if (!state.isSuccess()) {
      return state;
    }

    try {
      BufferedOutputStream bos = new BufferedOutputStream(
          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

    return state;
  }

  public static State saveFileByInputStream(InputStream is, String path,
      long maxSize) {
    State state = null;

    File tmpFile = getTmpFile();

    byte[] dataBuf = new byte[ 2048 ];
    BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);

    try {
      BufferedOutputStream bos = new BufferedOutputStream(
          new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);

      int count = 0;
      while ((count = bis.read(dataBuf)) != -1) {
        bos.write(dataBuf, 0, count);
      }
      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;
     
View Full Code Here

    }
    return new BaseState(false, AppInfo.IO_ERROR);
  }

  public static State saveFileByInputStream(InputStream is, String path) {
    State state = null;

    File tmpFile = getTmpFile();

    byte[] dataBuf = new byte[ 2048 ];
    BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);

    try {
      BufferedOutputStream bos = new BufferedOutputStream(
          new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);

      int count = 0;
      while ((count = bis.read(dataBuf)) != -1) {
        bos.write(dataBuf, 0, count);
      }
      bos.flush();
      bos.close();

      state = saveTmpFile(tmpFile, path);

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

      return state;
    } catch (IOException e) {
View Full Code Here

    String tmpFileName = (Math.random() * 10000 + "").replace(".", "");
    return new File(tmpDir, tmpFileName);
  }

  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

  }
 
  public State listFile ( int index ) {
   
    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() ) {
      state = new MultiState( true );
    } else {
      Object[] fileList = Arrays.copyOfRange( list.toArray(), index, index + this.count );
      state = this.getState( fileList );
    }
   
    state.putInfo( "start", index );
    state.putInfo( "total", list.size() );
   
    return state;
   
  }
View Full Code Here

      }
     
      String savePath = this.getPath( this.savePath, this.filename, suffix );
      String physicalPath = this.rootPath + savePath;

      State state = StorageManager.saveFileByInputStream( connection.getInputStream(), physicalPath );
     
      if ( state.isSuccess() ) {
        state.putInfo( "url", PathFormat.format( savePath ) );
        state.putInfo( "source", urlStr );
      }
     
      return state;
     
    } catch ( Exception e ) {
View Full Code Here

TOP

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

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.