Example usage for javax.servlet.jsp JspWriter write

List of usage examples for javax.servlet.jsp JspWriter write

Introduction

In this page you can find the example usage for javax.servlet.jsp JspWriter write.

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

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

/**
 * Method for executing a batchjob./*from   ww  w. ja v a  2 s .com*/
 *
 * @param context The page context containing the needed information for executing the batchjob.
 */
@SuppressWarnings("rawtypes")
public static void execute(PageContext context) {
    try {
        ServletRequest request = context.getRequest();

        // get parameters
        String filetype = request.getParameter(Constants.FILETYPE_PARAMETER);
        String jobId = request.getParameter(Constants.JOB_ID_PARAMETER);
        String jobName = request.getParameter(Constants.BATCHJOB_PARAMETER);
        String repName = request.getParameter(Constants.REPLICA_PARAMETER);

        FileBatchJob batchjob;

        // Retrieve the list of arguments.
        List<String> args = new ArrayList<String>();
        String arg;
        Integer i = 1;
        // retrieve the constructor to find out how many arguments
        Class c = getBatchClass(jobName);
        Constructor con = findStringConstructor(c);

        // retrieve the arguments and put them into the list.
        while (i <= con.getParameterTypes().length) {
            arg = request.getParameter("arg" + i.toString());
            if (arg != null) {
                args.add(arg);
            } else {
                log.warn("Should contain argument number " + i + ", but "
                        + "found a null instead, indicating missing " + "argument. Use empty string instead.");
                args.add("");
            }
            i++;
        }

        File jarfile = getJarFile(jobName);
        if (jarfile == null) {
            // get the constructor and instantiate it.
            Constructor construct = findStringConstructor(getBatchClass(jobName));
            batchjob = (FileBatchJob) construct.newInstance(args.toArray());
        } else {
            batchjob = new LoadableJarBatchJob(jobName, args, jarfile);
        }

        // get the regular expression.
        String regex = jobId + "-";
        if (filetype.equals(BatchFileType.Metadata.toString())) {
            regex += Constants.REGEX_METADATA;
        } else if (filetype.equals(BatchFileType.Content.toString())) {
            // TODO fix this 'content' regex. (NAS-1394)
            regex += Constants.REGEX_CONTENT;
        } else {
            regex += Constants.REGEX_ALL;
        }

        // validate the regular expression (throws exception if wrong).
        Pattern.compile(regex);

        Replica rep = Replica.getReplicaFromName(repName);

        new BatchExecuter(batchjob, regex, rep).start();

        JspWriter out = context.getOut();
        out.write("Executing batchjob with the following parameters. " + "<br/>\n");
        out.write("BatchJob name: " + jobName + "<br/>\n");
        out.write("Replica: " + rep.getName() + "<br/>\n");
        out.write("Regular expression: " + regex + "<br/>\n");
    } catch (Exception e) {
        throw new IOFailure("Could not instantiate the batchjob.", e);
    }
}

From source file:com.siemens.sw360.portal.tags.links.DisplayDownloadAttachment.java

