Java Code Examples for com.google.gwt.regexp.shared.RegExp

The following examples show how to use com.google.gwt.regexp.shared.RegExp. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: proarc   Source File: ImportTreeDataSource.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
    protected void transformResponse(DSResponse response, DSRequest request, Object data) {
        if (RestConfig.isStatusOk(response)) {
            for (Record record : response.getData()) {
                String path = record.getAttribute(FIELD_PATH);
                RegExp pathRegExp = RegExp.compile("(.*/)?(.*)/$");
                MatchResult mr = pathRegExp.exec(path);
                String parent = mr.getGroup(1);
                String name = mr.getGroup(2);
//                System.out.println("## ITRDS.path: " + path);
//                System.out.println("## ITRDS.parent: " + parent);
//                System.out.println("## ITRDS.name: " + name);

                record.setAttribute(FIELD_NAME, name);
                record.setAttribute(FIELD_PARENT, parent);
            }
        }
        super.transformResponse(response, request, data);
    }
 
Example 2
Source Project: flow   Source File: DefaultConnectionStateHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void xhrInvalidContent(XhrConnectionError xhrConnectionError) {
    debug("xhrInvalidContent");
    endRequest();

    String responseText = xhrConnectionError.getXhr().getResponseText();
    /*
     * A servlet filter or equivalent may have intercepted the request and
     * served non-UIDL content (for instance, a login page if the session
     * has expired.) If the response contains a magic substring, do a
     * synchronous refresh. See #8241.
     */
    MatchResult refreshToken = RegExp
            .compile(UIDL_REFRESH_TOKEN + "(:\\s*(.*?))?(\\s|$)")
            .exec(responseText);
    if (refreshToken != null) {
        WidgetUtil.redirect(refreshToken.getGroup(2));
    } else {
        handleUnrecoverableCommunicationError(
                "Invalid JSON response from server: " + responseText,
                xhrConnectionError);
    }

}
 
Example 3
private void setDefaultValues(TimeseriesProperties tsProperties) {
    
    /*
     * TODO refactor default rendering properties for a phenomenon
     */
    
    PropertiesManager properties = PropertiesManager.getPropertiesManager();
    ArrayList<String> mappings = properties.getParameters("phenomenon");
    for (String mapping : mappings) {
        String[] values = mapping.split(",");
        if (tsProperties.getPhenomenon().equals(values[0])) {
            try {
                tsProperties.setLineStyle(values[1]);
                tsProperties.setSeriesType(values[2]);
                if (RegExp.compile("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$").test(values[3])) {
                    tsProperties.setHexColor(values[3]);
                } else {
                    throw new Exception("Pattern for hex color do not match");
                }
            } catch (Exception e) {
                Toaster.getToasterInstance().addErrorMessage(i18n.errorPhenomenonProperties());
            }
        }
    }
}
 
Example 4
Source Project: unitime   Source File: ClassAssignmentInterface.java    License: Apache License 2.0 5 votes vote down vote up
public float[] guessCreditRange() {
	if (!hasCredit()) return new float[] {0f, 0f};
	MatchResult r = RegExp.compile("(\\d+\\.?\\d*)-(\\d+\\.?\\d*)").exec(getCreditAbbv());
	if (r != null) return new float[] {Float.parseFloat(r.getGroup(1)), Float.parseFloat(r.getGroup(2))};
	float credit = guessCreditCount();
	return new float[] { credit, credit };
}
 
