Java Code Examples for org.primefaces.model.UploadedFile

The following examples show how to use org.primefaces.model.UploadedFile. These examples are extracted from open source projects. 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 Project: sailfish-core   Source File: TestScriptsBean.java    License: Apache License 2.0 6 votes vote down vote up
public void handleFileUpload(FileUploadEvent event) {

		logger.debug("Upload invoked {}", BeanUtil.getUser());

		UploadedFile uploadedFile = event.getFile() ;

		try {
			BeanUtil.getSfContext().getMatrixStorage().addMatrix(uploadedFile.getInputstream(), uploadedFile.getFileName(), null, "Unknown creator", null, null, null);
		} catch (Exception e) {
			logger.error("Could not store uploaded file", e);
			BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "Error", "Could not store uploaded file " + e.getMessage() );
			return;
		}

		logger.debug("Upload finished");
    }
 
Example 2
Source Project: sailfish-core   Source File: DictionaryEditorModel.java    License: Apache License 2.0 6 votes vote down vote up
public boolean handleFileUpload(UploadedFile uploadFile) {

        ModifiableXmlDictionaryStructureLoader loader = new ModifiableXmlDictionaryStructureLoader();

        try {

            try (InputStream in = uploadFile.getInputstream()) {
                this.uploadDict = loader.load(in);
            }

            populateDictFieldModels(fieldsToFieldEditorModels(uploadDict.getImplFieldStructures(), true));

            return true;
        } catch (Exception ex) {
            logger.error("Can't parse uploaded dictionary", ex);
            BeanUtil.addErrorMessage("Error", "Can't parse uploaded dictionary");
            this.uploadDict = null;
            return false;
        }
    }
 
Example 3
Source Project: sailfish-core   Source File: EnvironmentBean.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void handleServicesUpload(FileUploadEvent event) throws FileNotFoundException {

		logger.info("handleServicesUpload invoked {}", getUser());

		UploadedFile uploadedFile = event.getFile() ;

        InputStream stream;
        try {
            stream = uploadedFile.getInputstream();
        } catch (IOException e) {
            logger.error("Could not get stream from uploaded file", e);
            BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "", e.getMessage() );
            return;
        }

        if (respectFileName) {
        	int index = uploadedFile.getFileName().indexOf("_environment.zip");
        	if (index != -1) {
        		currentEnvironment = uploadedFile.getFileName().substring(0, index);
        	}
        }

        // For getting an environment name from environment_description.xml file
        ImportServicesResult importServicesResult = TestToolsAPI.getInstance().importServices(stream, uploadedFile.getFileName().endsWith(".zip"), currentEnvironment, replaceExistingServices, skipExistingServices, !respectFileName, notifyListener);

        setCurrentEnvironment(importServicesResult.getEnvironment());
        changeEnvironment();

        RequestContext.getCurrentInstance().update("form");

        logger.info("Upload finished");
    }
 
Example 4
Source Project: sailfish-core   Source File: ToolsBean.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
private File getFile(UploadedFile uploadedFile) {
    try {
        Path tmpFile = Files.createTempFile(FilenameUtils.getBaseName(uploadedFile.getFileName()), "." + FilenameUtils.getExtension(uploadedFile.getFileName()));
        Files.copy(uploadedFile.getInputstream(), tmpFile, StandardCopyOption.REPLACE_EXISTING);
        return tmpFile.toFile();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e));
        return null;
    }
}
 
Example 5
Source Project: ctsms   Source File: PhotoBeanBase.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile uploadedFile = event.getFile();
	setFileName(uploadedFile.getFileName());
	setMimeType(uploadedFile.getContentType());
	setData(uploadedFile.getContents());
	setTimestamp(new Date());
	storeImage();
	Messages.addLocalizedMessage(FacesMessage.SEVERITY_INFO, MessageCodes.UPLOAD_OPERATION_SUCCESSFUL);
}
 
Example 6
Source Project: ctsms   Source File: JobBean.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile uploadedFile = event.getFile();
	in.setFileName(uploadedFile.getFileName());
	in.setMimeType(uploadedFile.getContentType());
	in.setDatas(uploadedFile.getContents());
	addOperationSuccessMessage(MessageCodes.UPLOAD_OPERATION_SUCCESSFUL);
}
 
