本文整理汇总了Java中org.restlet.ext.fileupload.RestletFileUpload.parseRepresentation方法的典型用法代码示例。如果您正苦于以下问题:Java RestletFileUpload.parseRepresentation方法的具体用法?Java RestletFileUpload.parseRepresentation怎么用?Java RestletFileUpload.parseRepresentation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.ext.fileupload.RestletFileUpload
的用法示例。
在下文中一共展示了RestletFileUpload.parseRepresentation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAttachment
import org.restlet.ext.fileupload.RestletFileUpload; //导入方法依赖的package包/类
@Put
public AttachmentResponse addAttachment(Representation entity) {
if(authenticate() == false) return null;
String taskId = (String) getRequest().getAttributes().get("taskId");
try {
RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory());
List<FileItem> items = upload.parseRepresentation(entity);
FileItem uploadItem = null;
for (FileItem fileItem : items) {
if(fileItem.getName() != null) {
uploadItem = fileItem;
}
}
String fileName = uploadItem.getName();
Attachment attachment = ActivitiUtil.getTaskService().createAttachment(
uploadItem.getContentType(), taskId, null, fileName, fileName, uploadItem.getInputStream());
return new AttachmentResponse(attachment);
} catch(Exception e) {
throw new ActivitiException("Unable to add new attachment to task " + taskId);
}
}
示例2: upload
import org.restlet.ext.fileupload.RestletFileUpload; //导入方法依赖的package包/类
public void upload(Representation representation) throws ResourceException {
Object result = null;
List<FileItem> files = null;
try {
RestletFileUpload uploadRequest = new RestletFileUpload(getFileItemFactory());
files = uploadRequest.parseRepresentation(representation);
result = delegate.upload(this, files);
} catch (FileUploadException e) {
// try to take simply the body as stream
String name = getRequest().getResourceRef().getPath();
if (name.contains("/")) {
name = name.substring(name.lastIndexOf("/") + 1, name.length());
}
FileItem file = new FakeFileItem(name, representation);
files = new ArrayList<FileItem>();
files.add(file);
result = delegate.upload(this, files);
}
// only if the status was not changed to be something else, like a 202
if (getResponse().getStatus() == Status.SUCCESS_OK) {
getResponse().setStatus(Status.SUCCESS_CREATED);
}
if (result != null) {
// TODO: representation cannot be returned as multipart!
// (representation above is possibly multipart)
getResponse().setEntity(doRepresent(result, getPreferredVariant()));
}
}
示例3: newModelFromForm
import org.restlet.ext.fileupload.RestletFileUpload; //导入方法依赖的package包/类
@Post("multi")
public Representation newModelFromForm(Representation formRep) {
//TODO: rework to use FileUpload Streaming API...
DiskFileItemFactory factory = new DiskFileItemFactory() ;
RestletFileUpload upload = new RestletFileUpload(factory) ;
List<FileItem> items ;
try {
items = upload.parseRepresentation(formRep) ;
} catch (FileUploadException e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Exception parsing multipart form: " + e.getMessage(), e) ;
}
ComputationalModel model = parseModel(items) ;
model = addModel(model) ;
FileItem iframeItem = items.get(items.size() - 1) ;
if (iframeItem.getString().equals("true")) {
return new StringRepresentation(buildIframeResponse(model), MediaType.TEXT_HTML) ;
} else {
Reference modelRef = getNamespace().modelRef(entryName, getResolver().getModelName(model.getId()), true) ;
redirectSeeOther(modelRef) ;
return new StringRepresentation("Model created, URL: " + modelRef.toString() + ".") ;
}
}
示例4: uploadDeployment
import org.restlet.ext.fileupload.RestletFileUpload; //导入方法依赖的package包/类
@Post
public void uploadDeployment(Representation entity) {
try {
if(authenticate(SecuredResource.ADMIN) == false) return;
RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory());
List<FileItem> items = upload.parseRepresentation(entity);
FileItem uploadItem = null;
String successMethod = null;
for (FileItem fileItem : items) {
if(fileItem.getName() != null) {
uploadItem = fileItem;
} else if(fileItem.getFieldName().equals("success")){
successMethod = fileItem.getString();
}
}
DeploymentBuilder deploymentBuilder = ActivitiUtil.getRepositoryService().createDeployment();
String fileName = uploadItem.getName();
if (fileName.endsWith(".bpmn20.xml")) {
deploymentBuilder.addInputStream(fileName, uploadItem.getInputStream());
} else if (fileName.endsWith(".bar") || fileName.endsWith(".zip")) {
deploymentBuilder.addZipInputStream(new ZipInputStream(uploadItem.getInputStream()));
} else {
throw new ActivitiException("File must be of type .bpmn20.xml, .bar or .zip");
}
deploymentBuilder.name(fileName);
deploymentBuilder.deploy();
StringBuilder html = new StringBuilder();
html.append("<html>\n");
html.append(" <script type=\"text/javascript\">\n");
html.append(" " + successMethod + "()\n");
html.append(" </script>\n");
html.append("</html>\n");
getResponse().setEntity(html.toString(), MediaType.TEXT_HTML);
} catch (Exception e) {
throw new ActivitiException(e.getMessage(), e);
}
}
示例5: update
import org.restlet.ext.fileupload.RestletFileUpload; //导入方法依赖的package包/类
@Put
@Post
public void update(Representation multipartForm) throws Exception {
String path = getPath();
LOG.debug("开始处理上传资源...");
// 获取参数
String userId = getAttribute("userId");
Representation a = getRequest().getEntity();
System.out.println((multipartForm == a));
getRequest();
// 创建上传文件的解析工厂
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
RestletFileUpload fileUpload = new RestletFileUpload(fileItemFactory);
if (null != multipartForm) {
// 获取引擎
ProcessEngine processEngine = FoxBpmUtil.getProcessEngine();
// 获取身份服务
IdentityService identityService = processEngine.getIdentityService();
UserEntity userEntity = Authentication.selectUserByUserId(userId);
List<FileItem> fileItems = fileUpload.parseRepresentation(multipartForm);
String fileName = null;
String imgName = null;
for (FileItem fileItem : fileItems) {
fileName = fileItem.getName();
if (StringUtil.isEmpty(fileName)) {
continue;
}
LOG.debug("Save image ... " + fileName);
/* 新建一个图片文件 */
String extName = fileName.substring(fileName.lastIndexOf("."));
createDir(path);
imgName = userId + extName;
deleteFile(new File(path + userEntity.getImage()));
File file = new File(path + imgName);
createFile(file);
fileItem.write(file);
}
userEntity = new UserEntity(userId);
userEntity.setImage(imgName);
identityService.updateUser(userEntity);
CacheUtil.getIdentityCache().remove("user_" + userEntity.getUserId());
}
}
示例6: accept
import org.restlet.ext.fileupload.RestletFileUpload; //导入方法依赖的package包/类
/**
* processes uploaded file, storing in a temporary directory
*
* @param entity
* @return the directory storing the uploaded file
* @throws Exception
*/
@Post
public UploadedFile accept(
final Representation entity )
throws Exception {
UploadedFile result;
if ((entity != null) && MediaType.MULTIPART_FORM_DATA.equals(
entity.getMediaType(),
true)) {
// 1/ Create a factory for disk-based file items
final DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1000240);
// 2/ Create a new file upload handler based on the Restlet
// FileUpload extension that will parse Restlet requests and
// generates FileItems.
final RestletFileUpload upload = new RestletFileUpload(
factory);
final List<FileItem> fileList = upload.parseRepresentation(entity);
if (fileList.size() != 1) {
throw new ResourceException(
Status.CLIENT_ERROR_BAD_REQUEST);
}
FileItem item = fileList.get(0);
// 3/ Request is parsed by the handler which generates a
// list of FileItems
final String tempDir = System.getProperty("java.io.tmpdir");
// HP Fortify "Path Traversal" false positive
// A user would need to have OS-level access anyway
// to change the system properties
final File dir = new File(
tempDir);
final File filename = File.createTempFile(
"uploadedfile-",
"-" + item.getName(),
dir);
result = new UploadedFile(
filename.getAbsolutePath());
FileUtils.copyInputStreamToFile(
item.getInputStream(),
filename);
}
else {
throw new ResourceException(
Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
}
return result;
}