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:burrito.util.StringUtils.java

public static String formatHeaderAsHTMLWithLineBreaks(String string) {
    if (string != null)
        string = StringEscapeUtils.escapeHtml(string).replaceAll("\\|", "<br />");
    return string;
}

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

public int doStartTag() {
    try {/*from  w  w  w . jav a2 s  .c  om*/
        VitroRequest vreq = new VitroRequest((HttpServletRequest) pageContext.getRequest());
        WebappDaoFactory wdf = vreq.getWebappDaoFactory();
        if (wdf == null)
            throw new Exception("could not get WebappDaoFactory from request.");

        VClass vclass = wdf.getVClassDao().getVClassByURI(getClassUri());
        if (vclass == null)
            throw new Exception("could not get class for " + getClassUri());

        List<Individual> individuals = wdf.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1,
                -1);

        JspWriter out = pageContext.getOut();

        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>");
            }

        }
    } catch (Exception ex) {
        throw new Error("Error in doStartTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:com.googlecode.psiprobe.jsp.OutTag.java

private void print(String displayValue, JspWriter out) throws JspException {
    try {//from   w  w  w  . j  a v a2s .c o  m
        if (maxLength != -1 && displayValue.length() > maxLength) {
            String newValue;
            if (ellipsisRight) {
                newValue = displayValue.substring(0, maxLength - 3) + "...";
            } else {
                newValue = "..." + displayValue.substring(displayValue.length() - maxLength + 3);
            }
            String title = StringEscapeUtils.escapeHtml(displayValue);
            out.print("<span title=\"" + title + "\">" + newValue + "</span>");
        } else {
            out.print(displayValue);
        }
    } catch (IOException e) {
        throw new JspException(e);
    }
}

From source file:edu.lafayette.metadb.model.dataman.DataExporter.java

/**
 * Export data from a project for one item. 
 * @param projectName The project name.//w ww  . java 2s  . c o m
 * @param itemNumber The item number to export.
 * @param delimiter The delimiter to use when writing the export (currently TSV/CSV)
 * @param encoder The character set encoding.
 * @param technical Flag indicating whether to include technical data in the export file.
 * @param replaceEntity Flag indicating whether to escape special characters with their HTML entity codes.
 * @return a String[] representing one row in the exported data file.
 */
public static String[] exportData(String projectName, int itemNumber, char delimiter, String encoder,
        boolean technical, boolean replaceEntity) {
    ArrayList adminDescData = null;
    Item it = ItemsDAO.getItem(projectName, itemNumber);
    adminDescData = it.getData(Global.MD_TYPE_DESC);
    adminDescData.addAll(it.getData(Global.MD_TYPE_ADMIN));

    ArrayList techData = new ArrayList();
    if (technical)
        techData = ItemsDAO.getTechData(projectName, itemNumber);

    String[] out = new String[adminDescData.size() + techData.size()];
    for (int i = 0; i < adminDescData.size(); i++) {
        try {
            String outStr = StringUtils.trimToEmpty(
                    new String(((AdminDescItem) adminDescData.get(i)).getData().getBytes("UTF-8"), encoder)
                            .replace('\t', ' '));
            out[i] = (replaceEntity ? StringEscapeUtils.escapeHtml(outStr)//outStr.replaceAll("&", "&#38;").replaceAll("[\"]", "&#34;").replaceAll("%", "&#37;").replaceAll("'", "&#39;").replaceAll(",", "&#44;")
                    : outStr);
        } catch (Exception e) {
            MetaDbHelper.logEvent(e);
            out[i] = ((AdminDescItem) adminDescData.get(i)).getData();
        }
    }
    //MetaDbHelper.note("Exporting tech data");
    for (int i = 0; i < techData.size(); i++)
        try {
            out[i + adminDescData.size()] = StringUtils
                    .trimToEmpty(new String(((Metadata) techData.get(i)).getData().getBytes("UTF-8"), encoder)
                            .replace('\t', ' '));
        } catch (Exception e) {
            MetaDbHelper.logEvent(e);
            out[i + adminDescData.size()] = ((Metadata) techData.get(i)).getData();
        }

    return out;
}

From source file:co.cask.cdap.logging.gateway.handlers.LogReaderCallback.java

@Override
public void handle(LogEvent event) {
    String log = patternLayout.doLayout(event.getLoggingEvent());
    log = escape ? StringEscapeUtils.escapeHtml(log) : log;

    logResults.add(new FormattedLogEvent(log, event.getOffset()));
    count.incrementAndGet();/*from   www.ja va 2s . c o  m*/
}

From source file:com.redhat.rhn.frontend.action.rhnpackage.PackageChangeLogAction.java

/** {@inheritDoc} */
@Override/*from ww w  .  ja  v a  2  s  .c om*/
public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
        HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();

    long pid = requestContext.getRequiredParam("pid");
    Package pkg = PackageFactory.lookupByIdAndUser(pid, user);

    // show permission error if pid is invalid like we did before
    if (pkg == null) {
        throw new PermissionException("Invalid pid");
    }

    String changelog = PackageManager.getPackageChangeLog(pkg);
    if (changelog == null) {
        request.setAttribute("changelog", null);
    } else {
        changelog = StringEscapeUtils.escapeHtml(changelog);
        String[] changes = changelog.split("\n");
        request.setAttribute("changelog", changes);
    }

    request.setAttribute("pid", pid);
    request.setAttribute("package_name", pkg.getFilename());
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);

}

