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.silverpeas.tags.navigation.links.CachedLinkGeneratorImpl.java

/**
 * Changement des caractres "spciaux" du nom d'un lment.
 * @param name//w w w  .  j a va 2 s  .  c om
 * @return
 */
private String tranformName(String name) {
    name = name.toLowerCase();
    name = stripAccents(name);
    name = name.replace("'", "_");
    name = name.replace(" ", "_");
    name = name.replace("?", "");
    name = name.replaceAll("\\<.*?>", "");
    name = StringEscapeUtils.escapeHtml(name);
    return name;
}

From source file:de.hybris.platform.acceleratorservices.metainformation.HtmlMetaTag.java

protected Map<String, String> getAttributesMap(final MetaElementData metaElementData) {
    final Map<String, String> attributes = new LinkedHashMap<>();
    try {//from w  w  w  .j  ava  2s.  c  o  m
        final Map<String, Object> fieldValues = PropertyUtils.describe(metaElementData);
        for (final Entry<String, Object> fieldData : fieldValues.entrySet()) {
            if ("class".equals(fieldData.getKey())) {
                continue;
            }
            final String name = metaElementAttributeNameResolver.resolveName(fieldData.getKey());
            String value = fieldData.getValue() == null ? null : fieldData.getValue().toString();
            if (value != null) {
                value = StringEscapeUtils.escapeHtml(value);
            }

            if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(value)) {
                attributes.put(name, value);
            }
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        LOG.error("Exception while running PropertyUtils.describe", e);
    }
    return attributes;
}

From source file:hello.jaxrs.GreetingsResource.java

private void printGreetings(final PrintWriter writer, final Collection<String> greetings) {
    writer.println("<h2>Greetings!</h2>");
    if (greetings.isEmpty()) {
        writer.println("No greetings available. Be the first and say hello!");
    } else {//from   w  w w  . j ava  2  s . c  om
        writer.println("<ul>");
        for (String greeting : greetings) {
            // escape HTML
            greeting = StringEscapeUtils.escapeHtml(StringUtils.trimToEmpty(greeting));
            // format
            greeting = StringUtils.replaceEach(greeting, new String[] { "(", ")" },
                    new String[] { "<br><small>(", ")</small>" });

            // print
            writer.println("<li>");
            writer.println(greeting);
            writer.println("</li>");
        }
        writer.println("</ul>");
    }
}

From source file:com.onehippo.gogreen.components.search.AbstractSearchComponent.java

protected void searchDocuments(final HstRequest request, final String query) {

    String parsedQuery = SearchInputParsingUtils.parse(query, false);

    request.setAttribute("query", StringEscapeUtils.escapeHtml(parsedQuery));
    HippoBean scope = getSiteContentBaseBean(request);
    if (scope == null) {
        log.error("Scope for search is null");
        return;//www .j a  v  a2 s. co m
    }

    try {
        HstQueryManager manager = getQueryManager(request);

        @SuppressWarnings("unchecked")
        HstQuery hstQuery = manager.createQuery(scope, EventDocument.class, JobsDocument.class, NewsItem.class,
                Product.class, HippoAsset.class, SimpleDocument.class, Faq.class);

        HippoBean assetScope = getAssetBaseBean(request);
        hstQuery.addScopes(Collections.singletonList(assetScope));

        if (!StringUtils.isEmpty(parsedQuery)) {
            Filter filter = hstQuery.createFilter();
            hstQuery.setFilter(filter);
            // title field
            Filter titleFilter = hstQuery.createFilter();
            titleFilter.addContains("@hippogogreen:title", parsedQuery);
            // summary field
            Filter summaryFilter = hstQuery.createFilter();
            summaryFilter.addContains("@hippogogreen:summary", parsedQuery);
            // full text
            Filter fullTextFilter = hstQuery.createFilter();
            fullTextFilter.addContains(".", parsedQuery);

            filter.addOrFilter(titleFilter);
            filter.addOrFilter(summaryFilter);
            filter.addOrFilter(fullTextFilter);
            //https://issues.onehippo.com/browse/GOGREEN-254
            hstQuery.addOrderByDescending("hippogogreen:rating");
        } else {
            hstQuery.addOrderByDescending("hippogogreen:title");
        }
        HstQueryResult result = hstQuery.execute();

        HippoBeanIterator beans = result.getHippoBeans();
        int pageSize = getPageSize(request);
        int currentPage = getCurrentPage(request);

        PageableCollection<HippoBean> results = new PageableCollection<HippoBean>(beans, pageSize, currentPage);
        request.setAttribute("searchResult", results);
    } catch (QueryException e) {
        if (log.isDebugEnabled()) {
            log.warn("Error during search: ", e);
        } else {
            log.warn("Error during search: ", e.getMessage());
        }
    }
}

From source file:io.github.tavernaextras.biocatalogue.ui.search_results.RESTMethodListCellRenderer.java

