List of usage examples for com.google.gwt.regexp.shared RegExp replace
public final String replace(String input, String replacement)
From source file:ch.takoyaki.email.html.client.utils.Xsl.java
License:Open Source License
public static String stripXmlComments(String content) { RegExp p = RegExp.compile("<!--[\\w\\W]*?-->", "gmi"); String stripped = p.replace(content, ""); return stripped; }
From source file:com.akanoo.client.views.CanvasView.java
License:Apache License
/** * Replace URLs in the given string with anchors that will open in a new * window//ww w .j a va 2s. com * * @param html * @return */ private String replaceUrlsWithLinks(String html) { RegExp r = RegExp.compile("(https?://[^ ]+)", "gim"); return r.replace(html, "<a href=\"$1\" target=\"_blank\">$1</a>"); }
From source file:com.arcbees.chosen.client.ClientResultsFilter.java
License:Apache License
@Override public void filter(String searchText, ChosenImpl chosen, boolean isShowing) { ChosenOptions options = chosen.getOptions(); // TODO should be part of this object String regexAnchor = options.isSearchContains() ? "" : "^"; // escape reg exp special chars String escapedSearchText = regExpChars.replace(searchText, "\\$&"); RegExp regex = RegExp.compile(regexAnchor + escapedSearchText, "i"); RegExp zregex = RegExp.compile("(" + escapedSearchText + ")", "i"); int results = 0; List<SelectItem> selectItems = chosen.getSelectItems(); for (SelectItem item : selectItems) { if (item.isDisabled() || item.isEmpty()) { continue; }//from w w w. j a v a 2s .c o m if (item.isGroup()) { $('#' + item.getDomId()).css("display", "none"); } else { OptionItem option = (OptionItem) item; if (!(chosen.isMultiple() && option.isSelected())) { boolean found = false; String resultId = option.getDomId(); GQuery result = $("#" + resultId); String optionContent = option.getHtml(); if (optionContent == null || optionContent.trim().isEmpty()) { optionContent = option.getText(); } if (regex.test(optionContent)) { found = true; results++; } else if (optionContent.contains(" ") || optionContent.indexOf("[") == 0) { String[] parts = optionContent.replaceAll("\\[|\\]", "").split(" "); for (String part : parts) { if (regex.test(part)) { found = true; results++; } } } if (found) { String text; if (searchText.length() > 0) { text = zregex.replace(optionContent, "<em>$1</em>"); } else { text = optionContent; } result.html(text); chosen.resultActivate(result); if (option.getGroupArrayIndex() != -1) { $("#" + selectItems.get(option.getGroupArrayIndex()).getDomId()).css("display", "list-item"); } } else { if (chosen.getResultHighlight() != null && resultId.equals(chosen.getResultHighlight().attr("id"))) { chosen.resultClearHighlight(); } chosen.resultDeactivate(result); } } } } if (results < 1 && !searchText.isEmpty()) { chosen.noResults(searchText); } else { chosen.winnowResultsSetHighlight(); } if (isShowing) { chosen.positionDropdownResult(); } }
From source file:com.cgxlib.core.component.tooltip.SingleTooltip.java
License:Apache License
protected SingleTooltip doShow() { NativeEvent e = CGXHelper.createNativeEvent("show", "cgx." + type, null); if (this.hasContent() && this.enabled) { this.trigger(e); boolean inDom = viewHandler.inDom(); if (JsUtils.isDefaultPrevented(e) || !inDom) { return this; }//from w w w . j a va 2 s . com final SingleTooltip that = this; XQ $tip = tip(); String tipId = getUID(type); setContent(); viewHandler.assignId($tip, tipId); if (this.options.animation()) { viewHandler.animateTip($tip); } Placement placement = this.options.placement(); String placementStr = placement != null ? placement.name() : null; String autoToken = "/\\s?auto?\\s?/i"; RegExp regExp = RegExp.compile(autoToken); boolean autoPlace = placementStr != null && regExp.test(placementStr); if (autoPlace) { placementStr = regExp.replace(autoToken, ""); if (placementStr == null || placementStr.length() < 1) { placement = Placement.top; } } viewHandler.setupTip($tip, placement); $tip.data("cgx." + this.type, this); if (this.options.container() != null) { $tip.appendTo(this.options.container()); } else { $tip.insertAfter(this); } this.trigger("inserted.cgx." + this.type); Position pos = viewHandler.getPosition(this); int actualWidth = viewHandler.tipWidth($tip); int actualHeight = viewHandler.tipHeight($tip); if (autoPlace) { Placement orgPlacement = placement; Position viewportDim = viewHandler.getPosition($viewport); if (placement == Placement.bottom && pos.bottom + actualHeight > viewportDim.bottom) { placement = Placement.top; } else if (placement == Placement.top && pos.top - actualHeight < viewportDim.top) { placement = Placement.bottom; } else if (placement == Placement.right && pos.right + actualWidth > viewportDim.width) { placement = Placement.left; } else if (placement == Placement.left && pos.left - actualWidth < viewportDim.left) { placement = Placement.right; } viewHandler.switchPlacement($tip, orgPlacement, placement); } Offset calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight); applyPlacement(calculatedOffset, placement); Function complete = new Function() { @Override public void f() { HoverState prevHoverState = that.hoverState; that.trigger("shown.cgx." + that.type); that.hoverState = null; if (prevHoverState == HoverState.OUT) { that.leave(that, false); } } }; final boolean useTransitions = transitions() && viewHandler.useTransitions($tip); if (useTransitions) { $tip.as(CGXlib.CGX).onceWhenTransitionEnds(complete).emulateTransitionEnd(transitionDuration()); } else { complete.f(); } } return this; }
From source file:com.client.hp.hpl.jena.sparql.expr.nodevalue.XSDFuncOp.java
License:Apache License
public static NodeValue strReplace(NodeValue nvStr, RegExp pattern, NodeValue nvReplacement) { String n = checkAndGetStringLiteral("replace", nvStr).getLiteralLexicalForm(); String rep = checkAndGetStringLiteral("replace", nvReplacement).getLiteralLexicalForm(); MatchResult m = pattern.exec(n); String x = pattern.replace(n, rep); // String x = pattern.matcher(n).replaceAll(rep) ; return calcReturn(x, nvStr.asNode()); }
From source file:com.google.gerrit.client.UrlAliasMatcher.java
License:Apache License
public String replace(String token) { for (Map.Entry<RegExp, String> e : userUrlAliases.entrySet()) { RegExp pat = e.getKey(); if (pat.exec(token) != null) { return pat.replace(token, e.getValue()); }/* w w w . ja va2 s. c o m*/ } for (Map.Entry<RegExp, String> e : globalUrlAliases.entrySet()) { RegExp pat = e.getKey(); if (pat.exec(token) != null) { return pat.replace(token, e.getValue()); } } return token; }
From source file:com.lorepo.icf.utils.URLUtils.java
License:Open Source License
/** * Find all relative URLs in CSS and add base URL */// w w w. j a v a2 s . c om public static String resolveCSSURL(String baseUrl, String css) { // if url isn't starts with 'http' or '/' then add baseUrl RegExp regExp = RegExp.compile("url\\(['\"]?(?!http|data:|/)([^'\"\\)]+)['\"]?\\)", "g"); if (css != null) { return regExp.replace(css, "url('" + baseUrl + "$1')"); } else { return null; } }
From source file:com.risevision.viewer.client.controller.ViewerPlaylistItemController.java
License:Open Source License
private void updateHtmlText(PresentationInfo presentation) { String transition = "none"; String text = playlistItem.getObjectData().replace("\n", "").replace("\r", ""); // Removing comments with regExp // String exp = "(?s)<!--.*?-->"; // text = text.replaceAll("(?s)<!--.*?-->", ""); // text = text.replaceAll("?s<!--.*?--\\s*>?gs", ""); // text = text.replaceAll("(?s)<!--.*?--\\s*>?gs", ""); // String exp = "/<!--[\\s\\S]*?-->/g"; String exp = "<!--.*?-->"; RegExp regExp = RegExp.compile(exp, "gm"); text = regExp.replace(text, ""); // int height = 0, width = 0; // if (placeholderInfo.getWidthUnits().equals("%")) { // width = (int)((placeholderInfo.getWidth() / 100.0) * Window.getClientWidth()); // height = (int)((placeholderInfo.getHeight() / 100.0) * Window.getClientHeight()); // }/*ww w . j a v a2 s. c o m*/ // else { // height = (int)placeholderInfo.getHeight(); // width = (int)placeholderInfo.getWidth(); // } // double scale = ViewerUtils.getItemScale(playlistItem.getScale()); // height = (int)(height * scale); // width = (int)(width * scale); transition = placeholderInfo.getTransition(); addTextScript(presentation, text, phName, htmlName, transition); }
From source file:com.watopi.chosen.client.ChosenImpl.java
License:Open Source License
private void winnowResults() { noResultClear();//from w ww . ja va 2 s . co m int results = 0; String searchText = defaultText.equals(searchField.val()) ? "" : searchField.val().trim(); searchText = SafeHtmlUtils.htmlEscape(searchText); String regexAnchor = options.isSearchContains() ? "" : "^"; // escape reg exp special chars String escapedSearchText = regExpChars.replace(searchText, "\\$&"); String test2 = "test"; test2.substring(1); RegExp regex = RegExp.compile(regexAnchor + escapedSearchText, "i"); RegExp zregex = RegExp.compile("(" + escapedSearchText + ")", "i"); for (int i = 0; i < selectItems.length(); i++) { SelectItem item = selectItems.get(i); if (item.isDisabled() || item.isEmpty()) { continue; } if (item.isGroup()) { $('#' + item.getDomId()).css("display", "none"); } else { OptionItem option = (OptionItem) item; if (!(isMultiple && option.isSelected())) { boolean found = false; String resultId = option.getDomId(); GQuery result = $("#" + resultId); String optionContent = option.getHtml(); if (regex.test(optionContent)) { found = true; results++; } else if (optionContent.indexOf(" ") >= 0 || optionContent.indexOf("[") == 0) { String[] parts = optionContent.replaceAll("\\[|\\]", "").split(" "); for (String part : parts) { if (regex.test(part)) { found = true; results++; } } } if (found) { String text; if (searchText.length() > 0) { text = zregex.replace(optionContent, "<em>$1</em>"); } else { text = optionContent; } result.html(text); resultActivate(result); if (option.getGroupArrayIndex() != -1) { $("#" + selectItems.get(option.getGroupArrayIndex()).getDomId()).css("display", "list-item"); } } else { if (resultHighlight != null && resultId.equals(resultHighlight.attr("id"))) { resultClearHighlight(); } resultDeactivate(result); } } } } if (results < 1 && searchText.length() > 0) { noResults(searchText); } else { winnowResultsSetHighlight(); } }
From source file:cz.filmtit.client.pages.TranslationWorkspace.java
License:Open Source License
public void searchAndReplace(RegExp searchExp, String replace) { Map<ChunkIndex, TranslationResult> translationResults = currentDocument.getTranslationResults(); Collection<TranslationResult> results = translationResults.values(); for (TranslationResult result : results) { MatchResult matchResult = searchExp.exec(result.getUserTranslation()); if (matchResult == null) { continue; }/*from w w w . j a v a2 s. c om*/ if (matchResult.getGroupCount() > 0) { String replacedString = searchExp.replace(result.getUserTranslation(), replace); PosteditPair replacePair = new PosteditPair(result.getUserTranslation(), replacedString); replacePair.setSource(PosteditSource.SEARCHANDREPLACE); result.getPosteditSuggestions().add(replacePair); int index = synchronizer.getIndexOf(result); PosteditBox.FakePosteditBox posteditBox = posteditBoxes.get(index); if (posteditBox.isReplaced()) { posteditBox.getFather().addStyleDependentName("replace"); } else { posteditBox.addStyleDependentName("replace"); } } } }