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:org.apache.shindig.social.opensocial.util.BeanXStreamAtomConverterTest.java
public void testMapsToXml() throws Exception { // This is the structure our app data currently takes Map<String, Map<String, String>> map = Maps.newTreeMap(); Map<String, String> item1Map = Maps.newHashMap(); item1Map.put("value", "1"); map.put("item1", item1Map); Map<String, String> item2Map = Maps.newHashMap(); item2Map.put("value", "2"); map.put("item2", item2Map); String xml = beanXmlConverter.convertToString(map); XmlUtil.parse(xml);//from ww w. j a v a 2 s.c om String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" > " + " <entry><id>item1</id>" + " <content type=\"application/xml\" ><entry><key>value</key><value>1</value></entry></content>" + " </entry> " + " <entry><id>item2</id>" + " <content type=\"application/xml\" ><entry><key>value</key><value>2</value></entry></content>" + " </entry> " + " <osearch:startIndex>0</osearch:startIndex> " + " <osearch:totalResults>2</osearch:totalResults> " + " <osearch:itemsPerPage>2</osearch:itemsPerPage></feed> "; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.shindig.social.opensocial.util.BeanXStreamAtomConverterTest.java
public void testMapToXml() throws XmlException { Map<String, String> m = Maps.newLinkedHashMap(); m.put("key1", "value1"); m.put("key2", "value2"); String xml = beanXmlConverter.convertToString(m); XmlUtil.parse(xml);// w ww. j a v a2 s .c o m String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" " + " xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\">" + " <entry><id>key1</id><content type=\"application/xml\" >" + " <value>value1</value></content>" + " </entry>" + " <entry><id>key2</id>" + " <content type=\"application/xml\" ><value>value2</value></content>" + " </entry>" + " <osearch:startIndex>0</osearch:startIndex>" + " <osearch:totalResults>2</osearch:totalResults>" + " <osearch:itemsPerPage>2</osearch:itemsPerPage></feed>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.shindig.social.opensocial.util.BeanXStreamAtomConverterTest.java
public void testEmptyList() throws XmlException { List<String> empty = Lists.newArrayList(); String xml = beanXmlConverter.convertToString(empty); XmlUtil.parse(xml);/*from ww w.j av a2 s. co m*/ String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" " + "xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" >" + "<entry><content/></entry>" + "<osearch:startIndex>0</osearch:startIndex>" + "<osearch:totalResults>1</osearch:totalResults>" + "<osearch:itemsPerPage>1</osearch:itemsPerPage></feed>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); List<List<String>> emptyLists = Lists.newArrayList(); List<String> emptyList = Lists.newArrayList(); emptyLists.add(emptyList); emptyLists.add(emptyList); emptyLists.add(emptyList); xml = beanXmlConverter.convertToString(emptyLists); XmlUtil.parse(xml); expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" " + "xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" >" + "<entry><content><list/><list/><list/></content></entry>" + "<osearch:startIndex>0</osearch:startIndex>" + "<osearch:totalResults>1</osearch:totalResults>" + "<osearch:itemsPerPage>1</osearch:itemsPerPage></feed>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.shindig.social.opensocial.util.BeanXStreamAtomConverterTest.java
public void testElementNamesInList() throws XmlException { List<Activity> activities = Lists.newArrayList(); activities.add(activity);/*from w w w . j ava 2 s. c o m*/ activities.add(activity); activities.add(activity); String xml = beanXmlConverter.convertToString(activities); XmlUtil.parse(xml); String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" " + " xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\"><entry><content>" + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">" + " <id>activityId</id>" + " <mediaItems>" + " <mimeType>image/jpg</mimeType>" + " <type>IMAGE</type>" + " <url>http://foo.bar</url>" + " </mediaItems>" + " <url>http://foo.com</url>" + " <userId>johnDoeId</userId>" + " </activity>" + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">" + " <id>activityId</id>" + " <mediaItems>" + " <mimeType>image/jpg</mimeType>" + " <type>IMAGE</type>" + " <url>http://foo.bar</url>" + " </mediaItems>" + " <url>http://foo.com</url>" + " <userId>johnDoeId</userId>" + " </activity>" + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">" + " <id>activityId</id>" + " <mediaItems>" + " <mimeType>image/jpg</mimeType>" + " <type>IMAGE</type>" + " <url>http://foo.bar</url>" + " </mediaItems>" + " <url>http://foo.com</url>" + " <userId>johnDoeId</userId>" + " </activity>" + "</content></entry>" + "<osearch:startIndex>0</osearch:startIndex>" + "<osearch:totalResults>1</osearch:totalResults>" + "<osearch:itemsPerPage>1</osearch:itemsPerPage>" + "</feed>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.shindig.social.opensocial.util.BeanXStreamConverterTest.java
@Test public void testMapsToXml() throws Exception { // This is the structure our app data currently takes Map<String, Map<String, String>> map = Maps.newTreeMap(); Map<String, String> item1Map = Maps.newHashMap(); item1Map.put("value", "1"); map.put("item1", item1Map); Map<String, String> item2Map = Maps.newHashMap(); item2Map.put("value", "2"); map.put("item2", item2Map); String xml = beanXmlConverter.convertToString(map); XmlUtil.parse(xml);/* w w w .j av a2 s .c om*/ String expectedXml = XSDValidator.XMLDEC + "<response xmlns=\"http://ns.opensocial.org/2008/opensocial\"><map>" + " <entry><key>item1</key><value><entry><key>value</key><value>1</value></entry></value></entry> " + " <entry><key>item2</key><value><entry><key>value</key><value>2</value></entry></value></entry> " + "</map></response>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.shindig.social.opensocial.util.BeanXStreamConverterTest.java
@Test public void testMapToXml() throws XmlException { Map<String, String> m = Maps.newLinkedHashMap(); m.put("key1", "value1"); m.put("key2", "value2"); String xml = beanXmlConverter.convertToString(m); XmlUtil.parse(xml);//from w w w .ja va 2 s .c o m String expectedXml = XSDValidator.XMLDEC + "<response xmlns=\"http://ns.opensocial.org/2008/opensocial\"><map>" + " <entry><key>key1</key><value>value1</value></entry> " + " <entry><key>key2</key><value>value2</value></entry> " + "</map></response>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.shindig.social.opensocial.util.BeanXStreamConverterTest.java
@Test public void testEmptyList() throws XmlException { List<String> empty = Lists.newArrayList(); String xml = beanXmlConverter.convertToString(empty); XmlUtil.parse(xml);//from ww w . ja v a 2s . c o m String expectedXml = XSDValidator.XMLDEC + "<response xmlns=\"http://ns.opensocial.org/2008/opensocial\"><list/></response>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); List<List<String>> emptyLists = Lists.newArrayList(); List<String> emptyList = Lists.newArrayList(); emptyLists.add(emptyList); emptyLists.add(emptyList); emptyLists.add(emptyList); xml = beanXmlConverter.convertToString(emptyLists); XmlUtil.parse(xml); expectedXml = XSDValidator.XMLDEC + "<response xmlns=\"http://ns.opensocial.org/2008/opensocial\"><list.container>" + " <list/>" + " <list/>" + " <list/>" + "</list.container></response>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(xml)); }
From source file:org.apache.sling.models.impl.ModelPackageBundleListener.java
@Override public Object addingBundle(Bundle bundle, BundleEvent event) { List<ServiceRegistration> regs = new ArrayList<ServiceRegistration>(); Dictionary<?, ?> headers = bundle.getHeaders(); String packageList = PropertiesUtil.toString(headers.get(HEADER), null); if (packageList != null) { packageList = StringUtils.deleteWhitespace(packageList); String[] packages = packageList.split(","); for (String singlePackage : packages) { @SuppressWarnings("unchecked") Enumeration<URL> classUrls = bundle.findEntries("/" + singlePackage.replace('.', '/'), "*.class", true);// ww w . j a v a 2s.c o m if (classUrls == null) { log.warn("No adaptable classes found in package {}, ignoring", singlePackage); continue; } while (classUrls.hasMoreElements()) { URL url = classUrls.nextElement(); String className = toClassName(url); try { Class<?> implType = bundle.loadClass(className); Model annotation = implType.getAnnotation(Model.class); if (annotation != null) { // get list of adapters from annotation - if not given use annotated class itself Class<?>[] adapterTypes = annotation.adapters(); if (adapterTypes.length == 0) { adapterTypes = new Class<?>[] { implType }; } // register adapter only if given adapters are valid if (validateAdapterClasses(implType, adapterTypes)) { for (Class<?> adapterType : adapterTypes) { adapterImplementations.add(adapterType, implType); } ServiceRegistration reg = registerAdapterFactory(adapterTypes, annotation.adaptables(), implType, annotation.condition()); regs.add(reg); } String[] resourceTypes = annotation.resourceType(); for (String resourceType : resourceTypes) { if (StringUtils.isNotEmpty(resourceType)) { for (Class<?> adaptable : annotation.adaptables()) { adapterImplementations.registerModelToResourceType(bundle, resourceType, adaptable, implType); } } } } } catch (ClassNotFoundException e) { log.warn("Unable to load class", e); } } } } return regs.toArray(new ServiceRegistration[0]); }
From source file:org.b3log.symphony.util.Markdowns.java
/** * Gets the safe HTML content of the specified content. * * @param content the specified content/*from www . j a v a2s . c o m*/ * @param baseURI the specified base URI, the relative path value of href will starts with this URL * @return safe HTML content */ public static String clean(final String content, final String baseURI) { final Document.OutputSettings outputSettings = new Document.OutputSettings(); outputSettings.prettyPrint(false); final String tmp = Jsoup.clean(content, baseURI, Whitelist.relaxed().addAttributes(":all", "id", "target", "class") .addTags("span", "hr", "kbd", "samp", "tt", "del", "s", "strike", "u") .addAttributes("iframe", "src", "width", "height", "border", "marginwidth", "marginheight") .addAttributes("audio", "controls", "src") .addAttributes("video", "controls", "src", "width", "height") .addAttributes("source", "src", "media", "type") .addAttributes("object", "width", "height", "data", "type") .addAttributes("param", "name", "value") .addAttributes("input", "type", "disabled", "checked").addAttributes("embed", "src", "type", "width", "height", "wmode", "allowNetworking"), outputSettings); final Document doc = Jsoup.parse(tmp, baseURI, Parser.htmlParser()); final Elements ps = doc.getElementsByTag("p"); for (final Element p : ps) { p.removeAttr("style"); } final Elements iframes = doc.getElementsByTag("iframe"); for (final Element iframe : iframes) { final String src = StringUtils.deleteWhitespace(iframe.attr("src")); if (StringUtils.startsWithIgnoreCase(src, "javascript") || StringUtils.startsWithIgnoreCase(src, "data:")) { iframe.remove(); } } final Elements objs = doc.getElementsByTag("object"); for (final Element obj : objs) { final String data = StringUtils.deleteWhitespace(obj.attr("data")); if (StringUtils.startsWithIgnoreCase(data, "data:") || StringUtils.startsWithIgnoreCase(data, "javascript")) { obj.remove(); continue; } final String type = StringUtils.deleteWhitespace(obj.attr("type")); if (StringUtils.containsIgnoreCase(type, "script")) { obj.remove(); } } final Elements embeds = doc.getElementsByTag("embed"); for (final Element embed : embeds) { final String data = StringUtils.deleteWhitespace(embed.attr("src")); if (StringUtils.startsWithIgnoreCase(data, "data:") || StringUtils.startsWithIgnoreCase(data, "javascript")) { embed.remove(); continue; } } final Elements as = doc.getElementsByTag("a"); for (final Element a : as) { a.attr("rel", "nofollow"); final String href = a.attr("href"); if (href.startsWith(Latkes.getServePath())) { continue; } a.attr("target", "_blank"); } final Elements audios = doc.getElementsByTag("audio"); for (final Element audio : audios) { audio.attr("preload", "none"); } final Elements videos = doc.getElementsByTag("video"); for (final Element video : videos) { video.attr("preload", "none"); } String ret = doc.body().html(); ret = ret.replaceAll("(</?br\\s*/?>\\s*)+", "<br>"); // patch for Jsoup issue return ret; }
From source file:org.betaconceptframework.astroboa.console.jsf.browse.ContentObjectSearchByText.java
public String findContentObjectsByTextAndPresent_UIAction() { // reset search criteria to begin a new search contentObjectCriteria = null;/* w ww . j a va2s. c o m*/ contentObjectCriteria = CmsCriteriaFactory.newContentObjectCriteria(); if (uiComponentBinding != null) uiComponentBinding.resetContentObjectTableScrollerComponent(); contentObjectList.resetViewAndStateBeforeNewContentSearchResultsPresentation(); if (StringUtils.isBlank(searchedText)) { //In case a new page is rendered, that is TaxonomyEditpage was loaded and //user clicked to search content objects with an empty string this message won't be //loaded to the new page JSFUtilities.addMessage(null, "? ? ", FacesMessage.SEVERITY_WARN); return null; } // add searched text to the criteria if (StringUtils.deleteWhitespace(searchedText).equals(searchedText) && !searchedText.contains("\"") && !searchedText.contains("'") && !searchedText.contains("*")) { //If Search Text contains only one word and not any special search character then Append * at the end contentObjectCriteria.addFullTextSearchCriterion(searchedText + CmsConstants.ANY_NAME); } else { contentObjectCriteria.addFullTextSearchCriterion(searchedText); } contentObjectCriteria.setOffsetAndLimit(0, pageController.getRowsPerDataTablePage()); contentObjectCriteria.doNotCacheResults(); // set required ordering if (searchResultsFilterAndOrdering.getSelectedResultsOrder() != null) { contentObjectCriteria.addOrderProperty("profile.modified", Order.valueOf(searchResultsFilterAndOrdering.getSelectedResultsOrder())); } else { contentObjectCriteria.addOrderProperty("profile.modified", Order.descending); } //contentObjectCriteria.addOrderByRelevance(Order.descending); // now we are ready to run the query try { long startTime = System.currentTimeMillis(); int resultSetSize = contentObjectStatefulSearchService.searchForContentWithPagedResults( contentObjectCriteria, true, JSFUtilities.getLocaleAsString(), pageController.getRowsPerDataTablePage()); long endTime = System.currentTimeMillis(); getLogger().debug("Find Content Objects by Topic UUID:FIRST EXECUTION to get object count took: " + (endTime - startTime) + "ms"); if (resultSetSize > 0) { contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n( "object.list.message.contentObjectListHeaderMessageForTextSearch", new String[] { searchedText, String.valueOf(resultSetSize) })); contentObjectList.setLabelForFileGeneratedWhenExportingListToXml(searchedText); } else JSFUtilities.addMessage(null, "object.list.message.noContentObjectsContainingThisTextInfo", null, FacesMessage.SEVERITY_INFO); } catch (Exception e) { logger.error("Error while loading content objects ", e); JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null, FacesMessage.SEVERITY_ERROR); return null; } return null; }