List of usage examples for com.google.gwt.regexp.shared MatchResult getGroup
public final String getGroup(int index)
From source file:cc.kune.chat.client.KuneChatNotifier.java
License:GNU Affero Public License
@Override public void show(final String userMessage, final String messageType) { // FIXME Dirty hack while emite/hablar lib don't provide user info if (regExp.test(userMessage)) { final MatchResult m = regExp.exec(userMessage); final String user = m.getGroup(1); NotifyUser.avatar(downUtils.getUserAvatar(user), i18n.t("User [%s] says [%s]", user, m.getGroup(2)), new ClickHandler() { @Override/*www . j a va 2 s.c o m*/ public void onClick(final ClickEvent event) { ShowChatDialogEvent.fire(eventBus, true); } }); } else { NotifyUser.info(userMessage); } }
From source file:ch.takoyaki.email.html.client.utils.Html.java
License:Open Source License
public static String inlinecss(String content, FileService fService) { RegExp p = RegExp.compile("<link [^>]*href=\"([^\"]*)\"[^>]*/?>", "gmi"); MatchResult matcher = p.exec(content); while (matcher != null) { String tag = matcher.getGroup(0); String href = matcher.getGroup(1); String cssContent = fService.retrieve(href); if (cssContent == null) { cssContent = ""; }/*from w w w .j a va2 s. c o m*/ cssContent = "<style>" + cssContent + "</style>"; content = content.replace(tag, cssContent); matcher = p.exec(content); } return content; }
From source file:ch.takoyaki.email.html.client.utils.Xsl.java
License:Open Source License
public static String loadStyleSheetContent(String content, FileService fservice) { String type = ""; String href = ""; content = stripXmlComments(content); RegExp p = RegExp.compile("<\\?xml-stylesheet[^>]*type=\"([^\"]*)", "m"); MatchResult r = p.exec(content); if (r != null) { type = r.getGroup(1); }/*from w ww .java 2 s . c om*/ p = RegExp.compile("<\\?xml-stylesheet[^>]*href=\"([^\"]*)", "m"); r = p.exec(content); if (r != null) { href = r.getGroup(1); } if (!type.equals("text/xsl") || "".equals(href)) { return null; } String xsl = fservice.retrieve(href); xsl = inlineXslInclude(xsl, fservice); return xsl; }
From source file:ch.takoyaki.email.html.client.utils.Xsl.java
License:Open Source License
private static String inlineXslInclude(String xsl, FileService fService) { RegExp p = RegExp.compile("<[^:]*:?include[^>]*href=\"([^\"]*)\"[^>]*/?>", "gmi"); MatchResult matcher = p.exec(xsl); while (matcher != null) { String tag = matcher.getGroup(0); String href = matcher.getGroup(1); String xslinclude = fService.retrieve(href); if (xslinclude == null) { xslinclude = ""; }//ww w. j a v a 2 s .c om xslinclude = xslIncludeStrip(xslinclude); xsl = xsl.replace(tag, xslinclude); matcher = p.exec(xsl); } return xsl; }
From source file:ch.takoyaki.email.html.client.utils.Xsl.java
License:Open Source License
private static String xslIncludeStrip(String xslinclude) { RegExp p = RegExp.compile("<[^:]*:?stylesheet[^>]*>([\\w\\W]*)</[^:]*:?stylesheet>", "gmi"); MatchResult m = p.exec(xslinclude); if (m != null) { return m.getGroup(1); }//from w ww.ja v a 2s. c om return ""; }
From source file:ch.unifr.pai.twice.mousecontrol.client.TouchPadWidget.java
License:Apache License
/** * Helper method to extract values from the HTTP-response by the given regular expression * //from w w w .ja v a 2s . c o m * @param response * @param regex * @return */ private static String extractByRegex(Response response, String regex) { RegExp re = RegExp.compile(regex); MatchResult result = re.exec(response.getText()); return result.getGroup(0); }
From source file:client.managers.history.HistoryState.java
License:Open Source License
/** * Create a {@code HistoryState} from a history token. * //w w w .j a v a2 s . c o m * <pre>([0-9]*) : ([0-9]*) / ([^/]*) /? ([^/]*) /? ((.{2},?)*)</pre> * * <ol> * <li>Interval start</li> * <li>Interval end</li> * <li>Series tab name</li> * <li>Indicator identifier (optional)</li> * <li>Comma-separated list of ISO codes (optional)</li> * </ol> * * Examples: * * <ul> * <li>2010:2014/map:europe/ABC.DEF.1234/SE,DK,NO</li> * <li>2010:2014/map:europe/ABC.DEF.1234</li> * <li>2010:2014/map:europe</li> * </ul> * * @param historyToken History token. * @return Created {@code HistoryState} instance. * * @see HistoryState#REGEX */ public static HistoryState fromHistoryToken(String historyToken) { MatchResult result = REGEX.exec(historyToken); if (result == null || result.getGroupCount() <= 1) { return new HistoryState(); } /* * Interval */ Integer intervalStartYear = Integer.valueOf(result.getGroup(REGEX_INTERVAL_START_YEAR)); Integer intervalEndYear = Integer.valueOf(result.getGroup(REGEX_INTERVAL_END_YEAR)); /* * Tab name */ String seriesTabName = result.getGroup(REGEX_SERIES_TAB_NAME); if (seriesTabName != null) { seriesTabName = seriesTabName.trim(); if (seriesTabName.isEmpty()) { seriesTabName = null; } } /* * Indicator */ String indicatorIdent = result.getGroup(REGEX_INDICATOR_IDENT); if (indicatorIdent != null) { indicatorIdent = indicatorIdent.trim(); if (indicatorIdent.isEmpty()) { indicatorIdent = null; } } /* * Country ISO list */ String countryISOListString = result.getGroup(REGEX_COUNTRY_ISO_LIST); List<String> countryISOList = null; if (countryISOListString != null) { countryISOListString = countryISOListString.trim(); if (!countryISOListString.isEmpty()) { countryISOList = new ArrayList<String>( Arrays.asList(countryISOListString.split(COUNTRY_ISO_LIST_SEPARATOR))); } } return new HistoryState(intervalStartYear, intervalEndYear, seriesTabName, indicatorIdent, countryISOList); }
From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java
License:Mozilla Public License
private String getStyleAttribute(Element elem) { // style attribute must exist and must be quoted properly // IE9 does not include style attributes text if their value is not valid // we therefore don't expect non-quoted styles like <h1 style=color id="abc"... String value = getOuterHTML(elem); RegExp quotesPattern = RegExp.compile("(?:\".*?\"|\'.*?\'|[^\'\"]+|['\"])", "g"); // g=global: = all-matches RegExp stylePattern = RegExp.compile("[\\s]style\\s*="); // e.g. match: <h1 style= MatchResult m = quotesPattern.exec(value); int i = 0;//from w w w . j a v a2s . c o m boolean styleFound = false; String styleContent = ""; String nonQ = ""; while (quotesPattern.getLastIndex() > 0) { if (i % 2 == 0) { nonQ = m.getGroup(0); // not in quotes - so check MatchResult ms = stylePattern.exec(nonQ); styleFound = ms.getGroupCount() > 0; if (!styleFound && nonQ.indexOf('>') > -1) { break; // no more attributes } } else if (styleFound) { styleContent = m.getGroup(0); // remove enclosing quotes styleContent = styleContent.substring(1, styleContent.length() - 1); break; } i++; m = quotesPattern.exec(value); } return styleContent; }
From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java
License:Mozilla Public License
private HTMLAttributeNode[] getAltAttributes() { if (attributeList != null) { return attributeList; }// w w w . java 2s. c o m Element elem = (Element) node; // Browser implementations of attributes property are potentially buggy - but preferred to // parsing the string. But IE6 and IE7 both list all possible attributes whether they // exist or not - so use outerHTML in these cases. int ieVersion = Configuration.getIeVersion(); if (ieVersion < 0 || ieVersion > 8) { return getMainAttributes(elem); } String value = getOuterHTML(elem); if (value == null) { return getMainAttributes(elem); } ArrayList<String> nodeNames = new ArrayList<String>(); ArrayList<String> xmlnsNames = new ArrayList<String>(); ArrayList<String> xmlnsUris = new ArrayList<String>(); namespaceBindings = new ArrayList<NamespaceBinding>(); RegExp quotesPattern = RegExp.compile("(?:\"(.|\n)*?\"|\'(.|\n)*?\'|[^\'\"]+|['\"])", "gm"); // g=global: = all-matches m=multiline MatchResult m = quotesPattern.exec(value); int i = 0; String nonQ = ""; boolean awaitingXmlnsUri = false; while (quotesPattern.getLastIndex() > 0) { if (i % 2 == 0) { nonQ = m.getGroup(0); // not in quotes - so check StringBuffer sb = new StringBuffer(); boolean endOfTag = false; boolean isName = !(i == 0);// first part is not a name: e.g. \r\n<H1 style=" int start = 0; if (i == 0) { start = nonQ.indexOf('<') + 1; } for (int x = start; x < nonQ.length(); x++) { int[] offsetChar = skipWhitespace(x, nonQ, false); int offset = offsetChar[0]; if (offset > 0 && !(isName)) { // no whitespace allow in an unquoted value, so we're back on a name isName = true; } char ch = (char) offsetChar[1]; if (ch == '\0') break; if (ch == '=') { // part after the '=' is the value, until next whitespace isName = false; String attName = sb.toString(); if (attName.startsWith("xmlns")) { xmlnsNames.add(attName); awaitingXmlnsUri = true; } else if (attName.length() != 0) { nodeNames.add(attName); awaitingXmlnsUri = false; } sb = new StringBuffer(); continue; } else if (ch == '>') { endOfTag = true; break; } if (isName) { sb.append(ch); } x += offset; } // end for if (endOfTag) { break; } } else if (awaitingXmlnsUri) {// ends if i % 2 xmlnsUris.add(m.getGroup(0)); } i++; m = quotesPattern.exec(value); } // end while HTMLAttributeNode[] nodeArray = new HTMLAttributeNode[nodeNames.size()]; for (int y = 0; y < nodeNames.size(); y++) { String name = nodeNames.get(y); String nValue = getAltAttribute(name); // elem.getAttribute(name); // must be html because using outerHTML attribute - so no namespaces HTMLAttributeNode hNode = new HTMLAttributeNode(this, name, "", "", nValue); nodeArray[y] = hNode; } int count = 0; for (String name : xmlnsNames) { // use substring to exclude xmlns: prefix boolean noPrefix = (name.length() == 5); String prefix = (noPrefix) ? "" : name.substring(6); // xmlns declarations with prefixes can't be fetched using getAttribute String attValue = (noPrefix) ? getAltAttribute(name) : trimEdgeChars(xmlnsUris.get(count)); namespaceBindings.add(new NamespaceBinding(prefix, attValue)); count++; } attributeList = nodeArray; // for later use attributeNames = nodeNames; return nodeArray; }
From source file:client.net.sf.saxon.ce.functions.FormatDate.java
License:Mozilla Public License
private static CharSequence formatComponent(CalendarValue value, CharSequence specifier, Numberer numberer, String country, XPathContext context) throws XPathException { boolean ignoreDate = (value instanceof TimeValue); boolean ignoreTime = (value instanceof DateValue); DateTimeValue dtvalue = value.toDateTime(); MatchResult matcher = componentPattern.exec(specifier.toString()); if (matcher == null) { XPathException error = new XPathException("Unrecognized date/time component [" + specifier + ']'); error.setErrorCode("XTDE1340"); error.setXPathContext(context);/*from w w w. j a v a 2s . c o m*/ throw error; } String component = matcher.getGroup(1); if (component == null) { component = ""; } String format = matcher.getGroup(2); if (format == null) { format = ""; } boolean defaultFormat = false; if ("".equals(format) || format.startsWith(",")) { defaultFormat = true; switch (component.charAt(0)) { case 'F': format = "Nn" + format; break; case 'P': format = 'n' + format; break; case 'C': case 'E': format = 'N' + format; break; case 'm': case 's': format = "01" + format; break; default: format = '1' + format; } } switch (component.charAt(0)) { case 'Y': // year if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): an xs:time value does not contain a year component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int year = dtvalue.getYear(); if (year < 0) { year = 1 - year; } return formatNumber(component, year, format, defaultFormat, numberer, context); } case 'M': // month if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): an xs:time value does not contain a month component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int month = dtvalue.getMonth(); return formatNumber(component, month, format, defaultFormat, numberer, context); } case 'D': // day in month if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): an xs:time value does not contain a day component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int day = dtvalue.getDay(); return formatNumber(component, day, format, defaultFormat, numberer, context); } case 'd': // day in year if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): an xs:time value does not contain a day component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int day = DateValue.getDayWithinYear(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay()); return formatNumber(component, day, format, defaultFormat, numberer, context); } case 'W': // week of year if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): cannot obtain the week number from an xs:time value"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int week = DateValue.getWeekNumber(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay()); return formatNumber(component, week, format, defaultFormat, numberer, context); } case 'w': // week in month if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): cannot obtain the week number from an xs:time value"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int week = DateValue.getWeekNumberWithinMonth(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay()); return formatNumber(component, week, format, defaultFormat, numberer, context); } case 'H': // hour in day if (ignoreTime) { XPathException error = new XPathException( "In formatDate(): an xs:date value does not contain an hour component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { IntegerValue hour = (IntegerValue) value.getComponent(Component.HOURS); return formatNumber(component, (int) hour.intValue(), format, defaultFormat, numberer, context); } case 'h': // hour in half-day (12 hour clock) if (ignoreTime) { XPathException error = new XPathException( "In formatDate(): an xs:date value does not contain an hour component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { IntegerValue hour = (IntegerValue) value.getComponent(Component.HOURS); int hr = (int) hour.intValue(); if (hr > 12) { hr = hr - 12; } if (hr == 0) { hr = 12; } return formatNumber(component, hr, format, defaultFormat, numberer, context); } case 'm': // minutes if (ignoreTime) { XPathException error = new XPathException( "In formatDate(): an xs:date value does not contain a minutes component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { IntegerValue min = (IntegerValue) value.getComponent(Component.MINUTES); return formatNumber(component, (int) min.intValue(), format, defaultFormat, numberer, context); } case 's': // seconds if (ignoreTime) { XPathException error = new XPathException( "In formatDate(): an xs:date value does not contain a seconds component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { IntegerValue sec = (IntegerValue) value.getComponent(Component.WHOLE_SECONDS); return formatNumber(component, (int) sec.intValue(), format, defaultFormat, numberer, context); } case 'f': // fractional seconds // ignore the format if (ignoreTime) { XPathException error = new XPathException( "In formatDate(): an xs:date value does not contain a fractional seconds component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int micros = (int) ((IntegerValue) value.getComponent(Component.MICROSECONDS)).intValue(); return formatNumber(component, micros, format, defaultFormat, numberer, context); } case 'Z': // timezone in +hh:mm format, unless format=N in which case use timezone name if (value.hasTimezone()) { return getNamedTimeZone(value.toDateTime(), country, format); } else { return ""; } case 'z': // timezone if (value.hasTimezone()) { int tz = value.getTimezoneInMinutes(); FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.TINY); fsb.append("GMT"); if (tz != 0) { CalendarValue.appendTimezone(tz, fsb); } int comma = format.indexOf(','); int min = 0; if (comma > 0) { String widths = format.substring(comma); int[] range = getWidths(widths); min = range[0]; } if (min < 6) { if (tz % 60 == 0) { // No minutes component in timezone fsb.setLength(fsb.length() - 3); } } if (min < fsb.length() - 3) { if (fsb.charAt(4) == '0') { fsb.removeCharAt(4); } } return fsb; } else { return ""; } case 'F': // day of week if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): an xs:time value does not contain day-of-week component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int day = DateValue.getDayOfWeek(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay()); return formatNumber(component, day, format, defaultFormat, numberer, context); } case 'P': // am/pm marker if (ignoreTime) { XPathException error = new XPathException( "In formatDate(): an xs:date value does not contain an am/pm component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int minuteOfDay = dtvalue.getHour() * 60 + dtvalue.getMinute(); return formatNumber(component, minuteOfDay, format, defaultFormat, numberer, context); } case 'C': // calendar return numberer.getCalendarName("AD"); case 'E': // era if (ignoreDate) { XPathException error = new XPathException( "In formatTime(): an xs:time value does not contain an AD/BC component"); error.setErrorCode("XTDE1350"); error.setXPathContext(context); throw error; } else { int year = dtvalue.getYear(); return numberer.getEraName(year); } default: XPathException e = new XPathException( "Unknown formatDate/time component specifier '" + format.charAt(0) + '\''); e.setErrorCode("XTDE1340"); e.setXPathContext(context); throw e; } }