Example usage for org.springframework.util StringUtils replace

List of usage examples for org.springframework.util StringUtils replace

Introduction

In this page you can find the example usage for org.springframework.util StringUtils replace.

Prototype

public static String replace(String inString, String oldPattern, @Nullable String newPattern) 

Source Link

Document

Replace all occurrences of a substring within a string with another string.

Usage

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

/**
 * Get an I18N Label for a workflow item
 * /*from  w w  w .  jav  a  2s  .com*/
 * @param displayId
 *            message resource id lookup
 * @param labelKey
 *            label to lookup (title or description)
 * @param defaultLabel
 *            default value if not found in message resource bundle
 * @return  the label
 */
private String getLabel(String displayId, String labelKey, String defaultLabel) {
    String key = StringUtils.replace(displayId, ":", "_");
    key += "." + labelKey;
    String label = messageService.getMessage(key);

    return (label == null) ? defaultLabel : label;
}

From source file:io.cfp.service.email.EmailingService.java

protected String processTemplate(String templatePath, Map<String, Object> parameters) {

    // adds global params
    parameters.put("hostname", StringUtils.replace(hostname, "{{event}}", Event.current()));
    parameters.put("date", new DateTool());
    Event curEvent = eventRepo.findOne(Event.current());
    parameters.put("event", curEvent);
    parameters.put("contactMail",
            curEvent.getContactMail() != null ? curEvent.getContactMail() : "contact@cfp.io");

    VelocityContext context = new VelocityContext(parameters);

    Template template = velocityEngine.getTemplate(templatePath, "UTF-8");

    StringWriter writer = new StringWriter();
    template.merge(context, writer);/*w w  w  .  jav a  2  s.  c o m*/
    return writer.toString();
}

From source file:no.kantega.commons.util.LocaleLabels.java

private static String getLabel(String key, String bundleName, String locale, Map<String, Object> parameters) {
    String msg = key;/* w  w  w  .  j  a  va 2s. c  o m*/

    PropertyResourceBundle bundle = getBundle(bundleName, locale);
    if (bundle == null) {
        return msg;
    }

    try {
        msg = bundle.getString(key);
    } catch (MissingResourceException e) {
        // Do nothing
    }

    if (parameters != null) {
        for (Map.Entry<String, ?> o : parameters.entrySet()) {
            Object value = o.getValue();
            if (value != null) {
                msg = StringUtils.replace(msg, "${" + o.getKey() + "}", value.toString());
            }
        }
    }
    return msg;
}

From source file:org.alfresco.repo.importer.ImporterComponent.java

/**
 * Bind the specified value to the passed configuration values if it is a place holder
 * /*from   ww w. j  a  va 2  s.  c  o  m*/
 * @param value  the value to bind
 * @param binding  the configuration properties to bind to
 * @return  the bound value
 */
private String bindPlaceHolder(String value, ImporterBinding binding) {
    if (binding != null) {
        int iStartBinding = value.indexOf(START_BINDING_MARKER);
        while (iStartBinding != -1) {
            int iEndBinding = value.indexOf(END_BINDING_MARKER, iStartBinding + START_BINDING_MARKER.length());
            if (iEndBinding == -1) {
                throw new ImporterException(
                        "Cannot find end marker " + END_BINDING_MARKER + " within value " + value);
            }

            String key = value.substring(iStartBinding + START_BINDING_MARKER.length(), iEndBinding);
            String keyValue = binding.getValue(key);
            if (keyValue == null) {
                logger.warn("No binding value for placeholder (will default to empty string): " + value);
            }
            value = StringUtils.replace(value, START_BINDING_MARKER + key + END_BINDING_MARKER,
                    keyValue == null ? "" : keyValue);
            iStartBinding = value.indexOf(START_BINDING_MARKER);
        }
    }
    return value;
}

From source file:org.alfresco.web.bean.generator.BaseComponentGenerator.java

/**
 * Adds the given string parameter to the list of parameters to be used for
 * validating constraints on the client.
 * This method adds the quotes around the given parameter and also escapes
 * any ocurrences of the double quote character.
 * // w w  w .  ja v a 2s  .c  om
 * @param params The list of parameters for the constraint
 * @param param The string parameter to add
 */
