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
/** * //from w w w .jav a 2s . c o m * * @throws Exception */ @Test public void testLoopTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("loop.html")); ObjectBean objectValue = new ObjectBean(); objectValue.setTitle("test"); Map<String, Object> map = new HashMap<String, Object>(); map.put("object", objectValue); String content = process(template, map); content = StringUtils.deleteWhitespace(content); assertEquals(content, "testtest"); }
From source file:com.daveayan.rjson.RjsonInstantiationTest.java
public void verifyDefaultJsonObjectWithMultipleInstancesOfSameCustomJsonToObjectTransformer() throws IOException { String expectedJson = RjsonUtil.fileAsString( "./src/test/java/DATA-com.daveayan.rjson.Rjson/rjson_object_with_custom_json_to_object_transformer.txt"); String actualJson = serializer().toJson(Rjson.newInstance().and(new SampleJsonToObjectTransformer()) .and(new SampleJsonToObjectTransformer())); Assert.assertEquals(StringUtils.deleteWhitespace(expectedJson), StringUtils.deleteWhitespace(actualJson)); }
From source file:com.ewcms.publication.freemarker.directive.PropertyDirectiveTest.java
/** * /*from w w w . j a v a2s .co m*/ * * @throws Exception */ @Test public void testPropertyIsNullOfLoopTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("loop.html")); ObjectBean objectValue = new ObjectBean(); Map<String, Object> map = new HashMap<String, Object>(); map.put("object", objectValue); String content = process(template, map); content = StringUtils.deleteWhitespace(content); assertEquals(content, ""); }
From source file:edu.harvard.hul.ois.fits.EbuCoreModel.java
protected void createVideoFormatElement(Element elem, Namespace ns) throws XmlContentException { VideoFormat vfmt = new VideoFormat("videoFormat"); String id = elem.getAttribute("id").getValue(); VideoTrack vt = new VideoTrack(); vt.setTrackId(id);/* ww w .j ava 2s . c om*/ vfmt.setVideoTrack(vt); for (VideoFormatElements videoElem : VideoFormatElements.values()) { String fitsName = videoElem.getName(); Element dataElement = elem.getChild(fitsName, ns); if (dataElement == null) continue; String dataValue = dataElement.getText().trim(); if (StringUtils.isEmpty(dataValue)) continue; switch (videoElem) { case width: dataValue = StringUtils.deleteWhitespace(dataElement.getText().replace(" pixels", "")); WidthIdentifier width = new WidthIdentifier(dataValue, videoElem.getName()); width.setUnit("pixel"); vfmt.setWidthIdentifier(width); break; case height: dataValue = StringUtils.deleteWhitespace(dataElement.getText().replace(" pixels", "")); HeightIdentifier height = new HeightIdentifier(dataValue, videoElem.getName()); height.setUnit("pixel"); vfmt.setHeightIdentifier(height); break; case frameRate: EbuCoreFrameRateRatio frRatio = new EbuCoreFrameRateRatio(dataValue); FrameRate frameRate = new FrameRate(frRatio.getValue(), videoElem.getName()); frameRate.setFactorNumerator(frRatio.getNumerator()); frameRate.setFactorDenominator(frRatio.getDenominator()); vfmt.setFrameRate(frameRate); break; case bitRate: vfmt.setBitRate(Integer.parseInt(dataValue)); break; case bitRateMax: vfmt.setBitRateMax(Integer.parseInt(dataValue)); break; case bitRateMode: vfmt.setBitRateMode(dataValue.toLowerCase()); break; case scanningFormat: if (dataValue.equals("MBAFF")) vfmt.setScanningFormat("interlaced"); else vfmt.setScanningFormat(dataValue.toLowerCase()); break; case videoDataEncoding: VideoEncoding ve = new VideoEncoding(); ve.setTypeLabel(dataValue); vfmt.setVideoEncoding(ve); break; case aspectRatio: String[] splitValues = dataValue.split(":"); // TODO: throw exception if there are not 2 pieces if (splitValues != null && splitValues.length == 2) { AspectRatio ar = new AspectRatio(videoElem.getName()); // Normalize the ratio EbuCoreNormalizedRatio ratio = new EbuCoreNormalizedRatio(splitValues[0], splitValues[1]); ar.setFactorNumerator(ratio.getNormalizedNumerator()); ar.setFactorDenominator(ratio.getNormalizedDenominator()); ar.setTypeLabel("display"); vfmt.setAspectRatio(ar); } break; // Technical Attribute Strings case colorspace: TechnicalAttributeString tas = new TechnicalAttributeString(dataValue); tas.setTypeLabel(videoElem.getName()); vfmt.addTechnicalAttributeString(tas); break; case chromaSubsampling: case frameRateMode: case byteOrder: case delay: case compression: TechnicalAttributeString tasLc = new TechnicalAttributeString(dataValue.toLowerCase()); tasLc.setTypeLabel(videoElem.getName()); vfmt.addTechnicalAttributeString(tasLc); break; // Technical Attribute Integers case streamSize: case frameCount: case bitDepth: case duration: // For bitDepth, the string might have "bits" at the tail, so // we need to remove it if (videoElem.getName().equals("bitDepth")) { String[] parts = dataValue.split(" "); dataValue = parts[0]; } TechnicalAttributeInteger tai = new TechnicalAttributeInteger(Integer.parseInt(dataValue)); tai.setTypeLabel(videoElem.getName()); vfmt.addTechnicalAttributeInteger(tai); break; default: break; } } // TODO: break this out to enum code // Codec element Element dataElement = elem.getChild("codecId", ns); if (dataElement != null) { String dataValue = dataElement.getText().trim(); CodecIdentifier ci = new CodecIdentifier("codecIdentifier"); ci.setIdentifier(dataValue); Codec codec = new Codec("codec"); codec.setCodecIdentifier(ci); Element codecElement = elem.getChild("codecInfo", ns); if (codecElement != null) { dataValue = codecElement.getText().trim(); codec.setInfo(dataValue); } codecElement = elem.getChild("codecFamily", ns); if (codecElement != null) { dataValue = codecElement.getText().trim(); codec.setFamily(dataValue); } vfmt.setCodec(codec); } // Add the audio format object to the list this.format.addVideoFormat(vfmt); }
From source file:com.ewcms.publication.freemarker.directive.page.SkipNumberDirectiveTest.java
@Test public void testNumberLoopTemplate() throws Exception { Template template = cfg.getTemplate(getTemplatePath("numberloop.html")); Map<String, Object> params = new HashMap<String, Object>(); params.put(GlobalVariable.PAGE_NUMBER.toString(), Integer.valueOf(10)); params.put(GlobalVariable.PAGE_COUNT.toString(), Integer.valueOf(20)); 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); String expected = "##8910111213##"; Assert.assertEquals(expected, value); }
From source file:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) { buffer.setLength(0);/*from w w w . java 2 s . c o m*/ if (localName.equals("FIELD")) { if (doColSizes) { 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, "", "n"); value = StringUtils.replace(value, ":", ""); value = StringUtils.replace(value, ";", ""); //value = StringUtils.replace(value, "", "a"); value = StringUtils.replace(value, ".", ""); //value = StringUtils.replace(value, "", "a"); //value = StringUtils.replace(value, "", "a"); value = StringUtils.replace(value, "/", ""); //System.out.println(value); if ((value.charAt(0) >= '0' && value.charAt(0) <= '9') || value.equalsIgnoreCase("New") || value.equalsIgnoreCase("Group")) { value = "Fld" + value; } fldDef.setName(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 + "]"); } } //System.out.println(attrs.getLocalName(i)+" = "+attrs.getValue(i)); } } } else if (localName.equals("ROW")) { for (int i = 0; i < attrs.getLength(); i++) { String attr = attrs.getLocalName(i); String value = attrs.getValue(i); if (attr.equals("RECORDID")) { rowNum = Integer.parseInt(value); break; } } } }
From source file:com.ewcms.publication.freemarker.directive.ChannelListDirectiveTest.java
@Test public void testValueTemplate() throws Exception { Channel channel = createChannel(1, true); ChannelPublishServiceable service = mock(ChannelPublishServiceable.class); when(service.getChannel(any(Integer.class), any(Integer.class))).thenReturn(channel); ChannelListDirective directive = new ChannelListDirective(service); cfg.setSharedVariable("clist", directive); Template template = cfg.getTemplate(getTemplatePath("value.html")); Map<String, Object> params = templateParameters(); String value = process(template, params); value = StringUtils.deleteWhitespace(value); Assert.assertEquals("?1", value); }
From source file:com.analogmountains.flume.MongoSink.java
private List<ServerAddress> getSeeds(String seedsString) { List<ServerAddress> seeds = new LinkedList<ServerAddress>(); String[] seedStrings = StringUtils.deleteWhitespace(seedsString).split(","); for (String seed : seedStrings) { String[] hostAndPort = seed.split(":"); String host = hostAndPort[0]; int port; if (hostAndPort.length == 2) { port = Integer.parseInt(hostAndPort[1]); } else {/*from w w w . j av a2 s. c o m*/ port = 27017; } seeds.add(new ServerAddress(host, port)); } return seeds; }
From source file:de.thischwa.pmcms.gui.dialog.pojo.DialogFieldsSiteComp.java
@Override public boolean isValid() { String url = StringUtils.deleteWhitespace(StringUtils.lowerCase(textUrl.getText())); if (!checkUrl(url)) { dialogCreator.setErrorMessage(LabelHolder.get("dialog.pojo.site.error.url")); //$NON-NLS-1$ return false; }/* w w w .j a v a 2s . c o m*/ site.setUrl(url); if (StringUtils.isNotEmpty(textTitle.getText())) site.setTitle(textTitle.getText()); site.setTransferHost(textHost.getText()); site.setTransferLoginUser(textLoginUser.getText()); site.setTransferLoginPassword(cryptor.encrypt(textLoginPassword.getText())); site.setTransferStartDirectory(textStartDirectory.getText()); return true; }
From source file:com.daveayan.rjson.RjsonInstantiationTest.java
public void verifyDefaultJsonObjectWithCustomTransformerAsNull() throws IOException { String expectedJson = RjsonUtil .fileAsString("./src/test/java/DATA-com.daveayan.rjson.Rjson/default_rjson_object.txt"); String actualJson = serializer().toJson(Rjson.newInstance().and((ObjectToJsonTransformer) null)); Assert.assertEquals(StringUtils.deleteWhitespace(expectedJson), StringUtils.deleteWhitespace(actualJson)); }