Example usage for org.apache.commons.lang StringEscapeUtils escapeHtml

List of usage examples for org.apache.commons.lang StringEscapeUtils escapeHtml

Introduction

In this page you can find the example usage for org.apache.commons.lang StringEscapeUtils escapeHtml.

Prototype

public static String escapeHtml(String input) 

Source Link

Usage

From source file:com.openbravo.pos.util.ThumbNailBuilder.java

public Image getThumbNailText(Image img, String text) {
    /*/*from  w ww  .  j a  v  a2s. c om*/
     * Create an image containing a thumbnail of the product image,
     * or default image.
     * 
     * Then apply the text of the product name. Use text wrapping.
     * 
     * If the product name is too big for the label, ensure that
     * the first part is displayed.
     */

    img = getThumbNail(img);

    BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = imgtext.createGraphics();

    // The text
    // <p style="width: 100px"> DOES NOT WORK PROPERLY.
    // use width= instead.
    String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">"
            + StringEscapeUtils.escapeHtml(text) + "</p>";

    JLabel label = new JLabel(html);
    label.setOpaque(false);
    //label.setText("<html><center>Line1<br>Line2");
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setVerticalAlignment(javax.swing.SwingConstants.TOP);
    Dimension d = label.getPreferredSize();
    label.setBounds(0, 0, imgtext.getWidth(), d.height);

    // The background
    Color c1 = new Color(0xff, 0xff, 0xff, 0x40);
    Color c2 = new Color(0xff, 0xff, 0xff, 0xd0);

    //        Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight());
    //        float radius = imgtext.getWidth() / 3;
    //        float[] dist = {0.1f, 1.0f};
    //        Color[] colors = {c2, c1};        
    //        Paint gpaint = new RadialGradientPaint(center, radius, dist, colors);
    Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true);

    g2d.drawImage(img, 0, 0, null);
    int ypos = imgtext.getHeight() - label.getHeight();
    int ypos_min = -4; // todo: configurable
    if (ypos < ypos_min)
        ypos = ypos_min; // Clamp label
    g2d.translate(0, ypos);
    g2d.setPaint(gpaint);
    g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight());
    label.paint(g2d);

    g2d.dispose();

    return imgtext;
}

From source file:com.redhat.rhn.domain.action.config.ConfigUploadActionFormatter.java

private String renderFileName(ConfigFileName name) {
    //paths can have pretty much any character including newlines,
    //spaces, and control characters. Escaping html here is only
    //going to work happily for file names that make some kind of sense.
    return (StringEscapeUtils.escapeHtml(name.getPath()) + "<br />");
}

From source file:com.redhat.rhn.frontend.action.tasko.BunchDetailAction.java

/** {@inheritDoc} */
@Override//from  ww w  .j  av a2  s .c  o m
public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
        HttpServletResponse response) {
    RequestContext ctx = new RequestContext(request);
    User loggedInUser = ctx.getCurrentUser();
    String bunchLabel = request.getParameter("label");
    request.setAttribute("label", bunchLabel);
    request.setAttribute("bunchdescription",
            LocalizationService.getInstance().getMessage("bunch.jsp.description." + bunchLabel));

    if (ctx.wasDispatched("bunch.edit.jsp.button-schedule")) {
        try {
            Date date = new TaskomaticApi().scheduleSingleSatBunch(loggedInUser, bunchLabel);
            ActionMessages msgs = new ActionMessages();
            msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.bunch.singlescheduled",
                    bunchLabel, LocalizationService.getInstance().formatCustomDate(date)));
            saveMessages(request, msgs);
        } catch (TaskomaticApiException e) {
            createErrorMessage(request, "repos.jsp.message.taskomaticdown", null);
        }
    }
    ListHelper helper = new ListHelper(this, request);
    helper.setListName(LIST_NAME);
    helper.setParentUrl(request.getRequestURI() + "?label=" + StringEscapeUtils.escapeHtml(bunchLabel));
    helper.execute();
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}

From source file:com.appeligo.channelfeed.work.FileWriter.java

public void write(CCSentenceEvent sentenceEvent) {
    ProcessStats.checkStats(ccDocumentRoot);
    if (body == null) {
        return;/*from w  w w  .  j a  v  a 2s  . c  om*/
    }
    if (currentCaptionType != newCaptionType) {
        body.println("</div>");
        currentCaptionType = newCaptionType;
        body.println("<div class=\"" + currentCaptionType + "\">");
    }
    body.print("<a name=\"");
    body.print(sentenceEvent.getTimestamp());
    body.print("\"/>");
    String speaker = sentenceEvent.getSpeakerChange();
    if (speaker != null) {
        body.print("<span class=\"speaker\">");
        body.print(StringEscapeUtils.escapeHtml(speaker));
        body.print("&gt;&gt; </span>");
    }
    body.println(StringEscapeUtils.escapeHtml(sentenceEvent.getSentence()));
    body.println("<p/>");
}

