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.redhat.rhn.frontend.struts.RhnListDispatchAction.java

/**
 * Add a success message to the request with 1 parameter:
 *
 * Your System55 has been updated/*w w  w  .j  a  v a 2 s.c o m*/
 *
 * where System55 is the value placed in param1.  param1
 *
 * @param req to add the message to
 * @param msgKey resource key to lookup
 * @param param1 String value to fill in for the first parameter.
 *               (param1 is HTML escaped as well)
 */
protected void createSuccessMessage(HttpServletRequest req, String msgKey, String param1) {
    ActionMessages msg = new ActionMessages();
    Object[] args = new Object[1];
    args[0] = StringEscapeUtils.escapeHtml(param1);
    msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(msgKey, args));
    getStrutsDelegate().saveMessages(req, msg);
}

From source file:com.aurel.track.fieldType.runtime.custom.text.CustomLongTextRT.java

/**
 * Get the show value called when an item result set is implied
 * @param fieldID/*from  w w w. ja v  a 2  s  .  c om*/
 * @param parameterCode
 * @param value
 * @param workItemID
 * @param localLookupContainer
 * @param locale 
 * @return
 */
@Override
public String getShowValue(Integer fieldID, Integer parameterCode, Object value, Integer workItemID,
        LocalLookupContainer localLookupContainer, Locale locale) {
    String strValue = "";
    try {
        strValue = (String) value;
        String escapedHTML = StringEscapeUtils.escapeHtml(strValue);
        return Text2HTML.addHTMLBreaks(escapedHTML);
    } catch (Exception e) {
        return strValue;
    }
}

From source file:com.timesheet.export.PdfGenerator.java

@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    /* Add header*/
    Font fontHeader = FontFactory.getFont(FontFactory.TIMES_ROMAN, 22, Font.BOLD);
    Paragraph headerPara = new Paragraph("Time sheet report", fontHeader);
    headerPara.setSpacingAfter(20f);//from w  ww  . j  a  v a  2s . c o  m
    document.add(headerPara);

    /*Add user info*/
    User userProfile = (User) model.get("userprofile");
    Font fontUserInfo = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
    document.add(new Paragraph("Name : " + userProfile.getName(), fontUserInfo));
    document.add(new Paragraph("User no. : " + userProfile.getUserIdentifier(), fontUserInfo));
    document.add(new Paragraph("Department : " + userProfile.getDepartment(), fontUserInfo));
    document.add(new Paragraph("Email : " + userProfile.getEmail(), fontUserInfo));
    Paragraph spacing = new Paragraph("");
    spacing.setSpacingAfter(20f);
    document.add(spacing);

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100.0f);
    table.setWidths(new float[] { 5.0f, 3.0f, 3.0f, 3.0f, 10.0f });
    table.setSpacingBefore(10);

    // define font for table header row
    Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);
    //font.setColor(BaseColor.WHITE);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    //cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPadding(5);
    cell.setBorderWidth(2.0f);
    cell.setBorder(Rectangle.BOTTOM);
    // get data model which is passed by the Spring container
    List<Booking> bookings = (List<Booking>) model.get("bookings");

    // write table header
    cell.setPhrase(new Phrase("Project", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Option", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Date", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Duration", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Description", font));
    table.addCell(cell);

    int sum = 0;

    Font fontData = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11);

    for (Booking booking : bookings) {
        PdfPCell cell1 = new PdfPCell(new Phrase(
                booking.getProject().getProjectId() + "-" + booking.getProject().getName(), fontData));
        cell1.setBorder(Rectangle.BOTTOM);
        cell1.setPadding(5);
        table.addCell(cell1);
        PdfPCell cell2 = new PdfPCell(new Phrase(booking.getBookingOption().getOptionLabel(), fontData));
        cell2.setBorder(Rectangle.BOTTOM);
        cell2.setPadding(5);
        table.addCell(cell2);
        PdfPCell cell3 = new PdfPCell(new Phrase(formatDate(booking.getBookingDate()), fontData));
        cell3.setBorder(Rectangle.BOTTOM);
        cell3.setPadding(5);
        table.addCell(cell3);
        int hh = booking.getDuration() / 60;
        int mm = booking.getDuration() % 60;
        PdfPCell cell4 = new PdfPCell(new Phrase(hh + ":" + mm, fontData));
        cell4.setBorder(Rectangle.BOTTOM);
        cell4.setPadding(5);
        table.addCell(cell4);
        PdfPCell cell5 = new PdfPCell(
                new Phrase(StringEscapeUtils.escapeHtml(booking.getDescription()), fontData));
        cell5.setBorder(Rectangle.BOTTOM);
        cell5.setPadding(5);
        table.addCell(cell5);

        sum += booking.getDuration();
    }

    document.add(table);

    int sumHH = sum / 60;
    int sumMM = sum % 60;

    document.add(new Paragraph("Sum : " + sumHH + ":" + sumMM, fontUserInfo));
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

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

