List of usage examples for javax.servlet.http HttpServletRequest getSession
public HttpSession getSession();
From source file:ispyb.client.common.util.FileUtil.java
public static boolean isJpgForImage(Image3VO imageVO, HttpServletRequest request) throws Exception { boolean isJpg = false; Integer proposalId = (Integer) request.getSession().getAttribute(Constants.PROPOSAL_ID); if (proposalId == null) { try {/* w w w . java2s . c o m*/ proposalId = new Integer(request.getParameter(Constants.PROPOSAL_ID)); } catch (NumberFormatException e) { if (Confidentiality.isManager(request) || Confidentiality.isLocalContact(request)) { // isLocalContact or isManager = true; String sourceFileName = imageVO.getJpegFileFullPath(); sourceFileName = PathUtils.FitPathToOS(sourceFileName); isJpg = FileUtil.fileExists(sourceFileName); return isJpg; } return false; } } // Ejb3ServiceLocator ejb3ServiceLocator = Ejb3ServiceLocator.getInstance(); // Image3Service imageService = (Image3Service) ejb3ServiceLocator.getLocalService(Image3Service.class); // two variables to guarantee the user fecths only its own images // ArrayList imageFetchedList = (ArrayList) imgFacade.findByImageIdAndProposalId(imageId, proposalId); // List<Image3VO> imageFetchedList = imageService.findByImageIdAndProposalId(imageId, proposalId); // Image3VO imgValue = imageService.findByPk(imageId); Integer proposalIdFromImage = imageVO.getDataCollectionVO().getDataCollectionGroupVO().getSessionVO() .getProposalVOId(); if (proposalIdFromImage.equals(proposalId)) { String sourceFileName = imageVO.getJpegFileFullPath(); sourceFileName = PathUtils.FitPathToOS(sourceFileName); isJpg = FileUtil.fileExists(sourceFileName); } return isJpg; }
From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java
/** * Forward a request that was received by this servlet on to another JSP * page or servlet to continue handling the request. * // w ww . j a v a 2 s .co m * @param request * to be forwarded * @param response * that can be used for writing output to the client * @param destination * the context-relative URL to which the request is forwarded * @param params the request parameters. these will be added to the request */ public static void forwardRequest(HttpServletRequest request, HttpServletResponse response, String destinationUrl, Hashtable<String, String[]> params) throws MetacatUtilException { destinationUrl += "?" + paramsToQuery(params); logMetacat.debug("Forwarding request to " + destinationUrl); ServletContext servletContext = request.getSession().getServletContext(); try { servletContext.getRequestDispatcher(destinationUrl).forward(request, response); } catch (IOException ioe) { throw new MetacatUtilException("RequestUtil.forwardRequest - I/O error when forwarding to " + destinationUrl + " : " + ioe.getMessage()); } catch (ServletException se) { throw new MetacatUtilException("RequestUtil.forwardRequest - Servlet error when forwarding to " + destinationUrl + " : " + se.getMessage()); } }
From source file:com.opendesign.utils.CmnUtil.java
/** * ?? ?// www.j a v a 2 s.co m * * @param request * @return */ public static UserVO getLoginUser(HttpServletRequest request) { UserVO user = (UserVO) request.getSession().getAttribute(SessionKey.SESSION_LOGIN_USER); return user; }
From source file:com.edgenius.wiki.util.WikiUtil.java
/** * @param model// w w w. j av a 2s . c o m * @return */ public static boolean captchaValid(CaptchaServiceProxy captchaService, CaptchaCodeModel model) { if (model != null && model.reqireCaptcha) { HttpServletRequest request = WebUtil.getRequest(); HttpServletResponse response = WebUtil.getResponse(); String id = request.getSession().getId(); boolean valid = captchaService.validateReponseForId(id, model.captchaCode); if (!valid) { try { //here does not put webcontext - it is fine as GwtSpringController only do endWith() check. response.sendRedirect(WikiConstants.URL_CAPTCHA_VERIFIED_ERROR); } catch (IOException e) { log.error("Redir failed:" + WikiConstants.URL_CAPTCHA_VERIFIED_ERROR, e); } return false; } } return true; }
From source file:com.krawler.esp.handlers.AuthHandler.java
public static boolean chkHeirarchyPerm(HttpServletRequest req, String moduleName) throws ServiceException, JSONException, SessionExpiredException { boolean permsion = false; try {//from w w w . j a v a2 s . c o m JSONObject obj = new JSONObject(); String cmppref = req.getSession().getAttribute("companyPreferences").toString(); JSONObject jsnObj = new JSONObject(cmppref); if (StringUtil.equal(moduleName, "Lead")) { permsion = jsnObj.getBoolean("lead"); } else if (StringUtil.equal(moduleName, "Account")) { permsion = jsnObj.getBoolean("account"); } else if (StringUtil.equal(moduleName, "Contact")) { permsion = jsnObj.getBoolean("contact"); } else if (StringUtil.equal(moduleName, "Opportunity")) { permsion = jsnObj.getBoolean("opportunity"); } else if (StringUtil.equal(moduleName, "Cases")) { permsion = jsnObj.getBoolean("cases"); } else if (StringUtil.equal(moduleName, "Product")) { permsion = jsnObj.getBoolean("product"); } else if (StringUtil.equal(moduleName, "Activity")) { permsion = jsnObj.getBoolean("activity"); } else if (StringUtil.equal(moduleName, "Campaign")) { permsion = jsnObj.getBoolean("campaign"); } } catch (com.krawler.utils.json.base.JSONException e) { throw ServiceException.FAILURE("Auth.chkHeirarchyPerm", e); } return permsion; }
From source file:com.serotonin.m2m2.Common.java
public static User getUser(HttpServletRequest request) { // Check first to see if the user object is in the request. User user = (User) request.getAttribute(SESSION_USER); if (user != null) return user; // If not, get it from the session. user = (User) request.getSession().getAttribute(SESSION_USER); if (user != null) { // Add the user to the request. This prevents race conditions in which long-ish lasting requests have the // user object swiped from them by a quicker (logout) request. request.setAttribute(SESSION_USER, user); }/* w w w. j av a 2 s . c om*/ return user; }
From source file:com.ecyrd.jspwiki.attachment.AttachmentServlet.java
/** * Returns the mime type for this particular file. Case does not matter. * * @param ctx WikiContext; required to access the ServletContext of the request. * @param fileName The name to check for. * @return A valid mime type, or application/binary, if not recognized *//* w w w .ja va 2s . c o m*/ private static String getMimeType(WikiContext ctx, String fileName) { String mimetype = null; HttpServletRequest req = ctx.getHttpRequest(); if (req != null) { ServletContext s = req.getSession().getServletContext(); if (s != null) { mimetype = s.getMimeType(fileName.toLowerCase()); } } if (mimetype == null) { mimetype = "application/binary"; } return mimetype; }
From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java
/** * Returns a list of new resources in the specified folder or category folder depending on the request parameters.<p> * /*w w w . ja va 2s .co m*/ * @param cms the CmsObject to perform some operations * @param request the HttpServletRequest to get the needed request parameters * @return the list of new resources */ public static List getNewResources(CmsObject cms, HttpServletRequest request) { // get the current user's HHTP session //HttpSession session = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(); HttpSession session = request.getSession(); String startFolder = cms.getRequestContext().getFolderUri(); // get the required parameters String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL); String paramStartDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_STARTDATE); String paramEndDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ENDDATE); // parse the date Strings to long long startDate = Long.parseLong(paramStartDate); long endDate = Long.parseLong(paramEndDate); // create list of categories if selected List selectedCategoryList = new ArrayList(); paramAll = (paramAll == null) ? "false" : paramAll; if (!"true".equals(paramAll)) { // search individual categories selectedCategoryList = getCategoryList( (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST)); if (selectedCategoryList.size() == 0) { return new ArrayList(0); } } String openedCategories = CategoryTree.getTreeInfo(cms, CategoryTree.C_USER_INFO_OPENED_CATEGORIES, request); List openedCategoryList = CategoryTree.commaStringToList(openedCategories, CategoryTree.C_LIST_SEPARATOR); return getNewResourceList(cms, startFolder, startDate, endDate, selectedCategoryList, openedCategoryList); }
From source file:com.alkacon.opencms.v8.documentcenter.NewDocumentsTree.java
/** * Returns a list of new resources in the specified folder or category folder depending on the request parameters.<p> * // ww w . ja va 2s . c o m * @param cms the CmsObject to perform some operations * @param request the HttpServletRequest to get the needed request parameters * @return the list of new resources */ public static List<CmsResource> getNewResources(CmsObject cms, HttpServletRequest request) { // get the current user's HHTP session //HttpSession session = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(); HttpSession session = request.getSession(); String startFolder = cms.getRequestContext().getFolderUri(); // get the required parameters String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL); String paramStartDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_STARTDATE); String paramEndDate = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ENDDATE); // parse the date Strings to long long startDate = Long.parseLong(paramStartDate); long endDate = Long.parseLong(paramEndDate); // create list of categories if selected List<String> selectedCategoryList = new ArrayList<String>(); paramAll = (paramAll == null) ? "false" : paramAll; if (!"true".equals(paramAll)) { // search individual categories selectedCategoryList = getCategoryList( (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST)); if (selectedCategoryList.size() == 0) { return new ArrayList<CmsResource>(0); } } String openedCategories = CategoryTree.getTreeInfo(cms, CategoryTree.C_USER_INFO_OPENED_CATEGORIES, request); List<String> openedCategoryList = CategoryTree.commaStringToList(openedCategories, CategoryTree.C_LIST_SEPARATOR); return getNewResourceList(cms, startFolder, startDate, endDate, selectedCategoryList, openedCategoryList); }
From source file:fr.paris.lutece.plugins.extend.modules.comment.web.CommentApp.java
/** * Gets the view comment page.// w w w. j av a 2s . c o m * * @param request the request * @param strIdExtendableResource the str id extendable resource * @param strExtendableResourceType the str extendable resource type * @param strPostBackUrl The URL to use for post backs. * @return the view comment page */ public static String getViewCommentPageContent(HttpServletRequest request, String strIdExtendableResource, String strExtendableResourceType, String strPostBackUrl) { request.getSession().setAttribute(ExtendPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_POST_BACK_URL, strPostBackUrl); Integer nItemsPerPage = getDefaultItemsPerPage(); String strCurrentPageIndex = CommentConstants.CONSTANT_FIRST_PAGE_NUMBER; Boolean bIsAscSort = false; Object object = request.getSession().getAttribute(CommentConstants.SESSION_COMMENT_ITEMS_PER_PAGE); if (object != null) { nItemsPerPage = (Integer) object; } object = request.getSession().getAttribute(CommentConstants.SESSION_COMMENT_CURRENT_PAGE_INDEX); if (object != null) { strCurrentPageIndex = (String) object; } object = request.getSession().getAttribute(CommentConstants.SESSION_COMMENT_IS_ASC_SORT); if (object != null) { bIsAscSort = (Boolean) object; } String strSort = request.getParameter(CommentConstants.MARK_ASC_SORT); if (!StringUtils.isEmpty(strSort)) { bIsAscSort = Boolean.parseBoolean(strSort); } String strFromUrl = request.getParameter(CommentConstants.PARAMETER_FROM_URL); if (FROM_SESSION.equals(strFromUrl)) { strFromUrl = (String) request.getSession() .getAttribute(ExtendPlugin.PLUGIN_NAME + CommentConstants.PARAMETER_FROM_URL); } if (StringUtils.isEmpty(strFromUrl)) { strFromUrl = request.getHeader(CommentConstants.PARAMETER_REFERER); } if (strFromUrl != null) { strFromUrl = strFromUrl.replace(CONSTANT_AND, CONSTANT_AND_HTML); } request.getSession().setAttribute(ExtendPlugin.PLUGIN_NAME + CommentConstants.PARAMETER_FROM_URL, strFromUrl); strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, strCurrentPageIndex); int nOldITemsPerPage = nItemsPerPage; nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, nItemsPerPage, getDefaultItemsPerPage()); if (nItemsPerPage <= 0) { nItemsPerPage = getDefaultItemsPerPage(); } // If we changed the number of items per page, we go back to the first page if (nItemsPerPage != nOldITemsPerPage) { strCurrentPageIndex = CommentConstants.CONSTANT_FIRST_PAGE_NUMBER; } UrlItem urlSort = new UrlItem(strPostBackUrl); urlSort.addParameter(CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, strIdExtendableResource); urlSort.addParameter(CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType); urlSort.addParameter(CommentConstants.MARK_ASC_SORT, strSort); if (StringUtils.isNotEmpty(strFromUrl)) { urlSort.addParameter(CommentConstants.PARAMETER_FROM_URL, FROM_SESSION); } boolean bGetSubComments = false; boolean bUseBBCodeEditor = false; boolean bAllowSubComments = false; String strAdminBadge = StringUtils.EMPTY; CommentExtenderConfig config = getConfigService().find(CommentResourceExtender.EXTENDER_TYPE_COMMENT, strIdExtendableResource, strExtendableResourceType); if (config != null) { bGetSubComments = config.getAuthorizeSubComments(); bUseBBCodeEditor = config.getUseBBCodeEditor(); bAllowSubComments = config.getAuthorizeSubComments(); strAdminBadge = config.getAdminBadge(); } int nItemsOffset = nItemsPerPage * (Integer.parseInt(strCurrentPageIndex) - 1); List<Comment> listItems = getCommentService().findByResource(strIdExtendableResource, strExtendableResourceType, true, null, bIsAscSort, nItemsOffset, nItemsPerPage, bGetSubComments); int nItemsCount = getCommentService().getCommentNb(strIdExtendableResource, strExtendableResourceType, true, true); IPaginator<Comment> paginator = new LocalizedDelegatePaginator<Comment>(listItems, nItemsPerPage, urlSort.getUrl(), Paginator.PARAMETER_PAGE_INDEX, strCurrentPageIndex, nItemsCount, request.getLocale()); Map<String, Object> model = new HashMap<String, Object>(); model.put(CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, strIdExtendableResource); model.put(CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType); model.put(CommentConstants.MARK_PAGINATOR, paginator); model.put(CommentConstants.MARK_ASC_SORT, strSort); model.put(CommentConstants.PARAMETER_FROM_URL, strFromUrl); model.put(CommentConstants.PARAMETER_ID_COMMENT, request.getParameter(CommentConstants.PARAMETER_ID_COMMENT)); model.put(CommentConstants.MARK_USE_BBCODE, bUseBBCodeEditor); model.put(CommentConstants.MARK_ALLOW_SUB_COMMENTS, bAllowSubComments); model.put(CommentConstants.MARK_ADMIN_BADGE, strAdminBadge); model.put(CommentConstants.PARAMETER_POST_BACK_URL, strPostBackUrl); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_XPAGE_VIEW_COMMENTS, request.getLocale(), model); HttpSession session = request.getSession(); session.setAttribute(CommentConstants.SESSION_COMMENT_ITEMS_PER_PAGE, nItemsPerPage); session.setAttribute(CommentConstants.SESSION_COMMENT_CURRENT_PAGE_INDEX, strCurrentPageIndex); session.setAttribute(CommentConstants.SESSION_COMMENT_IS_ASC_SORT, bIsAscSort); return template.getHtml(); }