List of usage examples for org.apache.commons.lang StringUtils deleteWhitespace
public static String deleteWhitespace(String str)
Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .
From source file:com.ewcms.publication.freemarker.directive.PropertyDirectiveTest.java
/** * /* ww w . ja va 2 s. c om*/ * * <p>???</p> * * @throws Exception */ @Test public void testVauleTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("value.html")); ObjectBean objectValue = new ObjectBean(); objectValue.setTitle("test"); Map<String, Object> map = new HashMap<String, Object>(); map.put("object", objectValue); List<ObjectBean> list = new ArrayList<ObjectBean>(); objectValue = new ObjectBean(); objectValue.setTitle("test"); list.add(objectValue); objectValue = new ObjectBean(); objectValue.setTitle("test1"); list.add(objectValue); map.put("objects", list); String content = process(template, map); content = StringUtils.deleteWhitespace(content); assertEquals(content, "test|testtest1"); }
From source file:edu.ku.brc.af.ui.forms.persist.FormCell.java
/** * Constructor/*w w w .jav a2s . c o m*/ * @param type type of cell * @param id the unique id * @param name the name */ public FormCell(final CellType type, final String id, final String name) { this.type = type; this.id = id; this.name = name; this.isMultiField = name.indexOf(',') > -1; //if (isMultiField) //{ if (StringUtils.isNotBlank(name)) { fieldNames = split(StringUtils.deleteWhitespace(name), ","); } //} else // { // fieldNames = new String[1]; // fieldNames[0] = name; //} }
From source file:com.ewcms.publication.freemarker.directive.page.SkipDirectiveTest.java
@Test public void testSkipTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("skip.html")); Map<String, Object> params = new HashMap<String, Object>(); params.put(GlobalVariable.PAGE_NUMBER.toString(), Integer.valueOf(0)); params.put(GlobalVariable.PAGE_COUNT.toString(), Integer.valueOf(5)); UriRuleable rule = mock(UriRuleable.class); when(rule.getUri()).thenReturn(""); params.put(GlobalVariable.URI_RULE.toString(), rule); String value = this.process(template, params); value = StringUtils.deleteWhitespace(value); Assert.assertEquals("|||", value); }
From source file:com.ewcms.publication.freemarker.directive.IncludeDirectiveTest.java
@Test public void testPathTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("path.html")); Map<String, Object> params = new HashMap<String, Object>(); Site site = new Site(); site.setId(2);/* w ww .ja v a 2 s .c o m*/ params.put(GlobalVariable.SITE.toString(), site); String value = process(template, params); value = StringUtils.deleteWhitespace(value); Assert.assertEquals("test-path-include", value); }
From source file:br.com.renatoccosta.regexrenamer.element.FilterElement.java
@Override public String convert(String src) { StringBuilder sb = new StringBuilder(); char[] caracs = src.toCharArray(); switch (mode) { case LETTERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isLetter(c)) { sb.append(c);/* w w w . j a v a2 s. co m*/ } } return sb.toString(); case NUMBERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isDigit(c)) { sb.append(c); } } return sb.toString(); case SYMBOLS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) { sb.append(c); } } return sb.toString(); case WHITE_SPACE: return StringUtils.deleteWhitespace(src); } return src; }
From source file:edu.ku.brc.specify.toycode.ResFileCompare.java
@SuppressWarnings("unchecked") public void fixPropertiesFiles(final String baseFileName, final String lang, final boolean doBranch) { System.out.println("-------------------- " + baseFileName + " --------------------"); File engFile;// ww w . ja va 2 s .co m File lngFile; String engName = String.format("src/%s_en.properties", baseFileName); String langName = String.format("src/%s_%s.properties", baseFileName, lang); if (doBranch) { engFile = new File( String.format("/home/rods/workspace/Specify_6202SF/src/%s_en.properties", baseFileName)); lngFile = new File( String.format("/home/rods/workspace/Specify_6202SF/src/%s_%s.properties", baseFileName, lang)); } else { engFile = new File(engName); lngFile = new File(langName); } try { List<String> engList = (List<String>) FileUtils.readLines(engFile, "UTF8"); List<String> lngListTmp = (List<String>) FileUtils.readLines(lngFile, "UTF8"); int lineCnt = -1; HashMap<String, String> transHash = new HashMap<String, String>(); for (String line : lngListTmp) { lineCnt++; if (line.startsWith("#") || StringUtils.deleteWhitespace(line).length() < 3 || line.indexOf('=') == -1) { continue; } String[] toks = StringUtils.split(line, '='); if (toks.length > 1) { if (toks.length == 2) { transHash.put(toks[0], toks[1]); } else { StringBuilder sb = new StringBuilder(); for (int i = 1; i < toks.length; i++) { sb.append(String.format("%s=", toks[i])); } sb.setLength(sb.length() - 1); // chomp extra '=' transHash.put(toks[0], sb.toString()); } } else { log.error("Skipping:[" + line + "] Line:" + lineCnt); } } log.info(String.format("Lines Eng: %d; Terms Hash size: %s: %d", engList.size(), lang, transHash.size())); File dir = new File("translations"); if (!dir.exists()) { if (!dir.mkdir()) { log.error("Unable to create directory[" + dir.getAbsolutePath() + "]"); return; } } File transFile = new File(dir.getPath() + File.separator + langName.substring(4)); PrintWriter transFileOutput = new PrintWriter(transFile, "UTF8"); for (String line : engList) { if (line.startsWith("#") || StringUtils.deleteWhitespace(line).length() < 3 || line.indexOf('=') == -1) { transFileOutput.println(line); continue; } boolean doMove = true; String[] toks = StringUtils.split(line, '='); if (toks.length > 1) { String key = null; String value = null; if (toks.length == 2) { key = toks[0]; value = toks[1]; } else { key = toks[0]; StringBuilder sb = new StringBuilder(); for (int i = 1; i < toks.length; i++) { sb.append(String.format("%s=", toks[i])); } sb.setLength(sb.length() - 1); // chomp extra '=' value = sb.toString(); } if (key != null) { String text = transHash.get(key); transFileOutput.println(String.format("%s=%s", key, text != null ? text : value)); if (text == null) { log.info("Adding new term: " + key); } doMove = false; } else { log.info("Adding new term: " + key); } } if (doMove) { transFileOutput.println(line); } } transFileOutput.flush(); transFileOutput.close(); log.info(String.format("Write file: %s", transFile.getPath())); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.baasbox.service.sociallogin.GooglePlusLoginService.java
@Override public UserInfo extractUserInfo(Response r) { UserInfo i = new UserInfo(); JsonNode ji = Json.parse(r.getBody()); i.setId(ji.get("id").textValue()); if (ji.get("email") != null) { i.addData("email", ji.get("email").textValue()); }//from ww w . j a v a 2s. c o m if (ji.get("link") != null) { i.addData("personal_url", ji.get("link").textValue()); } if (ji.get("picture") != null) { i.addData("avatarUrl", ji.get("picture").textValue()); } if (ji.get("name") != null) { i.addData("name", ji.get("name").textValue()); String name = ji.get("name").textValue(); String username = StringUtils.deleteWhitespace(name.toLowerCase()); i.setUsername(username); } i.setFrom(SOCIAL); return i; }
From source file:fr.exanpe.t5.lib.mixins.Resizable.java
private JSONObject buildJSONData() { JSONObject data = new JSONObject(); data.accumulate("id", container.getClientId()); data.accumulate("alwaysVisible", alwaysVisible); JSONArray array = new JSONArray((Object[]) StringUtils.deleteWhitespace(sides).split(",")); data.accumulate("sides", array); return data;// w w w . j a v a 2s.c o m }
From source file:net.di2e.ecdr.search.transform.response.rss.RSSResponseTransformer.java
private Metacard convertEntryToMetacard(SyndEntry entry, String siteName) { MetacardImpl metacard = new MetacardImpl(); String id = entry.getUri();//from ww w.ja v a 2 s . c om String link = entry.getLink(); // might have had an issue with a whitespace in the ID so this is just a safety check id = StringUtils.deleteWhitespace(id); metacard.setId(id); if (entry.getLink() != null) { try { metacard.setResourceURI(new URI(link)); } catch (URISyntaxException use) { LOGGER.warn("Could not set URI due to bad link in data.", use); } } metacard.setSourceId(siteName); metacard.setTitle(entry.getTitle()); metacard.setCreatedDate(entry.getPublishedDate()); if (entry.getUpdatedDate() != null) { metacard.setModifiedDate(entry.getUpdatedDate()); } SyndContent content = entry.getDescription(); if (content.getType().equals("text/xml")) { metacard.setMetadata(content.getValue()); } else { metacard.setMetadata("<xml-fragment>" + content.getValue() + "</xml-fragment>"); } return metacard; }
From source file:com.baasbox.service.sociallogin.FacebookLoginService.java
@Override public UserInfo extractUserInfo(Response r) throws BaasBoxFacebookException { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("FacebookLoginService.extractUserInfo: " + r.getCode() + ": " + r.getBody()); UserInfo ui = new UserInfo(); JsonNode user = Json.parse(r.getBody()); if (user.has("error")) { throw new BaasBoxFacebookException(user.get("error")); }/*w w w.j a va 2 s. co m*/ ui.setId(user.get("id").textValue()); if (user.get("username") != null) { ui.setUsername(user.get("username").textValue()); } if (user.get("email") != null) { ui.addData("email", user.get("email").textValue()); } if (user.get("gender") != null) { ui.addData("gender", user.get("gender").textValue()); } if (user.get("link") != null) { ui.addData("personalUrl", user.get("link").textValue()); } if (user.get("name") != null) { ui.addData("name", user.get("name").textValue()); if (ui.getUsername() == null) { ui.setUsername(StringUtils.deleteWhitespace(user.get("name").textValue())); } } ui.setFrom(SOCIAL); return ui; }