Example usage for java.util.regex Matcher end

List of usage examples for java.util.regex Matcher end

Introduction

In this page you can find the example usage for java.util.regex Matcher end.

Prototype

public int end() 

Source Link

Document

Returns the offset after the last character matched.

Usage

From source file:ca.sqlpower.object.SPVariableHelper.java

/**
 * Helper method that takes a connection and a SQL statement which includes variable and 
 * converts all that in a nifty prepared statement ready for execution, on time for Christmas.
 * @param connection A connection object to use in order to generate the prepared statement.
 * @param sql A SQL string which might include variables.
 * @param variableHelper A {@link SPVariableHelper} object to resolve the variables.
 * @return A {@link PreparedStatement} object ready for execution.
 * @throws SQLException Might get thrown if we cannot generate a {@link PreparedStatement} with the supplied connection.
 *///from  www  . ja  v a 2  s . c  o  m
public static PreparedStatement substituteForDb(Connection connection, String sql,
        SPVariableHelper variableHelper) throws SQLException {

    // Make sure that the registry is ready.
    SPResolverRegistry.init(variableHelper.getContextSource());

    StringBuilder text = new StringBuilder();
    Matcher matcher = varPattern.matcher(sql);
    List<Object> vars = new LinkedList<Object>();

    // First, change all vars to '?' markers.
    int currentIndex = 0;
    while (!matcher.hitEnd()) {
        if (matcher.find()) {
            String variableName = matcher.group(1);
            if (variableName.equals("$")) {
                vars.add("$");
            } else {
                vars.add(variableHelper.resolve(variableName));
            }
            text.append(sql.substring(currentIndex, matcher.start()));
            text.append("?");
            currentIndex = matcher.end();
        }
    }
    text.append(sql.substring(currentIndex));

    // Now generate a prepared statement and inject it's variables.
    PreparedStatement ps = connection.prepareStatement(text.toString());
    for (int i = 0; i < vars.size(); i++) {
        ps.setObject(i + 1, vars.get(i));
    }

    return ps;
}

From source file:io.dataapps.chlorine.pattern.RegexFinder.java

/**
 * Scan the list of inputs using the finders.
 * Return a list of actual matched values.
 * @return a list of matches //from   w  w w  .j av a 2  s .c o m
 */
public FinderResult find(String input) {
    List<String> matches = new ArrayList<>();
    Matcher matcher = pattern.matcher(input);
    while (matcher.find()) {
        matches.add(input.substring(matcher.start(), matcher.end()));
    }
    return new FinderResult(matches, replace(input, ""));
}

From source file:ca.sqlpower.object.SPVariableHelper.java

/**
 * Helper method that takes a connection and a MDX statement which includes variable and 
 * converts all that in a nifty prepared statement ready for execution, on time for Christmas.
 * @param connection A connection object to use in order to generate the prepared statement.
 * @param sql A MDX string which might include variables.
 * @param variableHelper A {@link SPVariableHelper} object to resolve the variables.
 * @return A {@link PreparedStatement} object ready for execution.
 * @throws SQLException Might get thrown if we cannot generate a {@link PreparedStatement} with the supplied connection.
 *///  ww  w  .j  a  v  a 2 s.  com
public static PreparedOlapStatement substituteForDb(OlapConnection connection, String mdxQuery,
        SPVariableHelper variableHelper) throws SQLException {

    // Make sure that the registry is ready.
    SPResolverRegistry.init(variableHelper.getContextSource());

    StringBuilder text = new StringBuilder();
    Matcher matcher = varPattern.matcher(mdxQuery);
    List<Object> vars = new LinkedList<Object>();

    // First, change all vars to '?' markers.
    int currentIndex = 0;
    while (!matcher.hitEnd()) {
        if (matcher.find()) {
            String variableName = matcher.group(1);
            if (variableName.equals("$")) {
                vars.add("$");
            } else {
                vars.add(variableHelper.resolve(variableName));
            }
            text.append(mdxQuery.substring(currentIndex, matcher.start()));
            text.append("?");
            currentIndex = matcher.end();
        }
    }
    text.append(mdxQuery.substring(currentIndex));

    // Now generate a prepared statement and inject it's variables.
    PreparedOlapStatement ps = connection.prepareOlapStatement(text.toString());
    for (int i = 0; i < vars.size(); i++) {
        ps.setObject(i + 1, vars.get(i));
    }

    return ps;
}