@Override
public int doStartTag() throws JspException {
    try {/*from ww w . ja v a 2  s. c o m*/
        JspWriter jspWriter = pageContext.getOut();
        jspWriter.write("<a href='");

        resourceUrl(pageContext).withParam(PortalConstants.ACTION, PortalConstants.ATTACHMENT_DOWNLOAD)
                .withParam(PortalConstants.ATTACHMENT_ID, id).writeUrlToJspWriter();

        jspWriter
                .write(format("'><img src='%s/images/downloadEnable.jpg' alt='Download%s' title='Download%s'/>",
                        getContext(), name, name));
        jspWriter.write("</a>");
    } catch (Exception e) {
        throw new JspException(e);
    }

    return SKIP_BODY;
}

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 {/*from  w  w w  . j a va 2  s . co m*/
        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.redhat.rhn.frontend.taglibs.ToolTipTag.java

/**
 * {@inheritDoc}/*from   w ww  .  j  a  v a2s.c o m*/
 */
public int doEndTag() throws JspException {
    JspWriter writer = pageContext.getOut();
    try {
        writer.write("</p>");
    } catch (IOException e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}

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 {//from ww w  .  ja  v a  2s.c  om
        out.write("</" + elementName + ">");
    } catch (final IOException e) {
        LOG.warn("Could not write end element: " + e.getMessage());
    }
}

From source file:com.redhat.rhn.frontend.taglibs.ToolTipTag.java

/**
 * {@inheritDoc}//  ww  w .jav a 2 s  .c om
 */
@Override
public int doStartTag() throws JspException {
    LocalizationService ls = LocalizationService.getInstance();
    HtmlTag strong = new HtmlTag("strong");
    strong.addBody(ls.getMessage(geTypeKey()) + ": ");

    JspWriter writer = pageContext.getOut();
    try {
        writer.write("<p class=\"small-text\">");
        writer.write(strong.render());
        if (!StringUtils.isBlank(key)) {
            writer.write(ls.getMessage(key));
        }
        return EVAL_BODY_INCLUDE;
    } catch (IOException e) {
        throw new JspException(e);
    }

}

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 {//from ww w. j a v  a  2 s .  c  o  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:org.lanark.jsr303js.taglib.JSR303JSValidateTag.java

public int doEndTag() throws JspException {
    try {/*ww  w .  j a v  a2s . c  o m*/
        List<ValidationMetaData> rules = new ArrayList<ValidationMetaData>();
        if (commandName != null) {
            rules.addAll(getValidationMetaDataForCommand());
        }
        String bodyString = null;
        if (bodyContent != null) {
            // body can be a JSON object, specifying date formats, or other extra configuration info
            bodyString = FileCopyUtils.copyToString(bodyContent.getReader());
            bodyString = bodyString.trim().replaceAll("\\s{2,}", " ");
        }

        JspWriter out = pageContext.getOut();
        out.write("<script type=\"text/javascript\" id=\"");
        out.write(commandName + "JSR303JSValidator");
        out.write("\">");
        generator.generateJavaScript(out, commandName, true, bodyString, rules, new MessageSourceAccessor(
                getRequestContext().getWebApplicationContext(), getRequestContext().getLocale()));
        out.write("</script>");
        return EVAL_PAGE;
    } catch (IOException e) {
        throw new JspException("Could not write validation rules", e);
    }
}

From source file:org.springmodules.validation.valang.javascript.taglib.ValangValidateTag.java

public int doEndTag() throws JspException {
    try {/*from   w w w  . j a  va2  s  .  c o m*/
        Collection rules = new ArrayList();
        if (commandName != null) {
            rules.addAll(getRulesForCommand());
        }
        if (bodyContent != null) {
            rules.addAll(parseRulesFromBodyContent());
        }
        if (rules.size() == 0) {
            throw new JspException("no valang validation rules were found");
        }

        JspWriter out = pageContext.getOut();
        out.write("<script type=\"text/javascript\" id=\"");
        out.write(commandName + "ValangValidator");
        out.write("\">");
        translator.writeJavaScriptValangValidator(out, commandName, true, rules, new MessageSourceAccessor(
                getRequestContext().getWebApplicationContext(), getRequestContext().getLocale()));
        out.write("</script>");
        return EVAL_PAGE;
    } catch (IOException e) {
        throw new JspException("Could not write validation rules", e);
    }
}

From source file:com.redhat.rhn.frontend.configuration.tags.ConfigChannelTag.java

/**
 * {@inheritDoc}//from   w  w  w .j  av a2  s.  c om
 */
public int doEndTag() throws JspException {
    StringBuilder result = new StringBuilder();
    if (nolink || id == null) {
        result.append(writeIcon());
        result.append(name);
    } else {
        result.append("<a href=\"" + ConfigChannelTag.makeConfigChannelUrl(id) + "\">");
        result.append(writeIcon());
        result.append(StringEscapeUtils.escapeXml(name) + "</a>");
    }
    JspWriter writer = pageContext.getOut();
    try {
        writer.write(result.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }
    return BodyTagSupport.SKIP_BODY;
}