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.action.configuration.channel.ChannelOverviewTasks.java

private void makeMessage(int successes, HttpServletRequest request) {
    if (successes > 0) {
        String number = LocalizationService.getInstance().formatNumber(new Integer(successes));

        //create the success message
        ActionMessages msg = new ActionMessages();
        String key;/*  w ww. ja v a2 s . c  o  m*/
        if (successes == 1) {
            key = "configdiff.schedule.success.singular";
        } else {
            key = "configdiff.schedule.success";
        }

        Object[] args = new Object[1];
        args[0] = StringEscapeUtils.escapeHtml(number);

        //add in the success message
        msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(key, args));
        getStrutsDelegate().saveMessages(request, msg);
    } else {
        //Something went wrong, tell user!
        ActionErrors errors = new ActionErrors();
        getStrutsDelegate().addError("configdiff.schedule.error", errors);
        getStrutsDelegate().saveMessages(request, errors);
    }
}

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

public String getContributor() {
    return StringEscapeUtils.escapeHtml(contributor);
}

From source file:fr.paris.lutece.plugins.insertalbum.web.InsertAlbumJspBean.java

private HtmlTemplate getSlideshowTemplate(HttpServletRequest request) throws NoImageInWorkspaceException {
    //get the workspace of witch we want the images
    String strIdWorksapce = request.getParameter(DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID);
    int nIdWorksapce = Integer.parseInt(strIdWorksapce);

    //get the name of the template (for the slideshow) to use
    String strSlideshow = request.getParameter(SLIDESHOW);

    //Collection<Image> imagesList = InsertAlbumHome.findImagesListOfWorkspace( nIdWorksapce, _plugin );
    List<Document> documentsList = DocumentHome.findBySpaceKey(nIdWorksapce);

    for (Document doc : documentsList) {
        doc.setComment(StringEscapeUtils.escapeHtml(doc.getSummary()));
        doc.setComment(doc.getComment().replaceAll("'", "&#146;"));
    }/*from   w  w w  .  ja  v a  2 s.co m*/

    HtmlTemplate template = null;

    String strBaseUrl = AppPathService.getBaseUrl(request);
    Locale locale = AdminUserService.getLocale(request);

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(IMAGES_LIST, documentsList);
    model.put(BASE_URL, strBaseUrl);

    if ((documentsList != null) && (documentsList.size() > 0) && (strSlideshow != null)) {
        template = AppTemplateService
                .getTemplate("admin/plugins/insertalbum/slideshow/" + strSlideshow + ".html", locale, model);
    } else {
        throw new NoImageInWorkspaceException();
    }

    return template;
}

From source file:ch.entwine.weblounge.taglib.content.ElementTag.java

/**
 * Returns the element value with the given name or the empty string, if no
 * such element exists./*from  w  w  w. j  a v a2 s.  c  o m*/
 * 
 * @param name
 *          the element name
 * @param site
 *          the site
 * @return the element
 */
private String getElement(String name, Site site) {
    String element = null;
    AbstractContentIteratorTag iterator = null;
    if (pagelet != null) {
        iterator = (AbstractContentIteratorTag) findAncestorWithClass(this, AbstractContentIteratorTag.class);
        if (iterator != null) {
            int index = iterator.getIndex(name);
            if (language != null) {
                Object[] content = pagelet.getMultiValueContent(name, language, true);
                if (index < content.length) {
                    element = (String) content[index];
                }
            } else {
                Object[] content = pagelet.getMultiValueContent(name, request.getLanguage());
                if (content != null && index < content.length) {
                    element = (String) content[index];
                }
            }
        } else {
            if (language != null) {
                element = pagelet.getContent(name, language, true);
            } else {
                element = pagelet.getContent(name, request.getLanguage());
            }
        }
    }
    if (element == null)
        element = "";
    if (encode)
        element = StringEscapeUtils.escapeHtml(element);
    if (templates)
        element = Templates.format(element, encode, site);
    return element;
}

From source file:com.redhat.rhn.frontend.struts.RhnAction.java

/**
 * Add an error message to the request with argument array
 * @param req to add the message to//from  w  ww  .  ja v  a2  s  .  co  m
 * @param beanKey resource key to lookup
 * @param args String array to fill in for the message parameters
 */