From source file:com.npower.dm.server.synclet.HttpHeaderPhoneNumberDetector.java

public String getPhoneNumber(String deviceExternalID, HttpServletRequest httpRequest, SyncML message) {
    String name = this.getHeaderName();
    if (StringUtils.isEmpty(name)) {
        log.error(//from   ww w.  j a  va2  s. com
                "Http header name is null. please specified the name of header for HttpHeaderPhoneNumberDetector.");
        return null;
    }
    String headerValue = httpRequest.getHeader(name);
    if (StringUtils.isEmpty(headerValue)) {
        log.error("Missing value in http header: " + name);
        return null;
    }
    if (StringUtils.isEmpty(this.getPattern())) {
        return headerValue.trim();
    }
    boolean found = Pattern.compile(pattern).matcher(headerValue).find();
    if (found) {
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(headerValue);
        m.find();
        int start = m.start();
        int end = m.end();
        return headerValue.substring(start, end);
    } else {
        return null;
    }
}

From source file:com.gzj.tulip.jade.statement.cached.CachedStatement.java

/**
 * ? KEY  :name, :name.property ???// w  ww. ja v  a2  s.c  om
 * 
 * @param key - ? KEY
 * @param parameters - ?
 * 
 * @return  KEY
 * @author  in355hz@gmail.com
 */
private static String buildKey(String key, Map<String, Object> parameters) {
    // ??  :name ??
    Matcher matcher = PATTERN.matcher(key);
    if (matcher.find()) {

        StringBuilder builder = new StringBuilder();

        int index = 0;

        do {
            // ??????
            final String name = matcher.group(1).trim();

            Object value = null;

            // ?  a.b.c ?? 
            int find = name.indexOf('.');
            if (find >= 0) {

                //   BeanWrapper ?
                Object bean = parameters.get(name.substring(0, find));
                if (bean != null) {
                    value = new BeanWrapperImpl(bean).getPropertyValue(name.substring(find + 1));
                }

            } else {

                // ??
                value = parameters.get(name);
            }

            // ?
            builder.append(key.substring(index, matcher.start()));
            builder.append(value);

            index = matcher.end();

        } while (matcher.find());

        // ?
        builder.append(key.substring(index));

        return builder.toString();
    }

    return key;
}

From source file:com.mmdi.gmds.ws.pcs.resource.GeoLocationJsonResource.java

private void locateFromCache(Location location) {
    try {//www  .j  a va2 s .  c  o m
        String pc = location.getPostalCode();
        if (pc != null) {
            StringBuilder builder = new StringBuilder(pc);
            Pattern pattern = Pattern.compile("\\s");
            Matcher matcher = pattern.matcher(pc);

            while (matcher.find()) {
                builder.replace(matcher.start(), matcher.end(), "");
            }

            CacheResource cache = new PostalCodeCacheResource();
            PostalCode postalCode = (PostalCode) cache.getData(builder.toString(), locateCacheRegion);
            if (postalCode != null) {
                location.setLat(postalCode.getLat());
                location.setLng(postalCode.getLong());
            }
        }
    } catch (CacheException ce) {
        logger.error(ce.getMessage());
    }
}

From source file:net.sourceforge.mavenhippo.SourceCodeBeanFinder.java

private String denormalizePath(String path) {
    String result;/*from w ww  .j av  a  2 s .  c  o m*/
    Matcher matcher = START_WITH_SLASH_PATTERN.matcher(path);
    if (matcher.find()) {
        result = path.substring(matcher.end());
    } else {
        result = path;
    }
    return result.replace('/', File.separatorChar);
}

From source file:info.novatec.testit.livingdoc.html.BulletListFilter.java

