Example usage for javax.servlet.jsp JspWriter print

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

Introduction

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

Prototype


abstract public void print(Object obj) throws IOException;

Source Link

Document

Print an object.

Usage

From source file:org.apache.pluto.driver.tags.PortletModeDropDownTag.java

/**
 * Method invoked when the start tag is encountered.
 * @throws JspException  if an error occurs.
 *//*from   w w w  .  j a v  a2  s. com*/
public int doStartTag() throws JspException {

    // Ensure that the modeAnchor tag resides within a portlet tag.
    PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
    if (parentTag == null) {
        throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag.");
    }

    portletId = parentTag.getPortletId();
    // Evaluate portlet ID attribute.
    evaluatePortletId();

    // Retrieve the portlet window config for the evaluated portlet ID.
    ServletContext servletContext = pageContext.getServletContext();
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext
            .getAttribute(AttributeKeys.DRIVER_CONFIG);

    // Retrieve the portal environment.
    PortalRequestContext portalEnv = PortalRequestContext
            .getContext((HttpServletRequest) pageContext.getRequest());

    //find the current mode for use in 'selected' attrib of select option
    PortalURL requestedPortalUrl = portalEnv.getRequestedPortalURL();
    PortletWindowConfig windowConfig = PortletWindowConfig.fromId(evaluatedPortletId);
    // Retrieve the portlet container from servlet context.
    PortletContainer container = (PortletContainer) servletContext
            .getAttribute(AttributeKeys.PORTLET_CONTAINER);

    // Create the portlet window to render.
    PortletWindow window = new PortletWindowImpl(container, windowConfig, requestedPortalUrl);

    PortletMode currentMode = requestedPortalUrl.getPortletMode(window.getId().getStringId());

    //start the markup
    StringBuffer tag = new StringBuffer();
    //        String strCurrentMode = currentMode.toString();        
    //        tag.append("Current mode: " + currentMode.toString());
    tag.append(
            "<form action=\"\" name=\"modeSelectionForm\" style=\"display:inline\"><select onchange=\"self.location=this.options[this.selectedIndex].value\">");
    Set<PortletMode> modeSet = null;
    try {
        modeSet = driverConfig.getSupportedPortletModes(evaluatedPortletId);
    } catch (PortletContainerException e) {
        throw new JspException(e);
    }

    if (modeSet != null) {
        Iterator<PortletMode> i = modeSet.iterator();
        while (i.hasNext()) {
            PortletMode mode = i.next();

            PortalURL portalUrl = portalEnv.createPortalURL();
            portalUrl.setPortletMode(evaluatedPortletId, mode);

            // Build a string buffer containing the anchor tag
            tag.append("<option value=\"" + portalUrl.toString() + "\"");
            //Add 'selected' attribute for current mode.
            if (mode.equals(currentMode)) {
                tag.append(" selected=\"true\"");
            }
            tag.append(">");
            if (driverConfig.isPortletManagedMode(evaluatedPortletId, mode.toString())) {
                tag.append(getCustomModeDecorationName(driverConfig, mode));
            } else {
                tag.append(mode.toString().toUpperCase());
            }
            //               tag.append(mode.toString().toUpperCase());
            tag.append("</option>");
        }
    }
    tag.append("</select></form>");
    // Print the mode anchor tag.
    try {
        JspWriter out = pageContext.getOut();
        out.print(tag.toString());
    } catch (IOException ex) {
        throw new JspException(ex);
    }

    // Continue to evaluate the tag body.
    return EVAL_BODY_INCLUDE;
}