Example 5
Source Project: unitime   Source File: FilterBox.java    License: Apache License 2.0 5 votes vote down vote up
private void parse(final List<Chip> chips, final String text, final Collection<Filter> filters, final AsyncCallback<Parser.Results> callback) {
	if (text.isEmpty()) {
		callback.onSuccess(new Parser.Results(text, chips));
	} else {
		for (RegExp regExp: sRegExps) {
			final MatchResult r = regExp.exec(text);
			if (r == null) continue;
			for (Filter filter: filters) {
				if (filter.getCommand().equals(r.getGroup(1))) {
					filter.validate(r.getGroup(2), new AsyncCallback<Chip>() {
						@Override
						public void onFailure(Throwable caught) {
							callback.onSuccess(new Parser.Results(text, chips));
						}

						@Override
						public void onSuccess(Chip result) {
							if (result == null) {
								callback.onSuccess(new Parser.Results(text, chips));
							} else {
								chips.add(result);
								if (r.getGroupCount() > 3) {
									parse(chips, r.getGroup(3).trim(), filters, callback);
								} else {
									callback.onSuccess(new Parser.Results("", chips));
								}
							}
						}
					});
					return;
				}
			}
		}
		callback.onSuccess(new Parser.Results(text, chips));
	}
}
 
Example 6
public static String replaceParams(String pMessage, Object... parameters) {
	int i = 0;
	String message = pMessage;
	if (message != null && parameters != null && parameters.length > 0) {
		for (Object param : parameters) {
			RegExp pattern = RegExp.compile("\\{" + i + "\\}");
			String stringParam = param + "";
			message = pattern.replace(message, stringParam);
			i++;
		}
	}
	return message;
}
 
Example 7
public void setValue(T value) {
	this.value = value;
	double val = 0;
	if (value == null) {
		val = this.min;
	} else {
		val = value.doubleValue();
	}
	if (val > this.max) {
		val = this.max;
	} else if (val < this.min) {
		val = this.min;
	}

	this.progressBarElement.setAttribute(OutputProgressBar.ATT_ARIA_VALUE, value + "");
	double percent = 100 * (val - this.min) / (this.max - this.min);
	this.progressBarElement.getStyle().setProperty("width", percent, Unit.PCT);

	NumberFormat formatter = NumberFormat.getFormat("#.##");

	String stringToDisplay = this.format;
	stringToDisplay = RegExp.compile("\\{0\\}").replace(stringToDisplay, formatter.format(val));
	stringToDisplay = RegExp.compile("\\{1\\}").replace(stringToDisplay, formatter.format(percent));
	stringToDisplay = RegExp.compile("\\{2\\}").replace(stringToDisplay, formatter.format(this.min));
	stringToDisplay = RegExp.compile("\\{3\\}").replace(stringToDisplay, formatter.format(this.max));

	this.progressBarElement.removeAllChildren();
	if (this.displayValue) {
		this.progressBarElement.setInnerText(stringToDisplay);
	} else {
		SpanElement reader = Document.get().createSpanElement();
		reader.setInnerText(stringToDisplay);
		reader.addClassName("sr-only");
		this.progressBarElement.appendChild(reader);
	}
}
 
Example 8
private List<Token<?>> addEOLToken(String value, List<Token<?>> tokenList) {
	List<Token<?>> resultTokenList = Lists.newArrayList();
	// add EOL Tokens
	RegExp regExp = RegExp.compile(CharacterUtil.END_OF_LINE_PATTERN, "g");
	MatchResult eolMatcher = regExp.exec(value);
	while (eolMatcher != null) {
		for (Iterator<Token<?>> it = tokenList.iterator(); it.hasNext();) {
			Token<?> currToken = it.next();
			if (currToken.getTokenStart() >= regExp.getLastIndex()) {
				// current token is after last EL match
				break;
			}
			if (this.getTokenEnd(currToken) <= eolMatcher.getIndex()) {
				// current token is before last EL match
				resultTokenList.add(currToken);
				it.remove();
			} else {
				// current token contains last EOL match
				it.remove();
				this.splitTokenAndAddEOL(tokenList, resultTokenList, it, regExp.getLastIndex(),
					eolMatcher, currToken);
				break;
			}
		}
		eolMatcher = regExp.exec(value);
	}
	resultTokenList.addAll(tokenList);
	return resultTokenList;
}
 