/**
 * //from   w  ww.  j a  va 2s . c  om
 * @param itemToRender
 * @param expandedView <code>true</code> to indicate that this method generates the top
 *                     fragment of the expanded list entry for this SOAP operation / REST method.
 * @return
 */
protected GridBagConstraints prepareLoadedEntry(Object itemToRender, boolean selected) {
    RestMethod restMethod = (RestMethod) itemToRender;
    ;

    Ancestors ancestors = restMethod.getAncestors();
    Service service = ancestors.getService();
    String title = "<html>" + StringEscapeUtils.escapeHtml(Resource.getDisplayNameForResource(restMethod));

    if (restMethod.isSetArchived() || service.isSetArchived()) {
        jlTypeIcon.setIcon(ResourceManager.getImageIcon(ResourceManager.WARNING_ICON));
        title = title + "<i> - this operation is archived and probably cannot be used</i></html>";
    } else {
        jlTypeIcon.setIcon(resourceType.getIcon());
        title = title + "</html>";
    }

    // service status
    jlItemStatus.setIcon(ServiceMonitoringStatusInterpreter.getStatusIcon(service, false));
    jlItemTitle.setText(title);

    jlPartOf.setText("<html><b>Part of: </b>" + restMethod.getAncestors().getRestService().getResourceName()
            + "</html>");

    String strDescription = (restMethod.getDescription() == null || restMethod.getDescription().length() == 0
            ? "No description"
            : Util.stripAllHTML(restMethod.getDescription()));
    jtDescription.setText(strDescription);

    jlMethodType.setText("<html><b>HTTP Method: </b>"
            + StringEscapeUtils.escapeHtml(restMethod.getHttpMethodType().toString()) + "</html>");
    jlUrlTemplate.setText("<html><b>URL Template: </b>"
            + StringEscapeUtils.escapeHtml(restMethod.getUrlTemplate()) + "</html>");

    List<String> names = new ArrayList<String>();
    for (RestParameter restParameter : restMethod.getInputs().getParameters().getRestParameterList()) {
        names.add(restParameter.getName() + (restParameter.getIsOptional() ? " (optional)" : ""));
    }

    String methodParameters = "<b>" + names.size() + " " + Util.pluraliseNoun("Parameter", names.size())
            + "</b>";
    if (names.size() > 0) {
        methodParameters += ": " + StringEscapeUtils
                .escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false));
    }
    methodParameters = "<html>" + methodParameters + "</html>";
    jlMethodParameters.setText(methodParameters);

    names.clear();
    for (RestRepresentation restRepresentation : restMethod.getInputs().getRepresentations()
            .getRestRepresentationList()) {
        names.add(restRepresentation.getContentType());
    }

    String inputRepresentations = "<b>" + names.size() + " "
            + Util.pluraliseNoun("Input representation", names.size()) + "</b>";
    if (names.size() > 0) {
        inputRepresentations += ": " + StringEscapeUtils
                .escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false));
    }
    inputRepresentations = "<html>" + inputRepresentations + "</html>";

    jlInputRepresentations.setText(inputRepresentations);

    // output representations
    names.clear();
    for (RestRepresentation restRepresentation : restMethod.getOutputs().getRepresentations()
            .getRestRepresentationList()) {
        names.add(restRepresentation.getContentType());
    }

    String outputRepresentations = "<b>" + names.size() + " "
            + Util.pluraliseNoun("Output representation", names.size()) + "</b>";
    if (names.size() > 0) {
        outputRepresentations += ": " + StringEscapeUtils
                .escapeHtml(Util.ensureLineLengthWithinString(Util.join(names, ", "), LINE_LENGTH, false));
    }
    outputRepresentations = "<html>" + outputRepresentations + "</html>";

    jlOutputRepresentations.setText(outputRepresentations);

    return (arrangeLayout());
}

From source file:com.redhat.rhn.frontend.action.multiorg.OrgDeleteAction.java

/**
 *
 * @param oidIn Organization Id to delete
 * @return Success or Failure in form of Boolean
 *///from   www.  java2  s .c  o m
private void deleteOrg(Long oidIn, HttpServletRequest request) {
    Org org = OrgFactory.lookupById(oidIn);
    String name = org.getName();
    RequestContext requestContext = new RequestContext(request);

    OrgFactory.deleteOrg(oidIn, requestContext.getCurrentUser());
    ActionMessages msg = new ActionMessages();
    msg.add(ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage("message.org_deleted", StringEscapeUtils.escapeHtml(name)));
    getStrutsDelegate().saveMessages(request, msg);
}

From source file:com.fluidops.iwb.wiki.parserfunction.ShowParserFunction.java

