Example usage for org.apache.commons.lang StringUtils replace

List of usage examples for org.apache.commons.lang StringUtils replace

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replace.

Prototype

public static String replace(String text, String searchString, String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.hangum.tadpole.commons.util.XMLUtils.java

/**
 * String? xml string //from  w w w.java2s  . co  m
 * 
 * @param retVal
 * @return
 */
public static String stringToXml(String retVal) {
    for (int i = 0; i < xml.length; i++) {
        retVal = StringUtils.replace(retVal, javaString[i], xml[i]);
    }

    return retVal;
}

From source file:cc.kune.core.server.utils.XmlW.java

/**
 * Escape xml.//from   w  w w .ja  v a 2s .c  o  m
 * 
 * @param str
 *          the str
 * @return the string
 */
static public String escapeXml(String str) {
    str = StringUtils.replace(str, "&", "&amp;");
    str = StringUtils.replace(str, "<", "&lt;");
    str = StringUtils.replace(str, ">", "&gt;");
    str = StringUtils.replace(str, "\"", "&quot;");
    str = StringUtils.replace(str, "'", "&apos;");
    return str;
}

From source file:com.livinglogic.ul4.FunctionStr.java

public static String call(Object obj) {
    if (obj == null)
        return "";
    else if (obj instanceof Undefined)
        return "";
    else if (obj instanceof Boolean)
        return ((Boolean) obj).booleanValue() ? "True" : "False";
    else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long
            || obj instanceof BigInteger)
        return obj.toString();
    else if (obj instanceof Double || obj instanceof Float)
        return StringUtils.replace(obj.toString(), ".0E", "E").toLowerCase();
    else if (obj instanceof BigDecimal) {
        String result = obj.toString();
        if (result.indexOf('.') < 0 && result.indexOf('E') < 0 && result.indexOf('e') < 0)
            result += ".0";
        return result;
    } else if (obj instanceof String)
        return (String) obj;
    else if (obj instanceof Date) {
        if (BoundDateMethodMicrosecond.call((Date) obj) != 0)
            return strTimestampMicroFormatter.format(obj);
        else/*from www . j  a  v a 2  s.  c  o m*/
            return strDateTimeFormatter.format(obj);
    } else if (obj instanceof Color)
        return obj.toString();
    else if (obj instanceof TimeDelta)
        return obj.toString();
    else if (obj instanceof MonthDelta)
        return obj.toString();
    else
        return FunctionRepr.call(obj);
}

From source file:com.badugi.game.logic.model.utils.common.TextUtils.java

/**
 * Autoformat./*from   ww  w.ja  v a 2 s .  co m*/
 */
public static final String autoformat(String s) {
    String ret = StringUtils.replace(s, "\n", "<br />");
    return ret;
}

From source file:net.jforum.formatters.NewLineToHtmlBreakFormatter.java

/**
 * @see net.jforum.formatters.Formatter#format(java.lang.String, PostOptions)
 *//* www .j a va  2 s .  c  o  m*/
@Override
public String format(String text, PostOptions postOptions) {
    return StringUtils.replace(text, "\n", "<br/> ");
}

From source file:com.hangum.tadpole.erd.core.relation.CubridTableRelation.java

/**
 * ? relation  ?//from  w ww  .j a v  a 2s .  c  o  m
 * 
 * @param userDB
 * @return
 */
public static List<ReferencedTableDAO> makeCubridRelation(UserDBDAO userDB, String tableName) throws Exception {
    List<ReferencedTableDAO> listRealRefTableDAO = new ArrayList<ReferencedTableDAO>();

    Connection conn = null;
    ResultSet rs = null;

    String[] tableNames = StringUtils.split(tableName, ',');
    for (String table : tableNames) {
        table = StringUtils.replace(table, "'", "");

        try {
            SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
            conn = sqlClient.getDataSource().getConnection();

            rs = conn.getMetaData().getImportedKeys("", "", table);
            while (rs.next()) {

                ReferencedTableDAO ref = new ReferencedTableDAO();
                ref.setConstraint_name(rs.getString("FK_NAME"));

                // ? 
                ref.setTable_name(rs.getString("FKTABLE_NAME"));
                ref.setColumn_name(rs.getString("FKCOLUMN_NAME"));

                ref.setReferenced_table_name(rs.getString("PKTABLE_NAME"));
                ref.setReferenced_column_name(rs.getString("PKCOLUMN_NAME"));

                if (logger.isDebugEnabled())
                    logger.debug(ref.toString());

                listRealRefTableDAO.add(ref);
            }

        } catch (Exception e) {
            logger.error("cubrid relation", e);
            throw new Exception("Cubrid relation exception " + e.getMessage());
        } finally {
            if (rs != null)
                try {
                    rs.close();
                } catch (Exception e) {
                }
            if (conn != null)
                try {
                    conn.close();
                } catch (Exception e) {
                }
        }

    } // end last for

    return listRealRefTableDAO;
}

From source file:com.sfs.whichdoctor.formatter.GroupFormatter.java