protected void addStringConstraintParam(List<String> params, String param) {
    params.add("\"" + StringUtils.replace(param, "\"", "\\\"") + "\"");
}

From source file:org.alfresco.web.ui.wcm.component.UIDeploymentReports.java

protected void renderReport(FacesContext context, ResponseWriter out, NodeRef deploymentReport,
        NodeService nodeService, ContentService contentService) throws IOException {
    if (logger.isDebugEnabled())
        logger.debug("Rendering report: " + deploymentReport);

    // add some padding before the panel
    out.write("\n<div style='padding-top:8px;'></div>\n");

    // start the surrounding panel
    PanelGenerator.generatePanelStart(out, context.getExternalContext().getRequestContextPath(), "lightstorm",
            "#eaeff2");

    // extract the information we need to display
    Map<QName, Serializable> serverProps = nodeService.getProperties(deploymentReport);
    Long serverId = (Long) serverProps.get(ContentModel.PROP_NODE_DBID);
    String server = (String) serverProps.get(WCMAppModel.PROP_DEPLOYSERVER);
    boolean showServerAddress = true;
    String serverName = (String) serverProps.get(WCMAppModel.PROP_DEPLOYSERVERNAMEUSED);
    if (serverName == null || serverName.length() == 0) {
        serverName = server;//from w  w  w  . j a  v a  2 s.c  om
        showServerAddress = false;
    }

    String deployType = WCMAppModel.CONSTRAINT_ALFDEPLOY;
    if (server.startsWith(AVMDeployWebsiteAction.FILE_SERVER_PREFIX)) {
        deployType = WCMAppModel.CONSTRAINT_FILEDEPLOY;
    }

    String creator = (String) serverProps.get(ContentModel.PROP_CREATOR);
    Date startTime = (Date) serverProps.get(WCMAppModel.PROP_DEPLOYSTARTTIME);
    String started = "";
    if (startTime != null) {
        started = Utils.getDateTimeFormat(context).format(startTime);
    }

    Date endTime = (Date) serverProps.get(WCMAppModel.PROP_DEPLOYENDTIME);
    String finished = "";
    if (endTime != null) {
        finished = Utils.getDateTimeFormat(context).format(endTime);
    }

    Boolean success = (Boolean) serverProps.get(WCMAppModel.PROP_DEPLOYSUCCESSFUL);
    if (success == null) {
        success = Boolean.FALSE;
    }

    String url = (String) serverProps.get(WCMAppModel.PROP_DEPLOYSERVERURLUSED);
    String username = (String) serverProps.get(WCMAppModel.PROP_DEPLOYSERVERUSERNAMEUSED);
    String source = (String) serverProps.get(WCMAppModel.PROP_DEPLOYSOURCEPATHUSED);
    String target = (String) serverProps.get(WCMAppModel.PROP_DEPLOYSERVERTARGETUSED);
    String excludes = (String) serverProps.get(WCMAppModel.PROP_DEPLOYEXCLUDESUSED);
    String failReason = (String) serverProps.get(WCMAppModel.PROP_DEPLOYFAILEDREASON);

    String content = "";
    ContentReader reader = contentService.getReader(deploymentReport, ContentModel.PROP_CONTENT);
    if (reader != null) {
        content = reader.getContentString();
        if (content != null) {
            content = Utils.encode(content);
            content = StringUtils.replace(content, "\r\n", "<br/>");
        } else {
            content = "";
        }
    }

    int snapshot = -1;
    Serializable snapshotObj = serverProps.get(WCMAppModel.PROP_DEPLOYVERSION);
    if (snapshotObj != null && snapshotObj instanceof Integer) {
        snapshot = (Integer) snapshotObj;
    }

    out.write("<table cellspacing='0' cellpadding='2' border='0' width='100%'>");
    out.write("<tr><td width='40' valign='top'><img src='");
    out.write(context.getExternalContext().getRequestContextPath());
    out.write("/images/icons/deploy_server_");
    out.write(deployType);
    out.write(".gif' /></td><td>");
    out.write("<div class='mainHeading'>");
    out.write(Utils.encode(serverName));
    out.write("</div><div style='margin-top: 3px; margin-bottom: 6px;'><img src='");
    out.write(context.getExternalContext().getRequestContextPath());
    out.write("/images/icons/deploy_");
    if (success.booleanValue()) {
        out.write("successful");
    } else {
        out.write("failed");
    }
    out.write(".gif' style='vertical-align: -4px;' />&nbsp;&nbsp;");
    if (success.booleanValue()) {
        out.write(Application.getMessage(context, "deploy_successful"));
    } else {
        out.write(Application.getMessage(context, "deploy_failed"));
    }
    out.write("</div>");

    if (success.booleanValue() == false && failReason != null && failReason.length() > 0) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "reason"));
        out.write(":&nbsp;");
        out.write(Utils.encode(failReason));
        out.write("</div>");
    }

    if (showServerAddress) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "deploy_server"));
        out.write(":&nbsp;");
        out.write(Utils.encode(server));
        out.write("</div>");
    }

    out.write("<div style='margin-top: 3px;'>");
    out.write(Application.getMessage(context, "snapshot"));
    out.write(":&nbsp;");
    out.write(Integer.toString(snapshot));
    out.write("</div>");

    out.write("<div style='margin-top: 3px;'>");
    out.write(Application.getMessage(context, "deploy_started"));
    out.write(":&nbsp;");
    out.write(started);
    out.write("</div>");

    out.write("<div style='margin-top: 3px;'>");
    out.write(Application.getMessage(context, "deploy_finished"));
    out.write(":&nbsp;");
    out.write(finished);
    out.write("</div>");

    out.write("<div style='margin-top: 3px;'>");
    out.write(Application.getMessage(context, "deployed_by"));
    out.write(":&nbsp;");
    out.write(Utils.encode(creator));
    out.write("</div>");

    if (username != null) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "deploy_server_username"));
        out.write(":&nbsp;");
        out.write(Utils.encode(username));
        out.write("</div>");
    }

    if (source != null) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "deploy_server_source_path"));
        out.write(":&nbsp;");
        out.write(Utils.encode(source));
        out.write("</div>");
    }

    if (excludes != null) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "deploy_server_excludes"));
        out.write(":&nbsp;");
        out.write(Utils.encode(excludes));
        out.write("</div>");
    }

    if (target != null) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "deploy_server_target_name"));
        out.write(":&nbsp;");
        out.write(Utils.encode(target));
        out.write("</div>");
    }

    if (success.booleanValue() == true && url != null && url.length() > 0) {
        out.write("<div style='margin-top: 3px;'>");
        out.write(Application.getMessage(context, "deploy_server_url"));
        out.write(":&nbsp;<a target='new' href='");
        out.write(url);
        out.write("'>");
        out.write(Utils.encode(url));
        out.write("</a></div>");
    }

    if (content.length() > 0) {
        out.write("<div style='margin-top: 6px;'><img src='");
        out.write(context.getExternalContext().getRequestContextPath());
        out.write(
                "/images/icons/collapsed.gif' style='vertical-align: -1px; cursor: pointer;' class='collapsed' onclick=\"Alfresco.toggleDeploymentDetails(this, '");
        out.write(serverId.toString());
        out.write("');\" />&nbsp;");
        out.write(Application.getMessage(context, "details"));
        out.write("</div>\n");
        out.write("<div id='");
        out.write(serverId.toString());
        out.write(
                "-deployment-details' style='display: none; border: 1px dotted #eee; margin-left: 14px; margin-top: 4px; padding:3px;'>");
        out.write(content);
        out.write("</div>");
    }
    out.write("\n<div style='padding-top:6px;'></div>\n");
    out.write("</td></tr></table>");

    // finish the surrounding panel
    PanelGenerator.generatePanelEnd(out, context.getExternalContext().getRequestContextPath(), "lightstorm");
}

