List of usage examples for java.util.regex Matcher end
public int end()
From source file:mobi.jenkinsci.server.core.net.ProxyUtil.java
private String resolveCss(final String userAgent, final String pluginName, final String url, final String resultString) throws IOException { log.debug("Resolving CSS for URL " + url); final StringBuilder outString = new StringBuilder(); int currPos = 0; final Pattern cssLinkPattern = Pattern.compile("<link" + "[^>]*" + "rel=[\"']stylesheet[\"']" + "[^>]*" + "href=[\"']([^>\"']*)[\"']" + "[^>]*" + "/>", Pattern.DOTALL); final Matcher matcher = cssLinkPattern.matcher(resultString); while (matcher.find(currPos)) { final int start = matcher.start(); final int end = matcher.end(); outString.append(resultString.substring(currPos, start)); final String cssUrl = matcher.group(1); String cssText = retrieveCss(userAgent, pluginName, url, cssUrl); cssText = resolveImages(userAgent, pluginName, Pattern.compile(CSS_BACKGROUND_IMAGE_PATTERN, Pattern.DOTALL), 2, getBasePathUrl(resolveRelativeUrl(url, cssUrl)), cssText); outString.append(cssText);/*from w w w .ja v a 2 s.c o m*/ currPos = end; } outString.append(resultString.substring(currPos)); log.debug(outString.length() + " CSS chars included for URL " + url); return outString.toString(); }
From source file:com.jaspersoft.jasperserver.war.cascade.token.FilterCore.java
private Parameter nextParameter(String queryString, int start) { if (start < 0 && start > queryString.length() - 1) return null; Matcher m = ParameterTypes.pattern.matcher(queryString); Parameter p = null;/* w ww. j av a2s .c o m*/ if (m.find(start)) { p = createParameter(m.group(1), m.group(2)); if (p != null) { p.setStartPosition(m.start()); p.setEndPosition(m.end()); } } return p; }
From source file:com.anrisoftware.sscontrol.hosts.utils.HostFormat.java
@Override public Object parseObject(String source, ParsePosition pos) { source = source.trim();/*from w w w . j a v a2 s. c om*/ TemplateResource template; template = templates.getResource(PARSE_TEMPLATE_NAME, locale); Pattern pattern = Pattern.compile(template.getText()); Matcher matcher = pattern.matcher(source); if (!matcher.matches()) { pos.setErrorIndex(pos.getIndex()); return null; } String address = matcher.group(1); String name = matcher.group(2); Host host = hostFactory.create(name, address); String[] aliases = split(matcher.group(3), ","); for (int i = 0; i < aliases.length; i++) { String alias = aliases[i].replaceAll("[\"']", ""); host.addAlias(alias); } pos.setIndex(matcher.end()); return host; }
From source file:com.haulmont.cuba.core.global.QueryTransformerRegex.java
@Override public void addWhereAsIs(String where) { Matcher entityMatcher = FROM_ENTITY_PATTERN.matcher(buffer); findAlias(entityMatcher);//from w w w. j a v a 2 s.co m int insertPos = buffer.length(); Matcher lastClauseMatcher = LAST_CLAUSE_PATTERN.matcher(buffer); if (lastClauseMatcher.find(entityMatcher.end())) insertPos = lastClauseMatcher.start() - 1; StringBuilder sb = new StringBuilder(); Matcher whereMatcher = WHERE_PATTERN.matcher(buffer); if (whereMatcher.find(entityMatcher.end())) sb.append(" and "); else sb.append(" where "); sb.append("(").append(where).append(")"); buffer.insert(insertPos, sb); Matcher paramMatcher = PARAM_PATTERN.matcher(where); while (paramMatcher.find()) { addedParams.add(paramMatcher.group(1)); } }
From source file:com.centurylink.mdw.util.ExpressionUtil.java
/** * Substitutes dynamic values for expressions in the input string. * @param input raw input string/*from ww w.j ava 2s . co m*/ * @param model object containing the values to substitute * @param map of images to populate based on special ${image:*.gif} syntax * @return string with values substituted */ public static String substitute(String input, Object model, Map<String, String> imageMap, boolean lenient) throws MdwException { StringBuffer substituted = new StringBuffer(input.length()); try { Matcher matcher = tokenPattern.matcher(input); int index = 0; while (matcher.find()) { String match = matcher.group(); substituted.append(input.substring(index, matcher.start())); if (imageMap != null && (match.startsWith("${image:") || match.startsWith("#{image:"))) { String imageFile = match.substring(8, match.length() - 1); String imageId = imageFile.substring(0, imageFile.lastIndexOf('.')); substituted.append("cid:" + imageId); imageMap.put(imageId, imageFile); } else if (match.startsWith("#{")) { // ignore #{... in favor of facelets (except images) substituted.append(match); } else { Object value; if (lenient) { try { value = propUtilsBean.getProperty(model, match.substring(2, match.length() - 1)); if (value == null) value = match; } catch (Exception e) { value = match; } } else { value = propUtilsBean.getProperty(model, match.substring(2, match.length() - 1)); } if (value != null) substituted.append(value); } index = matcher.end(); } substituted.append(input.substring(index)); return substituted.toString(); } catch (Exception ex) { throw new MdwException("Error substituting expression value(s)", ex); } }
From source file:info.mikaelsvensson.devtools.sitesearch.SiteSearchPlugin.java
private boolean modifyStringBuilder(final StringBuilder sb, final Pattern insertionPointPattern, final ModifyAction modifyAction, final String text) { Matcher matcher = insertionPointPattern.matcher(sb); if (matcher.find()) { switch (modifyAction) { case APPEND: sb.insert(matcher.end(), text); return true; case PREPEND: sb.insert(matcher.start(), text); return true; case REPLACE: sb.replace(matcher.start(), matcher.end(), text); return true; }/*from w w w. j a v a2s . c om*/ } return false; }
From source file:org.ala.harvester.MaHarvester.java
/** * @see org.ala.harvester.Harvester#start() */// w w w . j a v a2 s .c o m @SuppressWarnings("unchecked") @Override public void start(int infosourceId) throws Exception { // TODO Auto-generated method stub Thread.sleep(timeGap); // Obtains the image listing on the page number specified. // Instance variable `currentResDom` will have new // DOM representation of the result. String indexStr = getIndexPageStr(); Pattern identifierPattern = Pattern.compile("(?:<a href=\")" + "([a-z#]{1,})" + "(?:\">)"); Matcher m = identifierPattern.matcher(indexStr); List<String> identifiers = new ArrayList<String>(); int speciesCounter = 0; int searchIdx = 0; // get all the family links while (m.find(searchIdx)) { int endIdx = m.end(); // String found = content.substring(startIdx, endIdx); String url = m.group(1); String generatedUrl = this.endpoint + url; System.out.println("URL:" + generatedUrl); speciesCounter++; identifiers.add(generatedUrl); searchIdx = endIdx; } for (String identifier : identifiers) { processSingleImage(identifier, indexStr, infosourceId); } System.out.println(speciesCounter); }
From source file:com.jkoolcloud.tnt4j.streams.custom.parsers.ApacheAccessLogParser.java
/** * Makes log entry parsing RegEx from defined Apache access log configuration pattern string. * * @param apacheLogPattern//from w ww . j a va 2 s. co m * Apache access log configuration pattern string * * @return regular expression string, or {@code null} if can't make RegEx string from defined Apache access log * configuration pattern string */ private String makeRegexPattern(String apacheLogPattern) { Pattern pattern = Pattern.compile(APACHE_LOG_CONFIG_TOKEN_REPLACEMENT_REGEX); Matcher matcher = pattern.matcher(apacheLogPattern); StringBuilder logRegexBuff = new StringBuilder(); int pos = 0; while (matcher.find()) { logRegexBuff.append(apacheLogPattern.substring(pos, matcher.start())); logRegexBuff.append(mapConfigTokenToRegex(matcher.group())); pos = matcher.end(); } if (pos < apacheLogPattern.length()) { logRegexBuff.append(apacheLogPattern.substring(pos, apacheLogPattern.length())); } String logRegex = logRegexBuff.toString().trim(); // return logRegex.isEmpty() ? null : "(?m)^" + logRegex; return logRegex.isEmpty() ? null : '^' + logRegex; // NON-NLS }
From source file:com.haulmont.cuba.core.global.QueryTransformerRegex.java
@Override public void addWhere(String where) { Matcher entityMatcher = FROM_ENTITY_PATTERN.matcher(buffer); String alias = findAlias(entityMatcher); int insertPos = buffer.length(); Matcher lastClauseMatcher = LAST_CLAUSE_PATTERN.matcher(buffer); if (lastClauseMatcher.find(entityMatcher.end())) insertPos = lastClauseMatcher.start() - 1; StringBuilder sb = new StringBuilder(); Matcher whereMatcher = WHERE_PATTERN.matcher(buffer); int whereEnd = -1; boolean needOpenBracket = false; if (whereMatcher.find(entityMatcher.end())) { whereEnd = whereMatcher.end();/* w ww . j av a2 s . co m*/ Matcher orMatcher = OR_PATTERN.matcher(buffer); orMatcher.region(whereEnd + 1, insertPos); if (orMatcher.find()) { // surround with brackets if there is OR inside WHERE sb.append(")"); needOpenBracket = true; } sb.append(" and "); } else { sb.append(" where "); } sb.append("(").append(where); int idx; while ((idx = sb.indexOf(ALIAS_PLACEHOLDER)) >= 0) { sb.replace(idx, idx + ALIAS_PLACEHOLDER.length(), alias); } sb.append(")"); if (needOpenBracket) { buffer.insert(whereEnd + 1, "("); insertPos++; } buffer.insert(insertPos, sb); Matcher paramMatcher = PARAM_PATTERN.matcher(where); while (paramMatcher.find()) { addedParams.add(paramMatcher.group(1)); } }
From source file:com.haulmont.cuba.core.global.QueryTransformerRegex.java
@Override public void addJoinAndWhere(String join, String where) { Matcher entityMatcher = FROM_ENTITY_PATTERN.matcher(buffer); String alias = findAlias(entityMatcher); int insertPos = buffer.length(); Matcher whereMatcher = WHERE_PATTERN.matcher(buffer); if (whereMatcher.find(entityMatcher.end())) { insertPos = whereMatcher.start() - 1; } else {// ww w. j av a 2 s. com Matcher lastClauseMatcher = LAST_CLAUSE_PATTERN.matcher(buffer); if (lastClauseMatcher.find(entityMatcher.end())) insertPos = lastClauseMatcher.start() - 1; } if (!StringUtils.isBlank(join)) { buffer.insert(insertPos, " "); insertPos++; buffer.insert(insertPos, join); Matcher paramMatcher = PARAM_PATTERN.matcher(join); while (paramMatcher.find()) { addedParams.add(paramMatcher.group(1)); } } if (!StringUtils.isBlank(where)) { insertPos = buffer.length(); Matcher lastClauseMatcher = LAST_CLAUSE_PATTERN.matcher(buffer); if (lastClauseMatcher.find(entityMatcher.end())) insertPos = lastClauseMatcher.start() - 1; StringBuilder sb = new StringBuilder(); whereMatcher = WHERE_PATTERN.matcher(buffer); int whereEnd = -1; boolean needOpenBracket = false; if (whereMatcher.find(entityMatcher.end())) { whereEnd = whereMatcher.end(); Matcher orMatcher = OR_PATTERN.matcher(buffer); orMatcher.region(whereEnd + 1, insertPos); if (orMatcher.find()) { // surround with brackets if there is OR inside WHERE sb.append(")"); needOpenBracket = true; } sb.append(" and "); } else { sb.append(" where "); } sb.append("(").append(where).append(")"); if (needOpenBracket) { buffer.insert(whereEnd + 1, "("); insertPos++; } buffer.insert(insertPos, sb); Matcher paramMatcher = PARAM_PATTERN.matcher(where); while (paramMatcher.find()) { addedParams.add(paramMatcher.group(1)); } } // replace ALIAS_PLACEHOLDER int idx; while ((idx = buffer.indexOf(ALIAS_PLACEHOLDER)) >= 0) { buffer.replace(idx, idx + ALIAS_PLACEHOLDER.length(), alias); } }