Example usage for javax.servlet.jsp PageContext getSession

List of usage examples for javax.servlet.jsp PageContext getSession

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext getSession.

Prototype


abstract public HttpSession getSession();

Source Link

Document

The current value of the session object (an HttpSession).

Usage

From source file:de.innovationgate.wgpublisher.bi.BiBase.java

public static String getPassword(javax.servlet.jsp.PageContext pageContext, String dbKey) throws WGException {

    Map hm = WGACore.getSessionLogins(pageContext.getSession());
    WGDatabase db = getDB(pageContext, dbKey);

    String domain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN);
    if (hm == null)
        return "";
    if (hm.isEmpty())
        return "";

    DBLoginInfo li = (DBLoginInfo) hm.get(domain);
    return li.getPassword();

}

From source file:de.innovationgate.wgpublisher.bi.BiBase.java

public static String getUsername(javax.servlet.jsp.PageContext pageContext, String dbKey, String format)
        throws WGException {

    Map hm = WGACore.getSessionLogins(pageContext.getSession());

    WGDatabase db = getDB(pageContext, dbKey);

    if (hm == null)
        return "";
    if (hm.isEmpty())
        return "";
    if (dbKey.equals(""))
        return "";

    String fullUsername = db.getSessionContext().getUser();

    WGFactory.getInstance().closeSessions();

    if (format != null) {
        if (format.equals("")) {
            return fullUsername;
        }//  w w  w .  ja va  2 s .  c  om
        if (format.equals("CN")) {
            int pos2 = fullUsername.indexOf("/");
            if (pos2 != -1) {
                return fullUsername.substring(3, pos2);
            } else {
                return fullUsername;
            }
        }
        return fullUsername;
    } else {
        return fullUsername;
    }

}

From source file:com.ecyrd.jspwiki.preferences.Preferences.java

/**
 *  This is an utility method which is called to make sure that the
 *  JSP pages do have proper access to any user preferences.  It should be
 *  called from the commonheader.jsp./*from w  ww . ja v a  2 s  .c  om*/
 *  <p>
 *  This method reads user cookie preferences and mixes them up with any
 *  default preferences (and in the future, any user-specific preferences)
 *  and puts them all in the session, so that they do not have to be rewritten
 *  again.
 *  <p>
 *  This method will remember if the user has already changed his prefs.
 *  
 *  @param pageContext The JSP PageContext.
 */
public static void setupPreferences(PageContext pageContext) {
    HttpSession session = pageContext.getSession();

    if (session.getAttribute(SESSIONPREFS) == null) {
        reloadPreferences(pageContext);
    }
}

From source file:com.ecyrd.jspwiki.preferences.Preferences.java

/**
 *  Returns a preference value programmatically.
 *  FIXME//from   w w  w.jav  a2  s. c  o  m
 *  
 *  @param pageContext
 *  @param name
 *  @return the preference value
 */
public static String getPreference(PageContext pageContext, String name) {
    Preferences prefs = (Preferences) pageContext.getSession().getAttribute(SESSIONPREFS);

    if (prefs != null)
        return prefs.get(name);

    return null;
}

From source file:com.liferay.portal.language.LanguageUtil.java

public static Locale getLocale(PageContext pageContext) {
    return (Locale) pageContext.getSession().getAttribute(Globals.LOCALE_KEY);
}

From source file:de.laures.cewolf.taglib.tags.ChartImgTag.java

/**
 * Build the image url/*from   ww  w . j  a  v  a2 s . c  o  m*/
 * @param renderer the url of the renderer
 * @param pageContext Page context
 * @param sessionKey The session key for the image stored.
 * @param width The width 
 * @param height The height
 * @param mimeType the mime-type (for example png) of it
 * @return The full url 
 */
