Example usage for javax.servlet.http HttpSession getServletContext

List of usage examples for javax.servlet.http HttpSession getServletContext

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns the ServletContext to which this session belongs.

Usage

From source file:com.crimelab.service.MacroEtchingServiceImpl.java

@Override
public Workbook create(MacroEtching macroEtching, HttpSession session) {
    Workbook wb = null;// w  ww  .ja v  a2 s.  c o m
    try {
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/meCert.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell dateCreated = findCell(sheet, "$dateCreated");
        Cell rclo = findCell(sheet, "$rclo");
        Cell make = findCell(sheet, "$make");
        Cell color = findCell(sheet, "$color");
        Cell plateNo = findCell(sheet, "$plateNo");
        Cell engineNo = findCell(sheet, "$engineNo");
        Cell chassisNo = findCell(sheet, "$chassisNo");
        Cell eNo = findCell(sheet, "$eNo");
        Cell cNo = findCell(sheet, "$cNo");
        Cell owner = findCell(sheet, "$owner");
        Cell address = findCell(sheet, "$address");
        Cell appName = findCell(sheet, "$appName");
        Cell appRank = findCell(sheet, "$appRank");
        Cell appPosition = findCell(sheet, "$appPosition");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");

        dateCreated.setCellValue(macroEtching.getDateCreated());
        rclo.setCellValue(macroEtching.getRclo());
        make.setCellValue(macroEtching.getMake());
        color.setCellValue(macroEtching.getColor());
        plateNo.setCellValue(macroEtching.getPlateNo());
        engineNo.setCellValue(macroEtching.getEngineNo());
        chassisNo.setCellValue(macroEtching.getChassisNo());
        eNo.setCellValue(macroEtching.getEngineNo());
        cNo.setCellValue(macroEtching.getChassisNo());
        owner.setCellValue(macroEtching.getOwner());
        address.setCellValue(macroEtching.getAddress());
        appName.setCellValue(macroEtching.getAppName());
        appRank.setCellValue(macroEtching.getAppRank());
        appPosition.setCellValue(macroEtching.getAppPosition());
        examinerName.setCellValue(macroEtching.getExaminerName());
        examinerRank.setCellValue(macroEtching.getExaminerRank());
        examinerPosition.setCellValue(macroEtching.getExaminerPosition());

        macroEtchingDAO.macroEtchingInfo(macroEtching);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.QdServiceImpl.java

@Override
public Workbook create(Qd qd, HttpSession session) {
    Workbook wb = null;//  www.  j a v a 2 s. co m

    try {
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/Default.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell division = findCell(sheet, "$division");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspect = findCell(sheet, "$suspect");
        Cell victim = findCell(sheet, "$victim");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusion = findCell(sheet, "$conclusion");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");

        division.setCellValue(qd.getDivision());
        reportNo.setCellValue(qd.getReportNo());
        caseType.setCellValue(qd.getCaseType());
        suspect.setCellValue(qd.getSuspect());
        victim.setCellValue(qd.getVictim());
        timeDateReceived.setCellValue(qd.getTimeDateReceived());
        requestingParty.setCellValue(qd.getRequestingParty());
        specimenSubmitted.setCellValue(qd.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(qd.getPurposeOfLabExam());
        findings.setCellValue(qd.getFindings());
        conclusion.setCellValue(qd.getConclusion());
        remarks.setCellValue(qd.getRemarks());
        timeDateCompleted.setCellValue(qd.getTimeDateCompleted());
        examinerName.setCellValue(qd.getExaminerName());
        examinerRank.setCellValue(qd.getExaminerRank());
        examinerPosition.setCellValue(qd.getExaminerPosition());
        notedName.setCellValue(qd.getNotedName());
        notedRank.setCellValue(qd.getNotedRank());
        notedPosition.setCellValue(qd.getNotedPosition());

        qdDAO.qdInfo(qd);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.orchestra.portale.controller.UserEditController.java

@RequestMapping(value = "userEditProfile", method = RequestMethod.POST)
@Secured("ROLE_USER")
public ModelAndView updateUser(HttpServletRequest request, @ModelAttribute("SpringWeb") User user,
        MultipartFile avatar) {//from  ww  w . jav a2s  .  co m
    ModelAndView model = new ModelAndView("userInfo");
    User olduser = pm.findUserByUsername(user.getUsername());
    user.setId(olduser.getId());

    if (user.getPassword() == null || user.getPassword().equals("")) {
        user.setPassword(olduser.getPassword());
    } else {
        user.setPassword(crypt(user.getPassword()));
    }

    pm.saveUser(user);

    if (avatar.getSize() > 0) {

        User user2 = pm.findUserByUsername(user.getUsername());
        MultipartFile file = avatar;

        try {
            byte[] bytes = file.getBytes();

            // Creating the directory to store file
            HttpSession session = request.getSession();
            ServletContext sc = session.getServletContext();

            File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "user" + File.separator + "img"
                    + File.separator + user2.getId());
            if (!dir.exists()) {
                dir.mkdirs();
            }

            // Create the file on server
            File serverFile = new File(dir.getAbsolutePath() + File.separator + "avatar.jpg");
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();
        } catch (Exception e) {

        }

    }
    model.addObject("user", user);
    HttpSession session = request.getSession();
    ServletContext sc = session.getServletContext();
    File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "user" + File.separator + "img"
            + File.separator + user.getId() + File.separator + "avatar.jpg");
    if (dir.exists()) {
        model.addObject("avatar", "./dist/user/img/" + user.getId() + "/avatar.jpg");
    } else {
        model.addObject("avatar", "./dist/img/default_avatar.png");
    }
    return model;
}

From source file:org.intermine.bio.web.displayer.MinePathwaysDisplayer.java

@Override
public void display(HttpServletRequest request, ReportObject reportObject) {

    Gene gene = (Gene) reportObject.getObject();
    request.setAttribute("gene", gene);
    Map<Mine, String> mineToOrthologues = null;
    if (minePathwayCache.get(reportObject) != null) {
        mineToOrthologues = minePathwayCache.get(reportObject);
    } else {/*from  w  w  w.  j  av a 2  s.  com*/
        Map<String, Set<String>> orthologues = getLocalHomologues(gene);
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        final Properties webProperties = SessionMethods.getWebProperties(servletContext);
        final FriendlyMineManager linkManager = FriendlyMineManager.getInstance(im, webProperties);
        Collection<Mine> mines = linkManager.getFriendlyMines();
        mineToOrthologues = buildHomologueMap(mines, orthologues);
        minePathwayCache.put(reportObject, mineToOrthologues);
    }
    request.setAttribute("minesForPathways", mineToOrthologues);
}

From source file:mayo.edu.server.JsonServiceImpl.java

public String getBasePath() {
    String dataPath;//from  w  w w.j  ava 2 s .co  m

    HttpSession httpSession = getThreadLocalRequest().getSession(true);
    ServletContext context = httpSession.getServletContext();

    String realContextPath = context.getRealPath(getThreadLocalRequest().getContextPath());

    if (isDevelopmentMode()) {
        dataPath = realContextPath;
    } else {
        dataPath = realContextPath + "/../";
    }

    return dataPath;
}

From source file:com.crimelab.service.PiServiceImpl.java

@Override
public Workbook create(PiReport piReport, HttpSession session) {
    Workbook wb = null;//  w  w w. ja  v a 2  s. co m
    try {
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/Default.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell examType = findCell(sheet, "$examType");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspects = findCell(sheet, "$suspects");
        Cell victims = findCell(sheet, "$victims");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusions = findCell(sheet, "$conclusions");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell appName = findCell(sheet, "$appName");
        Cell appRank = findCell(sheet, "$appRank");
        Cell appPosition = findCell(sheet, "$appPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");

        examType.setCellValue(piReport.getExamType());
        reportNo.setCellValue(piReport.getReportNo());
        caseType.setCellValue(piReport.getCaseType());
        suspects.setCellValue(piReport.getSuspects());
        victims.setCellValue(piReport.getVictims());
        timeDateReceived.setCellValue(piReport.getTimeDateReceived());
        requestingParty.setCellValue(piReport.getRequestingParty());
        specimenSubmitted.setCellValue(piReport.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(piReport.getPurposeOfLabExam());
        findings.setCellValue(piReport.getFindings());
        conclusions.setCellValue(piReport.getConclusions());
        remarks.setCellValue(piReport.getRemarks());
        timeDateCompleted.setCellValue(piReport.getTimeDateCompleted());
        examinerName.setCellValue(piReport.getExaminerName());
        examinerRank.setCellValue(piReport.getExaminerRank());
        examinerPosition.setCellValue(piReport.getExaminerPosition());
        appName.setCellValue(piReport.getAppName());
        appRank.setCellValue(piReport.getAppRank());
        appPosition.setCellValue(piReport.getAppPosition());
        notedName.setCellValue(piReport.getNotedName());
        notedRank.setCellValue(piReport.getNotedRank());
        notedPosition.setCellValue(piReport.getNotedPosition());

        piDAO.piReportInfo(piReport);
    } catch (Exception e) {
        e.printStackTrace();

    }
    return wb;
}

From source file:org.callistasoftware.netcare.web.controller.SecurityController.java

@RequestMapping(value = "/logout")
public String logout(final HttpSession sc, final HttpServletRequest request) {
    getLog().info("Logout");
    SecurityContextHolder.clearContext();

    if (WebUtil.isProfileActive(sc.getServletContext(), "qa")
            || WebUtil.isProfileActive(sc.getServletContext(), "prod")) {
        request.getSession(false).invalidate();
        return "redirect:/netcare/security/loggedout";
    } else {//  w w w . ja  v  a 2  s .c o  m
        request.getSession(false).invalidate();
        return "redirect:/netcare/security/login";
    }
}

From source file:org.owasp.webgoat.service.PluginReloadService.java

/**
 * Reload all the plugins//  w  w w  .  j  av  a 2  s  .co  m
 *
 * @param session a {@link HttpSession} object.
 */
@RequestMapping(value = "/reloadplugins.mvc")
public @ResponseBody ResponseEntity<String> reloadPlugins(HttpSession session) {
    WebSession webSession = (WebSession) session.getAttribute(WebSession.SESSION);
    logger.debug("Loading plugins into cache");
    String pluginPath = session.getServletContext().getRealPath("plugin_lessons");
    String targetPath = session.getServletContext().getRealPath("plugin_extracted");
    new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).copyJars();

    webSession.getCourse().loadLessonFromPlugin(session.getServletContext());
    return new ResponseEntity("Plugins reload refresh the WebGoat page!", HttpStatus.OK);
}

From source file:jp.co.opentone.bsol.linkbinder.view.filter.ProjectSwitchFilter.java

private ApplicationContext createApplicationContext(HttpSession session) {
    ServletContext context = session.getServletContext();
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(context);

    return applicationContext;
}