当前位置: 首页>>代码示例>>Java>>正文


Java FormFile类代码示例

本文整理汇总了Java中org.apache.struts.upload.FormFile的典型用法代码示例。如果您正苦于以下问题:Java FormFile类的具体用法?Java FormFile怎么用?Java FormFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FormFile类属于org.apache.struts.upload包,在下文中一共展示了FormFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFileListFromMultipleForm

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
/**
    * Create file list from multiple form.
    *
    * @param multipleForm
    * @return
    */
   public static List<FormFile> createFileListFromMultipleForm(MultipleImagesForm multipleForm) {

List<FormFile> fileList = new ArrayList<FormFile>();
if (multipleForm.getFile1() != null && !StringUtils.isEmpty(multipleForm.getFile1().getFileName())) {
    fileList.add(multipleForm.getFile1());
}
if (multipleForm.getFile2() != null && !StringUtils.isEmpty(multipleForm.getFile2().getFileName())) {
    fileList.add(multipleForm.getFile2());
}
if (multipleForm.getFile3() != null && !StringUtils.isEmpty(multipleForm.getFile3().getFileName())) {
    fileList.add(multipleForm.getFile3());
}
if (multipleForm.getFile4() != null && !StringUtils.isEmpty(multipleForm.getFile4().getFileName())) {
    fileList.add(multipleForm.getFile4());
}
if (multipleForm.getFile5() != null && !StringUtils.isEmpty(multipleForm.getFile5().getFileName())) {
    fileList.add(multipleForm.getFile5());
}

return fileList;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:ImageGalleryUtils.java

示例2: uploadTaskListItemFile

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
   public TaskListItemAttachment uploadTaskListItemFile(FormFile uploadFile, TaskListUser user)
    throws UploadTaskListFileException {
if ((uploadFile == null) || StringUtils.isEmpty(uploadFile.getFileName())) {
    throw new UploadTaskListFileException(
	    messageService.getMessage("error.msg.upload.file.not.found", new Object[] { uploadFile }));
}

// upload file to repository
NodeKey nodeKey = processFile(uploadFile);

// create new attachement
TaskListItemAttachment file = new TaskListItemAttachment();
file.setFileUuid(nodeKey.getUuid());
file.setFileVersionId(nodeKey.getVersion());
file.setFileName(uploadFile.getFileName());
file.setCreated(new Timestamp(new Date().getTime()));
file.setCreateBy(user);

return file;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:TaskListServiceImpl.java

示例3: addAttachment

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
public void addAttachment(final FormFile file) throws Exception {
	addAttachment(file.getFileName(), 
			new DataHandler(new DataSource() {
				@Override
				public OutputStream getOutputStream() throws IOException {
					throw new IOException("No output stream.");
				}
				
				@Override
				public String getName() {
					return file.getFileName();
				}
				
				@Override
				public InputStream getInputStream() throws IOException {
					return file.getInputStream();
				}
				
				@Override
				public String getContentType() {
					return file.getContentType();
				}
			}));
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:Email.java

示例4: validateMultipleImages

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
/**
    * Validate imageGallery item.
    *
    * @param multipleForm
    * @return
    */
   public static ActionErrors validateMultipleImages(MultipleImagesForm multipleForm, boolean largeFile) {
ActionErrors errors = new ActionErrors();

List<FormFile> fileList = createFileListFromMultipleForm(multipleForm);

// validate files size
for (FormFile file : fileList) {
    FileValidatorUtil.validateFileSize(file, largeFile, errors);

    // check for allowed format : gif, png, jpg
    String contentType = file.getContentType();
    if (isContentTypeForbidden(contentType)) {
	errors.add(ActionMessages.GLOBAL_MESSAGE,
		new ActionMessage(ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT_FOR, file.getFileName()));
    }
}

return errors;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ImageGalleryUtils.java

示例5: uploadAttachment

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
   public Attachment uploadAttachment(FormFile uploadFile) throws PersistenceException {
if ((uploadFile == null) || StringUtils.isEmpty(uploadFile.getFileName())) {
    throw new ForumException("Could not find upload file: " + uploadFile);
}

NodeKey nodeKey = processFile(uploadFile);
Attachment file = new Attachment();
file.setFileUuid(nodeKey.getUuid());
file.setFileVersionId(nodeKey.getVersion());
file.setFileName(uploadFile.getFileName());

return file;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:ForumService.java

示例6: parseGroupSpreadsheet

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
public int parseGroupSpreadsheet(FormFile fileItem, Long groupingID, Map<String, Set<String>> groups)
    throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(fileItem.getInputStream());
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);

int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
int skipped = 0;

for (int i = startRow + 1; i < (endRow + 1); i++) {
    HSSFRow row = sheet.getRow(i);
    String login = parseStringCell(row.getCell(0));
    if (login != null) {
	login = login.trim();
	if (login.length() > 0) {
	    String groupName = row.getLastCellNum() > 3 ? parseStringCell(row.getCell(3)) : null;
	    groupName = groupName != null ? groupName.trim() : null;
	    if (groupName == null || groupName.length() == 0) {
		skipped++;
		GroupingUploadAJAXAction.log.warn("Unable to add learner " + login
			+ " for group in related to grouping " + groupingID + " as group name is missing.");
	    } else {
		Set<String> users = groups.get(groupName);
		if (users == null) {
		    users = new HashSet<String>();
		    groups.put(groupName, users);
		}
		users.add(login);
	    }
	}
    }
}
return skipped;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:GroupingUploadAJAXAction.java

示例7: fillForm

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
public void fillForm(Resource resource) {
if (resource != null) {
    setToolContentID(resource.getContentId());
    setInstructions(resource.getInstructions());

    title = new ArrayList<String>();
    url = new ArrayList<String>();
    fileName = new ArrayList<String>();
    file = new ArrayList<FormFile>();
    type = new ArrayList<Short>();
    Set<ResourceItem> items = resource.getResourceItems();
    if (items != null) {
	int topicIndex = 0;
	for (ResourceItem item : items) {
	    short itemType = item.getType();
	    setTitle(topicIndex, item.getTitle());
	    setType(topicIndex, itemType);
	    setUrl(topicIndex, itemType == ResourceConstants.RESOURCE_TYPE_URL ? item.getUrl() : null);
	    setFileName(topicIndex,
		    itemType == ResourceConstants.RESOURCE_TYPE_FILE ? item.getFileName() : null);
	    setFileUuid(topicIndex,
		    itemType == ResourceConstants.RESOURCE_TYPE_FILE ? item.getFileUuid() : null);
	    setFileVersion(topicIndex,
		    itemType == ResourceConstants.RESOURCE_TYPE_FILE ? item.getFileVersionId() : null);
	    topicIndex++;
	}
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:ResourcePedagogicalPlannerForm.java

示例8: setFile

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
public void setFile(int number, FormFile formFile) {
if (file == null) {
    file = new ArrayList<FormFile>();
}
while (number >= file.size()) {
    file.add(null);
}
file.set(number, formFile);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:CommonCartridgePedagogicalPlannerForm.java

示例9: setFile

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
public void setFile(int number, FormFile file) {
if (file.getFileSize() > 0) {
    if (this.file == null) {
	this.file = new ArrayList<FormFile>();
    }
    while (number >= this.file.size()) {
	this.file.add(null);
    }
    this.file.set(number, file);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:RecordForm.java

示例10: uploadFileToSession

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
   public void uploadFileToSession(Long sessionID, FormFile uploadFile, String fileDescription, Integer userID)
    throws SubmitFilesException {

if ((uploadFile == null) || StringUtils.isEmpty(uploadFile.getFileName())) {
    throw new SubmitFilesException("Could not find upload file: " + uploadFile);
}

SubmitFilesSession session = submitFilesSessionDAO.getSessionByID(sessionID);
if (session == null) {
    throw new SubmitFilesException("No such session with a sessionID of: " + sessionID + " found.");
}

NodeKey nodeKey = processFile(uploadFile);

SubmissionDetails details = new SubmissionDetails();
details.setFileDescription(fileDescription);
details.setFilePath(uploadFile.getFileName());
details.setDateOfSubmission(new Date());

SubmitUser learner = submitUserDAO.getLearner(sessionID, userID);
details.setLearner(learner);
details.setUuid(nodeKey.getUuid());
details.setVersionID(nodeKey.getVersion());
SubmitFilesReport report = new SubmitFilesReport();
details.setReport(report);
details.setSubmitFileSession(session);

// update session, then insert the detail too.
Set detailSet = session.getSubmissionDetails();
detailSet.add(details);
session.setSubmissionDetails(detailSet);
submissionDetailsDAO.saveOrUpdate(session);

   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:SubmitFilesService.java

示例11: execute

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

if (isCancelled(request)) {
    return mapping.findForward("sysadmin");
}

IImportService importService = AdminServiceProxy.getImportService(getServlet().getServletContext());
ImportExcelForm importExcelForm = (ImportExcelForm) form;
FormFile file = importExcelForm.getFile();

// validation
if (file == null || file.getFileSize() <= 0) {
    return mapping.findForward("import");
}

String sessionId = SessionManager.getSession().getId();
SessionManager.getSession().setAttribute(IImportService.IMPORT_FILE, file);
// use a new thread only if number of users is > threshold
if (importService.getNumRows(file) < IImportService.THRESHOLD) {
    List results = importService.parseSpreadsheet(file, sessionId);
    SessionManager.getSession(sessionId).setAttribute(IImportService.IMPORT_RESULTS, results);
    return mapping.findForward("results");
} else {
    Thread t = new Thread(new ImportExcelThread(sessionId));
    t.start();
    return mapping.findForward("status");
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ImportExcelSaveAction.java

示例12: run

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
public void run() {
    IImportService importService = AdminServiceProxy.getImportService(getServlet().getServletContext());
    try {
	FormFile file = (FormFile) SessionManager.getSession(sessionId)
		.getAttribute(IImportService.IMPORT_FILE);
	List results = importService.parseSpreadsheet(file, sessionId);
	SessionManager.getSession(sessionId).setAttribute(IImportService.IMPORT_RESULTS, results);
    } catch (Exception e) {
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:ImportExcelSaveAction.java

示例13: execute

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

MessageService messageService = AdminServiceProxy.getMessageService(getServlet().getServletContext());
IImportService importService = AdminServiceProxy.getImportService(getServlet().getServletContext());
HttpSession ss = SessionManager.getSession();

List results = (List) ss.getAttribute(IImportService.IMPORT_RESULTS);
String successMessageKey = "";
try {
    FormFile file = (FormFile) ss.getAttribute(IImportService.IMPORT_FILE);
    successMessageKey = (importService.isUserSpreadsheet(file) ? "msg.users.created" : "msg.users.added");
} catch (Exception e) {
    log.error("Couldn't check spreadsheet type!", e);
}

int successful = 0;
for (int i = 0; i < results.size(); i++) {
    ArrayList rowResult = (ArrayList) results.get(i);
    if (rowResult.isEmpty()) {
	successful++;
    }
}
String[] args = new String[1];
args[0] = String.valueOf(successful);

request.setAttribute("results", results);
request.setAttribute("successful", messageService.getMessage(successMessageKey, args));

// remove temporary session vars that allowed status to be displayed
// to user during import
ss.removeAttribute(IImportService.STATUS_IMPORT_TOTAL);
ss.removeAttribute(IImportService.STATUS_IMPORTED);
ss.removeAttribute(IImportService.IMPORT_FILE);
ss.removeAttribute(IImportService.IMPORT_RESULTS);

return mapping.findForward("importresult");
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:ImportUserResultAction.java

示例14: validateFileSize

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
/**
    *
    * @param file
    * @param largeFile
    * @param errorKey
    *            the key in ActionMessages(errorKey,ActionMessage());
    * @param errors
    * @return Be careful, if the file size is under maximum size, return TRUE. Otherwise, return false.
    */
   public static boolean validateFileSize(FormFile file, boolean largeFile, String errorKey, ActionMessages errors) {
int fileSize = 0;
try {
    fileSize = file.getFileSize();
} catch (Exception e) {
    //skip, do nothing
    return true;
}

return FileValidatorUtil.validateFileSize(fileSize, largeFile, errorKey, errors);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:FileValidatorUtil.java

示例15: isRolesSpreadsheet

import org.apache.struts.upload.FormFile; //导入依赖的package包/类
@Override
   public boolean isRolesSpreadsheet(FormFile fileItem) throws IOException {
HSSFSheet sheet = getSheet(fileItem);
HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
String string = parseStringCell(row.getCell(ImportService.ORGANISATION));
return (StringUtils.equals(string, "* organisation")) ? true : false;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ImportService.java


注:本文中的org.apache.struts.upload.FormFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。