Java Code Examples for com.baidu.ueditor.define.State#toJSONString()

The following examples show how to use com.baidu.ueditor.define.State#toJSONString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Uploader.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public State doExecss(){
		State state = null;
		state = BinaryUploader.save(this.request, this.conf);
		JSONObject stateJson = new JSONObject(state.toJSONString());
//		String bucketName = OSSClientProperties.bucketName;
//		OSSClient client = OSSClientFactory.createOSSClient();
		if (OSSClientProperties.useAsynUploader) {
			Log.debug(state.toJSONString());
			AsynUploaderThreader asynThreader = new AsynUploaderThreader();
			asynThreader.init(stateJson, this.request);
			Thread uploadThreader = new Thread(asynThreader);
			uploadThreader.start();
		} else {
			Log.debug(state.toJSONString());
			SynUploader synUploader = new SynUploader();
			synUploader.upload(stateJson, this.request);
		}
		if (false == OSSClientProperties.useLocalStorager) {
			String uploadFilePath = (String) this.conf.get("rootPath") + (String) stateJson.get("url");
			File uploadFile = new File(uploadFilePath);
			if (uploadFile.isFile() && uploadFile.exists()) {
				uploadFile.delete();
			}
		}
		state.putInfo("url", OSSClientProperties.ossEndPoint + stateJson.getString("url"));
		Log.debug("state.url : "+OSSClientProperties.ossEndPoint + stateJson.getString("url"));
		Log.debug("state.url : "+state.toJSONString());
		return state;
	}
 
Example 2
Source File: UeditorController.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
/**
 * ueditor上传文件
 *
 * @return 上传结果
 * @throws IOException 文件上传错误
 */
@RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data")
@ApiOperation("上传文件")
public String upload(@RequestParam(value = "upfile", required = false) MultipartFile file) throws IOException {
    String fileName = file.getOriginalFilename();
    String suffix = FileType.getSuffixByFilename(fileName);
    String path = fileService.saveStaticFile(file.getInputStream(), System.currentTimeMillis() + suffix);
    State state = new BaseState(true);
    state.putInfo("size", file.getSize());
    state.putInfo("title",fileName);
    state.putInfo("url", path);
    state.putInfo("type", suffix);
    state.putInfo("original",fileName);
    return state.toJSONString();
}
 
Example 3
Source File: ActionEnter.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
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 );
	
	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();
	
}
 
Example 4
Source File: Uploader.java    From wangmarket with Apache License 2.0 4 votes vote down vote up
public final State doExec() {
	Log.debug("doExec--");
	State state = null;
	//是否有限制某用户上传
	if(OSSClientProperties.astrictUpload){
		if(!ShiroFunc.getUEditorAllowUpload()){
			return new BaseState(false, OSSClientProperties.astrictUploadMessage);
		}
	}
	
	String filedName = (String) this.conf.get("fieldName");
	if ("true".equals(this.conf.get("isBase64"))) {
		state = Base64Uploader.save(this.request.getParameter(filedName),
				this.conf);
		Log.debug("doExec--isBase64--"+state.toJSONString());
	} else {
		Log.debug("doExec--not isBase64");
		state = BinaryUploader.save(this.request, this.conf);
		JSONObject stateJson = new JSONObject(state.toJSONString());
		
		Log.debug("doExec--OSSClientProperties.useStatus: "+OSSClientProperties.useStatus);
		// 判别云同步方式
		if (OSSClientProperties.useStatus) {
			// upload type
			Log.debug("doExec--OSSClientProperties.useAsynUploader: "+OSSClientProperties.useAsynUploader);
			if (OSSClientProperties.useAsynUploader) {
				AsynUploaderThreader asynThreader = new AsynUploaderThreader();
				asynThreader.init(stateJson, this.request);
				Thread uploadThreader = new Thread(asynThreader);
				uploadThreader.start();
			} else {
				SynUploader synUploader = new SynUploader();
				synUploader.upload(stateJson, this.request);
			}

			// storage type
			if (false == OSSClientProperties.useLocalStorager) {
				String uploadFilePath = (String) this.conf.get("rootPath") + (String) stateJson.get("url");
				File uploadFile = new File(uploadFilePath);
				if (uploadFile.isFile() && uploadFile.exists()) {
					uploadFile.delete();
				}
			}

			state.putInfo("url", OSSClientProperties.ossEndPoint + stateJson.getString("url"));
			Log.debug("doExec--上传OSS: "+OSSClientProperties.ossEndPoint + stateJson.getString("url"));
		} else {
			//绝对路径,而非原本的相对路径
			String stateStr = stateJson.getString("state");
			if(stateStr.equals("SUCCESS")){
				state.putInfo("url",  AttachmentFile.netUrl() + SystemUtil.getProjectName() + stateJson.getString("url"));
				Log.debug("doExec--上传服务器磁盘: "+AttachmentFile.netUrl() + SystemUtil.getProjectName() + stateJson.getString("url"));
			}else{
				//不成功,忽略。自然会在客户端弹出提示
			}
		}
	}
	/*
	 * { "state": "SUCCESS", "title": "1415236747300087471.jpg", "original":
	 * "a.jpg", "type": ".jpg", "url":
	 * "/upload/image/20141106/1415236747300087471.jpg", "size": "18827" }
	 */
	Log.debug("doExec--最后返回:"+state.toJSONString());
	return state;
}
 
Example 5
Source File: ActionEnter.java    From wangmarket with Apache License 2.0 4 votes vote down vote up
public String invoke() {
//		Log.debug("invoke--into");
//		Log.debug("actionType -- "+actionType);
//		Log.debug("configManager -- "+this.configManager);
		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 );
		
		Map<String, Object> conf = null;
		
//		Log.debug("invoke--switch before actionCode: "+actionCode);
		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:
//				Log.debug("invoke--UPLOAD_IMAGE--actionCode: "+actionCode);
				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();
		
	}
 
Example 6
Source File: ActionEnter.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
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);

        Map<String, Object> conf ;

        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 == null ? "{}" : state.toJSONString();

    }
 
Example 7
Source File: ActionEnter.java    From cms with Apache License 2.0 4 votes vote down vote up
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 );
	
	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" ) );

			if(Configuration.useStatus()) {//使用阿里云oss 存储
				state = new OSSImageHunter(conf).capture(list);
			}else {
				//state = new ImageHunter(conf).capture(list);
				state = new LocalImageHunter(conf).capture(list);
			}
			break;
			
		case ActionMap.LIST_IMAGE:
		case ActionMap.LIST_FILE:
			conf = configManager.getConfig( actionCode );
			int start = this.getStartIndex();

			if(Configuration.useStatus()){//使用阿里云oss 存储
				state = new OSSFileManager( conf ).listFile( start );
			}else {
				state = new FileManager(conf).listFile(start);
			}
			break;
			
	}
	
	return state.toJSONString();
	
}
 
Example 8
Source File: ActionEnter.java    From ueditor with Apache License 2.0 4 votes vote down vote up
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 );
	
	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();
	
}
 
Example 9
Source File: MyActionEnter.java    From ueditor with Apache License 2.0 4 votes vote down vote up
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);

        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();

    }