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.inet.web.service.mail.utils.MailHeaderHelper.java

/**
 * convert to JSON from given mail header DTO
 * @param header MailHeaderDTO/*from w  w  w. j a  va2 s  .c  om*/
 * @return JSON
 */
public static JSON convertMailHeaderDTO2JSon(MailHeaderDTO header) {
    JSONObject json = new JSONObject();

    json.accumulate(MailConstants.CONTENT_ID, header.getContentId()).accumulate(MailConstants.SUBJECT,
            StringEscapeUtils.escapeHtml(StringService.hasLength(header.getSubject()) ? header.getSubject()
                    : StringService.EMPTY_STRING))
            .accumulate(MailConstants.FROM,
                    (header.getFrom() != null) ? StringEscapeUtils.escapeHtml(AddressParser
                            .toUnicodeString(header.getFrom()).replace("\"", StringService.EMPTY_STRING))
                            : StringService.EMPTY_STRING)
            .accumulate(MailConstants.SENT_DATE, header.getSent() != null ? header.getSent().getTime() : 0L)
            .accumulate(MailConstants.TO, JSONService.toJSONArray(convertAddress(header.getTo())))
            .accumulate(MailConstants.CC, JSONService.toJSONArray(convertAddress(header.getCc())))
            .accumulate(MailConstants.BCC, JSONService.toJSONArray(convertAddress(header.getBcc())))
            .accumulate(MailConstants.ATTACHMENTS, JSONService.toJSONArray(convertAttachments(header)))
            .accumulate(MailConstants.BODY_TEXT,
                    StringService.hasLength(header.getBodyText()) ? header.getBodyText()
                            : StringService.EMPTY_STRING);

    return json;
}

From source file:com.redhat.rhn.domain.action.rhnpackage.PackageAction.java

/**
 * {@inheritDoc}/*  w ww  . j a va2 s  .  com*/
 */
@Override
public String getHistoryDetails(Server server) {
    LocalizationService ls = LocalizationService.getInstance();
    StringBuilder retval = new StringBuilder();
    retval.append("</br>");
    if (this.getClass().equals(PackageUpdateAction.class)) {
        retval.append(ls.getMessage("system.event.packagesSchedule"));
    } else if (this.getClass().equals(PackageVerifyAction.class)) {
        retval.append(ls.getMessage("system.event.packagesVerify"));
    }
    if (this.getClass().equals(PackageRemoveAction.class)) {
        retval.append(ls.getMessage("system.event.packagesRemove"));
    }
    retval.append("</br><ul>");
    for (PackageActionDetails pad : details) {
        retval.append("<li>");
        String nevra = PackageManager.buildPackageNevra(pad.getPackageName(), pad.getEvr(), pad.getArch());
        retval.append(StringEscapeUtils.escapeHtml(nevra));
        retval.append("</li>");
    }
    retval.append("</ul>");
    return retval.toString();
}

From source file:com.redhat.rhn.frontend.action.systems.monitoring.ProbeDeleteAction.java

private boolean handleSubmit(Probe probe, User user, DynaActionForm form, HttpServletRequest req) {

    boolean submitted = isSubmitted(form);
    if (submitted) {
        MonitoringManager.getInstance().deleteProbe(probe, user);
        createSuccessMessage(req, "probeedit.probedeleted",
                StringEscapeUtils.escapeHtml(probe.getDescription()));
    }// w  ww  .  ja  va2  s.c o  m
    return submitted;
}

From source file:com.asual.summer.core.faces.FacesResourceProcessor.java

