Example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4.

Prototype

public static final String escapeHtml4(final String input) 

Source Link

Document

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

becomes:

"bread" & "butter".

Usage

From source file:com.day.cq.wcm.foundation.forms.FormsHelper.java

/**
 * Return the css classes for the field.
 * If the field has a property {@link FormsConstants#ELEMENT_PROPERTY_CSS}
 * the value of this property is appended to the default css. If not, only the
 * default css is returned./*from  ww  w. j av  a  2s  . c  om*/
 * @param props The field properties.
 * @param defaultCss The default css for this field.
 * @return The css classes
 *
 * @since 5.4
 */
public static String getCss(final ValueMap props, final String defaultCss) {
    final String configCss = props.get(FormsConstants.ELEMENT_PROPERTY_CSS, null);
    if (configCss == null) {
        return defaultCss;
    }
    return defaultCss + ' ' + StringEscapeUtils.escapeHtml4(configCss);
}

From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

private void createHTMLpagination(StringBuilder html, AnalyticsQuery query, DataTable data) {
    long lastRow = (data.getStartIndex() + data.getRows().size());
    long firstRow = data.getRows().size() > 0 ? (data.getStartIndex() + 1) : 0;
    html.append("<br><div>rows from " + firstRow + " to " + lastRow + " out of " + data.getTotalSize()
            + " records");
    if (data.getFullset()) {
        html.append(" (the query is complete)");
    } else {/*www  . j  av  a  2 s .c om*/
        html.append(" (the query has more data)");
    }
    if (lastRow < data.getTotalSize()) {
        // go to next page
        HashMap<String, Object> override = new HashMap<>();
        override.put(START_INDEX_PARAM, lastRow);
        URI nextLink = buildAnalyticsQueryURI(userContext, query, null, null, Style.HTML, override);
        html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(nextLink.toString()) + "\">next</a>]");
    }
    html.append("</div><div>");
    if (data.isFromSmartCache()) {
        html.append("data from smart-cache, last computed " + data.getExecutionDate());
    } else if (data.isFromCache()) {
        html.append("data from cache, last computed " + data.getExecutionDate());
    } else {
        html.append("fresh data just computed at " + data.getExecutionDate());
    }
    // add links
    createHTMLdataLinks(html, query);
    html.append("</div><br>");
}

From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

private void createHTMLdataLinks(StringBuilder html, AnalyticsQuery query) {
    // add links//w w w .  j  a va 2  s.  c  om
    { // for View
        HashMap<String, Object> override = new HashMap<>();
        override.put(LIMIT_PARAM, null);
        override.put(MAX_RESULTS_PARAM, null);
        URI sqlLink = buildAnalyticsViewURI(userContext, new ViewQuery(query), null, "ALL", Style.HTML,
                override);//(userContext, query, "SQL", null, Style.HTML, null);
        html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(sqlLink.toString()) + "\">View</a>]");
    }
    { // for SQL
        URI sqlLink = buildAnalyticsQueryURI(userContext, query, "SQL", null, Style.HTML, null);
        html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(sqlLink.toString()) + "\">SQL</a>]");
    }
    { // for CSV export
        URI csvExport = buildAnalyticsExportURI(userContext, query, ".csv");
        html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(csvExport.toString())
                + "\">Export CSV</a>]");
    }
    { // for XLS export
        URI xlsExport = buildAnalyticsExportURI(userContext, query, ".xls");
        html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(xlsExport.toString())
                + "\">Export XLS</a>]");
    }
}

From source file:com.ah.ui.actions.monitor.MapNodeAction.java

/**
 * For XSS issue reported by LinkLater, escape the menu text response to browser to avoid reflected XSS
 * /*from  w w w . j  a  v  a  2  s.c o m*/
 * @author Yunzhi Lin
 * - Time: Dec 20, 2013 4:27:09 PM
 * @param menuText
 * @return
 */
private String escapseMenuText(String menuText) {
    menuText = StringEscapeUtils.escapeHtml4(menuText);
    return menuText;
}

