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.swordlord.gozer.components.fop.GFopList.java

private String generateRows(String strRow, String strRowCell) {
    DataBindingMember dbMember = _obList.getDataBindingMember();
    DataBindingContext dbc = getFrameExtension().getDataBindingContext();
    DataBindingManager dbManager = dbc.getDataBindingManager(dbMember);

    List<DataRowBase> subList = null;

    String strOrdering = _obList.getOrdering();
    if ((strOrdering != null) && (strOrdering.length() > 0)) {
        OrderingParam orderingParam = new OrderingParam(strOrdering, true, false);
        subList = dbManager.getRows(dbMember, orderingParam);
    } else {/* w  w w.  java2 s.  c  om*/
        subList = dbManager.getRows(dbMember);
    }

    if ((subList == null) || (subList.size() == 0)) {
        return null;
    }

    StringBuilder sbRows = new StringBuilder();

    Iterator<DataRowBase> it = subList.iterator();
    while (it.hasNext()) {
        StringBuilder sbCells = new StringBuilder();

        DataRowBase row = it.next();

        for (final ObjectBase child : _obList.getChildren()) {
            Class<? extends ObjectBase> clazz = child.getClass();
            if (clazz.equals(GField.class) || clazz.equals(GCodeField.class)) {
                // get cell data
                DataBinding dataBindingChild = child.getDataBinding();
                Object o = dataBindingChild.getFormattedValue(row);

                String strContent = o == null ? "" : o.toString();
                strContent = StringEscapeUtils.escapeHtml(strContent);

                // append data to cell template
                String strRenderedCell = strRowCell;
                if (strRenderedCell != null && strRenderedCell.length() > 0) {
                    strRenderedCell = strRenderedCell.replace("<content/>", strContent);
                    sbCells.append(strRenderedCell);
                } else {
                    LOG.error("There is something wrong with the strRowCell in GFopList. Template is null.");
                }
            }
        }

        // now append the cells to the row
        String strRenderedList = strRow;
        if (strRenderedList != null && strRenderedList.length() > 0) {
            strRenderedList = strRenderedList.replace("<child/>", sbCells.toString());
            sbRows.append(strRenderedList);
        } else {
            LOG.error("There is something wrong with the strRow in GFopList. Template is null.");
        }
    }

    return sbRows.toString();
}

From source file:it.eng.spagobi.commons.presentation.tags.ScriptWizardTag.java