@Override
public String parseFunction(List<String> parts, IWikiModel model, char[] src, int beginIndex, int endIndex,
        boolean isSubst) throws IOException {

    if (parts.size() == 0)
        return null;

    URI resource = parseResource(parts.get(0), model);
    if (resource == null)
        return ParserFunctionUtil.renderError("Not a valid URI: " + parts.get(0));

    if (parts.size() == 1)
        return "<nowiki>" + StringEscapeUtils.escapeHtml(resource.stringValue()) + "</nowiki>";

    // check for incoming 
    String propertyPart = parts.get(1);
    boolean incoming = false;
    if (isIncomingProperty(propertyPart)) {
        incoming = true;//from   w  w w .  j a  va  2 s  .  com
        propertyPart = propertyPart.substring(propertyPart.indexOf("^") + 1);
    }

    URI property = parseProperty(propertyPart, model);
    if (property == null)
        return ParserFunctionUtil.renderError("Not a valid URI: " + parts.get(0));

    Map<String, String> options = ParserFunctionUtil.getTemplateParameters(parts.subList(1, parts.size()));

    try {
        return incoming ? renderShowIncoming(resource, property, options)
                : renderShowOutgoing(resource, property, options);
    } catch (Exception e) {
        return ParserFunctionUtil.renderError(e);
    }
}

From source file:com.fluidops.iwb.ajax.FValue.java

@Override
public String getValue() {
    if (this.value == null)
        return "";

    String label = null;//ww  w .  j a v a  2s  .c  o  m

    // try to resolve using value resolver
    if (variableResolver != null && variableResolver.containsKey(name))
        label = ValueResolver.resolveValue(variableResolver.get(name), value);

    // try to resolve using image resolver
    if (StringUtil.isNullOrEmpty(label) && imageResolver != null)
        label = imageResolver.resolveImageAsThumbnail(value);

    // fallback: if none of the above worked, just display the label
    if (StringUtil.isNullOrEmpty(label)) {
        label = showLabels ? dm.getLabel(value) : value.stringValue();
        if (label != null) {
            label = processLabel(StringEscapeUtils.escapeHtml(label));
        } else
            label = "";
    }

    // if the current dm operates on a different repository than the default
    // repository, the aHrefLink should contain a reference to the other
    HashMap<String, String> getParams = Maps.newHashMap();
    if (dm != null && !dm.getRepository().equals(Global.repository)) {
        PlatformRepositoryManager manager = PlatformRepositoryManager.getInstance();
        String repositoryID = manager.getRepositoryID(dm.getRepository());
        if (repositoryID != null) {
            getParams.put("repository", repositoryID);
        }
    }
    return EndpointImpl.api().getRequestMapper().getAHrefEncoded(value, label, null, getParams);
}

From source file:ch.entwine.weblounge.common.impl.site.I18nDictionaryImpl.java

/**
 * {@inheritDoc}//from   w ww . j ava  2 s  .c  o  m
 * 
 * @see ch.entwine.weblounge.common.site.I18nDictionary#getAsHTML(java.lang.String)
 */
public String getAsHTML(String key) {
    String value = get(key);
    return value != null ? StringEscapeUtils.escapeHtml(value) : null;
}

From source file:com.redhat.rhn.frontend.xmlrpc.packages.provider.PackagesProviderHandler.java

/**
 * Associate a package key with provider.  Provider is created if it doesn't exist.
 *  Key is created if it doesn't exist.// w w w  .j a v a  2s  . c o m
 * @param loggedInUser The current user
 * @param providerName the provider name
 * @param key the key string
 * @param typeStr the type string (currently only 'gpg' is supported)
 * @return 1 on success
 *
 * @xmlrpc.doc Associate a package security key and with the package provider.
 *      If the provider or key doesn't exist, it is created. User executing the
 *      request must be a Satellite administrator.
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param_desc("string", "providerName", "The provider name")
 * @xmlrpc.param #param_desc("string", "key", "The actual key")
 * @xmlrpc.param #param_desc("string", "type", "The type of the key. Currently,
 * only 'gpg' is supported")
 * @xmlrpc.returntype
 *      #return_int_success()
 */
public int associateKey(User loggedInUser, String providerName, String key, String typeStr) {
    isSatelliteAdmin(loggedInUser);
    PackageProvider prov = PackageFactory.lookupPackageProvider(providerName);
    if (prov == null) {
        prov = new PackageProvider();
        prov.setName(providerName);
    }

    //package key type might be invalid
    PackageKeyType type = PackageFactory.lookupKeyTypeByLabel(typeStr);
    if (type == null) {
        throw new InvalidPackageKeyTypeException(typeStr);
    }

    PackageKey pKey = PackageFactory.lookupPackageKey(key);
    if (pKey == null) {
        pKey = new PackageKey();
        pKey.setKey(StringEscapeUtils.escapeHtml(key));
        pKey.setType(type);
    }

    pKey.setProvider(prov);
    prov.addKey(pKey);

    PackageFactory.save(prov);

    return 1;
}