From source file:com.marc.lastweek.web.pages.main.MainPage.java

public MainPage() {

    this.add(new CreateNewAdPropagandaPanel("createNewAd"));

    this.add(new ListView("categoriesList", new LoadableCategoriesListModel()) {

        private static final long serialVersionUID = -5142681180212487928L;

        @Override/*from   ww w. ja v a  2 s. c o  m*/
        protected void populateItem(ListItem listItem) {
            Category category = (Category) listItem.getModelObject();
            PageParameters linkParameters = new PageParameters();
            linkParameters.put(PageParametersNaming.PARAM_NAME_CATEGORY_ID, category.getId());
            linkParameters.put(PageParametersNaming.PARAM_NAME_CATEGORY_NAME,
                    StringEscapeUtils.escapeHtml(category.getName()));

            BookmarkablePageLink categoryLink = new BookmarkablePageLink("categoryLink",
                    FilterResultsPage.class, linkParameters);
            categoryLink.add(new Label("categoryName", category.getName()));
            listItem.add(categoryLink);
        }
    });

    this.add(new ListView("provincesList", new LoadableProvincesListModel()) {

        private static final long serialVersionUID = -5843308083402561880L;

        @Override
        protected void populateItem(ListItem listItem) {
            Province province = (Province) listItem.getModelObject();
            PageParameters linkParameters = new PageParameters();
            linkParameters.put(PageParametersNaming.PARAM_NAME_PROVINCE_ID, province.getId());
            linkParameters.put(PageParametersNaming.PARAM_NAME_PROVINCE_NAME,
                    StringEscapeUtils.escapeHtml(province.getName()));
            BookmarkablePageLink provinceLink = new BookmarkablePageLink("provinceLink",
                    FilterResultsPage.class, linkParameters);
            provinceLink.add(new Label("provinceName", province.getName()));

            if (listItem.getIndex() % 2 == 1) {
                listItem.add(new SimpleAttributeModifier("class", "parallel-column"));
            }

            listItem.add(provinceLink);
        }
    });

    /*
     * Clickable provinces map
     */

    ImageMap mapProvinceMap = new ImageMap("mapProvinceMap");

    for (Province province : LastweekApplication.get().getGeneralService().findAll(Province.class)) {
        String[] stringCoords = StringUtils.split(province.getCoords(), ",");
        int[] intCoords = new int[stringCoords.length];
        for (int i = 0; i < stringCoords.length; i++) {
            intCoords[i] = (new Integer(stringCoords[i].trim())).intValue();
        }
        PageParameters linkParameters = new PageParameters();
        linkParameters.put(PageParametersNaming.PARAM_NAME_PROVINCE_ID, province.getId());
        linkParameters.put(PageParametersNaming.PARAM_NAME_PROVINCE_NAME,
                StringEscapeUtils.escapeHtml(province.getName()));
        mapProvinceMap.addPolygonLink(intCoords, new BookmarkablePageLink("imageMapLink" + province.getId(),
                FilterResultsPage.class, linkParameters));
    }
    this.add(mapProvinceMap);

}

From source file:com.sonymobile.backlogtool.NewStoryContainer.java

public String getEpicTitle() {
    return StringEscapeUtils.escapeHtml(epicTitle);
}

From source file:com.siberhus.web.ckeditor.Ckeditor.java

public String renderEditor() {
    StringBuilder outb = new StringBuilder();

    if (!this.tagConfig.append) {
        outb.append("<textarea id=\"" + tagConfig.instanceId + "\" name=\"");
        outb.append(this.tagConfig.instanceName);
        outb.append("\">");
        outb.append(StringEscapeUtils.escapeHtml(this.initialValue));
        outb.append("</textarea>\n");
    }/*  w w  w.ja va2 s  .  c  om*/
    outb.append("<script type=\"text/javascript\">\n");

    if (this.tagConfig.removeInstance) {
        outb.append("if (CKEDITOR.instances['" + tagConfig.instanceId
                + "']){CKEDITOR.remove(CKEDITOR.instances['" + this.tagConfig.instanceId + "']);}\n");
    }

    outb.append("CKEDITOR.");
    if (this.tagConfig.append) {
        outb.append("appendTo");
    } else {
        outb.append("replace");
    }
    outb.append("('" + tagConfig.instanceId + "'");
    outb.append(this.tagConfig.getConfiguration());
    outb.append(");\n");
    outb.append("</script>\n");
    return outb.toString();
}

From source file:com.epam.cme.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final String categoryCode,
        final ProductSearchPageData<SearchStateData, ProductData> searchPageData)
        throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    final boolean emptyBreadcrumbs = CollectionUtils.isEmpty(searchPageData.getBreadcrumbs());
    Breadcrumb breadcrumb;/*  w w  w .jav  a  2  s .c om*/
    if (categoryCode == null) {
        breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchPageData.getFreeTextSearch()),
                StringEscapeUtils.escapeHtml(searchPageData.getFreeTextSearch()),
                (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>();
        final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }
    return breadcrumbs;
}