List of usage examples for org.apache.commons.lang3 StringUtils substringsBetween
public static String[] substringsBetween(final String str, final String open, final String close)
Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.
A null input String returns null .
From source file:org.dashbuilder.dataprovider.backend.sql.JDBCUtils.java
public static String changeCaseExcludeQuotes(String s, boolean upper) { List<String> keepList = new ArrayList<String>(); for (int i = 0; i < QUOTES.length; i++) { String quote = QUOTES[i]; String[] words = StringUtils.substringsBetween(s, quote, quote); if (words != null) { keepList.addAll(Arrays.asList(words)); }/* ww w . j av a 2s .c o m*/ } String tmpStr = upper ? s.toUpperCase() : s.toLowerCase(); for (String word : keepList) { String tmpWord = upper ? word.toUpperCase() : word.toLowerCase(); tmpStr = StringUtils.replace(tmpStr, tmpWord, word); } return tmpStr; }
From source file:org.dashbuilder.dataprovider.sql.JDBCUtils.java
public static List<String> getWordsBetweenQuotes(String s) { List<String> result = new ArrayList<String>(); if (s != null) { for (int i = 0; i < QUOTES.length; i++) { String quote = QUOTES[i]; String[] words = StringUtils.substringsBetween(s, quote, quote); if (words != null) { result.addAll(Arrays.asList(words)); }//from w w w.j ava 2 s.co m } } return result; }
From source file:org.intermine.bio.dataconversion.GOAnnotationProcessor.java
/** * {@inheritDoc}//w ww .j av a 2 s . c om * We process the chado database by reading the feature records for genes. */ @Override public void process(Connection connection) throws SQLException, ObjectStoreException { LOG.info("Starting GOAnnotationProcessor.process()"); // initialize our DB statement Statement stmt = connection.createStatement(); // build an organism map from the supplied taxon IDs Map<Integer, Item> organismMap = new HashMap<Integer, Item>(); Map<Integer, OrganismData> chadoToOrgData = getChadoDBConverter().getChadoIdToOrgDataMap(); for (Map.Entry<Integer, OrganismData> entry : chadoToOrgData.entrySet()) { Integer organismId = entry.getKey(); OrganismData organismData = entry.getValue(); int taxonId = organismData.getTaxonId(); Item organism = getChadoDBConverter().createItem("Organism"); organism.setAttribute("taxonId", String.valueOf(taxonId)); store(organism); organismMap.put(organismId, organism); } LOG.info("Created and stored " + organismMap.size() + " organism Items."); // we'll store the GOTerm items in a map to avoid duplication, keyed by identifier (e.g. "GO:000037") Map<String, Item> goTermMap = new HashMap<String, Item>(); // loop over the organisms to fill the GO terms for (Map.Entry<Integer, Item> orgEntry : organismMap.entrySet()) { int organism_id = orgEntry.getKey().intValue(); Item organism = orgEntry.getValue(); // load the relevant genes from the gene table, store the description, then parse out the GO identifiers String query = "SELECT * FROM gene WHERE organism_id=" + organism_id; LOG.info("executing query: " + query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String primaryIdentifier = rs.getString("uniquename"); String description = rs.getString("description"); if (description != null) { Item gene = getChadoDBConverter().createItem("Gene"); gene.setReference("organism", organism); gene.setAttribute("primaryIdentifier", primaryIdentifier); gene.setAttribute("description", description); // parse the description for GO identifiers, creating a GOAnnotation each time, and adding it to the gene's collection String[] goNumbers = StringUtils.substringsBetween(description, "GO:", " "); if (goNumbers != null) { // create the Gene item and store the minimal stuff required for merging (and note that gene.symbol is bogus) // add the GO terms for (int j = 0; j < goNumbers.length; j++) { String identifier = "GO:" + goNumbers[j]; // get the GO term from the map if it's there; otherwise create, store and add it to the map. Item goTerm; if (goTermMap.containsKey(identifier)) { goTerm = goTermMap.get(identifier); } else { goTerm = getChadoDBConverter().createItem("GOTerm"); goTerm.setAttribute("identifier", identifier); store(goTerm); goTermMap.put(identifier, goTerm); } // create and store the GOAnnotation linking this gene to this GO term Item goAnnotation = getChadoDBConverter().createItem("GOAnnotation"); goAnnotation.setReference("subject", gene); goAnnotation.setReference("ontologyTerm", goTerm); store(goAnnotation); // have to manually set reverse reference since no reverse-reference from subject defined in OntologyAnnotation gene.addToCollection("goAnnotation", goAnnotation); } } // store the gene store(gene); } // description not null } // rs.next rs.close(); } // organism }
From source file:org.jevis.commons.driver.DataSourceHelper.java
private static boolean matchDateString(String currentFolder, String nextToken) { String[] substringsBetween = StringUtils.substringsBetween(nextToken, "${D:", "}"); for (int i = 0; i < substringsBetween.length; i++) { nextToken = nextToken.replace("${D:" + substringsBetween[i] + "}", ".{" + substringsBetween[i].length() + "}"); }/* ww w. ja v a 2 s.c o m*/ Pattern p = Pattern.compile(nextToken); Matcher m = p.matcher(currentFolder); return m.matches(); }
From source file:org.xwiki.contrib.mailarchive.utils.internal.MailUtils.java
@Override public IMAUser parseUser(final String user, final boolean isMatchLdap) { logger.debug("parseUser {}, {}", user, isMatchLdap); MAUser maUser = new MAUser(); maUser.setOriginalAddress(user);/*from ww w . ja v a 2 s. c om*/ if (StringUtils.isBlank(user)) { return maUser; } String address = null; String personal = null; // Do our best to extract an address and a personal try { InternetAddress ia = null; InternetAddress[] result = InternetAddress.parse(user, true); if (result != null && result.length > 0) { ia = result[0]; if (!StringUtils.isBlank(ia.getAddress())) { address = ia.getAddress(); } if (!StringUtils.isBlank(ia.getPersonal())) { personal = ia.getPersonal(); } } } catch (AddressException e) { logger.info("Email Address does not follow standards : " + user); } if (StringUtils.isBlank(address)) { String[] substrs = StringUtils.substringsBetween(user, "<", ">"); if (substrs != null && substrs.length > 0) { address = substrs[0]; } else { // nothing matches, we suppose recipient only contains email address address = user; } } if (StringUtils.isBlank(personal)) { if (user.contains("<")) { personal = StringUtils.substringBeforeLast(user, "<"); if (StringUtils.isBlank(personal)) { personal = StringUtils.substringBefore(address, "@"); } } } maUser.setAddress(address); maUser.setDisplayName(personal); // Now to match a wiki profile logger.debug("parseUser extracted email {}", address); String parsedUser = null; if (!StringUtils.isBlank(address)) { // to match "-external" emails and old mails with '@gemplus.com'... String pattern = address.toLowerCase(); pattern = pattern.replace("-external", "").replaceAll("^(.*)@.*[.]com$", "$1%@%.com"); logger.debug("parseUser pattern applied {}", pattern); // Try to find a wiki profile with this email as parameter. // TBD : do this in the loading phase, and only try to search db if it was not found ? String xwql = "select doc.fullName from Document doc, doc.object(XWiki.XWikiUsers) as user where LOWER(user.email) like :pattern"; List<String> profiles = null; try { profiles = queryManager.createQuery(xwql, Query.XWQL).bindValue("pattern", pattern).execute(); } catch (QueryException e) { logger.warn("parseUser Query threw exception", e); profiles = null; } if (profiles == null || profiles.size() == 0) { logger.debug("parseUser found no wiki profile from db"); return maUser; } else { if (isMatchLdap) { logger.debug("parseUser Checking for LDAP authenticated profile(s) ..."); // If there exists one, we prefer the user that's been authenticated through LDAP for (String usr : profiles) { if (bridge.exists(usr, "XWiki.LDAPProfileClass")) { parsedUser = usr; logger.debug("parseUser Found LDAP authenticated profile {}", parsedUser); } } if (parsedUser != null) { maUser.setWikiProfile(parsedUser); logger.debug("parseUser return {}", maUser); return maUser; } } } // If none has authenticated from LDAP, we return the first user found maUser.setWikiProfile(profiles.get(0)); logger.debug("parseUser return {}", maUser); return maUser; } else { logger.debug("parseUser No email found to match"); return maUser; } }
From source file:wong.spance.html.ArrayTableGroupTest.java
@Test public void testByOn() throws Exception { builder = new ArrayTableGroup(TableMeta.newMeta().addColumn("111").addColumn("222").addColumn("333")); Object[][] arr = new Object[][] { { "a", "b2", "c3" }, { "a", "b2", "c3" }, { "a", "b2", "c3" } }; builder.apply(new SimpleDataStore(arr)); assertEquals(builder.getTable().getBody().length, arr.length); builder.group(RowSpan.newRule().by(0).on(1)); String html = builder.render(); System.out.println(html);/* www . j a va 2s. c o m*/ assertArrayEquals("3".split(" "), StringUtils.substringsBetween(html, "rowspan=\"", "\"")); }
From source file:wong.spance.html.ArrayTableGroupTest.java
@Test public void testByOn2() throws Exception { builder = new ArrayTableGroup(TableMeta.newMeta().addColumn("111").addColumn("222").addColumn("333")); Object[][] arr = new Object[][] { { "a2", "b2", "c3" }, { "a2", "b2", "c3" }, { "a1", "b2", "c3" } }; builder.apply(new SimpleDataStore(arr)); assertEquals(builder.getTable().getBody().length, arr.length); builder.group(RowSpan.newRule().on(0), RowSpan.newRule().by(2).on(2)); String html = builder.render(); System.out.println(html);//from w ww . j ava2 s . c o m assertArrayEquals("2 3".split(" "), StringUtils.substringsBetween(html, "rowspan=\"", "\"")); }
From source file:wong.spance.html.ArrayTableGroupTest.java
@Test public void testByOn3() throws Exception { builder = new ArrayTableGroup(TableMeta.newMeta().addColumn("111").addColumn("222").addColumn("333")); Object[][] arr = new Object[][] { { "a3", "b2", "c3" }, { "a3", "b ", "c3" }, { "a3", "b2", "c3" }, { "a1", "b2", "c33" } }; builder.apply(new SimpleDataStore(arr)); assertEquals(builder.getTable().getBody().length, arr.length); builder.group(RowSpan.newRule().on(0), RowSpan.newRule().on(1), RowSpan.newRule().on(2)); String html = builder.render(); System.out.println(html);//from w ww .java 2 s.co m assertArrayEquals("3 3 2".split(" "), StringUtils.substringsBetween(html, "rowspan=\"", "\"")); }
From source file:wong.spance.html.ArrayTableGroupTest.java
@Test public void testCascade4() throws Exception { builder = new ArrayTableGroup(TableMeta.newMeta().addColumn("111").addColumn("222").addColumn("333")); Object[][] arr = new Object[][] { { "a4", "b2", "c3" }, { "a4", "b2", "c3" }, { "a1", "b2", "c3" } }; builder.apply(new SimpleDataStore(arr)); assertEquals(builder.getTable().getBody().length, arr.length); builder.group(RowSpan.newRule().on(0), RowSpan.newRule().cascade(0).by(2).on(2)); String html = builder.render(); System.out.println(html);/*from w w w .ja v a 2 s . co m*/ assertArrayEquals("2 2".split(" "), StringUtils.substringsBetween(html, "rowspan=\"", "\"")); }
From source file:wong.spance.html.ArrayTableGroupTest.java
@Test public void testCss1() throws Exception { builder = new ArrayTableGroup(TableMeta.newMeta().addColumn("111").addColumn("222").addColumn("333")); Object[][] arr = new Object[][] { { "s0", "b2", "2" }, { "s0", "b2", "3" }, { "s1", "b2", "4" }, { "s1", "b ", "5" }, { "s1", "bB 22--", "5" } }; builder.apply(new SimpleDataStore(arr)); assertEquals(builder.getTable().getBody().length, arr.length); builder.group(RowSpan.newRule().on(0), RowSpan.newRule().on(1)); String html = builder.render(new DefaultModifiers().setAttribute("table", "class", "table-class") .setAttribute("table th", "class", "head").setAttribute("tbody tr", "style", "kkkk") .replace("tr:last-child td:nth-child(1)", "(\\d+)", "XXX$1ttt")); System.out.println(html);/*from w w w .j a v a 2 s . c om*/ assertArrayEquals("2 3 3".split(" "), StringUtils.substringsBetween(html, "rowspan=\"", "\"")); assertEquals(1, StringUtils.countMatches(html, "class=\"table-class\"")); assertEquals(3, StringUtils.countMatches(html, "class=\"head\"")); assertEquals(5, StringUtils.countMatches(html, "style=\"kkk")); assertEquals(1, StringUtils.countMatches(html, "XXX22ttt")); }