From source file:info.magnolia.cms.taglibs.Out.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///from www  .j av  a 2 s . co  m
public int doEndTag() {
    // don't reset any value set using a tag attribute here, or it will break any container that does tag pooling!

    Content contentNode = getFirtMatchingNode();
    if (contentNode == null) {
        return EVAL_PAGE;
    }

    NodeData nodeData = contentNode.getNodeData(this.nodeDataName);

    if (!nodeData.isExist()) {
        return EVAL_PAGE;
    }

    String value = null;
    int type = nodeData.getType();

    switch (type) {
    case PropertyType.DATE:

        Date date = nodeData.getDate().getTime();
        if (date != null) {
            if (this.dateLanguage == null) {
                value = DateFormatUtils.formatUTC(date, this.datePattern);
            } else {
                value = DateFormatUtils.formatUTC(date, this.datePattern, new Locale(this.dateLanguage));
            }
        }
        break;

    case PropertyType.BINARY:
        value = this.getFilePropertyValue(contentNode);
        break;

    default:
        value = StringUtils.isEmpty(this.lineBreak) ? nodeData.getString() : nodeData.getString(this.lineBreak);
        // replace internal links
        value = LinkUtil.convertUUIDsToRelativeLinks(value,
                Resource.getActivePage((HttpServletRequest) pageContext.getRequest())); // static actpage
        break;
    }

    if (var != null) {
        // set result as a variable
        pageContext.setAttribute(var, value, scope);
    } else if (value != null) {
        JspWriter out = pageContext.getOut();
        try {
            out.print(value);
        } catch (IOException e) {
            // should never happen
            throw new NestableRuntimeException(e);
        }
    }

    return EVAL_PAGE;
}

From source file:edu.cornell.mannlib.vedit.tags.OptionTag.java

private void outputOptionsMarkup(List optList, JspWriter out) throws IOException {
    Iterator it = optList.iterator();
    while (it.hasNext()) {
        Option opt = (Option) it.next();
        if (opt.getValue() == null)
            opt.setValue("");
        if (opt.getBody() == null)
            opt.setBody("");
        out.print("<option value=\"" + StringEscapeUtils.escapeHtml(opt.getValue()) + "\"");
        if (opt.getSelected())
            out.print(" selected=\"selected\"");
        out.print(">");
        out.print(StringEscapeUtils.escapeHtml(opt.getBody()));
        out.print("</option>\n");
    }/*from  w ww.  ja  v a  2  s.c o  m*/
}

From source file:nl.strohalm.cyclos.taglibs.MultiDropDownTag.java

@Override
@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {
    divId = "_container_" + System.currentTimeMillis() + "_" + new Random().nextInt(Integer.MAX_VALUE);

    if (selectedValues == null) {
        try {/*from   w w w . j  av a  2  s . co  m*/
            final Object form = pageContext.findAttribute(Constants.BEAN_KEY);
            selectedValues = CoercionHelper.coerce(List.class, PropertyHelper.get(form, name));
            for (int i = 0; i < selectedValues.size(); i++) {
                selectedValues.set(i, CoercionHelper.coerce(String.class, selectedValues.get(i)));
            }
        } catch (final Exception e) {
            // Leave selected values empty
        }
    }

    try {
        final JspWriter out = pageContext.getOut();
        out.print("<div");
        if (maxWidth != null) {
            out.print(" style='width:" + maxWidth + "px'");
        }
        out.println(" id='" + divId + "'></div>");
        // Write the start of the script
        out.println("<script>");
        out.println("var mddNoItemsMessage = \""
                + StringEscapeUtils.escapeJavaScript(messageHelper.message("multiDropDown.noItemsMessage"))
                + "\";");
        out.println("var mddSingleItemsMessage = \""
                + StringEscapeUtils.escapeJavaScript(messageHelper.message("multiDropDown.singleItemMessage"))
                + "\";");
        out.println("var mddMultiItemsMessage = \""
                + StringEscapeUtils.escapeJavaScript(messageHelper.message("multiDropDown.multiItemsMessage"))
                + "\";");

        out.println("var " + divId + " = $('" + divId + "');");
        out.println(divId + ".values = [];");
    } catch (final IOException e) {
        throw new JspException(e);
    }

    return EVAL_BODY_INCLUDE;
}