/**
 * //from   ww w .  j a v a 2s .  c o m
 * @param itemToRender
* @param selected 
 * @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) {
    SoapOperation soapOp = (SoapOperation) itemToRender;

    Ancestors ancestors = soapOp.getAncestors();
    SoapService soapService = ancestors.getSoapService();
    Service service = ancestors.getService();
    String title = StringEscapeUtils.escapeHtml(Resource.getDisplayNameForResource(soapOp));

    if (soapOp.isSetArchived() || service.isSetArchived()) {
        jlTypeIcon.setIcon(ResourceManager.getImageIcon(ResourceManager.WARNING_ICON));
        title = "<html>" + title + "<i> - this operation is archived and probably cannot be used</i></html>";
    } else if (isSoapLab(service)) {
        jlTypeIcon.setIcon(ResourceManager.getImageIcon(ResourceManager.WARNING_ICON));
        title = "<html>" + title
                + "<i> - this operation can only be used as part of a SoapLab service</i></html>";
    } else {
        jlTypeIcon.setIcon(resourceType.getIcon());
        title = "<html>" + title + "</html>";
    }

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

    jlPartOf.setText("<html><b>Part of: </b>"
            + StringEscapeUtils.escapeHtml(soapOp.getAncestors().getSoapService().getResourceName())
            + "</html>");

    jlWsdlLocation.setText("<html><b>WSDL location: </b>" + soapService.getWsdlLocation() + "</html>");

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

    jtDescription.setText(strDescription);

    // add SOAP inputs
    List<String> names = new ArrayList<String>();
    for (SoapInput soapInput : soapOp.getInputs().getSoapInputList()) {
        names.add(soapInput.getName());
    }

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

    c.gridy++;
    this.add(jlSoapInputs, c);

    // add SOAP outputs
    names.clear();
    for (SoapOutput soapOutput : soapOp.getOutputs().getSoapOutputList()) {
        names.add(soapOutput.getName());
    }

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

    return (arrangeLayout());
}

From source file:com.google.visualization.datasource.render.EscapeUtil.java

/**
 * Escapes the string for embedding in html.
 *
 * @param str The string to escape.// ww w.j a  v a  2  s  .c  om
 *
 * @return The escaped string.
 */
public static String htmlEscape(String str) {
    return StringEscapeUtils.escapeHtml(str);
}

From source file:io.github.tavernaextras.biocatalogue.integration.Integration.java

/**
 * Adds a processor to the current workflow.
 * The processor is specified by WSDL location and the operation name.
 * //from   w  w  w  . ja  v a2s. c  o m
 * @param processorResource Resource to add to the current workflow.
 * @return Outcome of inserting the processor into the current workflow as a
 *         HTML-formatted string (with no opening and closing HTML tags).
 */