Example 7
Source Project: ctsms   Source File: InputFieldBean.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile uploadedFile = event.getFile();
	in.setFileName(uploadedFile.getFileName());
	in.setMimeType(uploadedFile.getContentType());
	in.setDatas(uploadedFile.getContents());
	in.setWidth(null);
	in.setHeight(null);
	addOperationSuccessMessage(MessageCodes.UPLOAD_OPERATION_SUCCESSFUL);
}
 
Example 8
Source Project: sailfish-core   Source File: BigButtonBean.java    License: Apache License 2.0 4 votes vote down vote up
public UploadedFile getUploadedFile() {
	return uploadedFile;
}
 
Example 9
Source Project: sailfish-core   Source File: BigButtonBean.java    License: Apache License 2.0 4 votes vote down vote up
public void setUploadedFile(UploadedFile uploadedFile) {
	this.uploadedFile = uploadedFile;
}
 
Example 10
Source Project: sailfish-core   Source File: DictionariesBean.java    License: Apache License 2.0 4 votes vote down vote up
public UploadedFile getUploadFile() {
    return uploadFile;
}
 
Example 11
Source Project: sailfish-core   Source File: DictionariesBean.java    License: Apache License 2.0 4 votes vote down vote up
public void setUploadFile(UploadedFile uploadFile) {
    this.uploadFile = uploadFile;
}
 
Example 12
Source Project: ctsms   Source File: FileBean.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
public void handleFileUpload(FileUploadEvent event) {
	if (streamUploadEnabled == null) {
		Messages.addLocalizedMessage(FacesMessage.SEVERITY_ERROR, MessageCodes.FILE_STREAM_UPLOAD_MODE_UNDEFINED);
		return;
	}
	UploadedFile uploadedFile = event.getFile();
	if (streamUploadEnabled) {
		contentIn = null;
		streamIn = new FileStreamInVO();
		streamIn.setFileName(uploadedFile.getFileName());
		streamIn.setMimeType(uploadedFile.getContentType());
		streamIn.setSize(uploadedFile.getSize());
		try {
			streamIn.setStream(uploadedFile.getInputstream());
			addOperationSuccessMessage(MessageCodes.UPLOAD_OPERATION_SUCCESSFUL);
		} catch (IOException e) {
			streamIn = null;
			Messages.addMessage(FacesMessage.SEVERITY_ERROR, e.getMessage());
			return;
		}
	} else {
		streamIn = null;
		contentIn = new FileContentInVO();
		contentIn.setFileName(uploadedFile.getFileName());
		contentIn.setMimeType(uploadedFile.getContentType());
		contentIn.setDatas(uploadedFile.getContents());
		addOperationSuccessMessage(MessageCodes.UPLOAD_OPERATION_SUCCESSFUL);
	}
	if (!(in.getTitle() != null && in.getTitle().length() > 0) || in.getTitle().equals(Messages.getString(MessageCodes.FILE_TITLE_PRESET))) {
		in.setTitle(uploadedFile.getFileName());
		if (isCreateable()) {
			String path = CommonUtil.fixLogicalPathFolderName(in.getLogicalPath());
			if (ADD_OUTCOME.equals(addAction(false))) {
				lastUploadedOut = out;
				out = null;
				initIn();
				in.setLogicalPath(path);
			}
		}
	}
}
 
Example 13
public UploadedFile getUploadData() {
    return uploadData;
}
 
Example 14
public void setUploadData(UploadedFile uploadData) {
    this.uploadData = uploadData;
}
 
Example 15
Source Project: ipst   Source File: ModelTemplateController.java    License: Mozilla Public License 2.0 4 votes vote down vote up
public UploadedFile getDataFile() {
    return dataFile;
}
 
Example 16
Source Project: ipst   Source File: ModelTemplateController.java    License: Mozilla Public License 2.0 4 votes vote down vote up
public void setDataFile(UploadedFile dataFile) {
    this.dataFile = dataFile;
}
 
Example 17
Source Project: journaldev   Source File: FileUploadManagedBean.java    License: MIT License 4 votes vote down vote up
public UploadedFile getFile() {
	return file;
}
 
Example 18
Source Project: journaldev   Source File: FileUploadManagedBean.java    License: MIT License 4 votes vote down vote up
public void setFile(UploadedFile file) {
	this.file = file;
}