public static String buildImgURL(String renderer, PageContext pageContext, String sessionKey, int width,
        int height, String mimeType, boolean forceSessionId, boolean removeAfterRender) {
    renderer = fixAbsolutURL(renderer, pageContext);
    final HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    StringBuffer url = new StringBuffer(response.encodeURL(renderer));
    if (url.toString().indexOf(WebConstants.SESSIONID_KEY) == -1) {
        if (forceSessionId) {
            final String sessionId = pageContext.getSession().getId();
            url.append(";" + WebConstants.SESSIONID_KEY + "=" + sessionId);
        }
    }
    url.append("?" + WebConstants.IMG_PARAM + "=" + sessionKey);
    url.append(WebConstants.AMPERSAND + WebConstants.WIDTH_PARAM + "=" + width);
    url.append(WebConstants.AMPERSAND + WebConstants.HEIGHT_PARAM + "=" + height);
    if (removeAfterRender) {
        url.append(WebConstants.AMPERSAND + WebConstants.REMOVE_AFTER_RENDERING + "=true");
    }
    url.append(WebConstants.AMPERSAND + "iehack=" + MIMEExtensionHelper.getExtensionForMimeType(mimeType));
    return url.toString();
}

From source file:de.laures.cewolf.storage.AbstractSessionStorage.java

public boolean contains(ChartImage cid, PageContext pageContext) {
    return pageContext.getSession().getAttribute(getKey(cid)) != null;
}

From source file:de.laures.cewolf.storage.AbstractSessionStorage.java

/**
 * @see de.laures.cewolf.Storage#storeChartImage(ChartImage, ServletContext)
 *//*  www  . ja  v  a 2s  .c om*/
public String storeChartImage(ChartImage cid, PageContext pageContext) throws CewolfException {
    if (contains(cid, pageContext)) {
        return getKey(cid);
    }
    log.debug("storing chart " + cid);
    final HttpSession session = pageContext.getSession();
    //String key = getKey(cid);
    return storeChartImage(cid, session);
}

From source file:mercury.tags.SetInitialLocale.java

