Example usage for javax.servlet.jsp PageContext getOut

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

Introduction

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

Prototype

abstract public JspWriter getOut();

Source Link

Document

The current value of the out object (a JspWriter).

Usage

From source file:com.acc.storefront.renderer.CMSLinkComponentRenderer.java

@Override
public void renderComponent(final PageContext pageContext, final CMSLinkComponentModel component)
        throws ServletException, IOException {
    try {//from   w  w w . j  av a  2s.  c o m
        final String url = getUrl(component);
        final String encodedUrl = UrlSupport.resolveUrl(url, null, pageContext);

        final JspWriter out = pageContext.getOut();

        if (encodedUrl == null || encodedUrl.isEmpty()) {
            // <span class="empty-nav-item">${component.linkName}</span>
            out.write("<span class=\"empty-nav-item\">");
            out.write(component.getLinkName());
            out.write("</span>");
        } else {
            // <a href="${encodedUrl}" ${component.styleAttributes} title="${component.linkName}" ${component.target == null || component.target == 'SAMEWINDOW' ? '' : 'target="_blank"'}>${component.linkName}</a>

            out.write("<a href=\"");
            out.write(encodedUrl);
            out.write("\" ");

            // Write additional attributes onto the link
            if (component.getStyleAttributes() != null) {
                out.write(component.getStyleAttributes());
            }

            out.write(" title=\"");
            out.write(component.getLinkName());
            out.write("\" ");

            if (component.getTarget() != null && !LinkTargets.SAMEWINDOW.equals(component.getTarget())) {
                out.write(" target=\"_blank\"");
            }
            out.write(">");
            out.write(component.getLinkName());
            out.write("</a>");
        }
    } catch (final JspException ignore) {
        // ignore
    }
}

From source file:de.hybris.platform.yacceleratorstorefront.renderer.CMSLinkComponentRenderer.java

@Override
public void renderComponent(final PageContext pageContext, final CMSLinkComponentModel component)
        throws ServletException, IOException {
    try {/*from  w w  w .  j  av a2  s.co  m*/
        final String url = getUrl(component);
        final String encodedUrl = UrlSupport.resolveUrl(url, null, pageContext);

        final JspWriter out = pageContext.getOut();

        if (encodedUrl == null || encodedUrl.isEmpty()) {
            // <span class="empty-nav-item">${component.linkName}</span>
            out.write("<span class=\"empty-nav-item\">");
            out.write(component.getLinkName());
            out.write("</span>");
        } else {
            // <a href="${encodedUrl}" ${component.styleAttributes}
            // title="${component.linkName}" ${component.target == null || component.target ==
            // 'SAMEWINDOW' ? '' : 'target="_blank"'}>${component.linkName}</a>

            out.write("<a href=\"");
            out.write(encodedUrl);
            out.write("\" ");

            // Write additional attributes onto the link
            if (component.getStyleAttributes() != null) {
                out.write(component.getStyleAttributes());
            }

            out.write(" title=\"");
            out.write(component.getLinkName());
            out.write("\" ");

            if (component.getTarget() != null && !LinkTargets.SAMEWINDOW.equals(component.getTarget())) {
                out.write(" target=\"_blank\"");
            }
            out.write(">");
            out.write(component.getLinkName());
            out.write("</a>");
        }
    } catch (final JspException ignore) {
        // ignore
    }
}

From source file:com.capgemini.b2bassets.storefront.renderer.CMSLinkComponentRenderer.java

@Override
public void renderComponent(final PageContext pageContext, final CMSLinkComponentModel component)
        throws ServletException, IOException {
    try {/*from w ww  .  j  a  v  a  2 s.  co m*/
        final String url = getUrl(component);
        final String encodedUrl = UrlSupport.resolveUrl(url, null, pageContext);

        final JspWriter out = pageContext.getOut();

        if (StringUtils.isNotBlank(component.getLinkName()) && StringUtils.isBlank(encodedUrl)) {
            // <span class="empty-nav-item">${component.linkName}</span>
            out.write("<span class=\"empty-nav-item\">");
            out.write(component.getLinkName());
            out.write("</span>");
        } else {
            // <a href="${encodedUrl}" ${component.styleAttributes} title="${component.linkName}"
            // ${component.target == null || component.target == 'SAMEWINDOW' ? '' : 'target="_blank"'}>${component.linkName}</a>

            out.write("<a href=\"");
            out.write(encodedUrl);
            out.write("\" ");

            // Write additional attributes onto the link
            if (component.getStyleAttributes() != null) {
                out.write(component.getStyleAttributes());
            }

            if (StringUtils.isNotBlank(component.getLinkName())) {
                out.write(" title=\"");
                out.write(component.getLinkName());
                out.write("\" ");
            }

            if (component.getTarget() != null && !LinkTargets.SAMEWINDOW.equals(component.getTarget())) {
                out.write(" target=\"_blank\"");
            }
            out.write(">");
            if (StringUtils.isNotBlank(component.getLinkName())) {
                out.write(component.getLinkName());
            }
            out.write("</a>");
        }
    } catch (final JspException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e);
        }
    }
}