public static JComponent insertProcessorIntoCurrentWorkflow(ResourceLink processorResource) {
    // check if this type of resource can be added to workflow diagram
    TYPE resourceType = Resource.getResourceTypeFromResourceURL(processorResource.getHref());
    if (resourceType.isSuitableForAddingToWorkflowDiagram()) {
        switch (resourceType) {
        case SOAPOperation:
            SoapOperation soapOp = (SoapOperation) processorResource;
            try {
                SoapService soapService = BioCatalogueClient.getInstance()
                        .getBioCatalogueSoapService(soapOp.getAncestors().getSoapService().getHref());

                try {
                    WSDLServiceDescription myServiceDescription = new WSDLServiceDescription();
                    myServiceDescription.setOperation(soapOp.getName());
                    myServiceDescription.setUse("literal"); // or "encoded"
                    myServiceDescription.setStyle("document"); // or "rpc"
                    myServiceDescription.setURI(new URI(soapService.getWsdlLocation()));
                    myServiceDescription
                            .setDescription(StringEscapeUtils.escapeHtml(soapService.getDescription())); // TODO - not sure where this is used

                    if (WorkflowView.importServiceDescription(myServiceDescription, false) != null) {
                        return (new JLabel(
                                "Selected " + TYPE.SOAPOperation.getTypeName()
                                        + " was successfully added to the current workflow",
                                ResourceManager.getImageIcon(ResourceManager.TICK_ICON), JLabel.CENTER));
                    } else {
                        return (new JLabel("<html><center>Taverna was unable to add selected "
                                + TYPE.SOAPOperation.getTypeName()
                                + " as a service to the current workflow.<br>This could be because the service is currently not accessible.</center></html>",
                                ResourceManager.getImageIcon(ResourceManager.ERROR_ICON), JLabel.CENTER));
                    }
                } catch (URISyntaxException e) {
                    logger.error("Couldn't add " + TYPE.SOAPOperation + " to the current workflow", e);
                    return (new JLabel(
                            "<html>Could not add the selected " + TYPE.SOAPOperation.getTypeName()
                                    + " to the current workflow.<br>"
                                    + "Log file will containt additional details about this error.</html>",
                            ResourceManager.getImageIcon(ResourceManager.ERROR_ICON), JLabel.CENTER));
                }

            } catch (Exception e) {
                logger.error("Failed to fetch required details to add this " + TYPE.SOAPOperation
                        + " into the current workflow.", e);
                return (new JLabel(
                        "<html>Failed to fetch required details to add this<br>"
                                + TYPE.SOAPOperation.getTypeName() + " into the current workflow.</html>",
                        ResourceManager.getImageIcon(ResourceManager.ERROR_ICON), JLabel.CENTER));
            }

        case RESTMethod:
            // received object may only contain limited data, therefore need to fetch full details first
            try {
                RestMethod restMethod = BioCatalogueClient.getInstance()
                        .getBioCatalogueRestMethod(processorResource.getHref());

                // actual import of the service into the workflow
                RESTFromBioCatalogueServiceDescription restServiceDescription = createRESTServiceDescriptionFromRESTMethod(
                        restMethod);
                WorkflowView.importServiceDescription(restServiceDescription, false);

                // prepare result of the operation to be shown in the the waiting dialog window
                String warnings = extractWarningsFromRESTServiceDescription(restServiceDescription, false);
                JLabel outcomes = new JLabel(
                        "<html>Selected " + TYPE.RESTMethod.getTypeName()
                                + " was successfully added to the current workflow" + warnings + "</html>",
                        ResourceManager.getImageIcon(warnings.length() > 0 ? ResourceManager.WARNING_ICON
                                : ResourceManager.TICK_ICON),
                        JLabel.CENTER);
                outcomes.setIconTextGap(20);
                return (outcomes);
            } catch (UnsupportedHTTPMethodException e) {
                logger.error(e);
                return (new JLabel(e.getMessage(), ResourceManager.getImageIcon(ResourceManager.ERROR_ICON),
                        JLabel.CENTER));
            } catch (Exception e) {
                logger.error("Failed to fetch required details to add this " + TYPE.RESTMethod
                        + " as a service to the current workflow.", e);
                return (new JLabel(
                        "<html>Failed to fetch required details to add this " + TYPE.RESTMethod.getTypeName()
                                + "<br>" + "as a service to the current workflow.</html>",
                        ResourceManager.getImageIcon(ResourceManager.ERROR_ICON), JLabel.CENTER));
            }

            // type not currently supported, but maybe in the future?
        default:
            return (new JLabel(
                    "Adding " + resourceType.getCollectionName()
                            + " to the current workflow is not yet possible",
                    ResourceManager.getImageIcon(ResourceManager.ERROR_ICON), JLabel.CENTER));
        }
    }

    // definitely not supported type
    return (new JLabel(
            "<html>It is not possible to add resources of the provided type<br>"
                    + "into the current workflow.</html>",
            ResourceManager.getImageIcon(ResourceManager.ERROR_ICON), JLabel.CENTER));
}