From source file:info.magnolia.cms.taglibs.util.TableTag.java

/**
 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
 */// ww  w . ja va 2 s .  c o  m
public int doEndTag() throws JspException {
    String data = getBodyContent().getString();
    JspWriter out = pageContext.getOut();

    if (StringUtils.isEmpty(data)) {
        return EVAL_PAGE;
    }

    try {
        out.print("<table cellspacing=\"0\" ");
        writeAttributes(out, htmlAttributes);
        out.print(">\n");

        String[] rows = data.split("\n");

        int startingRow = 0;

        if (header && rows.length > 0) {
            startingRow = 1; // for body
            out.print("<thead>\n");
            out.print("<tr>\n");

            String[] cols = StringUtils.split(rows[0], "\t");
            for (int col = 0; col < cols.length; col++) {
                out.print("<th>");
                out.print(cols[col]);
                out.print("</th>\n");
            }

            out.print("</tr>\n");
            out.print("</thead>\n");

        }

        if (rows.length > startingRow) {
            out.print("<tbody>\n");

            for (int row = startingRow; row < rows.length; row++) {

                out.print("<tr");

                out.print(" class=\"");
                out.print(row % 2 == 0 ? "even" : "odd");

                out.print("\">\n");

                String[] cols = StringUtils.split(rows[row], "\t");

                for (int col = 0; col < cols.length; col++) {
                    out.print("<td>");
                    out.print(cols[col]);
                    out.print("</td>\n");
                }
                out.print("</tr>\n");

            }
            out.print("</tbody>\n");
        }
        out.print("</table>\n");
    } catch (IOException e) {
        // should never happen
        log.debug(e.getMessage(), e);
    }

    return EVAL_PAGE;
}

From source file:info.magnolia.cms.taglibs.util.AHref.java

/**
 * Write a link.//from  w  w  w  .  j a v  a  2 s .  co m
 * @param path link path
 */
private void writeLink(String path) {
    JspWriter out = pageContext.getOut();
    try {
        if (StringUtils.isNotEmpty(path)) {

            out.print("<a href=\""); //$NON-NLS-1$
            if (this.preHref != null) {
                out.print(this.preHref);
            }
            out.print(path);
            if (MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).isPage(path)) {
                out.print("."); //$NON-NLS-1$
                out.print(Server.getDefaultExtension());
            }
            if (this.postHref != null) {
                out.print(this.postHref);
            }
            out.print("\""); //$NON-NLS-1$
            if ((attributes != null) && (attributes.size() > 0)) {
                Iterator i = attributes.iterator();
                while (i.hasNext()) {
                    String[] s = (String[]) i.next();
                    out.print(" "); //$NON-NLS-1$
                    out.print(s[0]);
                    out.print("=\""); //$NON-NLS-1$
                    out.print(s[1]);
                    out.print("\""); //$NON-NLS-1$
                }
            }
            out.print(">"); //$NON-NLS-1$
        }
        out.print(getBodyContent().getString());
        if (StringUtils.isNotEmpty(path)) {
            out.print("</a>"); //$NON-NLS-1$
        }
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        throw new NestableRuntimeException(e);
    }
    attributes = null;
}

From source file:com.steeleforge.aem.ironsites.xss.taglib.XSSFilterHTMLTag.java

@Override
public int doAfterBody() throws JspException {
    BodyContent bodyContent;/*from ww w  . jav  a  2 s  .  co  m*/
    String body;
    JspWriter out;
    try {
        bodyContent = getBodyContent();
        out = bodyContent.getEnclosingWriter();
        body = XSSUtil.filterHTML(getPolicy(), getContext(), bodyContent.getString(), pageContext);
        if (StringUtils.isNotEmpty(body)) {
            out.print(body);
        }
    } catch (IOException ioe) {
        LOG.debug(ioe.getMessage());
        throw new JspException(ioe);
    } finally {
        bodyContent = null;
        body = null;
        out = null;
    }
    return SKIP_BODY;
}

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