public static byte[] execute(URL url, InputStream input, String encoding) throws IOException {

    byte[] bytes;

    try {//from  www  . j  a  v a 2  s.  c  om

        StringBuilder sb = new StringBuilder();
        UnicodeReader reader = new UnicodeReader(input, encoding);

        try {

            char[] cbuf = new char[32];
            int r;
            while ((r = reader.read(cbuf, 0, 32)) != -1) {
                sb.append(cbuf, 0, r);
            }

            String str = sb.toString();

            if (!str.contains("ui:component")) {

                try {

                    String fileEncoding = reader.getEncoding();
                    InputSource is = new InputSource(new StringReader(str));
                    is.setEncoding(fileEncoding);

                    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

                    XMLDocumentFilter[] filters = { new Writer(baos, fileEncoding) {

                        protected void printStartElement(QName element, XMLAttributes attributes) {
                            fPrinter.print('<');
                            fPrinter.print(element.rawname);
                            int attrCount = attributes != null ? attributes.getLength() : 0;
                            for (int i = 0; i < attrCount; i++) {
                                String aname = attributes.getQName(i);
                                String avalue = attributes.getValue(i);
                                fPrinter.print(' ');
                                fPrinter.print(aname);
                                fPrinter.print("=\"");
                                printAttributeValue(avalue);
                                fPrinter.print('"');
                            }
                            if (HTMLElements.getElement(element.rawname).isEmpty()) {
                                fPrinter.print(' ');
                                fPrinter.print('/');
                            }
                            fPrinter.print('>');
                            fPrinter.flush();
                        }

                        protected void printAttributeValue(String text) {
                            fPrinter.print(StringEscapeUtils.escapeHtml(text));
                            fPrinter.flush();
                        }

                        protected void printEntity(String name) {
                            fPrinter.print('&');
                            fPrinter.print('#');
                            fPrinter.print(HTMLEntities.get(name));
                            fPrinter.print(';');
                            fPrinter.flush();
                        }

                    } };

                    DOMParser parser = new DOMParser();
                    parser.setFeature("http://cyberneko.org/html/features/balance-tags", false);
                    parser.setFeature("http://cyberneko.org/html/features/scanner/notify-builtin-refs", true);
                    parser.setProperty("http://cyberneko.org/html/properties/default-encoding", fileEncoding);
                    parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
                    parser.setProperty("http://cyberneko.org/html/properties/filters", filters);
                    parser.parse(is);

                    str = "<!DOCTYPE html>" + baos.toString(fileEncoding);

                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }

                if (url.getFile().contains("META-INF/templates")) {
                    str = "<ui:component xmlns:ui=\"http://java.sun.com/jsf/facelets\">"
                            + Pattern
                                    .compile("(<\\!DOCTYPE html>)|(</?html[^>]*>)|(<title>[^<]*</title>)",
                                            Pattern.CASE_INSENSITIVE)
                                    .matcher(str).replaceAll("").replaceAll("\\$\\{template\\.body\\}",
                                            "<ui:insert />")
                            + "</ui:component>";
                }

            }

            bytes = str.getBytes(reader.getEncoding());

        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw e;
    }

    return bytes;
}

From source file:com.alibaba.jstorm.ui.controller.ZookeeperController.java

@RequestMapping(value = UIDef.API_V2 + "/zookeeper/node", produces = "application/json;")
@ResponseBody/*ww w. j  a v  a 2 s  .  c  o  m*/
public Map<String, Object> getChildren(@RequestParam String path, String clusterName) {
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    List<ZookeeperNode> result = ZookeeperManager.listZKNodes(clusterName, path);
    Map<String, Object> map = new HashMap<>();
    map.put("nodes", result);
    return map;
}

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

public String getTitle() {
    return StringEscapeUtils.escapeHtml(title);
}

From source file:com.fluidops.iwb.ui.configuration.SparqlEditor.java

private void initialize() {

    frameId = "sparql-iframe-" + Rand.getIncrementalFluidUUID();
    FHTML editor = new FHTML("sparql",
            "<iframe id='" + frameId + "' frameborder='0' width='100%' height='450px' src='"
                    + EndpointImpl.api().getRequestMapper().getContextPath() + "/sparqleditor' "
                    + "onload=\"var iframe = document.getElementById('" + frameId + "');"
                    + " var flint = iframe.contentWindow.flintEditor;"
                    + " flint.getEditor().getCodeEditor().setValue('"
                    + StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(query)) + "');" + "\">"
                    + "</iframe>");
    add(editor);/*from  w  ww  .  ja va2  s. c om*/

    FButton submit = new FButton("update", submitBtnLabel) {
        @Override
        public void onClick() {
            addClientUpdate(new FClientUpdate(Prio.VERYBEGINNING,
                    getQueryStringJavascript() + " catchPostEventIdEncode('" + SparqlEditor.this.getId()
                            + "',9, query,'" + SUBMIT_EVENT_PARAM_NAME + "');"));
        }
    };
    add(submit, "floatLeft");

    FButton preview = new FButton("preview", "Preview") {
        @Override
        public void onClick() {
            addClientUpdate(new FClientUpdate(Prio.VERYBEGINNING,
                    getQueryStringJavascript() + " catchPostEventIdEncode('" + SparqlEditor.this.getId()
                            + "',9, query,'" + PREVIEW_EVENT_PARAM_NAME + "');"));
        }
    };
    add(preview, "floatLeft");

}

