Example usage for javax.servlet.http HttpServletRequest getRealPath

List of usage examples for javax.servlet.http HttpServletRequest getRealPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRealPath.

Prototype

public String getRealPath(String path);

Source Link

Usage

From source file:com.provenance.cloudprovenance.policyhandler.ws.support.PolicyRequestProcessor.java

private void resourceConversion(HttpServletRequest request) throws URISyntaxException,
        ParserConfigurationException, SAXException, IOException, TransformerException {

    rsConverter.directoryFilesConverter(request.getRealPath(cProvlPolicyDirectoryPath),
            request.getRealPath(xacmlPolicyConverterFile), request.getRealPath(xacmlPolicyDirectoryPath));

}

From source file:com.provenance.cloudprovenance.policyhandler.ws.support.PolicyRequestProcessor.java

public String executePolicyRequest(String serviceId, String cprovlPolicyRequest, String[] policyToSelectId,
        HttpServletRequest request) throws TransformerException, URISyntaxException,
        ParserConfigurationException, SAXException, IOException {

    File styleSheetPath = new File(request.getRealPath(xacmlRequestConverterFile));

    String xacmlPolicyRequest = rsConverter.convertAcProvRequestToXACML(cprovlPolicyRequest, styleSheetPath);

    logger.info("conversion to XACML policy request successful: " + xacmlPolicyRequest);

    // convert policy
    resourceConversion(request);/*from   ww w  .j  a  v a 2 s . c  o  m*/

    // getPolicyAbsolutePath
    String policyPathRef = request.getRealPath(xacmlPolicyDirectoryPath) + "/" + policyToSelectId[1];

    logger.info("path to policy one Id: " + policyPathRef);

    // String executionOutcome = policyEngine.executePolicy(
    String policyExecutionOutcome = policyEngine.executeWebPolicy(policyPathRef, xacmlPolicyRequest, serviceId);
    return policyExecutionOutcome;
}