@Override
public String process(String content) {
    Matcher matcher = Pattern.compile(ELEMENT_BOUNDARY).matcher(content);

    StringBuilder sb = new StringBuilder();
    int startIndex, matchIndex;
    for (startIndex = 0; matcher.find(); startIndex = matcher.end()) {
        matchIndex = matcher.start();//w  w w  .  j  av  a  2  s  .c o  m
        String preMatch = content.substring(startIndex, matchIndex);
        if (!StringUtils.isBlank(preMatch)) {
            sb.append(span(preMatch));
        }
        if (!StringUtils.isBlank(matcher.group(2))) {
            sb.append(matcher.group());
        }
    }
    String postMatch = content.substring(startIndex, content.length());
    if (!StringUtils.isBlank(postMatch)) {
        sb.append(span(postMatch));
    }

    return sb.toString();
}

From source file:com.clustercontrol.util.CommandCreator.java

/**
 * create command for Windows like CMD /C [COMMAND]
 * @param execUser execution user//w ww. j  a  va 2s  .c  om
 * @param execCommand command string parsed by CMD
 * @return command and arguments
 * @throws HinemosUnknown
 */
private static String[] createWindowsCommand(String execUser, String execCommand) throws HinemosUnknown {
    // Local Variables
    String[] command = null;
    ArrayList<String> commandList = new ArrayList<String>();
    boolean isDebugEnable = log.isDebugEnabled();

    // MAIN
    if (execUser.equals(sysUser)) {

        // ?????????????????
        // ???????
        String splitTarget = " " + execCommand;

        while (true) {
            if (isDebugEnable) {
                log.debug("parse command for windows. split target = " + splitTarget);
            }
            Matcher match = winCmdSplitPattern.matcher(splitTarget);
            if (match.find()) {
                // ???????? or ?????
                // ????? "^\\s+(((\".*?\")|([^\"\\s]+?))+)" ???
                // ? ^\\s+ ???? (((\".*?\")|([^\"\\s]+?))+) ?????????
                String arg = match.group(1);
                if (isDebugEnable) {
                    log.debug("parse command for windows. find arg = " + arg);
                }
                commandList.add(arg);
                splitTarget = splitTarget.substring(match.end());
            } else {
                if (isDebugEnable) {
                    log.debug("parse command for windows. can't find args");
                }
                break;
            }
        }

        command = commandList.toArray(new String[commandList.size()]);
        if (isDebugEnable) {
            log.debug("created command for windows. (cmd = " + Arrays.toString(command) + ")");
        }
    } else {
        throw new HinemosUnknown("execution user and jvm user must be same on Windows. (execUser = " + execUser
                + ", sysUser = " + sysUser + ")");
    }
    return command;
}

From source file:ca.sqlpower.object.SPVariableHelper.java

/**
 * Substitutes any number of variable references in the given string, returning
 * the resultant string with all variable references replaced by the corresponding
 * variable values./*from w  w w  . j  a  v a 2  s.  c  om*/
 * 
 * @param textWithVars
 * @param variableContext
 * @return
 */
public static String substitute(String textWithVars, SPVariableHelper variableHelper) {

    logger.debug("Performing variable substitution on " + textWithVars);

    // Make sure that the registry is ready.
    SPResolverRegistry.init(variableHelper.getContextSource());

    StringBuilder text = new StringBuilder();
    Matcher matcher = varPattern.matcher(textWithVars);

    int currentIndex = 0;
    while (!matcher.hitEnd()) {
        if (matcher.find()) {
            String variableName = matcher.group(1);
            Object variableValue;
            if (variableName.equals("$")) {
                variableValue = "$";
            } else {
                variableValue = variableHelper.resolve(variableName);
            }
            logger.debug("Found variable " + variableName + " = " + variableValue);
            text.append(textWithVars.substring(currentIndex, matcher.start()));
            text.append(variableValue);
            currentIndex = matcher.end();
        }
    }

    text.append(textWithVars.substring(currentIndex));

    return text.toString();
}