From source file:at.gv.egovernment.moa.id.auth.servlet.SSOSendAssertionServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String id = null;/* w ww  .j  a  v  a  2s.  com*/
    Logger.info("Receive " + SSOSendAssertionServlet.class + " Request");
    try {

        Object idObject = req.getParameter(ID);

        if (idObject != null && (idObject instanceof String)) {
            id = (String) idObject;
        }

        String value = req.getParameter(PARAM);
        value = StringEscapeUtils.escapeHtml(value);
        if (!ParamValidatorUtils.isValidUseMandate(value))
            throw new WrongParametersException("SSOSendAssertionServlet", PARAM, null);

        //get module and action
        Object moduleObject = req.getParameter(MODULE);
        String module = null;
        if (moduleObject != null && (moduleObject instanceof String)) {
            module = (String) moduleObject;
        }

        Object actionObject = req.getParameter(ACTION);
        String action = null;
        if (actionObject != null && (actionObject instanceof String)) {
            action = (String) actionObject;
        }

        if (MiscUtil.isEmpty(module) || MiscUtil.isEmpty(action) || MiscUtil.isEmpty(id)) {
            Logger.warn("No Moduel or Action parameter received!");
            throw new WrongParametersException("Module or Action is empty", "", "auth.10");
        }

        SSOManager ssomanager = SSOManager.getInstance();
        //get SSO Cookie for Request
        String ssoId = ssomanager.getSSOSessionID(req);

        //check SSO session
        if (ssoId != null) {
            String correspondingMOASession = ssomanager.existsOldSSOSession(ssoId);

            if (correspondingMOASession != null) {
                Logger.warn("Request sends an old SSO Session ID(" + ssoId + ")! "
                        + "Invalidate the corresponding MOASession with ID=" + correspondingMOASession);

                AuthenticationSessionStoreage.destroySession(correspondingMOASession);

                ssomanager.deleteSSOSessionID(req, resp);
            }
        }

        boolean isValidSSOSession = ssomanager.isValidSSOSession(ssoId, null);

        String moaSessionID = null;

        if (isValidSSOSession) {

            //check UseMandate flag
            String valueString = null;
            ;
            if ((value != null) && (value.compareTo("") != 0)) {
                valueString = value;
            } else {
                valueString = "false";
            }

            if (valueString.compareToIgnoreCase("true") == 0) {
                moaSessionID = AuthenticationSessionStoreage.getMOASessionSSOID(ssoId);
                AuthenticationSession moasession = AuthenticationSessionStoreage.getSession(moaSessionID);
                AuthenticationSessionStoreage.setAuthenticated(moaSessionID, true);

                String redirectURL = new DataURLBuilder().buildDataURL(moasession.getAuthURL(),
                        ModulUtils.buildAuthURL(module, action, id), "");

                resp.setContentType("text/html");
                resp.setStatus(302);

                resp.addHeader("Location", redirectURL);
                Logger.debug("REDIRECT TO: " + redirectURL);

            }

            else {
                throw new AuthenticationException("auth.21", new Object[] {});
            }

        } else {
            handleError("SSO Session is not valid", null, req, resp, id);
        }

    } catch (MOADatabaseException e) {
        handleError("SSO Session is not found", e, req, resp, id);

    } catch (WrongParametersException e) {
        handleError("Parameter is not valid", e, req, resp, id);

    } catch (AuthenticationException e) {
        handleError(e.getMessage(), e, req, resp, id);

    } catch (Exception e) {
        Logger.error("SSOSendAssertion has an interal Error.", e);
    }

}

From source file:joGraph.HtmlGraphWriter.java

private String escape(String text) {
    return StringEscapeUtils.escapeHtml(text);
}

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

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

    try {/* w w  w .  ja  v  a2s.  c  o m*/
        // Encode logLine and send chunks
        encodeSend(CharBuffer.wrap(logLine), false);
        count.incrementAndGet();
    } catch (IOException e) {
        // Just propagate the exception, the caller of this Callback should be handling it.
        throw Throwables.propagate(e);
    }
}