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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces a String with another String inside a larger String, once.

Usage

From source file:com.npower.dm.hibernate.entity.ModelFamilyEntity.java

public String getName() {
    String name = super.getName().replace('_', ' ');
    name = StringUtils.replaceOnce(name, "family ", "");
    return WordUtils.capitalize(name, new char[] { ' ' });
}

From source file:com.egt.core.db.util.InterpreteSqlSQLServer.java

@Override
public String getComandoSelect(String comando, int limite) {
    String select = StringUtils.stripToNull(comando);
    if (select != null && limite > 0) {
        boolean b1 = StringUtils.startsWithIgnoreCase(select, COMANDO_SELECT_1);
        boolean b2 = StringUtils.startsWithIgnoreCase(select, COMANDO_SELECT_2);
        if (b1 && !b2) {
            select = StringUtils.replaceOnce(select, COMANDO_SELECT_1, COMANDO_SELECT_2 + " " + limite);
        }/*from w  w w .j a  v a 2 s. c  o  m*/
    }
    return select;
}

From source file:info.magnolia.module.admininterface.PageMVCServlet.java

/**
 *
 *///from  w  ww .  ja v a  2s  . c om
protected MVCServletHandler getHandler(HttpServletRequest request, HttpServletResponse response) {

    String pageName = RequestFormUtil.getParameter(request, "mgnlPage"); //$NON-NLS-1$
    if (StringUtils.isEmpty(pageName)) {
        pageName = (String) request.getAttribute("javax.servlet.include.request_uri"); //$NON-NLS-1$
        if (StringUtils.isEmpty(pageName)) {
            pageName = (String) request.getAttribute("javax.servlet.forward.servlet_path"); //$NON-NLS-1$
        }
        if (StringUtils.isEmpty(pageName)) {
            pageName = request.getRequestURI();
        }
        pageName = StringUtils.replaceOnce(StringUtils.substringAfterLast(pageName, "/pages/"), ".html", //$NON-NLS-1$ //$NON-NLS-2$
                StringUtils.EMPTY);
    }

    PageMVCHandler handler = null;

    if (pageName != null) {
        // try to get a registered handler
        try {
            handler = PageHandlerManager.getInstance().getPageHandler(pageName, request, response);
        } catch (InvalidDialogPageHandlerException e) {
            log.error("no page found: [" + pageName + "]"); //$NON-NLS-1$
        }
    } else {
        log.error("no dialogpage name passed"); //$NON-NLS-1$
    }

    return handler;
}

From source file:ips1ap101.lib.core.db.util.InterpreteSqlSQLServer.java

@Override
public String getComandoSelect(String comando, int limite) {
    String select = super.getComandoSelect(comando, limite);
    if (select != null && limite > 0) {
        boolean b1 = StringUtils.startsWithIgnoreCase(select, COMANDO_SELECT_1);
        boolean b2 = StringUtils.startsWithIgnoreCase(select, COMANDO_SELECT_2);
        if (b1 && !b2) {
            select = StringUtils.replaceOnce(select, COMANDO_SELECT_1, COMANDO_SELECT_2 + " " + limite);
        }//from   w  w  w .ja  va2 s  .c  o  m
    }
    return select;
}

From source file:jetbrick.tools.chm.style.Javadoc8Style.java

@Override
public String getMethodFullName(String url) {
    String name = StringUtils.substringAfter(url, "#");
    int count = StringUtils.countMatches(name, "-");
    name = StringUtils.replaceOnce(name, "-", "(");
    for (int i = 0; i < count - 2; i++) {
        name = StringUtils.replaceOnce(name, "-", ", ");
    }/*from ww w.j  a v a  2  s  .  co  m*/
    name = StringUtils.replaceOnce(name, "-", ")");
    name = StringUtils.replace(name, ":A", "[]");
    return name;
}

From source file:com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.application.SQLToRealGridConvert.java

/**
 * sql to string//ww w .j a  va2 s. com
 * 
 * @param name
 * @param sql
 * @return
 */
public static String sqlToString(UserDBDAO userDB, String name, String sql) {
    String retHtml = "";
    try {
        String STR_TEMPLATE = IOUtils.toString(SQLToRealGridConvert.class.getResource("realgrid.js.template"));

        QueryExecuteResultDTO queryResult = QueryUtils.executeQuery(userDB, sql, 0, 4);
        Map<Integer, String> columnLabel = queryResult.getColumnLabelName();
        Map<Integer, Integer> columnType = queryResult.getColumnType();

        String strField = "";
        StringBuffer sbField = new StringBuffer();
        for (int i = 0; i < columnLabel.size(); i++) {
            String strColumnLabel = columnLabel.get(i);
            boolean isNumber = RDBTypeToJavaTypeUtils.isNumberType(columnType.get(i));
            sbField.append(String.format(GROUP_TEMPLATE, strColumnLabel, isNumber ? "number" : "text"));
        }
        strField = StringUtils.removeEnd(sbField.toString(), ",");

        String strColumn = "";
        StringBuffer sbColumn = new StringBuffer();
        for (int i = 0; i < columnLabel.size(); i++) {
            String strColumnLabel = columnLabel.get(i);
            sbColumn.append(String.format(GROUP_DATA_TEMPLATE, strColumnLabel, strColumnLabel));
        }
        strColumn = StringUtils.removeEnd(sbColumn.toString(), ",");

        retHtml = StringUtils.replaceOnce(STR_TEMPLATE, "_TDB_TEMPLATE_FIELD_", strField);
        retHtml = StringUtils.replaceOnce(retHtml, "_TDB_TEMPLATE_COLUMN_", strColumn);
    } catch (Exception e) {
        logger.error("SQL template exception", e);
    }

    return retHtml;
}

