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:de.unioninvestment.eai.portal.portlet.crud.scripting.category.StringCategory.java
/** * <p>/*from ww w . j a v a2s. co m*/ * Deletes all whitespaces from a String as defined by * {@link Character#isWhitespace(char)}. * </p> * <p> * For details and examples see {@link StringUtils#deleteWhitespace(String)} * . * </p> * * @param s * the String to delete whitespace from, may be null * @return the String without whitespaces, <code>null</code> if null String * input * @since 1.46 * @author Jan Malcomess (codecentric AG) */ public static String deleteWhitespaces(String s) { return StringUtils.deleteWhitespace(s); }
From source file:com.ewcms.publication.freemarker.directive.ArticleListDirectiveTest.java
@Test public void testChannelNotPublicenable() throws Exception { ChannelPublishServiceable channelLoaderService = mock(ChannelPublishServiceable.class); Channel channel = new Channel(); channel.setPublicenable(false);/*from www. j a v a 2s. c om*/ when(channelLoaderService.getChannel(any(Integer.class), any(Integer.class))).thenReturn(channel); ArticleListDirective directive = new ArticleListDirective(channelLoaderService, null); cfg.setSharedVariable("alist", directive); Template template = cfg.getTemplate(getTemplatePath("value.html")); Map<String, Object> params = new HashMap<String, Object>(); Site site = new Site(); site.setId(1); params.put(GlobalVariable.SITE.toString(), site); String value = process(template, params); value = StringUtils.deleteWhitespace(value); Assert.assertEquals("", value); }
From source file:com.ewcms.publication.freemarker.directive.IncludeDirectiveTest.java
@Test public void testChannelTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("channel.html")); Map<String, Object> params = new HashMap<String, Object>(); Site site = new Site(); site.setId(2);/* w w w . j ava2 s . c o m*/ params.put(GlobalVariable.SITE.toString(), site); Channel channel = new Channel(); channel.setId(1); params.put(GlobalVariable.CHANNEL.toString(), channel); String value = process(template, params); value = StringUtils.deleteWhitespace(value); Assert.assertEquals("test-channel-includetest-channel-includetest-channel-include", value); }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityGeoBoundsChecker2.java
/** * /*from w w w. j av a 2 s. co m*/ */ public void load() { File file = new File(XMLHelper.getConfigDirPath("st99_d00a.dat")); try { List<String> lines = (List<String>) FileUtils.readLines(file); for (int i = 0; i < lines.size(); i++) { String polygonId = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"'); String stateId = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"'); String stateNm = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"'); i += 2; StateInfo si = statesHash.get(stateNm); if (si == null) { String code = statesCodeHash.get(stateNm); si = new StateInfo(stateNm, code, stateId); statesHash.put(stateNm, si); codeToStateInfoHash.put(code, si); } statesIdHash.put(polygonId, si); } for (String polygonId : statesIdHash.keySet()) { System.out.println(String.format("%s - %s", polygonId, statesIdHash.get(polygonId).name)); } file = new File(XMLHelper.getConfigDirPath("st99_d00.dat")); FileInputStream fis = new FileInputStream(file); BufferedReader bufRdr = new BufferedReader(new InputStreamReader(fis)); StateInfo si = null; ArrayList<Position> points = null; String s; while ((s = bufRdr.readLine()) != null) { String[] tokens = StringUtils.split(s, ' '); if (tokens.length == 3) { //System.out.println(tokens[0]); /*if (points != null) { Polyline polygon = new Polyline(); polygon.setPositions(points); si.addPolygon(polygon); }*/ si = statesIdHash.get(tokens[0]); points = new ArrayList<Position>(); //double lat = Double.valueOf(tokens[1]); //double lon = Double.valueOf(tokens[2]); //points.add(Position.fromDegrees(lat, lon, 0)); } else if (tokens.length == 2) { double lat = Double.valueOf(tokens[1]); double lon = Double.valueOf(tokens[0]); points.add(Position.fromDegrees(lat, lon, 0)); } else if (si != null) { Polyline polygon = new Polyline(); polygon.setPositions(points); si.addPolygon(polygon); si = null; } } bufRdr.close(); fis.close(); for (StateInfo stateInfo : statesHash.values()) { System.out.println(String.format("%s - %d", stateInfo.name, stateInfo.polygons.size())); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ewcms.publication.freemarker.directive.page.SkipDirectiveTest.java
@Test public void testLoopTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("skiploop.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("loop|5|1", value); }
From source file:com.ewcms.publication.freemarker.generator.GeneratorBaseTest.java
@Test public void testWrite() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); UriRuleable rule = UriRules.newUriRuleBy(""); GeneratorBaseImpl html = new GeneratorBaseImpl(); freemarker.template.Template template = html.getFreemarkerTemplate(cfg, getTemplatePath("index.html")); ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(out); html.write(template, parameters, rule, writer); String content = getContent(out.toByteArray()); content = StringUtils.deleteWhitespace(content); Assert.assertEquals("homepage", content); out.close();//w w w. ja v a2 s . c om }
From source file:com.daveayan.rjson.RjsonInstantiationTest.java
public void verifyDefaultJsonObjectWithCustomObjectToJsonTransformer() throws IOException { String expectedJson = RjsonUtil.fileAsString( "./src/test/java/DATA-com.daveayan.rjson.Rjson/rjson_object_with_custom_object_to_json_transformer.txt"); String actualJson = serializer().toJson(Rjson.newInstance().and(new SampleObjectToJsonTransformer())); zen.Assert.thatEquals(StringUtils.deleteWhitespace(expectedJson), StringUtils.deleteWhitespace(actualJson)); }
From source file:com.ewcms.publication.freemarker.directive.PropertyDirectiveTest.java
/** * /*from w w w . ja va 2 s.c o m*/ * * @throws Exception */ @Test public void testPropertyIsNullOfValueTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("value.html")); ObjectBean objectValue = new ObjectBean(); 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, "|testtest1"); }
From source file:edu.ku.brc.specify.toycode.mexconabio.FMPCreateTable.java
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) { buffer.setLength(0);//from w w w . j av a2 s . c o m if (localName.equals("FIELD")) { FieldDef fldDef = new FieldDef(); fields.add(fldDef); for (int i = 0; i < attrs.getLength(); i++) { String attr = attrs.getLocalName(i); String value = attrs.getValue(i); if (attr.equals("EMPTYOK")) { fldDef.setNullable(value.equals("YES")); } else if (attr.equals("NAME")) { value = StringUtils.capitalize(value.trim()); value = StringUtils.deleteWhitespace(value); value = StringUtils.replace(value, "_", ""); if ((value.charAt(0) >= '0' && value.charAt(0) <= '9') || value.equalsIgnoreCase("New") || value.equalsIgnoreCase("Group")) { value = "Fld" + value; } String fixedStr = convertFromTwoByteUTF8(value); fixedStr = StringUtils.replace(fixedStr, ".", ""); fixedStr = StringUtils.replace(fixedStr, ":", ""); fixedStr = StringUtils.replace(fixedStr, "/", "_"); fldDef.setName(fixedStr); fldDef.setOrigName(value); } else if (attr.equals("TYPE")) { if (value.equals("TEXT")) { fldDef.setType(DataType.eText); } else if (value.equals("NUMBER")) { fldDef.setType(DataType.eNumber); } else if (value.equals("DATE")) { fldDef.setType(DataType.eDate); } else if (value.equals("TIME")) { fldDef.setType(DataType.eTime); } else { System.err.println("Unknown Type[" + value + "]"); } } } } }
From source file:com.ewcms.publication.freemarker.directive.ArticleDirectiveTest.java
@Test public void testArticleTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("article.html")); Map<Object, Object> params = new HashMap<Object, Object>(); Article article = new Article(); article.setTitle(""); params.put(GlobalVariable.ARTICLE.toString(), article); String value = this.process(template, params); value = StringUtils.deleteWhitespace(value); Assert.assertTrue(value.indexOf("_alias") != -1); Assert.assertTrue(value.indexOf("_property") != -1); Assert.assertTrue(value.indexOf("</html>") != -1); }