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.sipfoundry.sipxconfig.bulk.ldap.UserMapper.java
private Set<String> deleteWhitespace(Set<String> values) { if (values != null) { Set<String> withoutWhitespaces = new HashSet<String>(); for (String value : values) { withoutWhitespaces.add(StringUtils.deleteWhitespace(value)); }/*from ww w. j a v a2 s . c o m*/ return withoutWhitespaces; } return null; }
From source file:org.sipfoundry.sipxconfig.firewall.FirewallConfig.java
void writeIptables(Writer w, Set<String> whiteList, Set<String> blackList, FirewallSettings settings, List<CallRateRule> rateRules, List<FirewallRule> rules, List<CustomFirewallRule> custom, List<ServerGroup> groups, List<Location> cluster, Location thisLocation) throws IOException { YamlConfiguration c = new YamlConfiguration(w); Collection<?> ips = CollectionUtils.collect(cluster, Location.GET_ADDRESS); c.write("logdropped", settings.isLogDroppedPacketsEnabled()); c.write("logdos", settings.isLogDosPacketsEnabled()); c.write("lograte", settings.isLogRatePacketsEnabled()); c.write("logregister", settings.isLogSipRegisterEnabled()); c.write("loginvite", settings.isLogSipInviteEnabled()); c.write("logack", settings.isLogSipAckEnabled()); c.write("logoptions", settings.isLogSipOptionsEnabled()); c.write("logsubscribe", settings.isLogSipSubscribeEnabled()); c.write("loglimit", settings.getLogLimitNumber()); c.write("loginterval", settings.getLogLimitInterval()); c.writeInlineArray("cluster", ips); c.startArray("chains"); for (ServerGroup group : groups) { c.nextElement();//from w w w .j a va2 s. c o m c.write(":name", group.getName()); List<String> sourceIPs = new ArrayList<String>(); String servers = group.getServerList(); if (StringUtils.isNotBlank(servers)) { sourceIPs = Arrays.asList(StringUtils.split(servers, " ")); } c.writeArray(":ipv4s", sourceIPs); } c.endArray(); c.writeArray("whitelist", whiteList); c.writeArray("blacklist", blackList); c.writeArray("deniedsip", settings.getDeniedSipUAs()); c.startArray("raterules"); for (CallRateRule rule : rateRules) { c.nextElement(); c.write(":rule", StringUtils.deleteWhitespace(rule.getName())); c.write(":startIp", rule.getStartIp()); if (rule.getEndIp() != null) { c.write(":endIp", rule.getEndIp()); } c.startArray(":limits"); for (CallRateLimit limit : rule.getCallRateLimits()) { c.nextElement(); c.write(":method", limit.getSipMethod()); c.write(":rate", limit.getRate()); c.write(":interval", limit.getInterval()); } c.endArray(); } c.endArray(); c.startArray("rules"); for (FirewallRule rule : rules) { AddressType type = rule.getAddressType(); List<Address> addresses = m_addressManager.getAddresses(type, thisLocation); if (addresses != null) { for (Address address : addresses) { // not a rule for this server if (!address.getAddress().equals(thisLocation.getAddress())) { continue; } AddressType atype = address.getType(); String id = atype.getId(); int port = address.getCanonicalPort(); // internal error if (port == 0) { LOG.error("Cannot open up port zero for service id " + id); continue; } // blindly allowed if (FirewallRule.SystemId.CLUSTER == rule.getSystemId() && rule.getServerGroup() == null) { continue; } c.write(":port", port); c.write(":protocol", atype.getProtocol()); c.write(":sip", atype.isExternalSip()); c.write(":service", id); c.write(":priority", rule.isPriority()); if (address.getEndPort() != 0) { c.write(":end_port", address.getEndPort()); } ServerGroup group = rule.getServerGroup(); String chain; if (group != null) { chain = group.getName(); } else if (rule.getSystemId() == FirewallRule.SystemId.PUBLIC) { chain = "ACCEPT"; } else { chain = rule.getSystemId().name(); } c.write(":chain", chain); c.nextElement(); } } } c.endArray(); for (FirewallTable table : FirewallTable.values()) { Collection<?> tableRules = CollectionUtils.select(custom, CustomFirewallRule.byTable(table)); if (!tableRules.isEmpty()) { c.writeArray(table.toString(), tableRules); } } }
From source file:org.sipfoundry.sipxconfig.time.NtpSettings.java
public List<SubnetInfo> getAlowedSubnetInfo() { String allowedNetworks = (String) getSettingTypedValue(ALLOWED_NETWORKS_SETTING); List<SubnetInfo> subnetInfo = new ArrayList<SubnetInfo>(); if (isProvideTimeSettingsEnabled()) { String[] networks = StringUtils.split(allowedNetworks, ","); if (networks != null) { for (String cidNetwork : networks) { try { subnetInfo.add(new SubnetUtils(StringUtils.deleteWhitespace(cidNetwork)).getInfo()); } catch (IllegalArgumentException ex) { continue; }/*from ww w. ja v a 2s. c o m*/ } } } return subnetInfo; }
From source file:org.sipfoundry.sipxconfig.tls.TlsPeerManagerImpl.java
@Override public void saveTlsPeer(TlsPeer tlsPeer) { // check if tls peer name is empty if (StringUtils.isBlank(tlsPeer.getName())) { throw new UserException("&blank.peerName.error"); }/*from w ww .j a v a 2s . c om*/ // Check for duplicate names before saving the peer if (tlsPeer.isNew() || (!tlsPeer.isNew() && isNameChanged(tlsPeer))) { checkForDuplicateName(tlsPeer); } String userName = StringUtils.deleteWhitespace(String.format(INTERNAL_NAME, tlsPeer.getName())); tlsPeer.getInternalUser().setUserName(userName); if (!tlsPeer.isNew()) { getHibernateTemplate().merge(tlsPeer); } else { getHibernateTemplate().save(tlsPeer); } }
From source file:org.sipfoundry.voicemail.mailbox.AbstractMailboxManager.java
/** * Generate the next message Id static synchronized as it's machine wide * * @param directory which holds the messageid.txt file *///from ww w . ja v a2s. com private synchronized String nextMessageId(String directory) { File midFile = new File(directory, "messageid.txt"); String messageIdFilePath = midFile.getPath(); long numericMessageId; String messageId; if (!midFile.exists()) { numericMessageId = 1; String format = m_identity + "%08d"; messageId = String.format(format, numericMessageId); numericMessageId++; try { FileUtils.writeStringToFile(midFile, String.format(format, numericMessageId)); } catch (IOException e) { LOG.error("Message::nextMessageId cannot write " + messageIdFilePath, e); throw new RuntimeException(e); } return messageId; } try { // The messageid in the file is the NEXT one messageId = FileUtils.readFileToString(midFile); numericMessageId = Long.parseLong(StringUtils.deleteWhitespace(messageId)); } catch (IOException e) { LOG.error("Message::nextMessageId cannot read " + messageIdFilePath, e); throw new RuntimeException(e); } // Increment message id, store for another day numericMessageId++; try { FileUtils.writeStringToFile(midFile, String.valueOf(numericMessageId)); } catch (IOException e) { LOG.error("Message::nextMessageId cannot write " + messageIdFilePath, e); throw new RuntimeException(e); } return messageId; }
From source file:org.sonar.api.utils.Duration.java
/** * Create a Duration from a text duration and the number of hours in a day. * <br>/*from ww w. java 2 s. c o m*/ * For instance, Duration.decode("1d 1h", 8) will have a number of minutes of 540 (1*8*60 + 60). * */ public static Duration decode(String text, int hoursInDay) { int days = 0; int hours = 0; int minutes = 0; String sanitizedText = StringUtils.deleteWhitespace(text); Pattern pattern = Pattern.compile("\\s*+(?:(\\d++)\\s*+" + DAY + ")?+\\s*+(?:(\\d++)\\s*+" + HOUR + ")?+\\s*+(?:(\\d++)\\s*+" + MINUTE + ")?+\\s*+"); Matcher matcher = pattern.matcher(text); try { if (matcher.find()) { String daysDuration = matcher.group(1); if (daysDuration != null) { days = Integer.parseInt(daysDuration); sanitizedText = sanitizedText.replace(daysDuration + DAY, ""); } String hoursText = matcher.group(2); if (hoursText != null) { hours = Integer.parseInt(hoursText); sanitizedText = sanitizedText.replace(hoursText + HOUR, ""); } String minutesText = matcher.group(3); if (minutesText != null) { minutes = Integer.parseInt(minutesText); sanitizedText = sanitizedText.replace(minutesText + MINUTE, ""); } if (sanitizedText.isEmpty()) { return new Duration(days, hours, minutes, hoursInDay); } } throw invalid(text, null); } catch (NumberFormatException e) { throw invalid(text, e); } }
From source file:org.sonar.batch.scan.DefaultProjectBootstrapper.java
@VisibleForTesting protected File initModuleWorkDir(Properties properties) { String cleanKey = StringUtils.deleteWhitespace(properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY)); cleanKey = StringUtils.replace(cleanKey, ":", "_"); return new File(rootProjectWorkDir, cleanKey); }
From source file:org.sonar.batch.util.BatchUtils.java
/** * Clean provided string to remove chars that are not valid as file name. * @param projectKey e.g. my:file/*from w w w .j a v a2 s . co m*/ */ public static String cleanKeyForFilename(String projectKey) { String cleanKey = StringUtils.deleteWhitespace(projectKey); return StringUtils.replace(cleanKey, ":", "_"); }
From source file:org.sonar.ide.eclipse.core.internal.remote.SimpleSourceCodeDiffEngine.java
/** * Returns hash code for specified string after removing whitespaces. * * @param str string//from ww w . ja va 2 s. c o m * @return hash code for specified string after removing whitespaces */ static int getHashCode(String str) { if (str == null) { return 0; } return StringUtils.deleteWhitespace(str).hashCode(); }
From source file:org.sonar.plugins.csharp.core.VisualStudioProjectBuilder.java
private void createMultiProjectStructure(ProjectDefinition root) { VisualStudioSolution currentSolution = microsoftWindowsEnvironment.getCurrentSolution(); root.resetSourceDirs();/* w w w . j av a2 s .co m*/ LOG.debug("- Root Project: {}", root.getName()); String workDir = root.getWorkDir().getAbsolutePath() .substring(root.getBaseDir().getAbsolutePath().length() + 1); microsoftWindowsEnvironment.setWorkingDirectory(workDir); Properties rootProps = enhanceRootProperties(root); for (VisualStudioProject vsProject : currentSolution.getProjects()) { String projectKey = StringUtils.substringBefore(root.getKey(), ":") + ":" + StringUtils.deleteWhitespace(vsProject.getName()); if (projectKey.equals(root.getKey())) { throw new SonarException("The solution and one of its projects have the same key ('" + projectKey + "'). Please set a unique 'sonar.projectKey' for the solution."); } ProjectDefinition subProject = ProjectDefinition.create((Properties) rootProps.clone()) .setBaseDir(vsProject.getDirectory()).setWorkDir(new File(vsProject.getDirectory(), workDir)) .setKey(projectKey).setVersion(root.getVersion()).setName(vsProject.getName()) .addContainerExtension(microsoftWindowsEnvironment); if (vsProject.isTest()) { subProject.setTestDirs("."); for (SourceFile sourceFile : vsProject.getSourceFiles()) { subProject.addTestFiles(sourceFile.getFile()); } } else { subProject.setSourceDirs("."); for (SourceFile sourceFile : vsProject.getSourceFiles()) { subProject.addSourceFiles(sourceFile.getFile()); } } LOG.debug(" - Adding Sub Project => {}", subProject.getName()); root.addSubProject(subProject); } }