From source file:com.opengamma.component.AbstractComponentConfigLoader.java

/**
 * Resolves any ${property} references in the value.
 * /*from  w w w .  ja  v  a2 s. co  m*/
 * @param value  the value to resolve, not null
 * @param lineNum  the line number, for error messages
 * @return the resolved value, not null
 */
protected String resolveProperty(String value, int lineNum) {
    String variable = findVariable(value);
    while (variable != null) {
        if (_properties.containsKey(variable) == false) {
            throw new OpenGammaRuntimeException(
                    "Variable expansion not found: ${" + variable + "}, line " + lineNum);
        }
        value = StringUtils.replaceOnce(value, "${" + variable + "}", _properties.get(variable));
        variable = findVariable(value);
    }
    return value;
}

From source file:info.magnolia.module.admininterface.DialogMVCServlet.java

/**
 *
 *//*from ww w  . j a  va 2 s .co m*/
protected MVCServletHandler getHandler(HttpServletRequest request, HttpServletResponse response) {
    String dialogName = RequestFormUtil.getParameter(request, "mgnlDialog"); //$NON-NLS-1$

    if (StringUtils.isEmpty(dialogName)) {
        if (StringUtils.isEmpty(dialogName)) {
            dialogName = (String) request.getAttribute("javax.servlet.include.request_uri"); //$NON-NLS-1$
            if (StringUtils.isEmpty(dialogName)) {
                dialogName = (String) request.getAttribute("javax.servlet.forward.servlet_path"); //$NON-NLS-1$
            }
            if (StringUtils.isEmpty(dialogName)) {
                dialogName = request.getRequestURI();
            }
            dialogName = StringUtils.replaceOnce(StringUtils.substringAfterLast(dialogName, "/dialogs/"), //$NON-NLS-1$
                    ".html", //$NON-NLS-1$
                    StringUtils.EMPTY);
        }
    }

    DialogMVCHandler handler = null;

    if (StringUtils.isNotBlank(dialogName)) {
        // try to get a registered handler
        try {
            handler = DialogHandlerManager.getInstance().getDialogHandler(dialogName, request, response);
        } catch (InvalidDialogHandlerException e) {
            log.info("can't find handler will try to load directly from the config", e); //$NON-NLS-1$
            Content configNode = ConfiguredDialog.getConfigNode(request, dialogName);
            // try to find a class property or return a ConfiguredDialog
            if (configNode != null) {
                handler = ConfiguredDialog.getConfiguredDialog(dialogName, configNode, request, response);
            } else {
                log.error("no config node found for dialog : " + dialogName); //$NON-NLS-1$
            }
        }
    }

    if (handler == null) {
        log.error(MessageFormat.format("Missing configuration for {0}. Check node {1}{0}", //$NON-NLS-1$
                new Object[] { dialogName, "/modules/templating/Paragraphs/" })); //$NON-NLS-1$

        throw new ConfigurationException(
                MessageFormat.format("Missing configuration for {0}. Check node {1}{0}", //$NON-NLS-1$
                        new Object[] { dialogName, "/modules/templating/Paragraphs/" })); //$NON-NLS-1$

    }

    return handler;
}

From source file:com.adobe.acs.commons.util.InfoWriter.java

/**
 * Creates a message with optional var injection.
 * Message format: "A String with any number of {} placeholders that will have the vars injected in order"
 * @param message the message string with the injection placeholders ({})
 * @param vars the vars to inject into the the message template; some type conversion will occur for common data
 *             types/*from w w  w . j a  v a2s.c  om*/
 */
public void message(String message, final Object... vars) {
    if (ArrayUtils.isEmpty(vars)) {
        pw.println(message);
    } else {
        for (final Object var : vars) {
            try {
                message = StringUtils.replaceOnce(message, "{}", TypeUtil.toString(var));
            } catch (Exception e) {
                log.error("Could not derive a valid String representation for {} using TypeUtil.toString(..)",
                        var, e);

                message = StringUtils.replaceOnce(message, "{}", "???");
            }
        }

        pw.println(message);
    }
}

From source file:de.hybris.platform.addonsupport.config.SpelBeanFactory.java

@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
    final ExpressionParser parser = new SpelExpressionParser();
    final StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(new BeanFactoryResolver(applicationContext));

    final String[] beanNames = applicationContext.getBeanNamesForType(AbstractConverter.class);
    for (final String beanName : beanNames) {
        final BeanDefinition def = beanFactory.getBeanDefinition(beanName);
        final PropertyValue pv = def.getPropertyValues().getPropertyValue("targetClass");
        if (pv != null) {

            if (pv.getValue() instanceof TypedStringValue) {

                String expr = StringUtils.strip(((TypedStringValue) pv.getValue()).getValue());
                if (expr.startsWith("#{")) {
                    expr = StringUtils.replaceOnce(expr, "#{", "@");
                    expr = StringUtils.stripEnd(expr, "}");
                    final Object result = parser.parseExpression(expr).getValue(context);
                    if (result != null) {

                        try {
                            applicationContext.getBean(beanName, AbstractConverter.class)
                                    .setTargetClass(ClassUtils.getClass(result.toString()));
                        } catch (final ClassNotFoundException e) {
                            LOG.error(beanName + " target class instantiation failed", e);
                        }// w w w. j a v  a 2 s. com
                    }
                }
            }
        }
    }
}