From source file:de.hybris.platform.acceleratorservices.util.HtmlElementHelper.java

public void writeEndElement(final PageContext pageContext, final String elementName) {
    validateParameterNotNull(pageContext, "Parameter pageContext must not be null");
    validateParameterNotNull(elementName, "Parameter elementName must not be null");
    checkArgument(StringUtils.isNotBlank(elementName), "Parameter elementName must not be blank");

    final JspWriter out = pageContext.getOut();

    try {//  w  w  w  .j ava  2s  .c om
        out.write("</" + elementName + ">");
    } catch (final IOException e) {
        LOG.warn("Could not write end element: " + e.getMessage());
    }
}

From source file:de.hybris.platform.acceleratorservices.util.HtmlElementHelper.java

public void writeOpenElement(final PageContext pageContext, final String elementName,
        final Map<String, String> attributes) {
    validateParameterNotNull(pageContext, "Parameter pageContext must not be null");
    validateParameterNotNull(elementName, "Parameter elementName must not be null");
    checkArgument(StringUtils.isNotBlank(elementName), "Parameter elementName must not be blank");

    final JspWriter out = pageContext.getOut();

    try {// w ww.  ja va 2 s.  co  m
        out.write("<" + elementName);
        if (attributes != null && !attributes.isEmpty()) {
            for (final Map.Entry<String, String> entry : attributes.entrySet()) {
                // TODO: Correct escaping
                out.write(" " + entry.getKey() + "=\"" + entry.getValue() + "\"");
            }
        }
        out.write(">");
        out.write("\n");
    } catch (final IOException e) {
        LOG.warn("Could not write open element: " + e.getMessage());
    }
}

From source file:dk.netarkivet.archive.webinterface.BatchGUI.java

/**
 * Method for creating the page for a batchjob. It contains the following informations:
 * <p>//from w w  w  .  ja v  a  2s .c  o m
 * <br/>
 * - Creates a line with the name of the batchjob.<br/>
 * - Write the description if the batchjob has a metadata resource annotation description of the batchjob class.<br/>
 * - The last run information, date and size of the error and output files. <br/>
 * - The arguments of the batchjob, with information if they have been defined in the resource annotations of the
 * class.<br/>
 * - Radio buttons for choosing the replica.<br/>
 * - Input box for regular expression for filenames to match.<br/>
 * - Execution button.<br/>
 *
 * @param context The context of the page. Must contains a class name of the batchjob.
 * @throws UnknownID If the class cannot be found.
 * @throws ArgumentNotValid If the context is null.
 * @throws IllegalState If the class is not an instance of FileBatchJob.
 * @throws ForwardedToErrorPage If the context does not contain the required information.
 * @throws IOFailure If there is problems with the JspWriter.
 */
