List of usage examples for org.apache.commons.lang3 StringUtils substringBetween
public static String substringBetween(final String str, final String open, final String close)
Gets the String that is nested in between two Strings.
From source file:io.restassured.path.xml.XmlPathObjectDeserializationTest.java
@Test public void xml_path_supports_custom_deserializer_using_static_configuration() { // Given/* ww w . j ava2 s . c o m*/ final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false); XmlPath.config = XmlPathConfig.xmlPathConfig().defaultObjectDeserializer(new XmlPathObjectDeserializer() { public <T> T deserialize(ObjectDeserializationContext ctx) { customDeserializerUsed.set(true); final String xml = ctx.getDataToDeserialize().asString(); final Greeting greeting = new Greeting(); greeting.setFirstName(StringUtils.substringBetween(xml, "<firstName>", "</firstName>")); greeting.setLastName(StringUtils.substringBetween(xml, "<lastName>", "</lastName>")); return (T) greeting; } }); // When try { final XmlPath xmlPath = new XmlPath(COOL_GREETING); final Greeting greeting = xmlPath.getObject("", Greeting.class); // Then assertThat(greeting.getFirstName(), equalTo("John")); assertThat(greeting.getLastName(), equalTo("Doe")); assertThat(customDeserializerUsed.get(), is(true)); } finally { XmlPath.reset(); } }
From source file:com.jayway.restassured.path.xml.XmlPathObjectDeserializationTest.java
@Test public void xml_path_supports_custom_deserializer_using_static_configuration() { // Given//from w w w . j a va 2s .c o m final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false); XmlPath.config = xmlPathConfig().defaultObjectDeserializer(new XmlPathObjectDeserializer() { public <T> T deserialize(ObjectDeserializationContext ctx) { customDeserializerUsed.set(true); final String xml = ctx.getDataToDeserialize().asString(); final Greeting greeting = new Greeting(); greeting.setFirstName(StringUtils.substringBetween(xml, "<firstName>", "</firstName>")); greeting.setLastName(StringUtils.substringBetween(xml, "<lastName>", "</lastName>")); return (T) greeting; } }); // When try { final XmlPath xmlPath = new XmlPath(COOL_GREETING); final Greeting greeting = xmlPath.getObject("", Greeting.class); // Then assertThat(greeting.getFirstName(), equalTo("John")); assertThat(greeting.getLastName(), equalTo("Doe")); assertThat(customDeserializerUsed.get(), is(true)); } finally { XmlPath.reset(); } }
From source file:com.thruzero.common.core.infonode.builder.DomInfoNodeBuilderTest.java
@Test public void testNestedNodeNoParentValue() throws IOException, SAXException { InfoNodeElement sampleInfoNode = SampleInfoNodeBuilderUtils .createComplexNestedInfoNodeWithoutParentValue(RootNodeOption.GENERATE_ROOT_NODE, 10); Document w3cDocument = XmlUtils.createDocument(sampleInfoNode.toStringFormatted()); InfoNodeDocument infoNodeDocument = DomInfoNodeBuilder.DEFAULT.buildInfoNode(w3cDocument); InfoNodeElement rootInfoNodeElement = infoNodeDocument.getRootInfoNodeElement(); // verify that parent to child transition is smooth (i.e., no null printed in result) String partialResultStr = StringUtils.substringBetween(rootInfoNodeElement.toString(), "<TestParentElement", "<Test0Element"); assertTrue(partialResultStr.trim().equals(">")); }
From source file:de.blizzy.documentr.markdown.MarkdownProcessor.java
private String markdownToHtml(RootNode rootNode, String projectName, String branchName, String path, Authentication authentication, boolean nonCacheableMacros, String contextPath) { HtmlSerializerContext context = new HtmlSerializerContext(projectName, branchName, path, this, authentication, pageStore, systemSettingsStore, contextPath); HtmlSerializer serializer = new HtmlSerializer(context); String html = serializer.toHtml(rootNode); List<MacroInvocation> macroInvocations = context.getMacroInvocations(); int nonCacheableMacroIdx = 1; for (MacroInvocation invocation : macroInvocations) { IMacro macro = macroFactory.get(invocation.getMacroName()); if (macro == null) { macro = new UnknownMacroMacro(); }// ww w . j a va 2 s . c om IMacroDescriptor macroDescriptor = macro.getDescriptor(); String startMarker = invocation.getStartMarker(); String endMarker = invocation.getEndMarker(); String body = StringUtils.substringBetween(html, startMarker, endMarker); if (macroDescriptor.isCacheable()) { MacroContext macroContext = MacroContext.create(invocation.getMacroName(), invocation.getParameters(), body, context, beanFactory); IMacroRunnable macroRunnable = macro.createRunnable(); String macroHtml = StringUtils.defaultString(macroRunnable.getHtml(macroContext)); html = StringUtils.replace(html, startMarker + body + endMarker, macroHtml); } else if (nonCacheableMacros) { String macroName = invocation.getMacroName(); String params = invocation.getParameters(); String idx = String.valueOf(nonCacheableMacroIdx++); html = StringUtils.replace(html, startMarker + body + endMarker, "__" + NON_CACHEABLE_MACRO_MARKER + "_" + idx + "__" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ macroName + " " + StringUtils.defaultString(params) + //$NON-NLS-1$ "__" + NON_CACHEABLE_MACRO_BODY_MARKER + "__" + //$NON-NLS-1$ //$NON-NLS-2$ body + "__/" + NON_CACHEABLE_MACRO_MARKER + "_" + idx + "__"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else { html = StringUtils.replace(html, startMarker + body + endMarker, StringUtils.EMPTY); } } html = cleanupHtml(html, macroInvocations, true); return html; }
From source file:com.erudika.para.client.ParaClient.java
/** * Sets the JWT access token./*from ww w .j av a 2 s. co m*/ * @param token a valid token */ @SuppressWarnings("unchecked") public void setAccessToken(String token) { if (!StringUtils.isBlank(token)) { try { String payload = Utils.base64dec(StringUtils.substringBetween(token, ".", ".")); Map<String, Object> decoded = ParaObjectUtils.getJsonMapper().readValue(payload, Map.class); if (decoded != null && decoded.containsKey("exp")) { this.tokenKeyExpires = (Long) decoded.get("exp"); this.tokenKeyNextRefresh = (Long) decoded.get("refresh"); } } catch (Exception ex) { this.tokenKeyExpires = null; this.tokenKeyNextRefresh = null; } } this.tokenKey = token; }
From source file:ddf.catalog.querymonitor.ActiveSearch.java
public ActiveSearch(Source source, QueryRequest request) { this(getCqlFromQueryRequest(request), source, UUID.randomUUID(), "client"); if (request == null) { LOGGER.warn("QueryRequest in ActiveSearch Constructor was null."); } else {//from ww w . ja v a 2 s. c o m clientInfo = SubjectUtils.getName( (Subject) request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), "unknown", true); if (clientInfo.contains(",CN=")) { clientInfo = StringUtils.substringBetween(clientInfo, ",CN=", ",OU="); } } }
From source file:ch.ivyteam.ivy.maven.engine.EngineControl.java
private void findStartEngineUrl(String newLine) { if (newLine.contains("info page of Axon.ivy Engine") && !engineStarted.get()) { String url = StringUtils.substringBetween(newLine, "http://", "/"); url = "http://" + url + "/ivy/"; context.log.info("Axon.ivy Engine runs on : " + url); context.properties.setMavenProperty(Property.TEST_ENGINE_URL, url); engineStarted.set(true);//from w ww . j a v a 2s. com } }
From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java
public JcrNewNodeAdapter determinePreviousLocation() { JcrNewNodeAdapter favoriteLocation;//from ww w . jav a 2 s .co m // at this point the current location in the browser hasn't yet changed to favorite shellapp, // so it is what we need to pre-populate the form for creating a new favorite final URI previousLocation = Page.getCurrent().getLocation(); final String previousLocationFragment = previousLocation.getFragment(); // skip bookmark resolution if for some reason fragment is empty if (previousLocationFragment == null) { return createNewFavoriteSuggestion("", "", ""); } final String appName = DefaultLocation.extractAppName(previousLocationFragment); final String appType = DefaultLocation.extractAppType(previousLocationFragment); // TODO MGNLUI-1190 should this be added to DefaultLocation as a convenience static method? final String path = StringUtils.substringBetween(previousLocationFragment, ";", ":"); // skip bookmark resolution shell apps if (Location.LOCATION_TYPE_SHELL_APP.equals(appType)) { favoriteLocation = createNewFavoriteSuggestion("", "", ""); } else { final AppDescriptor appDescriptor; try { DefinitionProvider<AppDescriptor> definitionProvider = appDescriptorRegistry.getProvider(appName); appDescriptor = i18nizer.decorate(definitionProvider.get()); } catch (Registry.NoSuchDefinitionException | IllegalStateException e) { throw new RuntimeException(e); } final String appIcon = StringUtils.defaultIfEmpty(appDescriptor.getIcon(), "icon-app"); final String title = appDescriptor.getLabel() + " " + (path == null ? "/" : path); final String urlFragment = getUrlFragmentFromURI(previousLocation); favoriteLocation = createNewFavoriteSuggestion(urlFragment, title, appIcon); } return favoriteLocation; }
From source file:com.ln.methods.Descparser.java
public static void parsedesc() { String Desc = ""; String Title = ""; String Hour = ""; String Minute = ""; String formatted[] = new String[Betaparser.Description.length]; int selectedindex = Main.Titlebox.getSelectedIndex(); for (int i1 = 0; i1 != Betaparser.Hours.length; i1++) { if (Betaparser.Events[i1].startsWith(Main.monthday)) { Desc = Desc + "" + Betaparser.Description[i1] + "~"; Title = Title + "" + Betaparser.Title[i1] + "~"; Hour = Hour + "" + Betaparser.Hours[i1] + "~"; Minute = Minute + "" + Betaparser.Minutes[i1] + "~"; }/*www . j ava2 s. c o m*/ } String[] Desc2 = StringUtils.substringsBetween(Desc, "", "~"); String[] Title2 = StringUtils.substringsBetween(Title, "", "~"); String[] Hour2 = StringUtils.substringsBetween(Hour, "", "~"); String[] Minute2 = StringUtils.substringsBetween(Minute, "", "~"); String[] Full = new String[Desc2.length]; TTT = ""; DDD = 0; HHH = 0; MMM = 0; for (int i = 0; i != Title2.length; i++) { int h = Integer.parseInt(Hour2[i]); int m = Integer.parseInt(Minute2[i]); DateFormat df = new SimpleDateFormat("dd"); DateFormat dm = new SimpleDateFormat("MM"); Date month = new Date(); Date today = new Date(); int mon = Integer.parseInt(dm.format(month)); int d = Integer.parseInt(df.format(today)); int dif = 0; int ds = 0; int pastd = 0; int pasth = 0; int pastm = 0; d = Main.sdate - d; h = h - Parser.hour; m = m - Parser.minute; if (d > 0) { ds = 1; } if (mon > Main.globmonth) { dif = dif + 1; } if (Main.sdate > d) { dif = dif + 1; } if (h < 0) { pasth = Math.abs(h); } if (m < 0) { pastm = Math.abs(m); h = h - 1; m = m + 60; } if (d < 0) { pastd = d; } if (d > 0 && h < 0) { d = d - 1; h = h + 24; } if (d == 0) { formatted[i] = "<font size=\"4\" color=\"lime\"><br><b>Starts in: " + String.format("%01d Hours %01d Minutes", h, m) + "</b></font>"; } if (d >= 1) { formatted[i] = "<font size=\"4\" color=\"lime\"><br><b>Starts in: " + String.format("%01d Days %01d Hours %01d Minutes", d, h, m) + "</b></font>"; } if (pastd == 0 && h < 0) { formatted[i] = "<font size=\"4\" color=\"#B00000\"><br><b>Event is finished/going on. Started " + String.format("%01d Hours %01d Minutes", pasth, pastm) + " Ago</b></font>"; } if (pastd < 0 && h < 0) { formatted[i] = "<font size=\"4\" color=\"#B00000\"><br><b>Event is finished/going on. Started " + String.format("%01d Days %01d Hours %01d Minutes", pastd, pasth, pastm) + " Ago</b></font>"; } } for (int i = 0; i != Title2.length; i++) { Full[i] = Title2[i]; } try { if (Desc2[selectedindex] != null) { StringBuilder sb = new StringBuilder(Desc2[selectedindex]); int i = 0; while ((i = sb.indexOf(" ", i + 50)) != -1) { // sb.replace(i, i + 1, "<br>"); String formatteddesc = sb.toString(); formatteddesc = formatteddesc.replace("/forum/", "http://www.teamliquid.net/forum/"); TextProcessor processor = BBProcessorFactory.getInstance().create(); formatteddesc = processor.process(formatteddesc); formatteddesc = formatteddesc.replace("#T#", "").replace("#P#", "").replace("#Z#", ""); formatteddesc = formatteddesc.replace("[tlpd#players", "[tlpd][cat]players[/cat]"); formatteddesc = formatteddesc.replace("[/cat]#", "[ID]"); formatteddesc = formatteddesc.replace("sc2-korean]", "[/ID][region]sc2-korean[/region][name]") .replace("sc2-international", "[/ID][region]sc2-international[/region][name]"); formatteddesc = formatteddesc.replace("[/tlpd]", "[/name][/tlpd]"); String[] tlpd = StringUtils.substringsBetween(formatteddesc, "[tlpd]", "[/tlpd]"); String[] cat = StringUtils.substringsBetween(formatteddesc, "[cat]", "[ID]"); String[] ids = StringUtils.substringsBetween(formatteddesc, "[ID]", "[/ID]"); String[] names = StringUtils.substringsBetween(formatteddesc, "[name]", "[/name]"); String[] region = StringUtils.substringsBetween(formatteddesc, "[region]", "[/region]"); try { if (formatteddesc.contains("tlpd")) { formatteddesc = formatteddesc.replace("[tlpd]", "").replace("[/tlpd]", ""); for (int i1 = 0; i1 != tlpd.length; i1++) { formatteddesc = formatteddesc.replace(tlpd[i1], "<a href=\"http://www.teamliquid.net/tlpd/" + cat[i1] + "/" + region[i1] + "/" + ids[i1] + "\">" + names[i1] + "</a>"); // formatteddesc = formatteddesc.replace("[tlpd]", "").replace("[/tlpd]", ""); } } } catch (NullPointerException e) { e.printStackTrace(); } formatteddesc = formatteddesc.replace("<", "").replace("gt;", ""); Main.Description .setText((Full[selectedindex] + formatted[selectedindex] + "<br>" + formatteddesc)); try { if (formatted[selectedindex].contains("lime")) { String[] notfytime = new String[formatted.length]; String[] form = new String[formatted.length]; form[selectedindex] = formatted[selectedindex].replace("Starts in: ", "$"); notfytime[selectedindex] = StringUtils.substringBetween(form[selectedindex], "$", "</b>"); if (formatted[selectedindex].contains("Days")) { String DD = StringUtils.substringBetween(notfytime[selectedindex], "", " Days"); String HH = StringUtils.substringBetween(notfytime[selectedindex], "Days ", " Hours"); String MM = StringUtils.substringBetween(notfytime[selectedindex], "Hours ", " Minutes"); DDD = Integer.parseInt(DD); HHH = Integer.parseInt(HH); MMM = Integer.parseInt(MM); TTT = Full[selectedindex]; } if (!formatted[selectedindex].contains("Days")) { String HH = StringUtils.substringBetween(notfytime[selectedindex], "", " Hours"); String MM = StringUtils.substringBetween(notfytime[selectedindex], "Hours ", " Minutes"); HHH = Integer.parseInt(HH); MMM = Integer.parseInt(MM); TTT = Full[selectedindex]; } } } catch (Exception e) { e.printStackTrace(); } Main.Description.setCaretPosition(0); } } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } }
From source file:com.zhumeng.dream.orm.PropertyFilter.java
/** * ? EQS_alais.name = val// w w w . j a v a 2 s . c o m * * @param filterName * @param value * @return */ public static String[] buildAliasEntity(List<String> filterParamKey) { Assert.notNull(filterParamKey, "filterParamKey must not be null"); String[] result = null; for (String filterName : filterParamKey) { String alais = StringUtils.substringBetween(filterName, "_", "."); if (StringUtils.isNotBlank(alais) && !ArrayUtils.contains(result, alais)) { result = ArrayUtils.add(result, alais); } } return result; }