From source file:org.apache.camel.spring.util.SpringAntPathMatcherFileFilter.java

/**
 * Accepts the given file by the path name
 *
 * @param path the path//from www  .  ja  v  a  2 s .c om
 * @return <tt>true</tt> if accepted, <tt>false</tt> if not
 */
public boolean acceptPathName(String path) {
    // must use single / as path separators
    path = StringUtils.replace(path, File.separator, "/");

    if (LOG.isTraceEnabled()) {
        LOG.trace("Filtering file: " + path);
    }

    // excludes take precedence
    if (excludes != null) {
        for (String exclude : excludes) {
            if (matcher.match(exclude, path)) {
                // something to exclude so we cant accept it
                if (LOG.isTraceEnabled()) {
                    LOG.trace("File is excluded: " + path);
                }
                return false;
            }
        }
    }

    if (includes != null) {
        for (String include : includes) {
            if (matcher.match(include, path)) {
                // something to include so we accept it
                if (LOG.isTraceEnabled()) {
                    LOG.trace("File is included: " + path);
                }
                return true;
            }
        }
    }

    // nothing to include so we cant accept it
    return false;
}

From source file:org.dbist.aspect.SqlAspect.java

private static String combine(String sql, Object params) {
    if (sql == null || params == null)
        return sql;
    if (params instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, ?> map = (Map<String, ?>) params;
        Set<String> keySet = new TreeSet<String>(COMPARATOR_REVERSED);
        keySet.addAll(map.keySet());//from   w  ww  .  j av  a  2  s.c o m
        for (String key : keySet)
            sql = StringUtils.replace(sql, ":" + key, toParamValue(map.get(key)));
    } else if (params instanceof Object[]) {
        for (Object param : (Object[]) params)
            sql = sql.replaceFirst("?", toParamValue(param));
    }
    return sql;
}

