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.betaconceptframework.astroboa.test.model.jaxb.CmsOutcomeJAXBTest.java
@Test public void testCmsOutcomeOfContentObjectWithLimitZero() throws Throwable { createContent();/*from w ww . j a va 2s .c om*/ for (String testContentType : getTestContentTypes()) { ContentObjectCriteria contentObjectCriteria = CmsCriteriaFactory .newContentObjectCriteria(testContentType); contentObjectCriteria.addSystemNameContainsCriterion("*testCmsOutcomeForJAXB*"); contentObjectCriteria.doNotCacheResults(); contentObjectCriteria.addPropertyPathWhoseValueWillBePreLoaded("profile.title"); contentObjectCriteria.setOffsetAndLimit(0, 0); String json = contentService.searchContentObjects(contentObjectCriteria, ResourceRepresentationType.JSON); try { final String expectedOutcome = "{\"" + CmsConstants.TOTAL_RESOURCE_COUNT + "\":\"2\",\"" + CmsConstants.OFFSET + "\":\"0\",\"" + CmsConstants.LIMIT + "\":\"0\"}"; Assert.assertEquals(StringUtils.deleteWhitespace(json), expectedOutcome, "Invalid JSON resource response outcome " + json); } catch (Throwable e) { logger.error(json, e); throw e; } String xml = contentService.searchContentObjects(contentObjectCriteria, ResourceRepresentationType.XML); try { final String expected = CmsConstants.TOTAL_RESOURCE_COUNT + "=\"2\"" + CmsConstants.OFFSET + "=\"0\"" + CmsConstants.LIMIT + "=\"0\"><" + CmsConstants.RESOURCE_COLLECTION + "/></" + CmsConstants.RESOURCE_RESPONSE_PREFIXED_NAME + ">"; Assert.assertTrue(StringUtils.deleteWhitespace(xml).contains(expected), "Invalid XML resource response outcome " + xml + " .Expected \n " + expected); } catch (Throwable e) { logger.error(json, e); throw e; } } }
From source file:org.betaconceptframework.astroboa.test.model.jaxb.ContentObjectJAXBTest.java
@Test public void testFullContentObjectExport() throws Throwable { ContentObject co = createContentObjectAndPopulateAllProperties(getSystemUser(), "testFullContentObjectExport"); ((LongProperty) co.getCmsProperty("statisticTypeMultiple.viewCounter")).setSimpleTypeValue((long) 1); ((LongProperty) co.getCmsProperty("statisticType.viewCounter")).setSimpleTypeValue((long) 1); co = contentService.save(co, false, true, null); markObjectForRemoval(co);/*from w w w . jav a2s . c o m*/ ContentObjectCriteria contentObjectCriteria = CmsCriteriaFactory.newContentObjectCriteria(); contentObjectCriteria.doNotCacheResults(); contentObjectCriteria.addSystemNameEqualsCriterion("testFullContentObjectExport"); CmsOutcome<ContentObject> cmsOutcome = contentService.searchContentObjects(contentObjectCriteria, ResourceRepresentationType.CONTENT_OBJECT_LIST); for (ContentObject contentObject : cmsOutcome.getResults()) { String jsonFromApi = null; String jsonFromService = null; String xmlFromApi = null; String xmlFromService = null; try { /* * Generate XML exports from API and Service API */ xmlFromApi = contentObject.xml(false); xmlFromApi = removeWhitespacesIfNecessary(contentObjectCriteria, xmlFromApi); xmlFromService = contentService.getContentObject(contentObject.getId(), ResourceRepresentationType.XML, FetchLevel.FULL, CacheRegion.NONE, null, false); xmlFromService = removeWhitespacesIfNecessary(contentObjectCriteria, xmlFromService); String expectedProperty = "cmsIdentifier=\"" + contentObject.getId() + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object identifier " + contentObject.getId()); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object identifier " + contentObject.getId()); expectedProperty = "systemName=\"" + contentObject.getSystemName() + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object system name " + contentObject.getSystemName()); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object system name " + contentObject.getSystemName()); expectedProperty = "contentObjectTypeName=\"" + contentObject.getContentObjectType() + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object type " + contentObject.getContentObjectType()); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object type " + contentObject.getContentObjectType()); expectedProperty = "url=\"" + contentObject.getResourceApiURL(ResourceRepresentationType.XML, false, contentObject.getSystemName() != null) + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object url " + contentObject.getResourceApiURL(ResourceRepresentationType.XML, false, contentObject.getSystemName() != null)); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object url " + contentObject.getResourceApiURL(ResourceRepresentationType.XML, false, contentObject.getSystemName() != null)); expectedProperty = "<profile"; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's profile "); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's profile "); expectedProperty = "<title>" + StringUtils.deleteWhitespace( ((StringProperty) contentObject.getCmsProperty("profile.title")).getSimpleTypeValue()) + "</title>"; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's profile.title"); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's profile.title"); expectedProperty = "<created>" + convertCalendarToXMLFormat( ((CalendarProperty) contentObject.getCmsProperty("profile.created")).getSimpleTypeValue(), true) + "</created>"; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's profile.created"); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's profile.created"); expectedProperty = "<accessibility"; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's accessibility"); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's accessibility"); expectedProperty = "<canBeReadBy>" + ((StringProperty) contentObject.getCmsProperty("accessibility.canBeReadBy")) .getFirstValue() + "</canBeReadBy>"; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's accessibility.canBeReadBy"); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's accessibility.canBeReadBy"); expectedProperty = "<owner"; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object owner "); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object owner "); expectedProperty = "cmsIdentifier=\"" + contentObject.getOwner().getId() + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's owner identifier " + contentObject.getOwner().getId()); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's owner identifier " + contentObject.getOwner().getId()); expectedProperty = "externalId=\"" + contentObject.getOwner().getExternalId() + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's owner external id " + contentObject.getOwner().getExternalId()); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's owner external id " + contentObject.getOwner().getExternalId()); expectedProperty = "label=\"" + contentObject.getOwner().getLabel() + "\""; Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object's owner external id " + contentObject.getOwner().getLabel()); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object's owner external id " + contentObject.getOwner().getLabel()); for (CmsPropertyPath cmsPropertyPath : CmsPropertyPath.values()) { String propertyName = cmsPropertyPath.getPeriodDelimitedPath(); expectedProperty = "<" + PropertyPath.getLastDescendant(propertyName); Assert.assertTrue(xmlFromApi.contains(expectedProperty), "XML export from API does not contain content object property " + propertyName); Assert.assertTrue(xmlFromService.contains(expectedProperty), "XML export from Service does not contain content object property " + propertyName); } /* * Generate JSON exports from API and Service API */ jsonFromApi = contentObject.json(false); jsonFromApi = removeWhitespacesIfNecessary(contentObjectCriteria, jsonFromApi); jsonFromService = contentService.getContentObject(contentObject.getId(), ResourceRepresentationType.JSON, FetchLevel.FULL, CacheRegion.NONE, null, false); jsonFromService = removeWhitespacesIfNecessary(contentObjectCriteria, jsonFromService); expectedProperty = "\"cmsIdentifier\":\"" + contentObject.getId() + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object identifier " + contentObject.getId()); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object identifier " + contentObject.getId()); expectedProperty = "\"systemName\":\"" + contentObject.getSystemName() + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object system name " + contentObject.getSystemName()); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object system name " + contentObject.getSystemName()); expectedProperty = "\"contentObjectTypeName\":\"" + contentObject.getContentObjectType() + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object type " + contentObject.getContentObjectType()); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object type " + contentObject.getContentObjectType()); expectedProperty = "\"url\":\"" + contentObject.getResourceApiURL(ResourceRepresentationType.JSON, false, contentObject.getSystemName() != null) + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object url " + contentObject.getResourceApiURL(ResourceRepresentationType.JSON, false, contentObject.getSystemName() != null)); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object url " + contentObject.getResourceApiURL(ResourceRepresentationType.JSON, false, contentObject.getSystemName() != null)); expectedProperty = "\"profile\":{"; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's profile "); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's profile "); expectedProperty = "\"title\":\"" + StringUtils.deleteWhitespace( ((StringProperty) contentObject.getCmsProperty("profile.title")).getSimpleTypeValue()) + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's profile.title"); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's profile.title"); expectedProperty = "\"created\":\"" + convertCalendarToXMLFormat( ((CalendarProperty) contentObject.getCmsProperty("profile.created")).getSimpleTypeValue(), true) + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's profile.created"); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's profile.created"); expectedProperty = "\"accessibility\":{"; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's accessibility"); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's accessibility"); expectedProperty = "\"canBeReadBy\":[\"" + ((StringProperty) contentObject.getCmsProperty("accessibility.canBeReadBy")) .getFirstValue() + "\"]"; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's accessibility.canBeReadBy"); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's accessibility.canBeReadBy"); expectedProperty = "\"owner\":{"; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object owner "); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object owner "); expectedProperty = "\"cmsIdentifier\":\"" + contentObject.getOwner().getId() + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's owner identifier " + contentObject.getOwner().getId()); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's owner identifier " + contentObject.getOwner().getId()); expectedProperty = "\"externalId\":\"" + contentObject.getOwner().getExternalId() + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's owner external id " + contentObject.getOwner().getExternalId()); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's owner external id " + contentObject.getOwner().getExternalId()); expectedProperty = "\"label\":\"" + contentObject.getOwner().getLabel() + "\""; Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object's owner external id " + contentObject.getOwner().getLabel()); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object's owner external id " + contentObject.getOwner().getLabel()); for (CmsPropertyPath cmsPropertyPath : CmsPropertyPath.values()) { final String propertyName = cmsPropertyPath.getPeriodDelimitedPath(); expectedProperty = PropertyPath.getLastDescendant(propertyName); Assert.assertTrue(jsonFromApi.contains(expectedProperty), "JSON export from API does not contain content object property " + propertyName); Assert.assertTrue(jsonFromService.contains(expectedProperty), "JSON export from Service does not contain content object property " + propertyName); } } catch (Throwable e) { StringBuilder sb = new StringBuilder(); sb.append("JSON From API \n"); sb.append(jsonFromApi); sb.append("\nJSON From Service \n"); sb.append(jsonFromService); sb.append("\nXML From API \n"); sb.append(xmlFromApi); sb.append("\nXML From Service \n"); sb.append(xmlFromService); logger.error(sb.toString(), e); throw e; } } }
From source file:org.catechis.Scoring.java
public String applyOptions(Hashtable user_options, String text) { String grade_whitespace = (String) user_options.get("grade_whitespace"); String exclude_chars = (String) user_options.get("exclude_chars"); String exclude_area = (String) user_options.get("exclude_area"); String exclude_area_begin_char = (String) user_options.get("exclude_area_begin_char"); String exclude_area_end_char = (String) user_options.get("exclude_area_end_char"); String alternate_answer_separator = (String) user_options.get(" alternate_answer_separator"); log.add("Scoring.applyOptions: exclude_chars " + exclude_chars); if (grade_whitespace.equals("false")) { text = StringUtils.deleteWhitespace(text); }//from ww w . j a va 2 s . c o m if (exclude_area.equals("true")) { text = excludeArea(exclude_area_begin_char, exclude_area_end_char, text); } if (exclude_chars.length() > 0) { text = removeExcludeChars(text, exclude_chars); } return text; }
From source file:org.cesecore.certificates.util.Base64Test.java
@Test public void testBase64Long() throws Exception { // This one has spaces in it byte[] bytes = Base64.decode(longMsg); assertNotNull(bytes);/* w w w . ja va 2 s . co m*/ byte[] encBytes = Base64.encode(bytes, false); String str1 = new String(encBytes); String str2 = new String(longMsg); // Should not be same, str2 has blanks in it assertFalse(str1 == str2); str2 = StringUtils.deleteWhitespace(str2); // now it should be same assertEquals(str1, str2); }
From source file:org.codinjutsu.tools.mongo.view.ServerConfigurationPanel.java
private List<String> getServerUrls() { String serverUrls = serverUrlsField.getText(); if (StringUtils.isNotBlank(serverUrls)) { return Arrays.asList(StringUtils.split(StringUtils.deleteWhitespace(serverUrls), ",")); }//from w w w . java 2 s . com return null; }
From source file:org.dspace.app.cris.service.ExtendedTabService.java
public void findOtherContainablesInBoxByConfiguration(String holderName, List<IContainable> containables, String extraPrefixConfiguration) { String boxName = StringUtils.deleteWhitespace(holderName).trim().toLowerCase(); String dspaceProperty = extraPrefixConfiguration + ".containables.box." + boxName; if (cacheStructuredMetadata.containsKey(dspaceProperty)) { containables.addAll(cacheStructuredMetadata.get(dspaceProperty)); } else {// www .ja va 2 s . c o m log.debug("Get from configuration additional containables object : " + dspaceProperty); String confContainables = ConfigurationManager.getProperty(CrisConstants.CFG_MODULE, dspaceProperty); List<IContainable> tmp = new LinkedList<IContainable>(); if (confContainables != null && !confContainables.isEmpty()) { String[] listConfContainables = confContainables.split(","); for (String containable : listConfContainables) { DecoratorRestrictedField drf = new DecoratorRestrictedField(); drf.setReal(containable.trim()); extractIsMandatory(containable, drf); extractIsRepeatable(containable, drf); extractAccessLevel(containable, drf); tmp.add(drf); } containables.addAll(tmp); } cacheStructuredMetadata.put(dspaceProperty, tmp); } }
From source file:org.ebayopensource.turmeric.eclipse.ui.AbstractSOAProjectWizardPage.java
private void populiateClassifierList() { List<String> classifiers = null; final String domainName = getServiceDomain(); try {//from w ww. j a va2 s .c o m Map<String, List<String>> domainList = Collections.emptyMap(); if (getWizard() instanceof AbstractSOADomainWizard) { domainList = ((AbstractSOADomainWizard) getWizard()).getDomainList(); } classifiers = domainList.get(domainName); } catch (Exception exp) { logger.warning(exp); } if (classifiers == null || classifiers.isEmpty() == true) { //user entered domain name classifiers = new ArrayList<String>(5); String classifier = StringUtils.deleteWhitespace(domainName.toLowerCase(Locale.US)); logger.warning("Could not find corresponding classifier for the provided domain name->'", domainName, "' using the converted domain name instead->", classifier); classifiers.add(classifier); } domainClassifierList.setItems(classifiers.toArray(new String[0])); if (classifiers.isEmpty() == false) { domainClassifierList.select(0); } }
From source file:org.eclipse.jubula.client.api.converter.utils.Utils.java
/** * Translates a node to a valid java package name * @param node the category/*w w w .ja va2 s . c o m*/ * @return the translated name */ public static String translateToPackageName(INodePO node) throws InvalidNodeNameException { String name = node.getName(); name = removeInvalidCharacters(name); name = replaceUmlauts(name); name = name.toLowerCase(); name = StringUtils.deleteWhitespace(name); name = name.replaceAll("^[0-9]*", StringConstants.EMPTY); //$NON-NLS-1$ if (!PACKAGE_NAME_PATTERN.matcher(name).matches() || isInvalid(name)) { throw new InvalidNodeNameException(); } return name; }
From source file:org.eclipse.jubula.client.api.converter.utils.Utils.java
/** * Determines a valid Java class name for a given node * @param node the node// ww w .j a v a 2s .c o m * @return the class name * @throws InvalidNodeNameException if a node name cannot be translated to a Java class name */ public static String determineClassName(IPersistentObject node) throws InvalidNodeNameException { String name = node.getName(); name = removeInvalidCharacters(name); name = replaceUmlauts(name); name = WordUtils.capitalize(name); name = StringUtils.deleteWhitespace(name); name = name.replaceAll("^[0-9_]*", StringConstants.EMPTY); //$NON-NLS-1$ if (!CLASS_NAME_PATTERN.matcher(name).matches()) { throw new InvalidNodeNameException(); } return name; }
From source file:org.eclipse.mylyn.reviews.connector.ui.EmfRepositorySettingsPage.java
private void create() { FileDialog browseDialog = new FileDialog(getShell(), SWT.SAVE); String fileName = null;//from www .j a va2 s. c o m String filterPath; File currentLocation = new File(uriEditor.getText()); if (currentLocation.exists()) { String currentPath = currentLocation.getAbsolutePath(); if (currentLocation.isFile()) { filterPath = StringUtils.substringBeforeLast(currentPath, File.separator); fileName = StringUtils.substringAfterLast(currentPath, File.separator); } else { filterPath = currentPath; } } else { IPath configurationDir = ConfigurationScope.INSTANCE.getLocation(); filterPath = configurationDir.toString(); } browseDialog.setFilterPath(filterPath); if (fileName == null) { fileName = StringUtils.deleteWhitespace(labelEditor.getText()); } if (fileName != null) { browseDialog.setFileName(getQualifiedName(fileName)); } browseDialog.setFilterExtensions(getConnectorUi().getFileNameExtensions()); String browseResult = browseDialog.open(); if (browseResult != null) { File checkFile = new File(browseResult); if (checkFile.exists()) { MessageDialog dialog = new MessageDialog(getShell(), "Replace Existing?", null, checkFile.getName() + " already exists. Are you sure you want to replace it?", MessageDialog.WARNING, new String[] { "Yes", "No" }, 1); int open = dialog.open(); if (open == 1) { return; } } ResourceSet resourceSet = new ResourceSetImpl(); URI fileURI = URI.createFileURI(browseResult); Resource resource = resourceSet.createResource(fileURI); EClass eContainingClass = getConnector().getContainerClass(); EObject rootObject = eContainingClass.getEPackage().getEFactoryInstance().create(eContainingClass); if (rootObject != null) { resource.getContents().add(rootObject); rootObject.eSet(getConnector().getContentsNameAttribute(), labelEditor.getText()); Map<Object, Object> options = new HashMap<Object, Object>(); try { resource.save(options); } catch (IOException e) { StatusManager.getManager().handle( new Status(IStatus.WARNING, EmfUiPlugin.PLUGIN_ID, "Couldn't create repository.")); return; } } uriEditor.setText(browseResult); } }