From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

private void createHTMLpagination(StringBuilder html, ViewQuery query, Info info) {
    long lastRow = (info.getStartIndex() + info.getPageSize());
    long firstRow = info.getTotalSize() > 0 ? (info.getStartIndex() + 1) : 0;
    html.append("<br><div>rows from " + firstRow + " to " + lastRow + " out of " + info.getTotalSize()
            + " records");
    if (info.isComplete()) {
        html.append(" (the query is complete)");
    } else {//from   w ww.j av a 2 s  .c o m
        html.append(" (the query has more data)");
    }
    if (lastRow < info.getTotalSize()) {
        // go to next page
        HashMap<String, Object> override = new HashMap<>();
        override.put(START_INDEX_PARAM, lastRow);
        URI nextLink = buildAnalyticsViewURI(userContext, query, null, null, Style.HTML, override);
        html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(nextLink.toString()) + "\">next</a>]");
    }
    html.append("</p>");
    if (info.isFromSmartCache()) {
        html.append("<p>data from smart-cache, last computed " + info.getExecutionDate() + "</p>");
    } else if (info.isFromCache()) {
        html.append("<p>data from cache, last computed " + info.getExecutionDate() + "</p>");
    } else {
        html.append("<p>fresh data just computed at " + info.getExecutionDate() + "</p>");
    }
}

From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

/**
 * @param string//  ww w. j  ava  2s  .c  o m
 * @return
 */
private Response createHTMLsql(String sql) {
    StringBuilder html = new StringBuilder("<html><head>");
    html.append(
            "<script src='https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=sql'></script>");
    html.append("</head><body>");
    html.append(
            "<pre class='prettyprint lang-sql' style='white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;padding:0px;margin:0px'>");
    html.append(StringEscapeUtils.escapeHtml4(sql));
    html.append("</pre>");
    html.append("</body></html>");
    return Response.ok(html.toString(), "text/html").build();
}

From source file:com.ah.ui.actions.BaseAction.java

private List<CheckItem> getBoCheckItems(String fieldName, Class<? extends HmBo> boClass, FilterParams filterPa,
        SortParams sortParams, short beginWith, short endWith, boolean escape) {
    // check input params
    if (fieldName == null || fieldName.isEmpty() || boClass == null) {
        return null;
    }/*w ww. j  av a  2  s.  c om*/

    // get list of id and name from database
    String sql = "SELECT bo.id, bo." + fieldName + " FROM " + boClass.getSimpleName() + " bo";
    List<?> bos = QueryUtil.executeQuery(sql, sortParams, filterPa, domainId);

    List<CheckItem> items = new ArrayList<CheckItem>();

    // some ssid cannot to be used
    boolean ifIsSsid = boClass.getName().equals("com.ah.bo.wlan.SsidProfile");
    for (Object obj : bos) {
        Object[] item = (Object[]) obj;
        String profileName = (String) item[1];
        if (ifIsSsid) {
            if (BeParaModule.SSID_PROFILE_TEMPLATE_SYMBOL_SCANNER.equals(profileName)
                    || BeParaModule.SSID_PROFILE_TEMPLATE_LEGACY_CLIENTS.equals(profileName)
                    || BeParaModule.SSID_PROFILE_TEMPLATE_HIGH_CAPACITY.equals(profileName)
                    || BeParaModule.SSID_PROFILE_TEMPLATE_BLACK_BERRY.equals(profileName)
                    || BeParaModule.SSID_PROFILE_TEMPLATE_SPECTRA_LINK.equals(profileName)) {
                continue;
            }
        }
        CheckItem checkItem = new CheckItem((Long) item[0],
                escape ? StringEscapeUtils.escapeHtml4(profileName) : profileName);
        items.add(checkItem);
    }

    // add the special item
    switch (beginWith) {
    case CHECK_ITEM_BEGIN_BLANK:
        if (boClass.getName().equals(Vlan.class.getName())) {
            items.add(0, new CheckItem((long) CHECK_ITEM_ID_BLANK, "Create new VLAN"));
        } else {
            items.add(0, new CheckItem((long) CHECK_ITEM_ID_BLANK, ""));
        }
        break;
    case CHECK_ITEM_BEGIN_NO:
        // fall through
    default:
        break;
    }

    if (items.isEmpty()) {
        items.add(new CheckItem((long) CHECK_ITEM_ID_NONE,
                MgrUtil.getUserMessage("config.optionsTransfer.none")));
    }

    // add the special item
    switch (endWith) {
    case CHECK_ITEM_END_NEW:
        if (this.getWriteDisabled().isEmpty())
            items.add(new CheckItem((long) CHECK_ITEM_ID_NEW, CHECK_ITEM_NEW));
        break;
    case CHECK_ITEM_END_NO:
        // fall through
    default:
        break;
    }
    return items;
}

