use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class ContextMapFactoryImpl method getUploadedFileMap.
@Override
public Map<String, List<UploadedFile>> getUploadedFileMap(PortletRequest portletRequest) {
Map<String, List<UploadedFile>> bridgeUploadedFileMap = Collections.emptyMap();
MultiPartFormData multiPartFormData = (MultiPartFormData) portletRequest.getAttribute(MULTIPART_FORM_DATA_FQCN);
if (multiPartFormData != null) {
Map<String, List<com.liferay.faces.util.model.UploadedFile>> uploadedFileMap = multiPartFormData.getUploadedFileMap();
if (uploadedFileMap != null) {
PortletSession portletSession = portletRequest.getPortletSession(true);
PortletContext portletContext = portletSession.getPortletContext();
Map<String, Object> applicationScopeMap = getApplicationScopeMap(portletContext, true);
ExternalContext externalContext = new ExternalContextProductImpl(applicationScopeMap);
ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
Product PRIMEFACES = productFactory.getProductInfo(Product.Name.PRIMEFACES);
boolean primeFacesDetected = PRIMEFACES.isDetected();
int primeFacesMajorVersion = PRIMEFACES.getMajorVersion();
bridgeUploadedFileMap = new HashMap<String, List<UploadedFile>>(uploadedFileMap.size());
Set<Map.Entry<String, List<com.liferay.faces.util.model.UploadedFile>>> entrySet = uploadedFileMap.entrySet();
for (Map.Entry<String, List<com.liferay.faces.util.model.UploadedFile>> mapEntry : entrySet) {
List<com.liferay.faces.util.model.UploadedFile> uploadedFileList = mapEntry.getValue();
if (uploadedFileList != null) {
List<UploadedFile> bridgeUploadedFileList = new ArrayList<UploadedFile>(uploadedFileList.size());
for (com.liferay.faces.util.model.UploadedFile uploadedFile : uploadedFileList) {
bridgeUploadedFileList.add(new UploadedFileBridgeImpl(uploadedFile, primeFacesDetected, primeFacesMajorVersion));
}
bridgeUploadedFileMap.put(mapEntry.getKey(), bridgeUploadedFileList);
}
}
}
}
return bridgeUploadedFileMap;
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class HtmlInputFileRenderer method decode.
@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
HtmlInputFile htmlInputFile = (HtmlInputFile) uiComponent;
Map<String, List<UploadedFile>> uploadedFileMap = InputFileRenderer.getUploadedFileMap(facesContext);
if (!uploadedFileMap.isEmpty()) {
String clientId = uiComponent.getClientId(facesContext);
if (uploadedFileMap.containsKey(clientId)) {
List<UploadedFile> uploadedFiles = uploadedFileMap.get(clientId);
if ((uploadedFiles != null) && (uploadedFiles.size() > 0)) {
Part part = new PartFileUploadAdapterImpl(uploadedFiles.get(0), clientId);
htmlInputFile.setTransient(true);
htmlInputFile.setSubmittedValue(part);
} else {
htmlInputFile.setSubmittedValue(new PartEmptyImpl());
}
}
}
RendererUtil.decodeClientBehaviors(facesContext, uiComponent);
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method handleFileUpload.
public void handleFileUpload(FileUploadEvent fileUploadEvent) throws Exception {
org.richfaces.model.UploadedFile uploadedFile = fileUploadEvent.getUploadedFile();
FacesContext facesContext = FacesContext.getCurrentInstance();
File attachmentDir = attachmentManager.getAttachmentDir(facesContext);
if (!attachmentDir.exists()) {
attachmentDir.mkdir();
}
File copiedFile = new File(attachmentDir, uploadedFile.getName());
try {
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
List<Attachment> attachments = attachmentManager.getAttachments(attachmentDir);
applicant.setAttachments(attachments);
} catch (IOException e) {
logger.error(e);
}
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class BridgeInputFileBackingBean method handleFileUpload.
public void handleFileUpload(FileUploadEvent fileUploadEvent) {
List<UploadedFile> uploadedFiles = bridgeInputFileModelBean.getUploadedFiles();
UploadedFile uploadedFile = fileUploadEvent.getUploadedFile();
if (uploadedFile.getStatus() == UploadedFile.Status.FILE_SAVED) {
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage facesMessage = new FacesMessage("Received fileUploadEvent for file named '" + uploadedFile.getName() + "' in the " + fileUploadEvent.getPhaseId().toString() + " phase.");
facesContext.addMessage(null, facesMessage);
uploadedFiles.add(uploadedFile);
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", uploadedFile.getName(), uploadedFile.getAbsolutePath());
} else {
logger.error("Failed to receive uploaded file due to error status=[{0}] message=[{1}]", uploadedFile.getStatus(), uploadedFile.getMessage());
}
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class BridgeInputFileBackingBean method deleteUploadedFile.
public void deleteUploadedFile(ActionEvent actionEvent) {
UICommand uiCommand = (UICommand) actionEvent.getComponent();
String fileId = (String) uiCommand.getValue();
try {
List<UploadedFile> uploadedFiles = bridgeInputFileModelBean.getUploadedFiles();
UploadedFile uploadedFileToDelete = null;
for (UploadedFile uploadedFile : uploadedFiles) {
if (uploadedFile.getId().equals(fileId)) {
uploadedFileToDelete = uploadedFile;
break;
}
}
if (uploadedFileToDelete != null) {
uploadedFileToDelete.delete();
uploadedFiles.remove(uploadedFileToDelete);
logger.debug("Deleted file=[{0}]", uploadedFileToDelete.getName());
}
} catch (Exception e) {
logger.error(e);
}
}
Aggregations