Example usage for javax.servlet.jsp PageContext getRequest

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

Introduction

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

Prototype


abstract public ServletRequest getRequest();

Source Link

Document

The current value of the request object (a ServletRequest).

Usage

From source file:org.kuali.mobility.tags.PageTag.java

/**
 * Returns the current platform.//w  w  w. j a va 2  s .co m
 * If the platform was set on the tag, that platform will be used, else
 * the platform detected by the {@link org.kuali.mobility.shared.interceptors.NativeCookieInterceptor}
 * will be used
 *
 * @return the platform
 */
public String getPlatform() {
    PageContext pageContext = (PageContext) getJspContext();
    HttpServletRequest hsr = (HttpServletRequest) pageContext.getRequest();
    String plat = (String) hsr.getSession(true).getAttribute(NativeCookieInterceptor.SESSION_PLATFORM);
    return StringUtils.isEmpty(this.platform) ? plat : this.platform;
}

From source file:org.kuali.mobility.tags.PageTag.java

/**
 * Returns the current phonegap version.
 * If the phonegap version was set on the tag, that version will be used, else
 * the version detected by the {@link org.kuali.mobility.shared.interceptors.NativeCookieInterceptor}
 * will be used.//from   ww  w.j  av a  2s.c  o m
 *
 * @return The phonegap version
 */
public String getPhonegap() {
    PageContext pageContext = (PageContext) getJspContext();
    HttpServletRequest hsr = (HttpServletRequest) pageContext.getRequest();
    String cor = (String) hsr.getSession(true).getAttribute(NativeCookieInterceptor.SESSION_PHONEGAP);
    return StringUtils.isEmpty(this.phonegap) ? cor : this.phonegap;
}

From source file:org.kuali.mobility.writer.tags.ArticleImageTag.java

public void doTag() {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String contextPath = request.getContextPath();
    ServletContext servletContext = pageContext.getServletContext();
    WebApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    IconsService iconService = (IconsService) ac.getBean("iconsService");

    String thumbNailPath;/*from   w ww. j a  va2s.  c o  m*/
    String fullPath = null;
    final String instanceURL = contextPath + prefix + instance;
    /*
     * First check if the article exits, and it has image media.
     * If it does not exist or has no image, we need to use
     * the default image for that instance of the tool
     */
    if (article == null || article.getImage() == null || article.getImage().getId() == 0) {

        /*
         * Check if there is an icon themed for this instance of the writer tool
         */
        if (StringUtils.isEmpty(instance) && iconService.getIcon(WRITER_ICON_NAME, instance) != null) {
            thumbNailPath = contextPath + "/getIcon/" + WRITER_ICON_NAME + "-" + instance + "-80@2.png";
        } else {
            thumbNailPath = contextPath + "/getIcon/WriterArticle-80@2.png";
        }
    } else {
        thumbNailPath = instanceURL + "/media/" + article.getImage().getId() + "?thumb=1";
        fullPath = instanceURL + "/media/view/" + article.getImage().getId();
    }
    boolean addLink = (wrapLink && fullPath != null);
    boolean isNative = (Boolean) request.getSession(true).getAttribute(NativeCookieInterceptor.SESSION_NATIVE);
    try {
        // Wrap with link if required
        if (addLink && isNative) {
            String serverPath = request.getScheme() + "://" + request.getServerName();
            if (request.getServerPort() != 80) {
                serverPath += ":" + request.getServerPort();
            }
            serverPath += fullPath;
            writeChildBrowserJS(out, serverPath);
        } else if (addLink) {
            out.print("<a href=\"");
            out.print(fullPath);
            out.print("\">");
        }

        // Put image container
        out.print("<img src=\"");
        out.print(thumbNailPath);
        out.print("\"");

        // Add image id if specified
        if (this.id != null) {
            out.print(" id=\"");
            out.print(this.id);
            out.print("\"");
        }

        // Add style if specified
        if (this.style != null) {
            out.print(" style=\"");
            out.print(this.style);
            out.print("\"");
        }

        out.print(" />");

        // Close wrapping link
        if (addLink) {
            out.print("</a>");
        }
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:org.opencms.jsp.CmsJspTagContentShow.java

/**
 * Internal action method to show an element from a XML content document.<p>
 * /*from  w ww .j a va 2  s. c o m*/
 * @param container the content container to read the XML content from
 * @param context the current JSP page context
 * @param element the node name of the element to show
 * @param locale the locale of the element to show
 * @param escape if the result html should be escaped or not
 * 
 * @return the value of the selected content element
 */
public static String contentShowTagAction(I_CmsXmlContentContainer container, PageContext context,
        String element, Locale locale, boolean escape) {

    // get the current users OpenCms context
    CmsObject cms = CmsFlexController.getCmsObject(context.getRequest());

    // get loaded content from content container
    I_CmsXmlDocument xmlContent = container.getXmlDocument();

    if (CmsStringUtil.isEmpty(element)) {
        element = container.getXmlDocumentElement();
    } else {
        element = CmsXmlUtils.concatXpath(container.getXmlDocumentElement(), element);
    }

    String content;
    if (CmsMacroResolver.isMacro(element)) {
        // this is a macro, initialize a macro resolver
        String resourcename = CmsJspTagResourceLoad.getResourceName(cms, container);
        CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(cms).setJspPageContext(context)
                .setResourceName(resourcename).setKeepEmptyMacros(true);
        // resolve the macro
        content = resolver.resolveMacros(element);
    } else if (xmlContent == null) {
        // no XML content- no output
        content = null;
    } else {

        // determine the locale to display
        if (locale == null) {
            // no locale was set, use default from parent tag (usually "contentload")
            locale = container.getXmlDocumentLocale();
        }
        // now get the content element value to display

        if (xmlContent.hasValue(element, locale)) {
            try {
                // read the element from the content
                content = xmlContent.getStringValue(cms, element, locale);
            } catch (Exception e) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_CONTENT_SHOW_1, element), e);
                content = null;
            }
        } else {
            content = null;
        }

        // make sure that no null String is returned
        if (content == null) {
            content = CmsMessages.formatUnknownKey(element);
        }
        if (escape) {
            // HTML escape the value 
            content = CmsEncoder.escapeHtml(content);
        }
    }

    return content;
}