From source file:com.fluidops.iwb.luxid.LuxidExtractor.java

public static String useLuxidWS(String input, String token, String outputFormat, String annotationPlan)
        throws Exception {
    String s = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd="
            + "\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> "
            + "<SOAP-ENV:Body> <ns1:annotateString xmlns:ns1=\"http://luxid.temis.com/ws/types\"> "
            + "<ns1:sessionKey>" + token + "</ns1:sessionKey> <ns1:plan>" + annotationPlan
            + "</ns1:plan> <ns1:data>";

    s += input;// "This is a great providing test";

    s += "</ns1:data> <ns1:consumer>" + outputFormat + "</ns1:consumer> </ns1:annotateString> </SOAP-ENV:Body> "
            + "</SOAP-ENV:Envelope>";

    URL url = new URL("http://193.104.205.28//LuxidWS/services/Annotation");

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);// www  .  j  a v a 2 s  . c  om

    conn.getOutputStream().write(s.getBytes());

    StringBuilder res = new StringBuilder();

    if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
        InputStream stream = conn.getInputStream();

        InputStreamReader read = new InputStreamReader(stream);
        BufferedReader rd = new BufferedReader(read);

        String line = "";

        StringEscapeUtils.escapeHtml("");
        while ((line = rd.readLine()) != null) {
            res.append(line);
        }
        rd.close();
    }
    //      res = URLDecoder.decode(res, "UTF-8");
    return StringEscapeUtils.unescapeHtml(res.toString().replace("&amp;lt", "<"));
}

From source file:com.fluidops.iwb.wiki.Wikimedia.java

/**
 * Gets the HTML.// w  ww  . j  a  v  a  2  s.  c om
 * 
 * @return the HTML
 */
