use of com.bc.pmpheep.ueditor.define.BaseState in project pmph by BCSquad.
the class FileManager method getState.
private State getState(Object[] files) {
MultiState state = new MultiState(true);
BaseState fileState = null;
File file = null;
for (Object obj : files) {
if (obj == null) {
break;
}
file = (File) obj;
fileState = new BaseState(true);
fileState.putInfo("url", PathFormat.format(this.getPath(file)));
state.addState(fileState);
}
return state;
}
use of com.bc.pmpheep.ueditor.define.BaseState in project pmph by BCSquad.
the class Base64Uploader method save.
public State save(String content, Map<String, Object> conf, HttpServletRequest request) {
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"), (String) conf.get("filename"));
savePath = savePath + suffix;
String physicalPath = (String) conf.get("rootPath") + savePath;
State storageState = StorageManager.saveBinaryFile(data, physicalPath);
if (storageState.isSuccess()) {
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
FileService fileService = (FileService) ctx.getBean("fileService");
File file = FileUpload.getFileByFilePath(physicalPath);
String picId;
try {
picId = fileService.saveLocalFile(file, ImageType.SYS_MESSAGE, 1L);
} catch (IOException e) {
return new BaseState(false, AppInfo.IO_ERROR);
}
storageState.putInfo("url", "/image/" + picId);
// storageState.putInfo("url", PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", "");
}
return storageState;
}
use of com.bc.pmpheep.ueditor.define.BaseState in project pmph by BCSquad.
the class StorageManager method saveTmpFile.
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;
}
use of com.bc.pmpheep.ueditor.define.BaseState in project pmph by BCSquad.
the class StorageManager method saveBinaryFile.
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;
}
use of com.bc.pmpheep.ueditor.define.BaseState in project pmph by BCSquad.
the class ImageHunter method captureRemoteData.
public State captureRemoteData(String urlStr) {
HttpURLConnection connection = null;
URL url = null;
String suffix = null;
try {
url = new URL(urlStr);
if (!validHost(url.getHost())) {
return new BaseState(false, AppInfo.PREVENT_HOST);
}
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(true);
connection.setUseCaches(true);
if (!validContentState(connection.getResponseCode())) {
return new BaseState(false, AppInfo.CONNECTION_ERROR);
}
suffix = MIMEType.getSuffix(connection.getContentType());
if (!validFileType(suffix)) {
return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
}
if (!validFileSize(connection.getContentLength())) {
return new BaseState(false, AppInfo.MAX_SIZE);
}
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) {
return new BaseState(false, AppInfo.REMOTE_FAIL);
}
}
Aggregations