Pessoal estou com um código aqui, que ficou meio feio, alguém teria uma dicar de como fazer, para ficar menos feio ?
public void upload() {
HttpServletRequest hsr = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
if (hsr instanceof MonitorRequestWrapper) {
MonitorRequestWrapper mrw = (MonitorRequestWrapper) hsr;
ServletRequest sr = mrw.getRequest();
if (sr instanceof SecurityContextHolderAwareRequestWrapper) {
SecurityContextHolderAwareRequestWrapper scharw = (SecurityContextHolderAwareRequestWrapper) sr;
ServletRequest sr2 = scharw.getRequest();
if (sr2 instanceof FirewalledRequest) {
FirewalledRequest fw = (FirewalledRequest) sr2;
ServletRequest sr3 = fw.getRequest();
if (sr3 instanceof MultipartRequestWrapper) {
MultipartRequestWrapper multi = (MultipartRequestWrapper) sr3;
Long tamanho = new Long(1 * 1024 * 1024); // 1MB
FileItem item = multi.getFileItem("arquivo");
if (item != null && !item.isFormField()) {
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();
if (fileName.length() > 0 && sizeInBytes > 0 && sizeInBytes <= tamanho
&& fileName.equals(NOME) && contentType.equals("text/plain")) {
try {
this.gravarArquivo(item);
} catch (IOException ex) {
getLogger().error(ex);
}
}
}
}
}
}
}
}