/** {@inheritDoc}
 * @throws JspException/*from  w  w w . j ava2 s .  c o  m*/
 */
public int doStartTag() throws JspException {
    if (!icons.containsKey(type)) {
        throw new IllegalArgumentException("Unknown icon type: \"" + type + "\".");
    }

    JspWriter out = null;
    try {
        out = pageContext.getOut();
        String result = renderStartTag();
        out.print(result);
    } catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
    return SKIP_BODY;
}

From source file:edu.cornell.mannlib.vitro.webapp.web.jsptags.OptionsForPropertyTag.java

public int doStartTag() {
    try {// w ww.  j a  v  a  2s .c o m
        VitroRequest vreq = new VitroRequest((HttpServletRequest) pageContext.getRequest());
        WebappDaoFactory wdf = vreq.getWebappDaoFactory();
        if (wdf == null)
            throw new Exception("could not get WebappDaoFactory from request.");

        Individual subject = wdf.getIndividualDao().getIndividualByURI(getSubjectUri());
        if (subject == null)
            throw new Exception("could not get individual for subject uri " + getSubjectUri());

        ObjectProperty objProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(getPredicateUri());
        if (objProp == null)
            throw new Exception("could not get object property for predicate " + getPredicateUri());

        List<VClass> vclasses = new ArrayList<VClass>();
        vclasses = wdf.getVClassDao().getVClassesForProperty(getPredicateUri(), true);

        HashMap<String, Individual> indMap = new HashMap<String, Individual>();
        for (VClass vclass : vclasses) {
            for (Individual ind : wdf.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1))
                if (!indMap.containsKey(ind.getURI()))
                    indMap.put(ind.getURI(), ind);
        }

        List<Individual> individuals = new ArrayList(indMap.values());

        List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
        if (stmts == null)
            throw new Exception("object properties for subject were null");

        individuals = removeIndividualsAlreadyInRange(individuals, stmts);
        Collections.sort(individuals, new compareEnts());

        JspWriter out = pageContext.getOut();

        int optionsCount = 0;
        for (Individual ind : individuals) {
            String uri = ind.getURI();
            if (uri != null) {
                out.print("<option value=\"" + StringEscapeUtils.escapeHtml(uri) + '"');
                if (uri.equals(getSelectedUri()))
                    out.print(" selected=\"selected\"");
                out.print('>');
                out.print(StringEscapeUtils.escapeHtml(ind.getName()));
                out.println("</option>");
                ++optionsCount;
            }

        }
        log.trace("added " + optionsCount + " options for object property \"" + getPredicateUri()
                + "\" in OptionsForPropertyTag.doStartTag()");
    } catch (Exception ex) {
        throw new Error("Error in doStartTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:com.xhsoft.framework.common.page.MiniPageTag.java

/**
 * <p>Description:</p>//  w  w  w.  ja v  a 2s  .  c  om
 * @return int
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
@SuppressWarnings("unchecked")
@Override
public int doStartTag() throws JspException {
    /**?request*/
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    Page page = (Page) request.getAttribute("page");

    /** request??????Actionrequest*/
    int pageNo = page.getPageNo();
    int totalPages = page.getTotalPages();

    JspWriter out = pageContext.getOut();
    try {
        out.print("<div class=\"np\">");
        printOutFront(pageNo, request);
        buildPager(request, pageNo, totalPages);
        printOutBack(pageNo, totalPages, request);
        buildGoto(request, pageNo, totalPages);
        printOutEnd();
        out.print("" + totalPages + "</div>");
        out.print("<script type=\"text/javascript\">");
        String pageURL = (String) request.getAttribute("pageURL");
        out.print("dojo.widget.byId(\"" + targets + "\").href = '" + pageURL + "';");
        out.print("</script>");
    } catch (IOException e) {
        e.printStackTrace();
    }

    return EVAL_PAGE;
}