From source file:com.redhat.rhn.domain.action.errata.ErrataActionFormatter.java

/**
 * {@inheritDoc}//from   w w w . ja v a2 s  .  com
 */
@Override
public String getRelatedObjectDescription() {
    Set<Errata> allErrata = ((ErrataAction) this.getAction()).getErrata();
    List<String> result = new LinkedList<String>();
    if (allErrata != null) {
        for (Errata errata : allErrata) {
            result.add("<a href=\"/rhn/errata/details/Details.do?eid=" + errata.getId().toString() + "\">"
                    + StringEscapeUtils.escapeHtml(errata.getAdvisory()) + "</a>");
        }
    }
    return StringUtil.join(", ", result);
}

From source file:com.github.dbourdette.glass.log.joblog.JobLog.java

public String getFormattedStackTrace() {
    String html = StringEscapeUtils.escapeHtml(stackTrace);

    html = StringUtils.replace(html, "\n", "<br/>");
    html = StringUtils.replace(html, "\t", "&nbsp;&nbsp;&nbsp;");

    return html;/*from  w  w w  .  j  av a 2  s .c  o m*/
}

From source file:com.epam.cme.storefront.util.PageTitleResolver.java

public String resolveHomePageTitle(final String title) {
    final CMSSiteModel currentSite = getCmsSiteService().getCurrentSite();
    final StringBuilder builder = new StringBuilder();
    builder.append(currentSite.getName());

    if (!StringUtils.isEmpty(title)) {
        builder.append(SEPARATOR).append(title);
    }//from w  w w  .j  av a2 s .c  o  m

    return StringEscapeUtils.escapeHtml(builder.toString());
}

From source file:ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper.java

/**
 * Extracts "full" sample code from {@link SamplePE}. For contained samples has a prefix
 * consisting of container sample DB code and a colon, otherwise it is just sample DB code,
 * where by "sample DB code" is the code kept in the DB.
 *//*  w ww .j  a  v a 2  s  .  c om*/
public final static String extractCode(SamplePE samplePE) {
    final String subCode = extractSubCode(samplePE);

    final String code;
    if (samplePE.getContainer() != null && HibernateUtils.isInitialized(samplePE.getContainer())) {
        final String containerCode = StringEscapeUtils.escapeHtml(samplePE.getContainer().getCode());
        code = containerCode + ":" + subCode;
    } else {
        code = subCode;
    }
    return code;
}

From source file:mitm.djigzo.web.components.DHTMLTooltip.java

@BeginRender
void beginRender(MarkupWriter writer) {
    /*/*from w ww .  j a v  a 2 s .  co  m*/
     * Only tooltip if minimal length is reached
     */
    if (value != null && (value.length() > minLength)) {
        clientId = renderSupport.allocateClientId(componentResources.getId());

        /*
         * The value need to be split up when the text becomes too long (we do not want
         * a extremely long tooltip). We therefore need to insert <br/> so we need to
         * do the HTML escaping ourselves and <br/> and use writeRaw.
         */
        String tooltip = StringEscapeUtils.escapeHtml(value);

        tooltip = WordUtils.wrap(tooltip, breakupLength, "<br/>", true);

        /*
         * Somehow FF requires the display: none style to be inline to prevent some flickering
         */
        writer.element("span", "id", clientId, "class", "dhtmlTooltip", "style", "display: none;");
        writer.writeRaw(tooltip);
        writer.end(); /* span */
        writer.element("span", "id", getBodyId());
    }
}

From source file:de.hybris.platform.acceleratorservices.storefront.util.PageTitleResolver.java

public String resolveHomePageTitle(final String title) {
    final CMSSiteModel currentSite = getCmsSiteService().getCurrentSite();
    final StringBuilder builder = new StringBuilder();
    builder.append(currentSite.getName());

    if (!StringUtils.isEmpty(title)) {
        builder.append(TITLE_WORD_SEPARATOR).append(title);
    }/*from   w ww .  j av  a  2s  .  c  o m*/

    return StringEscapeUtils.escapeHtml(builder.toString());
}