protected void createErrorMessageWithMultipleArgs(HttpServletRequest req, String beanKey, String[] args) {
    ActionErrors errs = new ActionErrors();
    String[] escArgs = new String[args.length];
    for (int i = 0; i < args.length; i++) {
        escArgs[i] = StringEscapeUtils.escapeHtml(args[i]);
    }
    errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(beanKey, escArgs));
    saveMessages(req, errs);
}

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

/**
 * Demo method for testing which alerts the name that was clicked on.
 * //from www  .j a v  a  2 s .c o m
 * @param ceCtx
 * @param name
 */
@CallableFromWidget
public static void helloWorld(CodeExecutionContext ceCtx, Value name, String constant) {
    ceCtx.parentComponent.doCallback("alert('Hello, " + StringEscapeUtils.escapeHtml(constant) + ". Clicked on "
            + StringEscapeUtils.escapeHtml(name.stringValue()) + "');");
}

From source file:com.board.games.handler.jl.JLPokerLoginServiceImpl.java

private String authenticate(String user, String password) throws Exception {
    try {//from ww w  .j  a va 2s . c o m
        int idx = user.indexOf("_");
        if (idx != -1) {
            // let bots through
            String idStr = user.substring(idx + 1);
            if (user.toUpperCase().startsWith("BOT")) {
                return idStr;
            }
        }
        if (user.toUpperCase().startsWith("GUESTXDEMO")) {
            return String.valueOf(pid.incrementAndGet());
        }

        log.debug("loading class name for database connection" + jdbcDriverClassName);
        // This will load the MySQL driver, each DB has its own driver
        // "com.mysql.jdbc.Driver"
        Class.forName(jdbcDriverClassName);
        // Setup the connection with the DB
        // "jdbc:mysql://localhost/dbName?" + "user=&password=");
        connect = DriverManager.getConnection(connectionStr);

        // Statements allow to issue SQL queries to the database
        statement = connect.createStatement();
        log.debug("Execute query: authenticate");
        // Result set get the result of the SQL query
        // SELECT * FROM ipb3_members WHERE members_seo_name = ''

        /*         smf_members 
                 password_salt = 0682
                 passwd = 92ff6c5426a23d105af69f49eb9d0210972ecbca
                 id_member
                 posts
                 member_name   */

        String selectSQL = "select member_name, id_member, " + " passwd,  password_salt,  " + " posts from "
                + dbPrefix + "members " + " where member_name = " + "\'" + user + "\'";
        log.debug("Executing query : " + selectSQL);
        resultSet = statement.executeQuery(selectSQL);

        String members_pass_hash = null;
        int member_id = 0;
        int posts = 0;
        if (resultSet != null && resultSet.next()) {
            member_id = resultSet.getInt("id_member");
            String name = resultSet.getString("member_name");
            members_pass_hash = resultSet.getString("passwd");

            log.debug("DB members_pass_hash = " + members_pass_hash);

            posts = resultSet.getInt("posts");
            log.debug("User: " + user + " Password " + password);

            String escapePwdHTML = StringEscapeUtils.escapeHtml(password);
            //   log.debug("escapeHTML = " + escapePwdHTML);
            String pwdSha1 = getSha1(user.toLowerCase() + password);

            log.debug("pwdSha1 = " + pwdSha1);

            log.debug("members_pass_hash = " + members_pass_hash);
            log.debug("# of Post " + posts);

            if (pwdSha1 != null && members_pass_hash != null) {
                if (pwdSha1.equals(members_pass_hash)) {
                    if (posts >= 1) {
                        return String.valueOf(member_id);
                    } else {
                        log.debug("Required number of posts not met, denied login");
                        return "-2";
                    }
                } else {
                    log.debug("hash not matched for user " + user + " password " + password);
                    return "-1";
                }
            }

        } else {
            log.debug("resultset is null " + selectSQL);
        }

    } catch (Exception e) {
        log.error("Error : " + e.toString());
        // throw e;
    } finally {
        close();
    }
    return "-3";
}

From source file:com.egt.ejb.toolkit.ToolKitUtils.java

public static String getStringHtml(String string) {
    return StringEscapeUtils.escapeHtml(string);
}

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

