List of usage examples for java.util.regex Matcher toString
public String toString()
Returns the string representation of this matcher.
From source file:org.sonar.cxx.sensors.coverage.TestwellCtcTxtParser.java
private boolean parseUnit(final Map<String, CoverageMeasures> coverageData, Matcher headerMatcher) { LOG.debug(headerMatcher.toString()); if (headerMatcher.find(FROM_START)) { parseFileUnit(coverageData, headerMatcher); } else {// w ww.jav a 2 s .c om return false; } return true; }
From source file:com.gtdfree.test.XMLTest.java
public void testRegularExpression() { try {/*from w w w.j ava 2 s . c o m*/ Pattern pattern = Pattern.compile("<\\?.*?encoding\\s*?=.*?\\?>", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gtd-data version=\"2.1\" modified=\"2008-10-10T12:42:55.905+0200\">"); System.out.println(matcher.toString()); assertTrue(matcher.find()); pattern = Pattern.compile("<\\?.*?encoding\\s*?=.*?\\?>", Pattern.CASE_INSENSITIVE); matcher = pattern.matcher( "\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><gtd-data version=\"2.1\" modified=\"2008-10-12T23:50:46.176+0200\">"); System.out.println(matcher.toString()); assertTrue(matcher.find()); pattern = Pattern.compile("<\\?.*?encoding\\s*?=.*?\\?>", Pattern.CASE_INSENSITIVE); matcher = pattern.matcher( "\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<gtd-data version=\"2.1\" modified=\"2008-10-12T23:50:46.176+0200\">"); System.out.println(matcher.toString()); assertTrue(matcher.find()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:com.microsoft.tfs.client.common.ui.helpers.HTMLIncludeHelper.java
/** * <p>/*from w w w.j av a 2s .c o m*/ * Transforms the given line, including referenced files by delegating to * the {@link HTMLIncludeResourceProvider}. * </p> * * <p> * Lines with text matching: %%%INCLUDE(file="filename")%%% will be * transformed by replacing the line with the given filename. The "format" * tag may also be specified with a value of "text" or "base64". If the * format is specified as "text", the file will be reinterpreted while being * included (ie, includes in included files will also be included.) If the * format is specified as "base64", the file will be included as base64 * data. * </p> * * <p> * Examples: * </p> * * <p> * %%%INCLUDE(file="filename")%%% will include the resource specified by * "filename". * </p> * * <p> * %%%INCLUDE(file="filename", format="text")%%% will include the resource * specified by "filename". (This is identical to the above example.) * </p> * * <p> * %%%INCLUDE(file="filename", format="base64")%%% will include the base64 * representation of the resource specified by "filename". * </p> * * @param input * An input line from a resource * @return The line with any include statements transformed. * @throws IOException * If any included resources could not be read */ private String transformIncludes(final String input) throws IOException { Check.notNull(input, "input"); //$NON-NLS-1$ final Matcher includeMatcher = includePattern.matcher(input); final StringBuffer transformation = new StringBuffer(); while (includeMatcher.find()) { if (includeMatcher.groupCount() != 1) { log.warn(MessageFormat.format("Invalid include statement: {0}", includeMatcher.toString())); //$NON-NLS-1$ continue; } final Matcher optionMatcher = optionPattern.matcher(includeMatcher.group(1)); String resourceName = null; String format = "text"; //$NON-NLS-1$ while (optionMatcher.find()) { if (optionMatcher.groupCount() != 2) { log.warn(MessageFormat.format("Invalid include statement: {0}", includeMatcher.group(1))); //$NON-NLS-1$ continue; } if ("file".equals(optionMatcher.group(1))) //$NON-NLS-1$ { resourceName = optionMatcher.group(2); } else if ("format".equals(optionMatcher.group(1))) //$NON-NLS-1$ { format = optionMatcher.group(2); } } if (resourceName == null) { log.warn(MessageFormat.format("Invalid include statement: {0}", includeMatcher.group(1))); //$NON-NLS-1$ } else if ("base64".equals(format)) //$NON-NLS-1$ { includeMatcher.appendReplacement(transformation, readResourceToBase64(resourceName)); } else { includeMatcher.appendReplacement(transformation, readResource(resourceName)); } } includeMatcher.appendTail(transformation); return transformation.toString(); }
From source file:gc.david.dfm.ui.activity.MainActivity.java
private void handleMapsHostIntent(final Uri uri) { final String queryParameter = uri.getQueryParameter("q"); if (queryParameter != null) { final Matcher matcher = getMatcherForUri(queryParameter); if (matcher.find()) { setDestinationPosition(matcher); } else {/* w ww .j a v a2 s .co m*/ final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); DFMLogger.logException(noSuchFieldException); toastIt("Unable to parse address", this); } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException("Query sin parmetro q."); DFMLogger.logException(noSuchFieldException); toastIt("Unable to parse address", this); } }
From source file:sos.scheduler.cron.CronConverter.java
private void createRunTime(final Matcher pcronRegExMatcher, final Element runTimeElement) throws Exception { try {//w w w. jav a 2 s . c o m if (!pcronRegExMatcher.matches()) { throw new JobSchedulerException("Fail to parse cron line \"" + strCronLine + "\", regexp is " + pcronRegExMatcher.toString()); } String minutes = pcronRegExMatcher.group(1); String hours = pcronRegExMatcher.group(2); String days = pcronRegExMatcher.group(3); String months = pcronRegExMatcher.group(4); String weekdays = pcronRegExMatcher.group(5); if (minutes.equals("@reboot")) { runTimeElement.setAttribute("once", "yes"); return; } Vector<Element> childElements = new Vector<Element>(); Element periodElement = runTimeElement.getOwnerDocument().createElement("period"); logger.debug("processing hours [" + hours + "] and minutes [" + minutes + "]"); if (minutes.startsWith("*")) { if (minutes.equalsIgnoreCase("*")) { // every minute periodElement.setAttribute("repeat", "60"); } else { // repeat interval is given String repeat = minutes.substring(2); repeat = formatTwoDigits(repeat); periodElement.setAttribute("repeat", "00:" + repeat); } if (hours.startsWith("*")) { if (!hours.equalsIgnoreCase("*")) { // repeat interval is given for hours and minutes. Doesn't make sense. // e.g. */2 */3 every 3 hours repeat every 2 minutes throw new JobSchedulerException( "Combination of minutes and hours not supported: " + minutes + " " + hours); } // every hour: keep interval from minutes childElements.add(periodElement); } else { logger.debug("Found specific hours, creating periods with begin and end."); String[] hourArray = hours.split(","); for (int i = 0; i < hourArray.length; i++) { String currentHour = hourArray[i]; if (currentHour.indexOf("/") != -1) { String[] additionalHours = getArrayFromColumn(currentHour); hourArray = combineArrays(hourArray, additionalHours); continue; } String[] currentHourArray = currentHour.split("-"); Element currentPeriodElement = (Element) periodElement.cloneNode(true); String beginHour = currentHourArray[0]; int iEndHour = (Integer.parseInt(beginHour) + 1) % 24; // workaround, bis endhour am nchsten Tag erlaubt if (iEndHour == 0) iEndHour = 24; String endHour = "" + iEndHour; if (currentHourArray.length > 1) endHour = currentHourArray[1]; beginHour = formatTwoDigits(beginHour); endHour = formatTwoDigits(endHour); currentPeriodElement.setAttribute("begin", beginHour + ":00"); currentPeriodElement.setAttribute("end", endHour + ":00"); childElements.add(currentPeriodElement); } } } // end if minutes.startsWith("*") else { // one or more minutes are fixed String[] minutesArray = getArrayFromColumn(minutes); for (String element : minutesArray) { Element currentPeriodElement = (Element) periodElement.cloneNode(true); String currentMinute = element; currentMinute = formatTwoDigits(currentMinute); if (hours.startsWith("*")) { currentPeriodElement.setAttribute("absolute_repeat", "01:00"); usedNewRunTime = true; if (!hours.equalsIgnoreCase("*")) {// repeat interval is given for hours String repeat = hours.substring(2); repeat = formatTwoDigits(repeat); currentPeriodElement.setAttribute("absolute_repeat", repeat + ":00"); } currentPeriodElement.setAttribute("begin", "00:" + currentMinute); childElements.add(currentPeriodElement); } else { //fixed hour(s) is set String[] hourArray = hours.split(","); for (String element2 : hourArray) { currentPeriodElement = (Element) periodElement.cloneNode(true); String currentHour = element2; if (currentHour.indexOf("-") == -1) { // fixed hour and fixed minute --> create single_start currentHour = formatTwoDigits(currentHour); currentPeriodElement.setAttribute("single_start", currentHour + ":" + currentMinute); } else { // range of hours is set, create begin and end attributes String[] currentHourArray = currentHour.split("[-/]"); int beginHour = Integer.parseInt(currentHourArray[0]); int endHour = Integer.parseInt(currentHourArray[1]); int beginMinute = Integer.parseInt(currentMinute); int endMinute = beginMinute + 1; // workaround, bis endhour am nchsten Tag erlaubt endMinute = beginMinute; if (endMinute == 60) { endMinute = 0; endHour = endHour + 1; } endHour = endHour % 24; // workaround, bis endhour am nchsten Tag erlaubt if (endHour == 0) endHour = 24; String stepSize = "1"; if (currentHourArray.length == 3) { stepSize = formatTwoDigits(currentHourArray[2]); } currentPeriodElement.setAttribute("absolute_repeat", stepSize + ":00"); usedNewRunTime = true; currentPeriodElement.setAttribute("begin", formatTwoDigits(beginHour) + ":" + formatTwoDigits(beginMinute)); currentPeriodElement.setAttribute("end", formatTwoDigits(endHour) + ":" + formatTwoDigits(endMinute)); } childElements.add(currentPeriodElement); } } } } logger.debug("processing days [" + days + "]"); boolean monthDaysSet = false; if (days.startsWith("*")) { if (days.equals("*")) { // every day - do nothing, just keep periods } else { // repeat interval is given for days // this is not possible in the JobScheduler but can be poorly emulated Element monthDaysElement = runTimeElement.getOwnerDocument().createElement("monthdays"); String repeat = days.substring(2); int iRepeat = Integer.parseInt(repeat); // use only 30 days for (int i = 1; i <= 30; i = i + iRepeat) { String day = "" + i; addDay(day, monthDaysElement, childElements); } childElements.clear(); childElements.add(monthDaysElement); monthDaysSet = true; } } else { Element monthDaysElement = runTimeElement.getOwnerDocument().createElement("monthdays"); String[] daysArray = getArrayFromColumn(days); for (String day : daysArray) { addDay(day, monthDaysElement, childElements); } childElements.clear(); childElements.add(monthDaysElement); monthDaysSet = true; } if (!weekdays.equals("*") && monthDaysSet) { logger.info("Weekdays will not be processed as days are already set in current line."); } else { logger.debug("processing weekdays [" + weekdays + "]"); weekdays = replaceDayNames(weekdays); if (weekdays.startsWith("*/")) throw new JobSchedulerException("Repeat intervals for the weekdays column [" + weekdays + "] are not supported. Please use the days column."); if (weekdays.equals("*")) { // all weekdays, do nothing } else { Element weekDaysElement = runTimeElement.getOwnerDocument().createElement("weekdays"); String[] daysArray = getArrayFromColumn(weekdays); for (String day : daysArray) { addDay(day, weekDaysElement, childElements); } childElements.clear(); childElements.add(weekDaysElement); } } logger.debug("processing months [" + months + "]"); if (months.startsWith("*")) { if (months.equals("*")) { // every month - do nothing } else { months = replaceMonthNames(months); // repeat interval is given for months // this is not possible in the JobScheduler but can be poorly emulated Vector<Element> newChildElements = new Vector<Element>(); String repeat = months.substring(2); int iRepeat = Integer.parseInt(repeat); for (int i = 1; i <= 12; i = i + iRepeat) { String month = "" + i; Element monthElement = runTimeElement.getOwnerDocument().createElement("month"); usedNewRunTime = true; monthElement.setAttribute("month", month); Iterator<Element> iter = childElements.iterator(); while (iter.hasNext()) { Element child = iter.next(); monthElement.appendChild(child.cloneNode(true)); } newChildElements.add(monthElement); } childElements = newChildElements; } } else {// list of months is given Vector<Element> newChildElements = new Vector<Element>(); String[] monthArray = getArrayFromColumn(months); for (String month : monthArray) { Element monthElement = runTimeElement.getOwnerDocument().createElement("month"); usedNewRunTime = true; monthElement.setAttribute("month", month); Iterator<Element> iter = childElements.iterator(); while (iter.hasNext()) { Element child = iter.next(); monthElement.appendChild(child.cloneNode(true)); } newChildElements.add(monthElement); } childElements = newChildElements; } // add topmost child elements to run_time element Iterator<Element> iter = childElements.iterator(); while (iter.hasNext()) { Element someElement = iter.next(); runTimeElement.appendChild(someElement); } } catch (Exception e) { throw new JobSchedulerException("Error creating run time: " + e, e); } }
From source file:gc.david.dfm.ui.activity.MainActivity.java
private void handleGeoSchemeIntent(final Uri uri) { final String schemeSpecificPart = uri.getSchemeSpecificPart(); final Matcher matcher = getMatcherForUri(schemeSpecificPart); if (matcher.find()) { if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) { if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label) setDestinationPosition(matcher); } else { // Manage geo:0,0?q=my+street+address String destination = Uri.decode(uri.getQuery()).replace('+', ' '); destination = destination.replace("q=", ""); // TODO check this ugly workaround addressPresenter.searchPositionByName(destination); searchMenuItem.collapseActionView(); mustShowPositionWhenComingFromOutside = true; }// w w w . j a v a 2 s .c o m } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom setDestinationPosition(matcher); } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); DFMLogger.logException(noSuchFieldException); toastIt("Unable to parse address", this); } }
From source file:gc.david.dfm.ui.MainActivity.java
/** * Handles a send intent with position data. * * @param intent Input intent with position data. *///from ww w . j av a2 s . c om private void handleViewPositionIntent(final Intent intent) throws Exception { Mint.leaveBreadcrumb("MainActivity::handleViewPositionIntent"); final Uri uri = intent.getData(); Mint.addExtraData("queryParameter", uri.toString()); final String uriScheme = uri.getScheme(); if (uriScheme.equals("geo")) { final String schemeSpecificPart = uri.getSchemeSpecificPart(); final Matcher matcher = getMatcherForUri(schemeSpecificPart); if (matcher.find()) { if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) { if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label) setDestinationPosition(matcher); } else { // Manage geo:0,0?q=my+street+address String destination = Uri.decode(uri.getQuery()).replace('+', ' '); destination = destination.replace("q=", ""); // TODO check this ugly workaround new SearchPositionByName().execute(destination); mustShowPositionWhenComingFromOutside = true; } } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom setDestinationPosition(matcher); } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); Mint.logException(noSuchFieldException); throw noSuchFieldException; } } else if ((uriScheme.equals("http") || uriScheme.equals("https")) && (uri.getHost().equals("maps.google.com"))) { // Manage maps.google.com?q=latitude,longitude final String queryParameter = uri.getQueryParameter("q"); if (queryParameter != null) { final Matcher matcher = getMatcherForUri(queryParameter); if (matcher.find()) { setDestinationPosition(matcher); } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); Mint.logException(noSuchFieldException); throw noSuchFieldException; } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Query sin parmetro q."); Mint.logException(noSuchFieldException); throw noSuchFieldException; } } else { final Exception exception = new Exception("Imposible tratar la query " + uri.toString()); Mint.logException(exception); throw exception; } }
From source file:com.novartis.opensource.yada.util.QueryUtils.java
/** * This method uses a variety of variables from {@code yq} to determine the * number of jdbc positional parameters which must be included in the SQL * {@code in} clause in the stored query. Once the parameter count is * determined, the original SQL is amended with additional jdbc parameter * placeholders (i.e., {@code ?}), and the amended SQL is stored in the * {@code yq}./*from w w w. j a v a 2s . c om*/ * * @param yq * the query being processed * @param row * the index of the list of value lists in the query containing the * data to evaluate * @return modified SQL code * @deprecated as of 7.1.0 */ @Deprecated public String processInColumns(YADAQuery yq, int row) { String[] inColumns = yq.getIns(); String coreSql = yq.getYADACode(); LinkedHashMap<String, String[]> newData = new LinkedHashMap<>(); // to be i.e., YADA_1:[],YADA_2:[] if (inColumns.length > 0) { String[] columns = yq.getParameterizedColumns(); Map<String, String[]> data = yq.getDataRow(row); char[] dataTypes = yq.getDataTypes(row); Matcher matcher; l.debug("Processing inColumns [" + StringUtils.join(inColumns, ",") + "]"); for (String in : inColumns) { int colIndex = -1, j = 0; String inCol = in.toUpperCase(); // TODO case sensitivity // get the index of the 'incolumn' in the 'JDBCcolumns' array l.debug("Looking for column [" + inCol + "] in columns array " + ArrayUtils.toString(columns)); while (j < columns.length && colIndex != j) { if (inCol.contains(columns[j])) { colIndex = j; l.debug("Found column [" + inCol + "] at index [" + String.valueOf(colIndex) + "] of columns array."); break; } j++; } // get the value list associated to the column in the data hash String colName = ""; String[] inData = null; int inLen = 0; if (data.containsKey(columns[colIndex])) // JSONParams { colName = columns[colIndex]; if (data.get(colName).length == 1) { inData = data.get(colName)[0].split(","); for (int m = 0; m < columns.length; m++) { if (columns[m].equals(colName)) { // add the new data for the column newData.put(colName, inData); } else { // add the existing data for the column newData.put(columns[m], data.get(columns[m])); } // add data row yq.getData().set(row, newData); } yq.getData().set(row, newData); } else inData = data.get(colName); l.debug("Splitting in args [" + data.get(colName) + "]"); } else // Standard Params { // Get an array of keys to compare and potentially manipulate String[] colNames = new String[data.size()]; int k = 0; for (String col : data.keySet()) { colNames[k] = col; k++; } // if colNames and columns array are of equal size, // then there is no param value manipulation required if (colNames.length == columns.length) { colName = QueryUtils.YADA_COLUMN + (colIndex + 1); inData = data.get(colName); } else // there is a length discrepancy { for (int m = colIndex; m < colNames.length; m++) { if (m == colIndex) // it's the first index inData = data.get(colNames[m]); else // further indexes must build aggregate array inData = (String[]) ArrayUtils.addAll(inData, data.get(colNames[m])); } for (int m = 0; m < columns.length; m++) { if (m == columns.length - 1) { // it's the last index, so add the aggregrate inData array newData.put(colNames[m], inData); } else { // not the last index, add the existing array newData.put(colNames[m], data.get(colNames[m])); } // add data row yq.getData().set(row, newData); } } l.debug("Setting IN args [" + ArrayUtils.toString(inData) + "]"); } if (inData != null) { inLen = inData.length; } if (inLen > 1) // there's an aggregate of multiple values { l.debug("Length of value list [" + String.valueOf(inLen) + "]"); l.debug("Getting data type of [" + columns[colIndex] + "]"); char dt = dataTypes[colIndex]; String dtStr = "?" + String.valueOf(dt); // generate the new parameter string with data type markers String[] pList = new String[inLen]; for (int k = 0; k < inLen; k++) { pList[k] = dtStr; } String pListStr = StringUtils.join(pList, ","); l.debug("New parameter list [" + pListStr + "]"); // add additional parameters to coreSql String rx = "(.+)(" + inCol + "\\s+in\\s+\\(\\" + dtStr + "\\))(.*)"; String repl = inCol + " IN (" + pListStr + ")"; String sql = coreSql.replaceAll(NEWLINE, " "); l.debug("Attempting to replace part of [" + sql + "] with [" + repl + "]"); matcher = Pattern.compile(rx, Pattern.CASE_INSENSITIVE).matcher(sql); if (matcher.matches()) { coreSql = matcher.group(1) + repl + matcher.group(3); } l.debug("Matched clause in coreSql [" + matcher.toString() + "]"); } // end current incolumn processing } // end all incolumn processing } // reset datatype and param count with new coreSql yq.addDataTypes(row, this.getDataTypes(coreSql)); yq.addParamCount(row, yq.getDataTypes(row).length); return coreSql; }