From source file:com.ah.ui.actions.monitor.MapsAction.java

public static JSONObject prepareNodes(Set<MapNode> nodes, Long pageId, double scale) throws Exception {
    JSONObject jsonObject = new JSONObject();
    Collection<JSONObject> jsonNodes = new Vector<JSONObject>();
    boolean hasPageId = false;

    Set<MapNode> mapNodes = new HashSet<MapNode>();
    Set<Long> leafNodeIds = new HashSet<Long>();
    for (MapNode mapNode : nodes) {
        if (mapNode.isLeafNode()) {
            MapLeafNode leafNode = (MapLeafNode) mapNode;
            mapNodes.add(leafNode);/*from ww w  . j  a  va  2  s  . c  om*/
            leafNodeIds.add(mapNode.getId());
        } else {
            mapNodes.add(mapNode);
        }
    }

    Map<Long, HiveAp> hiveApAttrs = new HashMap<Long, HiveAp>();
    if (!leafNodeIds.isEmpty()) {
        // Query for the managed status only
        String query = "select bo.id, bo.hiveAp.manageStatus, bo.hiveAp.hiveApType, "
                + "bo.hiveAp.radiusServerProfile.id, bo.hiveAp.configTemplate.vpnService.id, "
                + "bo.hiveAp.dhcpServerCount, bo.hiveAp.vpnMark, bo.hiveAp.simulated, "
                + "bo.hiveAp.radiusProxyProfile.id, bo.hiveAp.ipAddress, bo.hiveAp.deviceType, "
                + "bo.hiveAp.hiveApModel from " + MapLeafNode.class.getSimpleName() + " bo";
        List<?> attributes_list = QueryUtil.executeQuery(query, null, new FilterParams("id", leafNodeIds));
        for (Object obj : attributes_list) {
            Object[] attributes = (Object[]) obj;
            HiveAp hiveAp = new HiveAp();
            hiveAp.setManageStatus((Short) attributes[1]);
            hiveAp.setHiveApType((Short) attributes[2]);
            Long radiusId = (Long) attributes[3];
            Long vpnId = (Long) attributes[4];
            Integer dhcpCount = (Integer) attributes[5];
            Short vpnMark = (Short) attributes[6];
            Boolean simulated = (Boolean) attributes[7];
            Long radiusProxyId = (Long) attributes[8];
            hiveAp.setIpAddress((String) attributes[9]);
            hiveAp.setDeviceType((Short) attributes[10]);
            hiveAp.setHiveApModel((Short) attributes[11]);
            if (null != radiusId) {// RADIUS Server
                RadiusOnHiveap radius = new RadiusOnHiveap();
                radius.setId(radiusId);
                hiveAp.setRadiusServerProfile(radius);
            }
            if (null != vpnId) {// VPN Server
                VpnService vpn = new VpnService();
                vpn.setId(vpnId);
                ConfigTemplate wlan = new ConfigTemplate(ConfigTemplateType.WIRELESS);
                wlan.setVpnService(vpn);
                hiveAp.setConfigTemplate(wlan);
                hiveAp.setVpnMark(vpnMark == null ? HiveAp.VPN_MARK_NONE : vpnMark);
            }
            if (null != dhcpCount) {// DHCP Server
                hiveAp.setDhcpServerCount(dhcpCount);
            }
            if (null != simulated) {
                hiveAp.setSimulated(simulated);
            }
            if (null != radiusProxyId) {// set RADIUS Proxy Profile;
                RadiusProxy radius = new RadiusProxy();
                radius.setId(radiusProxyId);
                hiveAp.setRadiusProxyProfile(radius);
            }
            hiveApAttrs.put((Long) attributes[0], hiveAp);
        }
    }

    for (MapNode mapNode : mapNodes) {
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("nodeId", "n" + mapNode.getId());
        jsonObj.put("x", scale(mapNode.getX(), scale));
        jsonObj.put("y", scale(mapNode.getY(), scale));
        jsonObj.put("s", mapNode.getSeverity());
        jsonObj.put("i", mapNode.getIconName());
        if (!hasPageId) {
            jsonObj.put("pageId", pageId);
            hasPageId = true;
        }
        if (mapNode.isLeafNode()) {
            MapLeafNode mapLeafNode = (MapLeafNode) mapNode;
            jsonObj.put("apId", mapLeafNode.getApId());
            jsonObj.put("apName", mapLeafNode.getApName());
            String ethId = ((MapLeafNode) mapNode).getEthId();
            if (null != ethId && !("".equals(ethId.trim()))) {
                jsonObj.put("ethId", ethId);
            }
            if (mapLeafNode.isFetchLinksTimeout() && mapLeafNode.getApId().charAt(0) != 'M') {
                jsonObj.put("isCritical", true);
            }

            HiveAp hiveAp = hiveApAttrs.get(mapNode.getId());
            if (null != hiveAp) {
                jsonObj.put("ipAddress", hiveAp.getIpAddress());
                // device type
                jsonObj.put("dt", hiveAp.getDeviceType());
                // device model
                jsonObj.put("dm", hiveAp.getHiveApModel());
                String nodeId = ((MapLeafNode) mapNode).getApId();
                // set the managed status
                if (hiveAp.getManageStatus() == HiveAp.STATUS_MANAGED) {
                    jsonObj.put("isManaged", true);
                }
                /* AP_TYPE | RADIUS | VPN | DHCP | Proxy Server */
                boolean isPortal = hiveAp.getHiveApType() == HiveAp.HIVEAP_TYPE_PORTAL;
                boolean isRadius = null != hiveAp.getRadiusServerProfile();
                boolean isVpnServer = hiveAp.isVpnServer();
                boolean isVpnClient = hiveAp.isVpnClient();
                boolean isDhcp = 0 < hiveAp.getDhcpServerCount();
                boolean isProxyServer = null != hiveAp.getRadiusProxyProfile();

                Long vpnId = null;
                if (null != hiveAp.getConfigTemplate() && null != hiveAp.getConfigTemplate().getVpnService()) {
                    vpnId = hiveAp.getConfigTemplate().getVpnService().getId();
                }
                VpnStatus vpnStatus = isVpnServer ? AhVPNStatus.isVpnServerUp(nodeId)
                        : AhVPNStatus.isVpnClientUp(nodeId, vpnId);
                // set ap type
                String a = isPortal ? "1" : "0";
                String b = isRadius ? "1" : "0";
                String c = isVpnServer ? (VpnStatus.Up.equals(vpnStatus) ? "3" : "1")
                        : (isVpnClient ? (VpnStatus.Up.equals(vpnStatus) ? "4"
                                : (VpnStatus.Half.equals(vpnStatus) ? "5" : "2")) : "0");
                String d = isDhcp ? "1" : "0";
                String e = isProxyServer ? "1" : "0";
                jsonObj.put("apType", a + "|" + b + "|" + c + "|" + d + "|" + e);

                // check whether is SR only
                jsonObject.put("noRadio", jsonObject.optBoolean("noRadio", true) && hiveAp.isSwitchProduct());
            }

        } else {
            jsonObj.put("container", true);
            jsonObj.put("ctp", ((MapContainerNode) mapNode).getMapType());
            jsonObj.put("mapName", StringEscapeUtils.escapeHtml4(((MapContainerNode) mapNode).getMapName()));
            Float latitude = mapNode.getLatitude();
            Float longitude = mapNode.getLongitude();
            if (latitude == null || longitude == null) {
                latitude = mapNode.getCenterLatitude();
                longitude = mapNode.getCenterLongitude();
            }
            jsonObj.put("lat", latitude == null ? "" : latitude);
            jsonObj.put("lng", longitude == null ? "" : longitude);
            boolean na = longitude == null || longitude == null;
            jsonObj.put("na", na);
            if (na) {
                jsonObj.put("address", mapNode.getAddress() == null ? "" : mapNode.getAddress());
            }
        }
        jsonNodes.add(jsonObj);
    }
    jsonObject.put("ntp", "nodes");
    jsonObject.put("nodes", jsonNodes);
    return jsonObject;
}