@SuppressWarnings("rawtypes")
public static void getPageForClass(PageContext context)
        throws UnknownID, ArgumentNotValid, IllegalState, ForwardedToErrorPage, IOFailure {
    ArgumentNotValid.checkNotNull(context, "PageContext context");

    HTMLUtils.forwardOnEmptyParameter(context, Constants.BATCHJOB_PARAMETER);

    try {
        // Retrieve variables
        Locale locale = context.getResponse().getLocale();
        ServletRequest request = context.getRequest();
        String className = request.getParameter(Constants.BATCHJOB_PARAMETER);
        JspWriter out = context.getOut();

        // retrieve the batch class and the constructor.
        Class c = getBatchClass(className);

        out.print(I18N.getString(locale, "batchpage;Name.of.batchjob", new Object[] {}) + ": <b>" + c.getName()
                + "</b><br/>\n");
        out.print(getClassDescription(c, locale));
        out.print(getPreviousRuns(c.getName(), locale));

        // begin form
        out.println("<form method=\"post\" action=\"" + Constants.URL_BATCHJOB_EXECUTE + "?"
                + Constants.BATCHJOB_PARAMETER + "=" + className + "\">");

        out.print(getHTMLarguments(c, locale));
        out.print(getReplicaRadioButtons(locale));
        out.print(getRegularExpressionInputBox(locale));
        out.print(getSubmitButton(locale));

        // end form
        out.print("</form>");
    } catch (IOException e) {
        String errMsg = "Could not create page with batchjobs.";
        log.warn(errMsg, e);
        throw new IOFailure(errMsg, e);
    }
}

From source file:com.orange.wro.taglib.tag.OptionalScriptTag.java

@Override
public void doTag() throws JspException, IOException {

    WroConfig conf = WroConfig.getInstance();
    PageContext context = (PageContext) getJspContext();
    StringBuilder builder = new StringBuilder();

    Object lessObj = context.getRequest().getAttribute(WroTagLibConstants.LESS_INJECTED);
    boolean isLessNeeded = lessObj == null ? false : (Boolean) lessObj;

    if (isLessNeeded) {
        logger.debug("Writing LESS JS to output for client side compilation.");
        writeScript(context, builder, conf.getOptions().getLessJsPath());
    }/*from   w w  w .  j av a2 s  . com*/

    context.getOut().append(builder);
}

From source file:com.exxonmobile.ace.hybris.storefront.renderer.CMSLinkComponentRenderer.java

@Override
public void renderComponent(final PageContext pageContext, final CMSLinkComponentModel component)
        throws ServletException, IOException {
    try {/*  www.j ava  2 s  .com*/
        final String url = getUrl(component);
        final String encodedUrl = UrlSupport.resolveUrl(url, null, pageContext);

        // <a href="${encodedUrl}" title="${component.linkName}" ${component.target == null || component.target == 'SAMEWINDOW' ? '' : 'target="_blank"'}>${component.linkName}</a>

        final JspWriter out = pageContext.getOut();
        out.write("<a href=\"");
        out.write(encodedUrl);
        out.write("\" title=\"");
        out.write(component.getLinkName());
        if (component.getTarget() != null && !LinkTargets.SAMEWINDOW.equals(component.getTarget())) {
            out.write("\" target=\"_blank");
        }
        out.write("\">");
        out.write(component.getLinkName());
        out.write("</a>");
    } catch (final JspException ignore) {
        // ignore
    }
}

From source file:com.glaf.core.tag.TagUtils.java

/**
 * Write the specified text as the response to the writer associated with
 * this page. <strong>WARNING</strong> - If you are writing body content
 * from the <code>doAfterBody()</code> method of a custom tag class that
 * implements <code>BodyTag</code>, you should be calling
 * <code>writePrevious()</code> instead.
 * /* ww w  .ja  v  a2s  . co m*/
 * @param pageContext
 *            The PageContext object for this page
 * @param text
 *            The text to be written
 * @throws JspException
 *             if an input/output error occurs (already saved)
 */
public void write(PageContext pageContext, String text) throws JspException {
    JspWriter writer = pageContext.getOut();

    try {
        writer.print(text);
    } catch (IOException e) {
        saveException(pageContext, e);
        throw new JspException(messages.getMessage("write.io", e.toString()));
    }
}

From source file:com.glaf.core.tag.TagUtils.java

/**
 * Write the specified text as the response to the writer associated with
 * the body content for the tag within which we are currently nested.
 * /*from  w w w  . j a  v  a2  s . c  o m*/
 * @param pageContext
 *            The PageContext object for this page
 * @param text
 *            The text to be written
 * @throws JspException
 *             if an input/output error occurs (already saved)
 */
public void writePrevious(PageContext pageContext, String text) throws JspException {
    JspWriter writer = pageContext.getOut();

    if (writer instanceof BodyContent) {
        writer = ((BodyContent) writer).getEnclosingWriter();
    }

    try {
        writer.print(text);
    } catch (IOException e) {
        saveException(pageContext, e);
        throw new JspException(messages.getMessage("write.io", e.toString()));
    }
}