From source file:org.opencms.jsp.CmsJspTagEditable.java

/**
 * Editable action method.<p>/* w  w w  .  ja  va 2s.  c  o  m*/
 * 
 * @param context the current JSP page context
 * @param provider the class name of the direct edit privider to use (may be <code>null</code>, which means use the default)
 * @param mode the direct edit mode to use (may be <code>null</code>, which means current use mode on page)
 * @param fileName optional filename parameter for the direct edit provider (may be <code>null</code>, which means use the default)
 * 
 * @throws JspException in case something goes wrong
 */
public static void editableTagAction(PageContext context, String provider, CmsDirectEditMode mode,
        String fileName) throws JspException {

    if (mode == CmsDirectEditMode.FALSE) {
        // direct edit is turned off
        return;
    }

    ServletRequest req = context.getRequest();
    if (CmsHistoryResourceHandler.isHistoryRequest(req)) {
        // don't display direct edit buttons on an historical resource
        return;
    }

    CmsFlexController controller = CmsFlexController.getController(req);
    CmsObject cms = controller.getCmsObject();

    if (cms.getRequestContext().getCurrentProject().isOnlineProject()) {
        // direct edit is never enabled in the online project
        return;
    }

    if (CmsResource.isTemporaryFileName(cms.getRequestContext().getUri())) {
        // don't display direct edit buttons if a temporary file is displayed
        return;
    }

    I_CmsDirectEditProvider eb = getDirectEditProvider(context);
    if (eb == null) {
        if (CmsStringUtil.isNotEmpty(fileName) && CmsStringUtil.isEmpty(provider)) {
            // if only a filename but no provider class is given, use JSP includes for backward compatibility
            provider = CmsDirectEditJspIncludeProvider.class.getName();
        }
        // no provider available in page context
        if (CmsStringUtil.isNotEmpty(provider)) {
            try {
                // create a new instance of the selected provider
                eb = (I_CmsDirectEditProvider) Class.forName(provider).newInstance();
            } catch (Exception e) {
                // log error
                LOG.error(Messages.get().getBundle().key(Messages.ERR_DIRECT_EDIT_PROVIDER_1, provider), e);
            }
        }
        if (eb == null) {
            // use configured direct edit provider as a fallback
            eb = OpenCms.getWorkplaceManager().getDirectEditProvider();
        }
        if (mode == null) {
            // use automatic placement by default
            mode = CmsDirectEditMode.AUTO;
        }
        eb.init(cms, mode, fileName);
        // store the provider in the page context
        setDirectEditProvider(context, eb);
    }
    if (eb.isManual(mode)) {
        // manual mode, insert required HTML
        CmsDirectEditParams params = getDirectEditProviderParams(context);
        if (params != null) {
            // insert direct edit start HTML
            eb.insertDirectEditStart(context, params);
        } else {
            // insert direct edit end HTML
            eb.insertDirectEditEnd(context);
        }
    } else {
        // insert direct edit header HTML
        eb.insertDirectEditIncludes(context, new CmsDirectEditParams(cms.getRequestContext().getUri()));
    }
}

