//  [java]
    public void processRequest() throws Exception {
        FormProcessor fp = new FormProcessor(request);
        String filePathName = "";
        String fileName = fp.getString("fileName");
        File f = new File(fileName);
        
        if(fileName != null && fileName.indexOf("..") > -1) {
        	throw new RuntimeException("Traversal attempt - absolute path not allowed " + fileName);
        }
        
        if (fileName != null && fileName.length() > 0) {
            int parentStudyId = currentStudy.getParentStudyId();
            String testPath = Utils.getAttachedFileRootPath();
            String tail = File.separator + f.getName();
            String testName = testPath + currentStudy.getOid() + tail;
            File temp = new File(testName);
            if (temp.exists()) {
                filePathName = testName;
                logger.info(currentStudy.getName() + " existing filePathName=" + filePathName);
            } else {
                if (currentStudy.isSite(parentStudyId)) {
                    testName = testPath + ((StudyBean) new StudyDAO(sm.getDataSource()).findByPK(parentStudyId)).getOid() + tail;
                    temp = new File(testName);
                    if (temp.exists()) {
                        filePathName = testName;
                        logger.info("parent existing filePathName=" + filePathName);
                    }
                } else {
                    ArrayList<StudyBean> sites = (ArrayList<StudyBean>) new StudyDAO(sm.getDataSource()).findAllByParent(currentStudy.getId());
                    for (StudyBean s : sites) {
                        testPath = Utils.getAttachedFilePath(s);
                        testName = testPath + tail;//+ s.getIdentifier() + tail;
                        File test = new File(testName);
                        if (test.exists()) {
                            filePathName = testName;
                            logger.info("site of currentStudy existing filePathName=" + filePathName);
                            break;
                        }
                    }
                }
            }
        }
        logger.info("filePathName=" + filePathName + " fileName=" + fileName);
        File file = new File(filePathName);
        if (!file.exists() || file.length() <= 0) {
            addPageMessage("File " + filePathName + " " + respage.getString("not_exist"));
            
            // try to use the passed in the existing file
        	file = new File(fileName);
        }
        
        if (!file.exists() || file.length() <= 0) {
            addPageMessage("File " + filePathName + " " + respage.getString("not_exist"));
        } else {
//            response.setContentType("application/octet-stream");
            response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\";");
            response.setHeader("Pragma", "public");

            ServletOutputStream outStream = response.getOutputStream();
            DataInputStream inStream = null;
            try {
                response.setContentType("application/download");
                response.setHeader("Cache-Control", "max-age=0");
                response.setContentLength((int) file.length());

                byte[] bbuf = new byte[(int) file.length()];
                inStream = new DataInputStream(new FileInputStream(file));
                int length;
                while (inStream != null && (length = inStream.read(bbuf)) != -1) {
                    outStream.write(bbuf, 0, length);
                }

                inStream.close();
                outStream.flush();
                outStream.close();
            } catch (Exception ee) {
                ee.printStackTrace();
            } finally {
                if (inStream != null) {
                    inStream.close();
                }
                if (outStream != null) {
                    outStream.close();
                }
            }
        }
    }