Example 9
private List<PreparedTransaction> parseTransactions(List<ModelNode> transactions) {
    RegExp transactionPattern = RegExp.compile("^(.*) base64: ([^ ]*)");
    List<PreparedTransaction> preparedTransactions = new ArrayList<>();

    for(ModelNode t : transactions) {
        MatchResult match = transactionPattern.exec(t.asString());
        if (match == null) {
            Console.error("Error parsing prepared transactions");
            break;
        }
        preparedTransactions.add(new PreparedTransaction(match.getGroup(2), match.getGroup(1)));
    }
    return preparedTransactions;
}
 
Example 10
Source Project: gwt-material   Source File: RegExValidator.java    License: Apache License 2.0 4 votes vote down vote up
public RegExValidator(String pattern) {
    super(Keys.REGEX, new Object[0]);
    regex = RegExp.compile(pattern);
}
 
Example 11
Source Project: gwt-material   Source File: RegExValidator.java    License: Apache License 2.0 4 votes vote down vote up
public RegExValidator(String pattern, String invalidMessageOverride) {
    super(invalidMessageOverride);
    regex = RegExp.compile(pattern);
}
 
Example 12
public JsPattern(String pattern) {
    super(pattern);
    this.compiled = RegExp.compile(pattern);
}
 
Example 13
Source Project: unitime   Source File: ClassAssignmentInterface.java    License: Apache License 2.0 4 votes vote down vote up
public float guessCreditCount() {
	if (!hasCredit()) return 0f;
	MatchResult m = RegExp.compile("\\d+\\.?\\d*").exec(getCreditAbbv());
	if (m != null) return Float.parseFloat(m.getGroup(0));
	return 0f;
}
 
Example 14
Source Project: unitime   Source File: ClassAssignmentInterface.java    License: Apache License 2.0 4 votes vote down vote up
public float guessCreditCount() {
	if (!hasCredit()) return 0f;
	MatchResult m = RegExp.compile("\\d+\\.?\\d*").exec(getCredit());
	if (m != null) return Float.parseFloat(m.getGroup(0));
	return 0f;
}
 
Example 15
Source Project: geofence   Source File: EditRuleWidget.java    License: GNU General Public License v2.0 4 votes vote down vote up
public boolean checkIpRange(String s) {
    if(s == null || s.trim().equals(""))
        return true;

    RegExp regExp = RegExp.compile(CIDR_FORMAT);
    MatchResult matcher = regExp.exec(s);
    boolean matchFound = (matcher != null); // equivalent to regExp.test(inputStr);

    if (! matchFound) {
        Dispatcher.forwardEvent(GeofenceEvents.SEND_ALERT_MESSAGE,
            new String[]
            {
                "Input error", "Bad Range format"
            });
        return false;
    }

    // Get address bytes
    for (int i=1; i<5; i++) {
        String groupStr = matcher.getGroup(i);
        int b = Integer.parseInt(groupStr);
        if(b>255) {
            Dispatcher.forwardEvent(GeofenceEvents.SEND_ALERT_MESSAGE,
                new String[]
                {
                    "Input error", "Range bytes should be 0..255"
                });
            return false;
        }

    }

    int size = Integer.parseInt(matcher.getGroup(5));
    if(size > 32) {
        Dispatcher.forwardEvent(GeofenceEvents.SEND_ALERT_MESSAGE,
            new String[]
            {
                "Input error", "Bad CIDR block size"
            });
        return false;
    }

    return true;
}
 
Example 16
public PatternValidator(String message, String regexp) {
	super(message);
	String flagString = "";
	this.pattern = RegExp.compile(regexp, flagString);
	this.regexp = regexp;
}
 
Example 17
@Override
public String highlight(T value, String query) {
	RegExp pattern = RegExp.compile("(" + query + ")", "ig");
	return pattern.replace(getRenderer().render(value), "<strong>$1</strong>");
}
 
Example 18
public RegExpWordMatcher(TokenContent tokenContent, String regExpPattern) {
	super(tokenContent);
	Preconditions.checkArgument(regExpPattern != null, "The RegExp pattern can not be null");
	String fullWordPattern = this.completePattern(regExpPattern);
	this.regexp = RegExp.compile(fullWordPattern);
}