From source file:fi.foyt.fni.materials.MaterialController.java

private Material uploadText(Folder parentFolder, User loggedUser, FileData fileData)
        throws UnsupportedEncodingException {

    String title = fileData.getFileName();
    String bodyContent = StringEscapeUtils.escapeHtml4(new String(fileData.getData(), "UTF-8"));
    bodyContent = bodyContent.replaceAll("\n", "<br/>");
    String data = HtmlUtils.getAsHtmlText(title, bodyContent);

    return createDocument(parentFolder, loggedUser, data, title);
}

From source file:fi.foyt.fni.materials.MaterialController.java

private FileData getCharacterSheetMaterialData(String contextPath, CharacterSheet characterSheet)
        throws UnsupportedEncodingException {
    StringBuilder htmlBuilder = new StringBuilder();
    htmlBuilder.append("<!DOCTYPE html>");
    htmlBuilder.append("<html>");
    htmlBuilder.append("<head>");
    htmlBuilder.append("<meta charset=\"UTF-8\">");

    htmlBuilder.append(//w  ww.  j a v  a 2  s .  c  o m
            "<script type=\"text/javascript\" charset=\"utf8\" src=\"//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>");
    htmlBuilder.append(
            "<script type=\"text/javascript\" charset=\"utf8\" src=\"//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js\"></script>");
    htmlBuilder.append(
            "<script type=\"text/javascript\" charset=\"utf8\" src=\"//cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js\"></script>");
    htmlBuilder.append(
            "<link rel=\"StyleSheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/css/jquery-ui.min.css\"></link>");
    htmlBuilder.append("<script type=\"text/javascript\" charset=\"utf8\" src=\"" + contextPath
            + "/scripts/gui/character-sheet.js\"></script>");

    if (StringUtils.isNotBlank(characterSheet.getTitle())) {
        htmlBuilder.append("<title>");
        htmlBuilder.append(StringEscapeUtils.escapeHtml4(characterSheet.getTitle()));
        htmlBuilder.append("</title>");
    }

    if (StringUtils.isNoneBlank(characterSheet.getStyles())) {
        htmlBuilder.append("<style type=\"text/css\">");
        htmlBuilder.append(characterSheet.getStyles());
        htmlBuilder.append("</style>");
    }

    if (StringUtils.isNoneBlank(characterSheet.getScripts())) {
        htmlBuilder.append("<script type=\"text/javascript\">");
        htmlBuilder.append(characterSheet.getScripts());
        htmlBuilder.append("</script>");
    }

    htmlBuilder.append("</head>");
    htmlBuilder.append("<body>");
    htmlBuilder.append(characterSheet.getContents());
    htmlBuilder.append("</body>");
    htmlBuilder.append("</html>");

    return new FileData(null, characterSheet.getUrlName(), htmlBuilder.toString().getBytes("UTF-8"),
            "text/html", characterSheet.getModified());
}