From source file:org.dbist.dml.impl.DmlJdbc.java

private <T> Table checkAndPopulateDomainAndName(Table table, String... tableNameCandidates) {
    // Check table existence and populate
    String sql = getQueryCountTable();
    if (sql == null)
        throw new IllegalArgumentException(ValueUtils.populate(MSG_QUERYNOTFOUND,
                ValueUtils.toMap("queryName: number of table", "dbType:" + getDbType())));
    String vsql = getQueryCountView();
    boolean checkView = !ValueUtils.isEmpty(vsql) && !sql.equals(vsql);

    List<String> domainNameList = ValueUtils.isEmpty(table.getDomain()) ? this.domainList
            : ValueUtils.toList(table.getDomain());

    boolean populated = false;
    for (String domainName : domainNameList) {
        domainName = domainName.toLowerCase();
        String _sql = StringUtils.replace(sql, "${domain}", toFirstDomainName(domainName));
        String _vsql = checkView ? StringUtils.replace(vsql, "${domain}", toFirstDomainName(domainName)) : null;
        for (String tableName : tableNameCandidates) {
            if (jdbcOperations.queryForInt(_sql, tableName) > 0) {
                table.setDomain(domainName);
                table.setName(tableName);
                table.setType("table");
                populated = true;//from w  w w .  j  a  v  a 2 s.  c  o m
                break;
            }
            if (checkView && jdbcOperations.queryForInt(_vsql, tableName) > 0) {
                table.setDomain(domainName);
                table.setName(tableName);
                table.setType("view");
                populated = true;
                break;
            }
        }
        if (populated)
            break;
    }

    if (!populated) {
        String errMsg = "Couldn't find table[${table}] from this(these) domain(s)[${domain}]";
        throw new IllegalArgumentException(ValueUtils.populate(errMsg,
                ValueUtils.toMap("domain:" + mapOr(domainNameList), "table:" + mapOr(tableNameCandidates))));
    }

    // populate PK name
    sql = getQueryPkColumnNames();
    if (sql == null)
        throw new IllegalArgumentException(ValueUtils.populate(MSG_QUERYNOTFOUND,
                ValueUtils.toMap("queryName: primary key", "dbType:" + getDbType())));

    sql = StringUtils.replace(sql, "${domain}", toFirstDomainName(table.getDomain()));
    table.setPkColumnNameList(jdbcOperations.queryForList(sql, String.class, table.getName()));
    if (ValueUtils.isEmpty(table.getPkColumnNameList())) {
        List<String> list = new ArrayList<String>();
        for (Field field : ReflectionUtils.getFieldList(table.getClazz(), false)) {
            if (field.getAnnotation(PrimaryKey.class) == null)
                continue;
            list.add(field.getName());
        }
        if (!list.isEmpty())
            table.setPkFieldNames(list.toArray(new String[list.size()]));
    }

    return table;
}