本文整理汇总了Java中org.wso2.carbon.utils.FileItemData类的典型用法代码示例。如果您正苦于以下问题:Java FileItemData类的具体用法?Java FileItemData怎么用?Java FileItemData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileItemData类属于org.wso2.carbon.utils包,在下文中一共展示了FileItemData类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addUploadedFileItem
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
/**
* Upload the attachment and return the attachment id
* @param fileItemData wrapper for the attachment
* @return attachment id for the uploaded attachment
* @throws AttachmentMgtException If an error occurred in the back-end component
* @throws RemoteException if an error during the communication
*/
public String addUploadedFileItem(FileItemData fileItemData)
throws AttachmentMgtException, RemoteException, ExceptionException {
DataHandler handler = fileItemData.getDataHandler();
TAttachment attachment = new TAttachment();
attachment.setName(handler.getName());
attachment.setContentType(handler.getContentType());
attachment.setCreatedBy(getUserName());
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
attachment.setCreatedTime(calendar);
attachment.setContent(handler);
String attachmentID = stub.add(attachment);
log.info("Attachment was uploaded with id:" + attachmentID);
return attachmentID;
}
开发者ID:wso2,项目名称:carbon-business-process,代码行数:24,代码来源:AttachmentUploadClient.java
示例2: init
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
private void init(HttpServletRequest request) throws Exception {
HttpSession session = request.getSession();
String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) session.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
client = new ReportTemplateClient(configContext, serverURL, cookie);
Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
formFieldsMap = getFormFieldsMap();
images = fileItemsMap.get("logo");
String type = null;
if(formFieldsMap.get("reportType") != null){
type = formFieldsMap.get("reportType").get(0);
}
if(type == null){
tableReport= (TableReportDTO)session.getAttribute("table-report");
}
else {
chartReport = (ChartReportDTO)session.getAttribute("chart-report");
}
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:26,代码来源:reportUploadExecutor.java
示例3: handleLogo
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
private void handleLogo() throws ReportTemplateAdminReportingExceptionException {
ReportHeaderInformationDTO header = null;
if(tableReport != null){
header = tableReport.getReportHeaderInformation();
}else if(chartReport != null){
header = chartReport.getReportHeaderInformation();
}
if (images != null && images.size() > 0)
{
FileItemData image = images.get(0);
if(image.getFileItem().getContentType().contains("image/")){
Resource resource = new Resource();
resource.setDataHandler(image.getDataHandler());
resource.setFileName(formFieldsMap.get("imageName").get(0));
header.setLogo(resource);
}
else {
throw new ReportTemplateAdminReportingExceptionException("Unsupported file format. Only Image can be uploaded here.");
}
}
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:23,代码来源:reportUploadExecutor.java
示例4: addUploadedFileItem
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
public void addUploadedFileItem(FileItemData fileItemData) throws AttachmentMgtException, RemoteException {
DataHandler handler = fileItemData.getDataHandler();
TAttachment attachment = new TAttachment();
attachment.setName(handler.getName());
attachment.setContentType(handler.getContentType());
attachment.setCreatedBy("DummyUser"); //TODO: Remove this hard-coded value
attachment.setContent(fileItemData.getDataHandler());
String attachmentID = stub.add(attachment);
log.info("Attachment was uploaded with id:" + attachmentID);
}
开发者ID:wso2,项目名称:carbon-business-process,代码行数:12,代码来源:AttachmentUploadClient.java
示例5: getAllFileItems
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
protected List<FileItemData> getAllFileItems() {
Collection<ArrayList<FileItemData>> listCollection = fileItemsMap.get().values();
List<FileItemData> fileItems = new ArrayList<FileItemData>();
for (ArrayList<FileItemData> fileItemData : listCollection) {
fileItems.addAll(fileItemData);
}
return fileItems;
}
开发者ID:apache,项目名称:stratos,代码行数:9,代码来源:AbstractFileUploadExecutor.java
示例6: execute
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
Map<String, ArrayList<String>> formFieldsMap = getFormFieldsMap();
String taskID = null;
String redirect = null;
try {
if (formFieldsMap.get("taskID") != null) {
taskID = formFieldsMap.get("taskID").get(0);
}
if (formFieldsMap.get("redirect") != null) {
redirect = formFieldsMap.get("redirect").get(0);
}
ArrayList<FileItemData> fileItemsMap = getFileItemsMap().get("fileToUpload");
FileItemData fileToBeUpload = fileItemsMap.get(0);
AttachmentUploadClient attachmentUploadClient = new AttachmentUploadClient(configurationContext,
serverURL, cookie);
HumanTaskClientAPIServiceClient taskOperationClient = new HumanTaskClientAPIServiceClient(cookie,
serverURL, configurationContext);
response.setContentType("text/html; charset=utf-8");
String attachmentID = attachmentUploadClient.addUploadedFileItem(fileToBeUpload);
String attachmentName = fileToBeUpload.getDataHandler().getName();
String contentType = fileToBeUpload.getDataHandler().getContentType();
boolean isAdded = taskOperationClient.addAttachment(taskID, attachmentName, contentType, attachmentID);
String msg = "Your attachment has been uploaded successfully.";
if (!isAdded) {
throw new Exception("Attachment was added successfully with id:" + attachmentID + ". But the task " +
"with id: " + taskID + " was not associated with it correctly.");
} else {
if (redirect != null && redirect.contains("humantask/basic_task_view.jsp")) {
//redirection is going to the carbon mgt console
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response,
getContextRoot(request) + "/" + webContext + "/" + redirect);
} else if (redirect != null) {
//redirection exists, not to carbon mgt console
out.write(msg);
response.sendRedirect(redirect);
} else {
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request);
}
return true;
}
} catch (Exception ex) {
String errMsg = "File upload failed. Reason :" + ex.getLocalizedMessage();
log.error(errMsg, ex);
if (redirect != null) {
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request,
response, getContextRoot(request) + "/" + webContext + "/" + redirect);
} else {
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request);
}
}
return false;
}
开发者ID:wso2,项目名称:carbon-business-process,代码行数:71,代码来源:AttachmentUploadExecutor.java
示例7: uploadArtifacts
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
protected boolean uploadArtifacts(HttpServletRequest request,
HttpServletResponse response,
String uploadDirName,
String[] extensions,
String utilityString)
throws IOException {
response.setContentType("text/html; charset=utf-8");
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
String msg;
Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
if (fileItemsMap == null || fileItemsMap.isEmpty()) {
msg = "File uploading failed. No files are specified";
log.error(msg);
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.ERROR, request,
response, getContextRoot(request) + "/" + webContext + "/carbonapps/app_upload.jsp");
}
//Creating the stub to call the back-end service
CarbonAppUploaderClient uploaderClient = new CarbonAppUploaderClient(
configurationContext, serverURL + "CarbonAppUploader", cookie);
try {
for (Object o : fileItemsMap.keySet()) {
String fieldName = (String) o;
FileItemData fileItemData = fileItemsMap.get(fieldName).get(0);
String fileName = getFileName(fileItemData.getFileItem().getName());
uploaderClient.addUploadedFileItem(fileItemData.getDataHandler(), fileName, "jar");
}
//Uploading files to back end service
uploaderClient.uploadFileItems();
msg = "Your Application has been uploaded successfully. Please refresh this page in a" +
" while to see the status of the new Application.";
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request,
response, getContextRoot(request) + "/" + webContext + "/carbonapps/index.jsp" );
return true;
} catch (Exception e) {
msg = "File upload failed.";
log.error(msg, e);
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.ERROR, request,
response, getContextRoot(request) + "/" + webContext + "/carbonapps/app_upload.jsp");
}
return false;
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:50,代码来源:CarbonAppUploadExecutor.java
示例8: execute
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
public boolean execute(HttpServletRequest request, HttpServletResponse response)
throws CarbonException, IOException {
PrintWriter out = response.getWriter();
try {
List<FileItemData> fileItems = getAllFileItems();
StringBuffer filePathsStrBuffer = new StringBuffer();
for (FileItemData fileItem : fileItems) {
String uuid = String.valueOf(
System.currentTimeMillis() + Math.random());
String serviceUploadDir =
configurationContext
.getProperty(ServerConstants.WORK_DIR) +
File.separator +
"extra" + File
.separator +
uuid + File.separator;
File dir = new File(serviceUploadDir);
if (!dir.exists()) {
boolean dirCreated = dir.mkdirs();
if (!dirCreated) {
log.error("Error creating dir " + dir.getPath());
return false;
}
}
File uploadedFile = new File(dir, uuid);
FileOutputStream fileOutStream = new FileOutputStream(uploadedFile);
fileItem.getDataHandler().writeTo(fileOutStream);
fileOutStream.flush();
fileOutStream.close();
response.setContentType("text/plain; charset=utf-8");
filePathsStrBuffer.append(uploadedFile.getAbsolutePath());
filePathsStrBuffer.append(',');
}
out.write(filePathsStrBuffer.substring(0, filePathsStrBuffer.length() - 1));
out.flush();
} catch (Exception e) {
log.error("File upload FAILED", e);
out.write("<script type=\"text/javascript\">" +
"top.wso2.wsf.Util.alertWarning('File upload FAILED. File may be non-existent or invalid.');" +
"</script>");
} finally {
out.close();
}
return true;
}
开发者ID:apache,项目名称:stratos,代码行数:49,代码来源:ToolsFileUploadExecutor.java
示例9: parseRequest
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
protected void parseRequest(HttpServletRequest request) throws FileUploadFailedException,
FileSizeLimitExceededException {
fileItemsMap.set(new HashMap<String, ArrayList<FileItemData>>());
formFieldsMap.set(new HashMap<String, ArrayList<String>>());
ServletRequestContext servletRequestContext = new ServletRequestContext(request);
boolean isMultipart = ServletFileUpload.isMultipartContent(servletRequestContext);
Long totalFileSize = 0L;
if (isMultipart) {
List items;
try {
items = parseRequest(servletRequestContext);
} catch (FileUploadException e) {
String msg = "File upload failed";
log.error(msg, e);
throw new FileUploadFailedException(msg, e);
}
boolean multiItems = false;
if (items.size() > 1) {
multiItems = true;
}
// Add the uploaded items to the corresponding maps.
for (Iterator iter = items.iterator(); iter.hasNext();) {
FileItem item = (FileItem) iter.next();
String fieldName = item.getFieldName().trim();
if (item.isFormField()) {
if (formFieldsMap.get().get(fieldName) == null) {
formFieldsMap.get().put(fieldName, new ArrayList<String>());
}
try {
formFieldsMap.get().get(fieldName).add(new String(item.get(), "UTF-8"));
} catch (UnsupportedEncodingException ignore) {
}
} else {
String fileName = item.getName();
if ((fileName == null || fileName.length() == 0) && multiItems) {
continue;
}
if (fileItemsMap.get().get(fieldName) == null) {
fileItemsMap.get().put(fieldName, new ArrayList<FileItemData>());
}
totalFileSize += item.getSize();
if (totalFileSize < totalFileUploadSizeLimit) {
fileItemsMap.get().get(fieldName).add(new FileItemData(item));
} else {
throw new FileSizeLimitExceededException(getFileSizeLimit() / 1024 / 1024);
}
}
}
}
}
开发者ID:apache,项目名称:stratos,代码行数:55,代码来源:AbstractFileUploadExecutor.java
示例10: executeCommon
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
/**
* This is the common method that can be used for Fileupload.
* extraStoreDirUUID is the name of the javascript that's going to
* execute on the client side at the secound run.
*
* @param request
* @param response
* @return Status true/fase.
* @throws org.apache.commons.fileupload.FileUploadException
*
*/
protected boolean executeCommon(HttpServletRequest request, HttpServletResponse response)
throws FileUploadException {
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
HttpSession session = request.getSession();
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
PrintWriter out = null;
try {
out = response.getWriter();
FileUploadServiceClient client =
new FileUploadServiceClient(configurationContext, serverURL, cookie);
response.setContentType("text/plain; charset=utf-8");
Set<String> keys = fileItemsMap.get().keySet();
boolean multiItems = false;
if (fileItemsMap.get().size() > 1) {
multiItems = true;
}
// Process the uploaded items
UploadedFileItem[] uploadedFileItems = new UploadedFileItem[fileItemsMap.get().size()];
Iterator<String> iterator = keys.iterator();
int i = 0;
while (iterator.hasNext()) {
String fieldName = iterator.next();
String fileName = fileItemsMap.get().get(fieldName).get(0).getFileItem().getName();
if ((fileName == null || fileName.length() == 0) && multiItems) {
continue;
}
FileItemData fileItemData = fileItemsMap.get().get(fieldName).get(0);
UploadedFileItem uploadedFileItem = new UploadedFileItem();
uploadedFileItem.setDataHandler(fileItemData.getDataHandler());
uploadedFileItem.setFileName(fileName);
uploadedFileItem.setFileType("");
uploadedFileItems[i] = uploadedFileItem;
i++;
}
String[] uuidArray = client.uploadFiles(uploadedFileItems);
StringBuffer uuids = new StringBuffer();
for (String uuid : uuidArray) {
uuids.append(uuid).append(",");
}
out.write(uuids.toString().substring(0, uuids.length() - 1));
out.flush();
} catch (Exception e) {
String msg = "File upload FAILED. File may be non-existent or invalid.";
log.error(msg, e);
throw new FileUploadException(msg, e);
} finally {
if (out != null) {
out.close();
}
}
return true;
}
开发者ID:apache,项目名称:stratos,代码行数:67,代码来源:AbstractFileUploadExecutor.java
示例11: getFileItemsMap
import org.wso2.carbon.utils.FileItemData; //导入依赖的package包/类
protected Map<String, ArrayList<FileItemData>> getFileItemsMap() {
return fileItemsMap.get();
}
开发者ID:apache,项目名称:stratos,代码行数:4,代码来源:AbstractFileUploadExecutor.java
注:本文中的org.wso2.carbon.utils.FileItemData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论