@Override
public void doTag() throws JspException {
    try {//w  ww . j a  v  a 2  s  .  c  o m
        PageContext pageContext = (PageContext) getJspContext();

        if (pageContext.getServletContext().getAttribute("FIRST_EXECUTION") != null) {
            pageContext.getServletContext().removeAttribute("FIRST_EXECUTION");
            pageContext.getSession().removeAttribute("LAST_VISITED_PAGE");
            pageContext.getSession().removeAttribute("MESSAGE_TEXT");
            pageContext.getSession().removeAttribute("MESSAGE_LEVEL");
            pageContext.getSession().setAttribute("MESSAGE_TEXT", "DIALOG_VOID");
            pageContext.getSession().setAttribute("MESSAGE_LEVEL", "NORMAL");
        }

        String lastVisitedPage = (String) pageContext.getSession().getAttribute("LAST_VISITED_PAGE");
        if (lastVisitedPage == null || lastVisitedPage.trim().equals("")) {
            lastVisitedPage = errorJsp;
            pageContext.getSession().setAttribute("LAST_VISITED_PAGE", lastVisitedPage);
        }

        if ((String) pageContext.getSession().getAttribute("I18N") == null) {
            String locale = pageContext.getRequest().getLocale().toString();
            Properties languages = (Properties) pageContext.getServletContext().getAttribute("LANGUAGES");

            if (StringUtils.isNotBlank(locale) && languages.containsKey(locale)) {
                pageContext.getSession().setAttribute("I18N", locale);
            } else {
                pageContext.getSession().setAttribute("I18N", defaultLanguage);
            }
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        throw new JspException("[mercury.SetInitialLocale.doTag()] Exception: " + ex.getMessage());
    }
}

From source file:com.sslexplorer.input.tags.VariablesTag.java

/**
 * Method to generate the Replacement Variable Chooser Fragment.
 * //from   w  ww  .j ava2  s .com
 * @param titleKey
 * @param pageContext
 * @param bundle
 * @param locale
 * @param inputId
 * @param variables
 * @param includeSession
 * @param includeUserAttributes
 * @param includeRequest
 * @return String
 * @throws JspException
 */
public static String generateReplacementVariableChooserFragment(String titleKey, PageContext pageContext,
        String bundle, String locale, String inputId, String variables, boolean includeSession,
        boolean includeUserAttributes, boolean includeRequest) throws JspException {
    StringBuffer buf = new StringBuffer();

    String title = null;
    if (titleKey != null) {
        title = TagUtils.getInstance().message(pageContext, bundle, locale, titleKey, new String[] {});
    }
    if (title == null) {
        title = TagUtils.getInstance().message(pageContext, bundle, locale, "replacementVariablesChooser.title",
                new String[] {});
        if (title == null) {
            title = "Replacement Variables";
        }
    }
    buf.append("<div class=\"component_replacementVariablesToggle\">");

    // buf.append("<input type=\"button\"
    // onclick=\"toggleAndPositionBelow(document.getElementById('replacementVariablesChooser");
    // buf.append(inputId);
    // buf.append("'), document.getElementById('");
    // buf.append(inputId);
    // buf.append("'))\" ");
    // buf.append("value=\"${}\"/>");

    buf.append("<img onclick=\"togglePopupBelowLeft(document.getElementById('replacementVariablesChooser");
    buf.append(inputId);
    buf.append("'), document.getElementById('");
    buf.append(inputId);
    buf.append("'))\" ");
    buf.append("src=\"");
    buf.append(CoreUtil.getThemePath(pageContext.getSession()));
    buf.append("/images/variables.gif\"/>");

    buf.append("</div>");
    buf.append("<div id=\"replacementVariablesChooser");
    buf.append(inputId);
    buf.append("\" style=\"position:absolute;display: none;overflow:visible;top:4px;left:4px;z-index:900;\">");
    buf.append("<div class=\"replacementVariablesMain\">");
    buf.append("<div class=\"replacementVariablesTitleBar\">");
    buf.append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
    buf.append("<tr><td class=\"title\">");
    buf.append(title);
    buf.append("</td><td class=\"close\"><img src=\"");
    buf.append(CoreUtil.getThemePath(pageContext.getSession()));
    buf.append("/images/actions/erase.gif\" ");
    buf.append("onclick=\"document.getElementById('");
    buf.append(inputId);
    buf.append("').value = ''\"/><img src=\"");
    buf.append(CoreUtil.getThemePath(pageContext.getSession()));
    buf.append("/images/actions/closeReplacementVariables.gif\" ");
    buf.append("onclick=\"togglePopup(document.getElementById('replacementVariablesChooser");
    buf.append(inputId);
    buf.append("'))\"/>");
    buf.append("</td></tr></table></div><div class=\"replacementVariablesContent\">");
    buf.append("<ul>");
    if (variables != null) {
        StringTokenizer t = new StringTokenizer(variables, ",");
        while (t.hasMoreTokens()) {
            String n = t.nextToken();
            addVariable(n, n, buf, pageContext, bundle, locale, inputId);
        }
    }
    if (includeSession) {
        addVariable("session:username", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:password", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:email", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:fullname", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:clientProxyURL", null, buf, pageContext, bundle, locale, inputId);
    }

    if (includeRequest) {
        addVariable("request:serverName", null, buf, pageContext, bundle, locale, inputId);
        addVariable("request:serverPort", null, buf, pageContext, bundle, locale, inputId);
        addVariable("request:userAgent", null, buf, pageContext, bundle, locale, inputId);
    }

    if (includeUserAttributes) {
        Collection<PropertyDefinition> l;
        try {
            for (PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) {
                if (propertyClass instanceof AttributesPropertyClass
                        && !propertyClass.getName().equals(ResourceAttributes.NAME)) {
                    l = propertyClass.getDefinitions();
                    for (PropertyDefinition d : l) {
                        AttributeDefinition def = (AttributeDefinition) d;
                        if (def.isReplaceable()) {
                            addVariable(def.getPropertyClass().getName() + ":" + def.getName(),
                                    def.getDescription(), buf, pageContext, bundle, locale, inputId);
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("Failed to get user attribute definitions.");
        }
    }
    buf.append("</ul>");
    buf.append("</div>");
    buf.append("</div>");
    return buf.toString();
}