From source file:org.opencms.jsp.CmsJspTagEditable.java

/**
 * Returns the current initialized instance of the direct edit provider.<p>
 * /*from   w  ww.  j a v  a2 s .c o  m*/
 * @param context the current JSP page context
 * 
 * @return the current initialized instance of the direct edit provider
 */
public static I_CmsDirectEditProvider getDirectEditProvider(PageContext context) {

    // get the direct edit provider from the request attributes
    return (I_CmsDirectEditProvider) context.getRequest()
            .getAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER);
}

From source file:org.opencms.jsp.CmsJspTagEditable.java

/**
 * Returns the current initialized instance of the direct edit provider parameters from the given page context.<p>
 * /*from w w w.  j a va 2s  .c om*/
 * Also removes the parameters from the given page context.<p>
 * 
 * @param context the current JSP page context
 * 
 * @return the current initialized instance of the direct edit provider parameters
 */
protected static CmsDirectEditParams getDirectEditProviderParams(PageContext context) {

    // get the current request
    ServletRequest req = context.getRequest();
    // get the direct edit params from the request attributes
    CmsDirectEditParams result = (CmsDirectEditParams) req
            .getAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS);
    if (result != null) {
        req.removeAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS);
    }
    return result;
}

From source file:org.opencms.jsp.CmsJspTagEditable.java

/**
 * Sets the current initialized instance of the direct edit provider.<p>
 * /*from w  ww.  ja va 2s.com*/
 * @param context the current JSP page context
 * 
 * @param provider the current initialized instance of the direct edit provider to set
 */
protected static void setDirectEditProvider(PageContext context, I_CmsDirectEditProvider provider) {

    // set the direct edit provider as attribute to the request
    context.getRequest().setAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER, provider);
}

From source file:org.opencms.jsp.CmsJspTagEditable.java

/**
 * Sets the current initialized instance of the direct edit provider parameters to the page context.<p>
 * //from  w  ww.  j ava2s  .  co m
 * @param context the current JSP page context
 * @param params the current initialized instance of the direct edit provider parameters to set
 */
protected static void setDirectEditProviderParams(PageContext context, CmsDirectEditParams params) {

    // set the direct edit params as attribute to the request
    context.getRequest().setAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS, params);
}

From source file:org.opencms.jsp.CmsJspTagParse.java

/**
 * Internal action method.<p>/*from  w ww  .ja v a2 s. com*/
 * 
 * Parses (and potentially transforms) a HTMl content block.<p>
 * 
 * @param content the content to be parsed / transformed
 * @param context needed for getting the encoding / the locale
 * @param parser the visitor / parser to use
 * 
 * @return the transformed content
 */
public String parseTagAction(String content, PageContext context, A_CmsConfiguredHtmlParser parser) {

    String result = null;
    CmsRequestContext cmsContext = CmsFlexController.getCmsObject(context.getRequest()).getRequestContext();

    if (parser == null) {
        if (LOG.isErrorEnabled()) {
            LOG.error(Messages.get().getBundle(cmsContext.getLocale()).key(
                    Messages.GUI_ERR_TAG_ATTRIBUTE_MISSING_2, new Object[] { TAG_NAME, ATT_VISITOR_CLASS }));
        }
        result = content;
    } else {

        String encoding = cmsContext.getEncoding();
        try {
            result = parser.doParse(content, encoding, m_noAutoCloseTags);

        } catch (ParserException pex) {

            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle(cmsContext.getLocale()).key(Messages.ERR_PROCESS_TAG_1,
                        new Object[] { TAG_NAME }), pex);
            }
            StringWriter stackTrace = new StringWriter();
            PrintWriter writer = new PrintWriter(new StringWriter());
            StringBuffer msg = new StringBuffer("<!--\n").append(pex.getLocalizedMessage()).append("\n");
            pex.printStackTrace(writer);
            msg.append(stackTrace.toString()).append("\n-->");
            result = msg.toString();
        } catch (CmsException cmex) {
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle(cmsContext.getLocale()).key(Messages.ERR_PROCESS_TAG_1,
                        new Object[] { TAG_NAME }), cmex);
            }
            StringWriter stackTrace = new StringWriter();
            PrintWriter writer = new PrintWriter(new StringWriter());
            StringBuffer msg = new StringBuffer("<!--\n").append(cmex.getLocalizedMessage()).append("\n");
            cmex.printStackTrace(writer);
            msg.append(stackTrace.toString()).append("\n-->");
            result = msg.toString();
        }

    }
    return result;
}