public int doStartTag() throws JspException {

    httpRequest = (HttpServletRequest) pageContext.getRequest();
    requestContainer = ChannelUtilities.getRequestContainer(httpRequest);
    responseContainer = ChannelUtilities.getResponseContainer(httpRequest);
    urlBuilder = UrlBuilderFactory.getUrlBuilder();
    msgBuilder = MessageBuilderFactory.getMessageBuilder();

    currTheme = ThemesManager.getCurrentTheme(requestContainer);
    if (currTheme == null)
        currTheme = ThemesManager.getDefaultTheme();

    TracerSingleton.log(SpagoBIConstants.NAME_MODULE, TracerSingleton.DEBUG,
            "ScriptWizardTag::doStartTag:: invocato");
    RequestContainer aRequestContainer = RequestContainer.getRequestContainer();
    SessionContainer aSessionContainer = aRequestContainer.getSessionContainer();
    SessionContainer permanentSession = aSessionContainer.getPermanentContainer();
    IEngUserProfile userProfile = (IEngUserProfile) permanentSession
            .getAttribute(IEngUserProfile.ENG_USER_PROFILE);
    boolean isable = false;
    try {/*  w w w .  j a v a2 s .  c  o m*/
        isable = userProfile.isAbleToExecuteAction(SpagoBIConstants.LOVS_MANAGEMENT);
    } catch (EMFInternalError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (isable) {
        isreadonly = false;
        readonly = "";
        disabled = "";
    }
    StringBuffer output = new StringBuffer();

    String lanuageScriptLabel = msgBuilder.getMessage("SBISet.ListDataSet.languageScript", "messages",
            httpRequest);
    String scriptLabel = msgBuilder.getMessage("SBIDev.scriptWiz.scriptLbl", "messages", httpRequest);

    output.append("<table width='100%' cellspacing='0' border='0'>\n");
    output.append("   <tr>\n");
    output.append("      <td class='titlebar_level_2_text_section' style='vertical-align:middle;'>\n");
    output.append("         &nbsp;&nbsp;&nbsp;"
            + msgBuilder.getMessage("SBIDev.scriptWiz.wizardTitle", "messages", httpRequest) + "\n");
    output.append("      </td>\n");
    output.append("      <td class='titlebar_level_2_empty_section'>&nbsp;</td>\n");
    output.append("      <td class='titlebar_level_2_button_section'>\n");
    output.append(
            "         <a style='text-decoration:none;' href='javascript:opencloseScriptWizardInfo()'> \n");
    output.append("            <img width='22px' height='22px'\n");
    output.append("                 src='"
            + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/info22.jpg", currTheme) + "'\n");
    output.append("                name='info'\n");
    output.append("                alt='"
            + msgBuilder.getMessage("SBIDev.scriptWiz.showSintax", "messages", httpRequest) + "'\n");
    output.append("                title='"
            + msgBuilder.getMessage("SBIDev.scriptWiz.showSintax", "messages", httpRequest) + "'/>\n");
    output.append("         </a>\n");
    output.append("      </td>\n");
    String urlImgProfAttr = urlBuilder.getResourceLinkByTheme(httpRequest, "/img/profileAttributes22.jpg",
            currTheme);
    output.append(generateProfAttrTitleSection(urlImgProfAttr));
    output.append("   </tr>\n");
    output.append("</table>\n");

    output.append("<br/>\n");

    output.append("<div class='div_detail_area_forms_lov'>\n");

    //LANGUAGE SCRIPT COMBO      

    output.append("      <div class='div_detail_label_lov'>\n");
    output.append("         <span class='portlet-form-field-label'>\n");
    output.append(lanuageScriptLabel);
    output.append("         </span>\n");
    output.append("      </div>\n");
    output.append("      <div class='div_detail_form'>\n");
    output.append(
            "         <select  style='width:180px;' class='portlet-form-input-field' name='LANGUAGESCRIPT' id='LANGUAGESCRIPT' >\n");

    String selected = "";
    try {

        List scriptLanguageList = DAOFactory.getDomainDAO().loadListDomainsByType(DataSetConstants.SCRIPT_TYPE);
        if (scriptLanguageList != null) {
            for (int i = 0; i < scriptLanguageList.size(); i++) {
                Domain domain = (Domain) scriptLanguageList.get(i);
                String name = domain.getValueName();
                name = StringEscapeUtils.escapeHtml(name);
                String value = domain.getValueCd();
                value = StringEscapeUtils.escapeHtml(value);
                if (languageScript.equalsIgnoreCase(value)) {
                    selected = "selected='selected'";
                }
                output.append("<option value='" + value + "' label='" + value + "' " + selected + ">");
                output.append(name);
                output.append("</option>");
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    /*
    Map engineNames=ScriptUtilities.getEngineFactoriesNames();
    for(Iterator it=engineNames.keySet().iterator();it.hasNext();){
       String engName=(String)it.next(); 
       String alias=(String)engineNames.get(engName);
       alias = StringEscapeUtils.escapeHtml(alias);
       selected="";
       if(languageScript.equalsIgnoreCase(alias)){
            
    selected="selected='selected'";
       }      
       String aliasName=ScriptUtilities.bindAliasEngine(alias);
            
       output.append("<option value='"+alias+"' label='"+alias+"' "+selected+">");
       output.append(aliasName);   
       output.append("</option>");
    }
    */

    output.append("</select>");
    output.append("</div>");

    // FINE LANGUAGE SCRIPT

    output.append("      <div class='div_detail_label_lov'>\n");
    output.append("         <span class='portlet-form-field-label'>\n");
    output.append(scriptLabel);
    output.append("         </span>\n");
    output.append("      </div>\n");
    output.append("      <div style='height:110px;' class='div_detail_form'>\n");
    output.append("         <textarea style='height:100px;'  " + disabled
            + " class='portlet-text-area-field' name='SCRIPT' onchange='setLovProviderModified(true);'  cols='50'>"
            + script + "</textarea>\n");
    output.append("      </div>\n");
    output.append("      <div class='div_detail_label_lov'>\n");
    output.append("         &nbsp;\n");
    output.append("      </div>\n");

    // fine DETAIL AREA FORMS
    output.append("</div>\n");

    output.append("<script>\n");
    output.append("      var infowizardscriptopen = false;\n");
    output.append("      var winSWT = null;\n");
    output.append("      function opencloseScriptWizardInfo() {\n");
    output.append("         if(!infowizardscriptopen){\n");
    output.append("            infowizardscriptopen = true;");
    output.append("            openScriptWizardInfo();\n");
    output.append("         }\n");
    output.append("      }\n");
    output.append("      function openScriptWizardInfo(){\n");
    output.append("         if(winSWT==null) {\n");
    output.append("            winSWT = new Window('winSWTInfo', {className: \"alphacube\", title:\""
            + msgBuilder.getMessage("SBIDev.scriptWiz.showSintax", "messages", httpRequest)
            + "\",width:680, height:150, destroyOnClose: false});\n");
    output.append("            winSWT.setContent('scriptwizardinfodiv', true, false);\n");
    output.append("            winSWT.showCenter(false);\n");
    output.append("            winSWT.setLocation(40,50);\n");
    output.append("          } else {\n");
    output.append("            winSWT.showCenter(false);\n");
    output.append("          }\n");
    output.append("      }\n");
    output.append("      observerSWT = { onClose: function(eventName, win) {\n");
    output.append("         if (win == winSWT) {\n");
    output.append("            infowizardscriptopen = false;");
    output.append("         }\n");
    output.append("        }\n");
    output.append("      }\n");
    output.append("      Windows.addObserver(observerSWT);\n");
    output.append("</script>\n");

    output.append("<div id='scriptwizardinfodiv' style='display:none;'>\n");
    output.append(msgBuilder.getMessageTextFromResource(
            "it/eng/spagobi/commons/presentation/tags/info/scriptwizardinfo", httpRequest));
    output.append("</div>\n");

    try {
        pageContext.getOut().print(output.toString());
    } catch (Exception ex) {
        TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.CRITICAL, "ScriptWizardTag::doStartTag::",
                ex);
        throw new JspException(ex.getMessage());
    }

    return SKIP_BODY;
}

From source file:com.vsct.dt.hesperides.feedback.FeedbacksAggregate.java

public String getHipchatMessageBody(FeedbackJson template, String imageName, User user) {
    StringBuilder urlDownloadImage = new StringBuilder().append(template.getFeedback().getUrl().split("/")[0])
            .append("/").append("/").append(template.getFeedback().getUrl().split("/")[2]).append("/")
            .append(feedbackConfiguration.getImagePathStorage()).append("/").append(imageName);

    LOGGER.debug("Download URL : " + urlDownloadImage.toString());

    StringBuilder hipchatMessage = new StringBuilder().append("<p>When access to <a href='")
            .append(template.getFeedback().getUrl()).append("'>").append(template.getFeedback().getUrl())
            .append("</a></p>");

    // Encapsulate each line ended by \n with <p><\p>
    List<String> wordList = Arrays.asList(template.getFeedback().getNote().split("\n"));
    Iterator itWordList = wordList.iterator();

    while (itWordList.hasNext()) {
        hipchatMessage.append("<p>").append(StringEscapeUtils.escapeHtml(itWordList.next().toString()))
                .append(("</p>"));
    }/*from  www. java 2  s  .co m*/

    hipchatMessage.append("<a href='").append(urlDownloadImage).append("'>Download screenshot</a>");

    return new StringBuilder().append("{\"from\": \"").append(user.getUsername()).append("\",\"color\": \"")
            .append("green").append("\",\"message\": \"").append(hipchatMessage.toString())
            .append("\",\"notify\": \"").append("true").append("\",\"message_format\": \"").append("html")
            .append("\"}").toString();
}

From source file:edu.harvard.iq.dataverse.DataCitation.java

private String formatURL(String text, String url, boolean html) {
    if (text == null) {
        return null;
    }/*from w  w w.j  a  v a  2  s . c  o m*/

    if (html && url != null) {
        return "<a href=\"" + url + "\" target=\"_blank\">" + StringEscapeUtils.escapeHtml(text) + "</a>";
    } else {
        return text;
    }

}

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

/**
 * Verifies the identity link and responds with a new 
 * <code>CreateXMLSignatureRequest</code>.
 * <br>/*from ww  w  .  jav  a2s  . c o  m*/
 * Request parameters:
 * <ul>
 * <li>MOASessionID: ID of associated authentication session</li>
 * <li>XMLResponse: <code>&lt;InfoboxReadResponse&gt;</code></li>
 * </ul>
 * Response:
 * <ul>
 * <li>Content type: <code>"text/xml"</code></li>
 * <li>Content: see return value of {@link AuthenticationServer#verifyIdentityLink}</li>
 * <li>Error status: <code>500</code>
 * </ul>
 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest, HttpServletResponse)
 */
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    Logger.debug("POST GetForeignIDServlet");

    Logger.warn(getClass().getName() + " is deprecated and should not be used any more.");

    resp.setHeader(MOAIDAuthConstants.HEADER_EXPIRES, MOAIDAuthConstants.HEADER_VALUE_EXPIRES);
    resp.setHeader(MOAIDAuthConstants.HEADER_PRAGMA, MOAIDAuthConstants.HEADER_VALUE_PRAGMA);
    resp.setHeader(MOAIDAuthConstants.HEADER_CACHE_CONTROL, MOAIDAuthConstants.HEADER_VALUE_CACHE_CONTROL);
    resp.addHeader(MOAIDAuthConstants.HEADER_CACHE_CONTROL, MOAIDAuthConstants.HEADER_VALUE_CACHE_CONTROL_IE);

    Map<String, String> parameters;

    String pendingRequestID = null;

    try {
        parameters = getParameters(req);
    } catch (FileUploadException e) {
        Logger.error("Parsing mulitpart/form-data request parameters failed: " + e.getMessage());
        throw new IOException(e.getMessage());
    }
    String sessionID = req.getParameter(PARAM_SESSIONID);
    pendingRequestID = AuthenticationSessionStoreage.getPendingRequestID(sessionID);

    // escape parameter strings
    sessionID = StringEscapeUtils.escapeHtml(sessionID);

    String redirectURL = null;
    AuthenticationSession session = null;
    try {
        String xmlCreateXMLSignatureResponse = (String) parameters.get(PARAM_XMLRESPONSE);
        // check parameter
        if (!ParamValidatorUtils.isValidSessionID(sessionID))
            throw new WrongParametersException("GetForeignID", PARAM_SESSIONID, "auth.12");
        if (!ParamValidatorUtils.isValidXMLDocument(xmlCreateXMLSignatureResponse))
            throw new WrongParametersException("GetForeignID", PARAM_XMLRESPONSE, "auth.12");

        session = AuthenticationServer.getSession(sessionID);

        //change MOASessionID
        sessionID = AuthenticationSessionStoreage.changeSessionID(session);

        Logger.debug(xmlCreateXMLSignatureResponse);

        CreateXMLSignatureResponse csresp = new CreateXMLSignatureResponseParser(xmlCreateXMLSignatureResponse)
                .parseResponseDsig();

        try {
            String serializedAssertion = DOMUtils.serializeNode(csresp.getDsigSignature());
            session.setAuthBlock(serializedAssertion);

        } catch (TransformerException e) {
            throw new ParseException("parser.04", new Object[] { REQ_VERIFY_AUTH_BLOCK, PARAM_XMLRESPONSE });

        } catch (IOException e) {
            throw new ParseException("parser.04", new Object[] { REQ_VERIFY_AUTH_BLOCK, PARAM_XMLRESPONSE });

        }

        Element signature = csresp.getDsigSignature();

        try {
            session.setSignerCertificate(AuthenticationServer.getCertificateFromXML(signature));
        } catch (CertificateException e) {
            Logger.error("Could not extract certificate from CreateXMLSignatureResponse");
            throw new MOAIDException("auth.14", null);
        }

        // make SZR request to the identity link
        CreateIdentityLinkResponse response = AuthenticationServer.getInstance().getIdentityLink(signature);

        if (null != response.getErrorResponse()) {
            // TODO fix exception parameter
            throw new SZRGWClientException("service.08", (String) response.getErrorResponse().getErrorCode(),
                    (String) response.getErrorResponse().getInfo());
        } else {
            IdentityLinkAssertionParser ilParser = new IdentityLinkAssertionParser(
                    new ByteArrayInputStream(response.getIdentityLink()));
            IdentityLink identitylink = ilParser.parseIdentityLink();
            session.setIdentityLink(identitylink);

            //set QAA Level four in case of card authentifcation
            session.setQAALevel(PVPConstants.STORK_QAA_1_4);

            String samlArtifactBase64 = AuthenticationServer.getInstance()
                    .getForeignAuthenticationData(session);

            //session is implicit stored in changeSessionID!!!! 
            String newMOASessionID = AuthenticationSessionStoreage.changeSessionID(session);

            Logger.info("Changed MOASession " + sessionID + " to Session " + newMOASessionID);
            Logger.info("Daten angelegt zu MOASession " + newMOASessionID);

            if (!samlArtifactBase64.equals("Redirect to Input Processor")) {
                /*redirectURL = session.getOAURLRequested();
                if (!session.getBusinessService()) {
                   redirectURL = addURLParameter(redirectURL, PARAM_TARGET, URLEncoder.encode(session.getTarget(), "UTF-8"));
                }
                redirectURL = addURLParameter(redirectURL, PARAM_SAMLARTIFACT, URLEncoder.encode(samlArtifactBase64, "UTF-8"));
                redirectURL = resp.encodeRedirectURL(redirectURL);*/

                redirectURL = new DataURLBuilder().buildDataURL(session.getAuthURL(),
                        ModulUtils.buildAuthURL(session.getModul(), session.getAction(), pendingRequestID),
                        newMOASessionID);
                redirectURL = resp.encodeRedirectURL(redirectURL);

            } else {
                redirectURL = new DataURLBuilder().buildDataURL(session.getAuthURL(),
                        AuthenticationServer.REQ_PROCESS_VALIDATOR_INPUT, newMOASessionID);

            }

            try {
                AuthenticationSessionStoreage.storeSession(session);
            } catch (MOADatabaseException e) {
                throw new MOAIDException("Session store error", null);
            }

            resp.setContentType("text/html");
            resp.setStatus(302);
            resp.addHeader("Location", redirectURL);
            Logger.debug("REDIRECT TO: " + redirectURL);
        }

    } catch (MOAIDException ex) {
        handleError(null, ex, req, resp, pendingRequestID);

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

    }
}

From source file:edu.usc.goffish.gofs.formats.gml.GMLWriter.java

private void writeKVPValue(int indentation, String value) throws IOException {
    _output.write("\"");
    _output.write(StringEscapeUtils.escapeHtml(value));
    _output.write("\"");
}

From source file:com.fluidops.iwb.widget.CodeExecutionWidget.java

/**
 * This is an example static method that could be called,
 * the widget configuration for calling this method is as follows.
 * // w ww.  ja v a 2s  .  c o  m
 * <code>
*   {{#widget: CodeExecution
* | label = 'Test 7'
* | clazz = 'com.fluidops.iwb.widget.CodeExecutionWidget'
* | method = 'testMe2'
* | args = {{ $this.a$ }}
* | passContext = true
* }}
* </code> 
 */
@SuppressWarnings("deprecation")
@CallableFromWidget
public static void testMe2(CodeExecutionContext ceCtx, String value) {
    ceCtx.parentComponent.doCallback("alert('Clicked on "
            + StringEscapeUtils.escapeHtml(value == null ? "(undefined)" : value.toString()) + "');");
}

From source file:com.redhat.rhn.frontend.action.configuration.files.ManageRevisionSubmit.java

private void createUploadSuccessMessage(ConfigRevision revision, HttpServletRequest request, Long cfid) {
    ActionMessages msg = new ActionMessages();
    Object[] args = new Object[2];
    StringBuilder buffy = new StringBuilder();
    buffy.append("/rhn/configuration/file/FileDetails.do?" + ConfigActionHelper.FILE_ID + "=");
    buffy.append(cfid);/*w  ww. j  av  a  2 s.c o m*/
    buffy.append("&amp;" + ConfigActionHelper.REVISION_ID + "=");
    buffy.append(revision.getId());
    args[0] = StringEscapeUtils.escapeHtml(buffy.toString());
    args[1] = revision.getRevision().toString();

    msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("manage.jsp.success", args));
    getStrutsDelegate().saveMessages(request, msg);
}

From source file:com.cyberway.issue.util.TextUtils.java

/**
 * Utility method for writing a (potentially large) String to a JspWriter,
 * escaping it for HTML display, without constructing another large String
 * of the whole content. //from  w ww  . ja  v a2  s  . c  o m
 * @param s String to write
 * @param out destination JspWriter
 * @throws IOException
 */
public static void writeEscapedForHTML(String s, JspWriter out) throws IOException {
    BufferedReader reader = new BufferedReader(new StringReader(s));
    String line;
    while ((line = reader.readLine()) != null) {
        out.println(StringEscapeUtils.escapeHtml(line));
    }
}

From source file:com.alibaba.otter.manager.web.common.NumberFormatUtil.java

public String getHtmlOriginalContent(String originalContent, String escape) {
    originalContent = StringUtils.replace(originalContent, "\n", "<br>");
    originalContent = StringEscapeUtils.escapeJavaScript(originalContent);
    if ("HTML".equalsIgnoreCase(escape)) {
        originalContent = StringEscapeUtils.escapeHtml(originalContent);
        originalContent = StringUtils.replace(originalContent, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        originalContent = StringUtils.replace(originalContent, "\\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        return originalContent;
    } else {//from  ww  w. j a  v a  2 s. co  m
        return originalContent;
    }
}