public static String getHTML(String wikitext, final URI id, FComponent parent, Date version, PageContext pc) {
    if (wikitext == null || wikitext.length() == 0)
        return "(No text defined for this topic)";

    final FluidWikiModel wikiModel = new FluidWikiModel(id, parent);
    ParserFunctionsFactory.registerPageContextAwareParserFunctions(wikiModel, pc);
    final WidgetParserFunction widgetParser = new WidgetParserFunction(parent);
    ParserFunctionsFactory.registerParserFunction(wikiModel, pc, widgetParser);
    ParserFunctionsFactory.registerParserFunction(wikiModel, pc, new SparqlParserFunction());
    ParserFunctionsFactory.registerParserFunction(wikiModel, pc, new ShowParserFunction());
    ParserFunctionsFactory.registerParserFunction(wikiModel, pc, new UrlGetParamParserFunction());

    wikiModel.setPageName(EndpointImpl.api().getDataManager().getLabel(id));
    wikiModel.addTemplateResolver(new FluidTemplateResolver(wikiModel, version));
    wikiModel.addTemplateResolver(new LegacyWidgetTemplateResolver(widgetParser));

    String html;
    PageContext _oldPc = PageContext.getThreadPageContext();
    try {
        PageContext.setThreadPageContext(pc);
        html = wikiModel.render(wikitext);
    } finally {
        PageContext.setThreadPageContext(_oldPc);
    }

    // handle "#REDIRECT [[myUri]]" directive:
    // a) redirect link must be given
    // b) redirect=no is no given as request parameter
    if (wikiModel.getRedirectLink() != null && !("no".equals(pc.getRequestParameter("redirect")))) {

        URI redirectUri = EndpointImpl.api().getNamespaceService().guessURI(wikiModel.getRedirectLink());
        if (redirectUri == null)
            return "Error: requested redirect to " + StringEscapeUtils.escapeHtml(wikiModel.getRedirectLink())
                    + " cannot be performed. Not a valid resource.";
        RequestMapper rm = EndpointImpl.api().getRequestMapper();
        String location = rm.getRequestStringFromValue(redirectUri);
        // add the redirectSource (used as a redirect hint on the new page)
        location += (location.contains("?") ? "&" : "?") + "redirectedFrom="
                + StringUtil.urlEncode(rm.getReconvertableUri(id, false));
        parent.addClientUpdate(new FClientUpdate("document.location = '" + location + "';"));
        return "Redirect to " + wikiModel.getRedirectLink();
    }

    // try to resolve template variables like $this.Host/cpuUsage
    html = replaceTemplateVariables(html, id, pc.repository);

    return html;
}

From source file:com.manydesigns.elements.forms.TableForm.java

public void toXhtml(@NotNull XhtmlBuffer xb) {
    xb.openElement("table");
    // yujun add table-bordered
    xb.addAttribute("class", "table table-bordered mde-table-form" + (condensed ? " table-condensed" : "")
            + (striped ? " table-striped" : ""));
    if (caption != null) {
        xb.writeCaption(caption);//from w  w w . j a va 2  s  . c o  m
    }
    xb.openElement("thead");
    xb.openElement("tr");

    if (selectable) {
        xb.openElement("th");
        xb.openElement("input");
        xb.addAttribute("type", "checkbox");
        String js =
                //       th       tr       thead    table
                "$(this).parent().parent().parent().parent().find('td." + SELECTION_CELL_CLASS
                        + " input').prop('checked', $(this).prop('checked'));";
        xb.addAttribute("onchange", js);
        xb.closeElement("input");
        xb.closeElement("th");
    }

    for (Column column : columns) {
        xb.openElement("th");
        if (column.title != null) {
            xb.addAttribute("title", column.title);
        }
        PropertyAccessor property = column.getPropertyAccessor();
        xb.addAttribute("data-property-name", property.getName());
        if (column.headerTextFormat != null) {
            Map<String, Object> formatParameters = new HashMap<String, Object>();
            formatParameters.put("label", StringEscapeUtils.escapeHtml(column.getActualLabel()));
            formatParameters.put("property", property);
            xb.writeNoHtmlEscape(column.headerTextFormat.format(formatParameters));
        } else {
            xb.write(column.getActualLabel());
        }
        xb.closeElement("th");
    }
    xb.closeElement("tr");
    xb.closeElement("thead");

    if (rows.length > 0) {
        xb.openElement("tbody");
        for (Row row : rows) {
            row.toXhtml(xb);
        }
        xb.closeElement("tbody");
    }

    xb.closeElement("table");
}

From source file:ddf.security.common.audit.SecurityLogger.java

/**
 * Ensure that logs cannot be forged.//from   w  ww .jav a 2s .  c o m
 *
 * @param message
 * @return clean message
 */
private static String cleanAndEncode(String message) {
    String clean = message.replace('\n', '_').replace('\r', '_');
    if (REQUIRE_AUDIT_ENCODING) {
        clean = StringEscapeUtils.escapeHtml(clean);
    }
    return clean;
}