public int doStartTag() throws JspException {
    logger.debug("DatasetLovWizardTag::doStartTag:: invoked");
    httpRequest = (HttpServletRequest) pageContext.getRequest();
    requestContainer = ChannelUtilities.getRequestContainer(httpRequest);
    responseContainer = ChannelUtilities.getResponseContainer(httpRequest);
    urlBuilder = UrlBuilderFactory.getUrlBuilder();
    msgBuilder = MessageBuilderFactory.getMessageBuilder();
    String datasetLabelField = msgBuilder.getMessage("SBIDev.datasetLovWiz.datasetLabelField", "messages",
            httpRequest);/*from   www  . ja va 2 s .c  om*/

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

    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 {
        isable = userProfile.isAbleToExecuteAction(SpagoBIConstants.LOVS_MANAGEMENT);
    } catch (EMFInternalError e) {
        e.printStackTrace();
    }
    if (isable) {
        isreadonly = false;
        readonly = "";
        disabled = "";
    }

    StringBuffer output = new StringBuffer();

    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.datasetLovWiz.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:opencloseDatasetWizardInfo()'> \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.datasetLovWiz.info", "messages", httpRequest) + "'\n");
    output.append("                title='"
            + msgBuilder.getMessage("SBIDev.datasetLovWiz.info", "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");
    output.append("      <div class='div_detail_label_lov'>\n");
    output.append("               <span class='portlet-form-field-label'>\n");
    output.append(msgBuilder.getMessage("SBIDev.datasetLovWiz.datasetLabelField", "messages", httpRequest));
    output.append("               </span>\n");
    output.append("         <span class='portlet-form-field-label'>\n");
    output.append("         </span>\n");
    output.append("      </div>\n");

    output.append("<div class='div_detail_label' id='datasetLabel' >\n");

    output.append("            </div>\n");
    output.append("            \n");
    String url = GeneralUtilities.getSpagoBiHost() + GeneralUtilities.getSpagoBiContext()
            + GeneralUtilities.getSpagoAdapterHttpUrl() + "?" + "PAGE=SelectDatasetLookupPage&NEW_SESSION=TRUE&"
            + LightNavigationManager.LIGHT_NAVIGATOR_DISABLED + "=TRUE";

    String currDataSetLabel = "";
    Integer currDataSetId = null;
    String currDataSetIdValue = "";

    //aggiunto condizione (!getDatasetId().isEmpty())
    if ((getDatasetId() != null) && (!getDatasetId().isEmpty())) {
        currDataSetId = new Integer(getDatasetId());
        currDataSetIdValue = currDataSetId.toString();
        IDataSet dataSet = null;
        try {
            dataSet = DAOFactory.getDataSetDAO().loadActiveIDataSetByID(currDataSetId);
        } catch (EMFUserError e) {
            logger.error("Error Dataset Loading");
            e.printStackTrace();
        }
        if (dataSet != null) {
            currDataSetLabel = dataSet.getLabel();
        }
    }

    output.append("            <div class='div_detail_form' id='datasetForm' >\n");
    output.append("                 <input type='hidden' name='dataset' id='dataset' value='"
            + currDataSetIdValue + "' />   \n");
    output.append("                                    \n");
    output.append(
            "               <input class='portlet-form-input-field' style='width:230px;' type='text'  readonly='readonly'\n");
    output.append("                           name='datasetReadLabel' id='datasetReadLabel' value='"
            + StringEscapeUtils.escapeHtml(currDataSetLabel)
            + "' maxlength='400' onchange='setLovProviderModified(true);' /> \n");
    output.append("            \n");
    output.append("               <a href='javascript:void(0);' id='datasetLink'>\n");
    output.append("                  <img src="
            + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/detail.gif", currTheme)
            + " title='Lookup' alt='Lookup' />\n");
    output.append("               </a>    \n");
    output.append("            </div>\n");
    output.append("         \n");
    output.append("         \n");
    output.append("      <script>\n");
    output.append("         var win_dataset;\n");
    output.append("         Ext.get('datasetLink').on('click', function(){\n");
    output.append("         if(!win_dataset){\n");
    output.append("            win_dataset = new Ext.Window({\n");
    output.append("            id:'popup_dataset',\n");
    output.append("            title:'dataset',\n");
    output.append("            bodyCfg:{\n");
    output.append("               tag:'div', \n");
    output.append("               cls:'x-panel-body', \n");
    output.append("               children:[{tag:'iframe', \n");
    output.append("                        name: 'iframe_par_dataset',   \n");
    output.append("                        id  : 'iframe_par_dataset',  \n");
    output.append("                        src: '" + url + "',  \n");
    output.append("                        frameBorder:0,\n");
    output.append("                        width:'100%',\n");
    output.append("                        height:'100%',\n");
    output.append("                        style: {overflow:'auto'}  \n");
    output.append("                        }]\n");
    output.append("                  },\n");
    output.append("               layout:'fit',\n");
    output.append("               width:800,\n");
    output.append("               height:320,\n");
    output.append("               closeAction:'hide',\n");
    output.append("               plain: true\n");
    output.append("               });\n");
    output.append("               };\n");
    output.append("            win_dataset.show();\n");
    output.append("            }\n");
    output.append("            );\n");
    output.append("            \n");
    output.append("      </script>\n");

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

    try {
        pageContext.getOut().print(output.toString());
    } catch (Exception ex) {
        logger.error(ex);
        throw new JspException(ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:com.intellij.lang.jsgraphql.ide.documentation.JSGraphQLDocumentationProvider.java

@Nullable
private String createQuickNavigateDocumentation(PsiElement element, boolean fullDocumentation) {
    if (!isDocumentationSupported(element)) {
        return null;
    }/*from   w w w. j  a  va  2 s  .com*/
    if (element instanceof JSGraphQLDocumentationPsiElement) {
        JSGraphQLDocumentationPsiElement docElement = (JSGraphQLDocumentationPsiElement) element;
        return getTypeDocumentation(docElement);
    }

    if (element instanceof JSGraphQLNamedPsiElement) {

        final Project project = element.getProject();

        if (element instanceof JSGraphQLNamedPropertyPsiElement) {
            final JSGraphQLNamedPropertyPsiElement propertyPsiElement = (JSGraphQLNamedPropertyPsiElement) element;
            String typeName = JSGraphQLSchemaLanguageProjectService.getService(project)
                    .getTypeName(propertyPsiElement);
            if (typeName == null) {
                // in structure view we don't get the schema psi element, so try to find it using the reference
                final PsiReference reference = propertyPsiElement.getReference();
                if (reference != null) {
                    final PsiElement schemaReference = reference.resolve();
                    if (schemaReference instanceof JSGraphQLNamedPropertyPsiElement) {
                        typeName = JSGraphQLSchemaLanguageProjectService.getService(project)
                                .getTypeName((JSGraphQLNamedPropertyPsiElement) schemaReference);
                    } else if (schemaReference instanceof JSGraphQLSchemaFile) {
                        // field belongs to a built in type which isn't shown in the schema file
                        // hence our reference to the file -- see JSGraphQLSchemaLanguageProjectService.getReference()
                        final String buffer = element.getContainingFile().getText();
                        final LogicalPosition pos = getTokenPos(buffer, element);
                        final String environment = JSGraphQLLanguageInjectionUtil
                                .getEnvironment(element.getContainingFile());
                        final TokenDocumentationResponse tokenDocumentation = JSGraphQLNodeLanguageServiceClient
                                .getTokenDocumentation(buffer, pos.line, pos.column, project, environment);
                        if (tokenDocumentation != null) {
                            String doc = "";
                            if (tokenDocumentation.getDescription() != null) {
                                if (tokenDocumentation.getType() != null
                                        && !JSGraphQLSchemaLanguageProjectService.SCALAR_TYPES
                                                .contains(tokenDocumentation.getType())) {
                                    doc += "<div style=\"margin-bottom: 4px\">"
                                            + tokenDocumentation.getDescription() + "</div>";
                                }
                            }
                            doc += "<code>" + element.getText() + ": "
                                    + getTypeHyperLink(tokenDocumentation.getType()) + "</code>";
                            return getDocTemplate(fullDocumentation).replace("${body}", doc);
                        }
                    }
                }
            }
            if (typeName != null) {
                final TokenDocumentationResponse fieldDocumentation = JSGraphQLNodeLanguageServiceClient
                        .getFieldDocumentation(typeName, propertyPsiElement.getName(), project);
                if (fieldDocumentation != null) {
                    String doc = "";
                    if (fieldDocumentation.getDescription() != null) {
                        doc += "<div style=\"margin-bottom: 4px\">"
                                + StringEscapeUtils.escapeHtml(fieldDocumentation.getDescription()) + "</div>";
                    }
                    String typeNameOrLink = fullDocumentation ? getTypeHyperLink(typeName) : typeName;
                    doc += "<code>" + typeNameOrLink + " <b>" + element.getText() + "</b>: "
                            + getTypeHyperLink(fieldDocumentation.getType()) + "</code>";
                    return getDocTemplate(fullDocumentation).replace("${body}", doc);
                }
            }
        } else if (element instanceof JSGraphQLNamedTypePsiElement) {
            if (((JSGraphQLNamedTypePsiElement) element).isDefinition()) {
                if (element.getParent() instanceof JSGraphQLFragmentDefinitionPsiElement) {
                    // the named type represents the name of a fragment definition,
                    // so return doc along the lines of 'fragment MyFrag on SomeType'
                    final StringBuilder doc = new StringBuilder("<code>fragment ");
                    doc.append("<b>").append(element.getText()).append("</b>");
                    final JSGraphQLNamedTypePsiElement fragmentType = PsiTreeUtil.getNextSiblingOfType(element,
                            JSGraphQLNamedTypePsiElement.class);
                    if (fragmentType != null) {
                        doc.append(" on ").append(getTypeHyperLink(fragmentType.getName()));
                    }
                    doc.append("</code>");
                    return getDocTemplate(fullDocumentation).replace("${body}", doc);
                }
            }
            if (fullDocumentation) {
                final PsiManager psiManager = PsiManager.getInstance(project);
                final String link = GRAPHQL_DOC_PREFIX + "/" + GRAPHQL_DOC_TYPE + "/" + element.getText();
                final PsiElement documentationElement = getDocumentationElementForLink(psiManager, link,
                        element);
                if (documentationElement instanceof JSGraphQLDocumentationPsiElement) {
                    return getTypeDocumentation((JSGraphQLDocumentationPsiElement) documentationElement);
                }
            }
            TypeDocumentationResponse typeDocumentation = JSGraphQLNodeLanguageServiceClient
                    .getTypeDocumentation(element.getText(), project);
            if (typeDocumentation != null) {
                String doc = "";
                if (typeDocumentation.description != null) {
                    doc += "<div style=\"margin-bottom: 4px\">"
                            + StringEscapeUtils.escapeHtml(typeDocumentation.description) + "</div>";
                }
                doc += "<code><b>" + element.getText() + "</b>";
                if (!ContainerUtil.isEmpty(typeDocumentation.interfaces)) {
                    doc += ": ";
                    for (int i = 0; i < typeDocumentation.interfaces.size(); i++) {
                        if (i > 0) {
                            doc += ", ";
                        }
                        doc += getTypeHyperLink(typeDocumentation.interfaces.get(i));
                    }
                }
                doc += "</code>";
                return getDocTemplate(fullDocumentation).replace("${body}", doc);
            }
        } else if (element instanceof JSGraphQLAttributePsiElement) {
            String doc = "";
            PsiElement prevLeaf = PsiTreeUtil.prevLeaf(element);
            String documentation = "";
            while (prevLeaf instanceof PsiWhiteSpace || prevLeaf instanceof PsiComment) {
                documentation = StringUtils.removeStart(prevLeaf.getText(), "# ") + documentation;
                prevLeaf = PsiTreeUtil.prevLeaf(prevLeaf);
            }
            documentation = documentation.trim();
            if (StringUtils.isNotBlank(documentation)) {
                doc += "<div style=\"margin-bottom: 4px\">" + StringEscapeUtils.escapeHtml(documentation)
                        + "</div>";
            }
            doc += "<code>" + element.getText();
            PsiElement nextLeaf = PsiTreeUtil.nextLeaf(element);
            // include the attribute type (stopping at newline, ",", and ")")
            while (nextLeaf != null && !nextLeaf.getText().contains("\n") && !nextLeaf.getText().contains(",")
                    && !nextLeaf.getText().contains(")")) {
                doc += nextLeaf.getText();
                nextLeaf = PsiTreeUtil.nextLeaf(nextLeaf);
            }
            doc += "</code>";
            return getDocTemplate(fullDocumentation).replace("${body}", doc);
        }

    } else if (element instanceof JSGraphQLEndpointDocumentationAware) {
        final JSGraphQLEndpointDocumentationAware documentationAware = (JSGraphQLEndpointDocumentationAware) element;
        final String documentation = documentationAware.getDocumentation(fullDocumentation);
        String doc = "";
        if (documentation != null) {
            doc += "<div style=\"margin-bottom: 4px\">" + StringEscapeUtils.escapeHtml(documentation)
                    + "</div>";
        }
        doc += "<code>" + documentationAware.getDeclaration() + "</code>";
        return getDocTemplate(fullDocumentation).replace("${body}", doc);
    }

    return null;
}