public static String getField(final GroupBean group, final String field, final String format) {

    String value = "";
    if (group == null || field == null) {
        return value;
    }/*from   www  . j  a  va2 s  .co  m*/

    if (field.compareTo("Tags") == 0) {
        value = OutputFormatter.toTagList(group.getTags());
    }

    if (field.compareTo("GUID") == 0) {
        if (group.getGUID() > 0) {
            value = String.valueOf(group.getGUID());
        }
    }

    if (field.compareTo("GroupId") == 0) {
        if (group.getId() > 0) {
            value = String.valueOf(group.getId());
        }
    }
    if (field.compareTo("Group Name") == 0) {
        value = group.getName();
    }
    if (field.compareTo("Group Description") == 0) {
        value = StringUtils.replace(group.getDescription(), "\n", "<br />");
    }
    if (field.compareTo("Group Type") == 0) {
        value = group.getType();
    }
    if (field.compareTo("Created By") == 0) {
        value = group.getCreatedBy();
    }
    if (field.compareTo("Date Created") == 0) {
        if (group.getCreatedDate() != null) {
            value = Formatter.conventionalDate(group.getCreatedDate());
        }
    }
    if (field.compareTo("Modified By") == 0) {
        value = group.getModifiedBy();
    }
    if (field.compareTo("Date Modified") == 0) {
        if (group.getModifiedDate() != null) {
            value = Formatter.conventionalDate(group.getModifiedDate());
        }
    }
    if (value == null) {
        value = "";
    }
    return value;
}

From source file:com.kalessil.phpStorm.phpInspectionsEA.inspectors.regularExpressions.modifiersStrategy.MissingUnicodeModifierStrategy.java

static public void apply(@Nullable String modifiers, @Nullable String pattern,
        @NotNull StringLiteralExpression target, @NotNull ProblemsHolder holder) {
    if ((modifiers == null || modifiers.indexOf('u') == -1) && !StringUtils.isEmpty(pattern)) {
        if (unicodeCharactersPattern.matcher(pattern).matches()) {
            holder.registerProblem(target, messageCharacters, ProblemHighlightType.GENERIC_ERROR);
        } else {//ww  w.ja va2  s  . c  o m
            final String normalized = StringUtils.replace(pattern, "\\\\", "");
            if (unicodeCodepointsPattern.matcher(normalized).matches()) {
                holder.registerProblem(target, messageCodepoints, ProblemHighlightType.GENERIC_ERROR);
            }
        }
    }
}

From source file:net.jforum.formatters.HtmlEntitiesFormatter.java

/**
 * @see net.jforum.formatters.Formatter#format(java.lang.String, PostOptions)
 *///  w w w  .j  a v  a  2s .  c  o m
@Override
public String format(String text, PostOptions postOptions) {
    if (!postOptions.isHtmlEnabled()) {
        text = StringUtils.replace(text, "<", "&lt;");
        text = StringUtils.replace(text, ">", "&gt;");
    }

    return text;
}

From source file:net.sf.zekr.engine.audio.RecitationPackConverter.java

public static AudioData convert(File oldRecitationPack) throws IOException, ConfigurationException {
    PropertiesConfiguration props = ConfigUtils.loadConfig(oldRecitationPack, "UTF-8");
    AudioData ad = new AudioData();
    ad.id = props.getString("audio.id");
    if (StringUtils.isBlank(ad.id)) {
        logger.debug("audio.id cannot be null or empty");
        return null;
    }//from   w w  w . ja v a2 s . c om
    ad.id += "-converted";

    ad.version = "0.7.5";
    ad.lastUpdate = props.getString("audio.lastUpdate");
    ad.quality = "?";

    ad.name = props.getString("audio.name");
    if (StringUtils.isBlank(ad.id)) {
        logger.debug("audio.name cannot be null or empty");
        return null;
    }
    ad.name += " (converted)";

    ad.license = props.getString("audio.license");
    ad.locale = new Locale(props.getString("audio.language"), props.getString("audio.country"));

    String fileName = props.getString("audio.fileName");
    fileName = StringUtils.replace(fileName, "{SURA}", "%1$03d");
    fileName = StringUtils.replace(fileName, "{AYA}", "%2$03d");

    String baseUrl = props.getString("audio.baseUrl");
    if (StringUtils.isBlank(baseUrl)) {
        logger.debug("audio.baseUrl cannot be null or empty");
        return null;
    }
    baseUrl = StringUtils.replace(baseUrl, "%", "%%");

    String path;
    if (props.containsKey("audio.serverUrl")) {
        ad.type = "online";
        String serverUrl = props.getString("audio.serverUrl");
        path = serverUrl + "/" + baseUrl + "/";
        ad.onlineUrl = path + fileName;

        if (props.containsKey("audio.prestartFileName")) {
            ad.onlineAudhubillah = path + props.getString("audio.prestartFileName");
        }
        if (props.containsKey("audio.startFileName")) {
            ad.onlineBismillah = path + props.getString("audio.startFileName");
        }
        if (props.containsKey("audio.endFileName")) {
            ad.onlineSadaghallah = path + props.getString("audio.endFileName");
        }
    } else {
        ad.type = "offline";

        baseUrl = StringUtils.replace(baseUrl, "[base]", "<base>");
        baseUrl = StringUtils.replace(baseUrl, "[workspace]", "<workspace>");
        baseUrl = StringUtils.replace(baseUrl, "[w_b]", "<workspace_base>");

        path = baseUrl + "/";
        ad.offlineUrl = path + fileName;

        if (props.containsKey("audio.prestartFileName")) {
            ad.offlineAudhubillah = path + props.getString("audio.prestartFileName");
        }
        if (props.containsKey("audio.startFileName")) {
            ad.offlineBismillah = path + props.getString("audio.startFileName");
        }
        if (props.containsKey("audio.endFileName")) {
            ad.offlineSadaghallah = path + props.getString("audio.endFileName");
        }
    }

    return ad;
}