From source file:org.openmrs.module.custombranding.web.controller.CustomBrandingController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    String fileSysLocation = request.getRealPath("/");
    String messageFileLocation = fileSysLocation + File.separator + "WEB-INF" + File.separator
            + "messages.properties";
    HttpSession session = request.getSession();

    if (request.getParameter("action") != null) {
        if (request.getParameter("id") != null) {
            if (request.getParameter("id").equals("largeLogo")) {
                if (new File(fileSysLocation + largeLogo + ".orig").exists()) {
                    FileUtils.copyFile(new File(fileSysLocation + largeLogo + ".orig"),
                            new File(fileSysLocation + largeLogo));
                    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Back to default large logo");
                }//from w w  w. j  a va  2 s  . co m
            } else if (request.getParameter("id").equals("smallLogo")) {
                if (new File(fileSysLocation + smallLogo + ".orig").exists()) {
                    FileUtils.copyFile(new File(fileSysLocation + smallLogo + ".orig"),
                            new File(fileSysLocation + smallLogo));
                    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Back to default small logo");
                }
            } else if (request.getParameter("id").equals("textLogo")) {
                if (new File(fileSysLocation + textLogo + ".orig").exists()) {
                    FileUtils.copyFile(new File(fileSysLocation + textLogo + ".orig"),
                            new File(fileSysLocation + textLogo));
                    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Back to default text logo");
                }
            } else if (request.getParameter("id").equals("messageFile")) {
                if (new File(messageFileLocation + ".orig").exists()) {
                    FileUtils.copyFile(new File(messageFileLocation + ".orig"), new File(messageFileLocation));
                    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Back to default messages");
                }
            } else if (request.getParameter("id").equals("faviconFile")) {
                if (new File(fileSysLocation + favicon + ".orig").exists()) {
                    FileUtils.copyFile(new File(fileSysLocation + favicon + ".orig"),
                            new File(fileSysLocation + favicon));
                    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Back to default favicon");
                }
            } else if (request.getParameter("id").equals("iconFile")) {
                if (new File(fileSysLocation + icon + ".orig").exists()) {
                    FileUtils.copyFile(new File(fileSysLocation + icon + ".orig"),
                            new File(fileSysLocation + icon));
                    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Back to default icon");
                }
            }
        }
    } else {
        try {
            FileUploadBean bean = (FileUploadBean) command;
            MultipartFile largeLogoFile = bean.getLargeLogoFile();
            MultipartFile smallLogoFile = bean.getSmallLogoFile();
            MultipartFile textLogoFile = bean.getTextLogoFile();
            MultipartFile messageFile = bean.getMessageFile();
            MultipartFile faviconFile = bean.getFaviconFile();
            MultipartFile iconFile = bean.getIconFile();

            String orgUrlStr = bean.getOrgUrl();

            if (largeLogoFile != null) {
                FileUtils.copyFile(new File(fileSysLocation + largeLogo),
                        new File(fileSysLocation + largeLogo + ".orig"));
                largeLogoFile.transferTo(new File(fileSysLocation + largeLogo));
                session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully replaced large logo");
            } else if (smallLogoFile != null) {
                FileUtils.copyFile(new File(fileSysLocation + smallLogo),
                        new File(fileSysLocation + smallLogo + ".orig"));
                smallLogoFile.transferTo(new File(fileSysLocation + smallLogo));
                session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully replaced small logo");
            } else if (textLogoFile != null) {
                FileUtils.copyFile(new File(fileSysLocation + textLogo),
                        new File(fileSysLocation + textLogo + ".orig"));
                textLogoFile.transferTo(new File(fileSysLocation + textLogo));
                session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully replaced text logo");
            } else if (messageFile != null) {
                FileUtils.copyFile(new File(messageFileLocation), new File(messageFileLocation + ".orig"));
                messageFile.transferTo(new File(messageFileLocation));
                session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully replaced messages file");
            } else if (faviconFile != null) {
                FileUtils.copyFile(new File(fileSysLocation + favicon),
                        new File(fileSysLocation + favicon + ".orig"));
                faviconFile.transferTo(new File(fileSysLocation + favicon));
                session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully replaced favicon file");
            } else if (iconFile != null) {
                FileUtils.copyFile(new File(fileSysLocation + icon),
                        new File(fileSysLocation + icon + ".orig"));
                iconFile.transferTo(new File(fileSysLocation + icon));
                session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully replaced favicon file");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return new ModelAndView(new RedirectView(request.getContextPath() + getSuccessView()));
}

From source file:controllers.IndexController.java

public String[][] picupload(HttpServletRequest request) {
    String path = request.getRealPath("/upload_images");
    path = path.substring(0, path.indexOf("\\mavenproject1"));
    path = path + "\\mavenproject1\\mavenproject1\\src\\main\\webapp\\upload_images";
    file2 = new File(path);
    filelist = file2.listFiles();//from   w  w  w  .  j  a  v  a2s  .  co  m
    String[][] filear = new String[filelist.length][filelist.length];
    for (int i = 0; i < filelist.length; i++) {
        path2 = filelist[i].getName();
        dataname = path2;
        for (int j = 0; j < filelist.length; j++) {

            filear[j][i] = dataname;

        }

    }

    return filear;

}

From source file:controllers.IndexController.java

public String searchpic(HttpServletRequest request, DataModel bau) {
    String path = request.getRealPath("/upload_images");
    path = path.substring(0, path.indexOf("\\mavenproject1"));
    path = path + "\\mavenproject1\\mavenproject1\\src\\main\\webapp\\upload_images";
    file2 = new File(path);
    filelist = file2.listFiles();/*from w  ww.j  a  v  a  2 s.  com*/

    for (int i = 0; i < filelist.length; i++) {
        path2 = filelist[i].getName();
        if (path2.equals(bau.getDatafetchfile())) {

            path = path + "\\" + path2;
            path = path.replace("\\", "\\\\");

            return path;
        }
    }
    return "";
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain; charset=Shift_JIS");
    PrintWriter out = res.getWriter();
    res.setHeader("Content-Language", "ja");

    Locale locale = new Locale("ja", "");
    DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    out.println("In Japanese:");

    try {/*from   w w w. j  ava  2  s.c  om*/
        FileInputStream fis = new FileInputStream(req.getRealPath("/HelloWorld.ISO-2022-JP"));
        InputStreamReader isr = new InputStreamReader(fis, "ISO-2022-JP");
        BufferedReader reader = new BufferedReader(isr);
        String line = null;
        while ((line = reader.readLine()) != null) {
            out.println(line);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    out.println(full.format(new Date()));
}

From source file:controllers.IndexController.java

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ModelAndView uploadpic(HttpServletRequest request, ModelAndView model) {

    String path = request.getRealPath("/upload_images");
    path = path.substring(0, path.indexOf("\\mavenproject1"));
    path = path + "\\mavenproject1\\mavenproject1\\src\\main\\webapp\\upload_images";
    DiskFileItemFactory dfif = new DiskFileItemFactory();
    ServletFileUpload uploader = new ServletFileUpload(dfif);

    try {/*  w ww . j  a va 2  s.c o m*/

        List<FileItem> fit = uploader.parseRequest(request);
        for (FileItem fileItem : fit) {
            try {
                contenttype = fileItem.getContentType();
                contenttype = contenttype.substring(6, contenttype.length());
                if (fileItem.isFormField() == false && contenttype.equals("jpeg")
                        || contenttype.equals("png")) {
                    file = new File(path + "/" + fileItem.getName());
                    fileItem.write(file);

                }
            } catch (Exception ey) {

            }

        }
        return model;
    } catch (Exception ex) {

        if (file.exists()) {

            file.delete();
        }

        model.addObject("errorcode", ex.toString());
        model.setViewName("nosuccessform");
        return model;
    }

}

From source file:com.provenance.cloudprovenance.policyhandler.ws.support.PolicyRequestProcessor.java

public String validatePolicyRequest(String serviceId, String policyRequestId, String policyId,
        String policyRequestContent, HttpServletRequest request) throws IOException, URISyntaxException,
        ParserConfigurationException, SAXException, TransformerException {

    // convert policies
    this.resourceConversion(request);

    // execute policy
    String executionOutcome = policyEngine.executePolicy(
            request.getRealPath(xacmlPolicyDirectoryPath + "/policy" + policyId + "-xacml.xml"),
            request.getRealPath(xacmlRequestDirectoryPath + "/request" + policyId + "-xacml.xml"), null);

    return executionOutcome;
}

From source file:egpi.tes.ahv.servicio.MenuReporteJasper.java

/**
 * /*w ww  .j av a  2  s  .co m*/
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException 
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {

        System.out.println("\n\ndoPost\n\n");

        String separador = System.getProperty("file.separator");
        System.out.println("getRealPath:" + request.getRealPath("") + separador + "menu" + separador + "cache");

        HttpSession session = request.getSession(true);
        client = (HttpClient) session.getAttribute("clientjasper");
        properties = (Properties) session.getAttribute("propiedadesjasper");
        autenticacionVO = (AutenticacionVO) session.getAttribute("authVO");
        sincronizarMenu.setPath(request.getRealPath("") + separador + properties.getProperty("pathinstalacion")
                + separador + "menu" + separador + "cache");
        obtenerDescriptorGeneral();
        session.setAttribute("menuDeplegable", sincronizarMenu.menuDesplegable());

        PrintWriter out = response.getWriter();
        out.println(obj);

    } catch (Exception e) {
        e.printStackTrace();
        procesarError(response, e);
    }

}

From source file:com.school.exam.web.student.StudentController.java

@RequestMapping(value = "answer", method = RequestMethod.POST, produces = MediaTypes.JSON_UTF_8)
@ResponseBody/*  w  ww.  j a va2s  .co m*/
public String answerFile(AnswerVO answerVO, HttpServletRequest request) {

    logger.debug("upload path:{}->file:{}", request.getRealPath("/"), answerVO.getFile().getName());

    String logoRealPathDir = request.getSession().getServletContext().getRealPath("/static/temp");

    /**?**/
    File logoSaveFile = new File(logoRealPathDir);
    if (!logoSaveFile.exists())
        logoSaveFile.mkdirs();

    Long currentMillis = System.currentTimeMillis();

    String suffix = answerVO.getFile().getOriginalFilename()
            .substring(answerVO.getFile().getOriginalFilename().lastIndexOf("."));

    Answer answerObj = new Answer();

    String course = answerVO.getCourse();
    if (null != course) {
        course = org.apache.commons.lang3.StringUtils.replace(course, "<br/>", "");
        course = org.apache.commons.lang3.StringUtils.replace(course, " ", "");
    }

    answerObj.setTitle(answerVO.getTitle());
    answerObj.setCourse(course);
    answerObj.setAnswer(answerVO.getFile().getOriginalFilename());
    answerObj.setType(suffix);
    answerObj.setAnswerDate(new Date(currentMillis));

    User user = new User();
    user.setId(getCurrentUserId());

    answerObj.setUser(user);

    answerService.save(answerObj);

    String fileName = logoRealPathDir + File.separator + answerObj.getUser().getId() + "-"
            + answerObj.getAnswer();
    File file = new File(fileName);

    try {
        answerVO.getFile().transferTo(file);
    } catch (IOException e) {
        logger.warn("save file error!", e);
    }
    return "true";
}