diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 83285ecfe..9652347a2 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -722,6 +722,8 @@ plugin.generalconfig.ERROR_PORT_NUMBER=Wrong port number plugin.generalconfig.CHECK_FOR_UPDATES=Check for updates on startup plugin.generalconfig.STARTUP_CONFIG=Startup plugin.generalconfig.LEAVE_CHATROOM_ON_WINDOW_CLOSE=Leave chat rooms when closing window +plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS=Remove special symbols before callng phone numbers +plugin.generalconfig.SIP_CALL_CONFIG=SIP configurations # gibberish accregwizz plugin.gibberishaccregwizz.PROTOCOL_NAME=Gibberish diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index e306b00d4..6a11490f5 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -80,6 +80,8 @@ public class GuiActivator implements BundleActivator private static SmiliesReplacementService smiliesService; + private static PhoneNumberI18nService phoneNumberService; + private static AccountManager accountManager; private static List contactSources; @@ -805,6 +807,24 @@ public static SmiliesReplacementService getSmiliesReplacementSource() return smiliesService; } + /** + * Returns the PhoneNumberI18nService obtained from the bundle + * context. + * + * @return the PhoneNumberI18nService implementation obtained + * from the bundle context + */ + public static PhoneNumberI18nService getPhoneNumberService() + { + if (phoneNumberService == null) + { + phoneNumberService + = ServiceUtils.getService(bundleContext, + PhoneNumberI18nService.class); + } + return phoneNumberService; + } + /** * Returns the SecurityAuthority implementation registered to * handle security authority events. diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java index 85d789fdc..03347bb01 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java @@ -15,6 +15,7 @@ import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.main.call.*; +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.skin.*; @@ -276,7 +277,20 @@ private void updateCallIcon(MouseEvent evt) if (searchText == null) return; - searchText = GuiUtils.formatCallString(searchText); + if (ConfigurationManager.isNormalizePhoneNumber()) + { + if (!StringUtils.containsLetters(searchText) + && GuiActivator.getPhoneNumberService() + .isPhoneNumber(searchText)) + { + searchText = GuiActivator.getPhoneNumberService() + .normalize(searchText); + } + else + { + searchText = StringUtils.concatenateWords(searchText); + } + } // Show a tool tip over the call button. getComponent().setToolTipText(callString + " " + searchText); diff --git a/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java index 8f7f0253c..844e1ef9e 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java @@ -737,6 +737,19 @@ public static String getSendFileLastDir() return sendFileLastDir; } + /** + * Returns true if phone numbers should be normalized, + * false otherwise. + * + * @return true if phone numbers should be normalized, + * false otherwise. + */ + public static boolean isNormalizePhoneNumber() + { + return configService.getBoolean( + "impl.gui.NORMALIZE_PHONE_NUMBER", true); + } + /** * Sets the transparency value for all transparent windows. * diff --git a/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java b/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java index d2e526d4c..6ff5a8ccf 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java +++ b/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java @@ -88,4 +88,40 @@ public boolean phoneNumbersMatch(String aPhoneNumber, String bPhoneNumber) throw new IllegalArgumentException(npex); } } + + public boolean isNumber(String possibleNumber) + { + PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance(); + try + { + if (numberUtil.isPossibleNumber(possibleNumber, null)) + return true; + else + return numberUtil.isPossibleNumber( + numberUtil.parse( possibleNumber, + Locale.getDefault().getCountry())); + } + catch (NumberParseException e) + { + return false; + } + } + + public boolean isPhoneNumber(String possibleNumber) + { + PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance(); + try + { + if (numberUtil.isPossibleNumber(possibleNumber, null)) + return true; + else + return numberUtil.isPossibleNumber( + numberUtil.parse( possibleNumber, + Locale.getDefault().getCountry())); + } + catch (NumberParseException e) + { + return false; + } + } } diff --git a/src/net/java/sip/communicator/plugin/generalconfig/ConfigurationManager.java b/src/net/java/sip/communicator/plugin/generalconfig/ConfigurationManager.java index fb7774d2b..3fc5a999a 100644 --- a/src/net/java/sip/communicator/plugin/generalconfig/ConfigurationManager.java +++ b/src/net/java/sip/communicator/plugin/generalconfig/ConfigurationManager.java @@ -15,32 +15,37 @@ public class ConfigurationManager { public static final String ENTER_COMMAND = "Enter"; - + public static final String CTRL_ENTER_COMMAND = "Ctrl-Enter"; - + /** * Indicates whether the message automatic popup is enabled. */ private static boolean autoPopupNewMessage; - + private static String sendMessageCommand; - + private static boolean isSendTypingNotifications; - + private static boolean isMultiChatWindowEnabled; private static boolean isLeaveChatRoomOnWindowCloseEnabled; - + private static boolean isHistoryLoggingEnabled; - + private static boolean isHistoryShown; - + private static int chatHistorySize; - + private static int windowTransparency; - + private static boolean isTransparentWindowEnabled; + /** + * Indicates if phone numbers should be normalized before dialed. + */ + private static boolean isNormalizePhoneNumber; + private static ConfigurationService configService = GeneralConfigPluginActivator.getConfigurationService(); @@ -52,12 +57,12 @@ public static void loadGuiConfigurations() // Load the "auPopupNewMessage" property. String autoPopupProperty = "service.gui.AUTO_POPUP_NEW_MESSAGE"; - + String autoPopup = configService.getString(autoPopupProperty); if(autoPopup == null) autoPopup = Resources.getSettingsString(autoPopupProperty); - + if(autoPopup != null && autoPopup.equalsIgnoreCase("yes")) autoPopupNewMessage = true; @@ -65,7 +70,7 @@ public static void loadGuiConfigurations() String messageCommandProperty = "service.gui.SEND_MESSAGE_COMMAND"; String messageCommand = configService.getString(messageCommandProperty); - + if(messageCommand == null) messageCommand = Resources.getSettingsString(messageCommandProperty); @@ -134,11 +139,11 @@ public static void loadGuiConfigurations() // Load the "isHistoryLoggingEnabled" property. String isHistoryLoggingEnabledPropertyString = "impl.msghistory.IS_MESSAGE_HISTORY_ENABLED"; - + String isHistoryLoggingEnabledString = configService.getString( isHistoryLoggingEnabledPropertyString); - + if(isHistoryLoggingEnabledString == null) isHistoryLoggingEnabledString = Resources. @@ -151,14 +156,14 @@ public static void loadGuiConfigurations() = new Boolean(isHistoryLoggingEnabledString) .booleanValue(); } - + // Load the "isHistoryShown" property. String isHistoryShownStringProperty = "service.gui.IS_MESSAGE_HISTORY_SHOWN"; - + String isHistoryShownString = configService.getString(isHistoryShownStringProperty); - + if(isHistoryShownString == null) isHistoryShownString = Resources.getSettingsString(isHistoryShownStringProperty); @@ -223,6 +228,14 @@ public static void loadGuiConfigurations() windowTransparency = Integer.parseInt(windowTransparencyString); } + + // Load the "NORMALIZE_PHONE_NUMBER" property. + String normalizePhoneNumberProperty = + "impl.gui.NORMALIZE_PHONE_NUMBER"; + + isNormalizePhoneNumber + = GeneralConfigPluginActivator.getConfigurationService() + .getBoolean(normalizePhoneNumberProperty, true); } /** @@ -364,6 +377,32 @@ public static void setTransparentWindowEnabled( new Boolean(isTransparentWindowEnabled).toString()); } + /** + * Returns true if phone numbers should be normalized, + * false otherwise. + * + * @return true if phone numbers should be normalized, + * false otherwise. + */ + public static boolean isNormalizePhoneNumber() + { + return isNormalizePhoneNumber; + } + + /** + * Updates the "NORMALIZE_PHONE_NUMBER" property. + * + * @param isNormalize indicates to the user interface whether all dialed + * phone numbers should be normalized + */ + public static void setNormalizePhoneNumber(boolean isNormalize) + { + ConfigurationManager.isNormalizePhoneNumber = isNormalize; + + configService.setProperty("impl.gui.NORMALIZE_PHONE_NUMBER", + Boolean.toString(isNormalize)); + } + /** * Returns the transparency value for all transparent windows. * @@ -374,6 +413,12 @@ public static int getWindowTransparency() return windowTransparency; } + /** + * Updates the "WINDOW_TRANSPARENCY" property. + * + * @param windowTransparency indicates to the user interface what is the + * window transparency value + **/ public static void setWindowTransparency(int windowTransparency) { ConfigurationManager.windowTransparency = windowTransparency; diff --git a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java index ae3f2459b..c1784f24b 100644 --- a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java +++ b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java @@ -102,13 +102,27 @@ public void start(BundleContext bc) .registerService( ConfigurationForm.class.getName(), new LazyConfigurationForm( - "net.java.sip.communicator.plugin.generalconfig.GeneralConfigurationPanel", + "net.java.sip.communicator.plugin." + + "generalconfig.GeneralConfigurationPanel", getClass().getClassLoader(), "plugin.generalconfig.PLUGIN_ICON", "service.gui.GENERAL", 0), properties); + // Registers the sip config panel as advanced configuration form. + properties.put( ConfigurationForm.FORM_TYPE, + ConfigurationForm.ADVANCED_TYPE); + bundleContext.registerService( + ConfigurationForm.class.getName(), + new LazyConfigurationForm( + SIPConfigForm.class.getName(), + getClass().getClassLoader(), + null, + "plugin.generalconfig.SIP_CALL_CONFIG", + 51, true), + properties); + /* * Wait for the first ProtocolProviderService to register in order to * start the auto-away functionality i.e. to call #startThread(). diff --git a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java index 45441b4d4..d913ba633 100644 --- a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java +++ b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java @@ -79,7 +79,7 @@ public GeneralConfigurationPanel() mainPanel.add(new JSeparator()); mainPanel.add(Box.createVerticalStrut(10)); - mainPanel.add(createSipConfigPanel()); + mainPanel.add(createCallConfigPanel()); mainPanel.add(Box.createVerticalStrut(10)); } @@ -596,10 +596,11 @@ public void actionPerformed(ActionEvent e) } /** - * Initializes the sip port configuration panel. - * @return the created panel + * Creates the call configuration panel. + * + * @return the call configuration panel */ - private Component createSipConfigPanel() + private Component createCallConfigPanel() { JPanel callConfigPanel = new TransparentPanel(new BorderLayout()); @@ -608,120 +609,51 @@ private Component createSipConfigPanel() Resources.getString("service.gui.CALL") + ":"), BorderLayout.WEST); - TransparentPanel sipClientPortConfigPanel = new TransparentPanel(); - sipClientPortConfigPanel.setLayout(new BorderLayout(10, 10)); - sipClientPortConfigPanel.setPreferredSize(new Dimension(250, 72)); + callConfigPanel.add(createNormalizeNumberCheckBox()); - callConfigPanel.add(sipClientPortConfigPanel); + return callConfigPanel; + } - TransparentPanel labelPanel - = new TransparentPanel(new GridLayout(0, 1, 2, 2)); - TransparentPanel valuePanel - = new TransparentPanel(new GridLayout(0, 1, 2, 2)); + /** + * Creates the normalized phone number check box. + * + * @return the created component + */ + private Component createNormalizeNumberCheckBox() + { + JPanel checkBoxPanel = new TransparentPanel(new BorderLayout()); - sipClientPortConfigPanel.add(labelPanel, - BorderLayout.WEST); - sipClientPortConfigPanel.add(valuePanel, - BorderLayout.CENTER); + JCheckBox formatPhoneNumber = new JCheckBox("", + ConfigurationManager.isNormalizePhoneNumber()); - labelPanel.add(new JLabel( - Resources.getString( - "plugin.generalconfig.SIP_CLIENT_PORT"))); - labelPanel.add(new JLabel( - Resources.getString( - "plugin.generalconfig.SIP_CLIENT_SECURE_PORT"))); + formatPhoneNumber.setAlignmentY(Component.TOP_ALIGNMENT); - TransparentPanel emptyPanel = new TransparentPanel(); - emptyPanel.setMaximumSize(new Dimension(40, 35)); - labelPanel.add(emptyPanel); - - final JTextField clientPortField = new JTextField(6); - clientPortField.setText( - String.valueOf(ConfigurationManager.getClientPort())); - valuePanel.add(clientPortField); - clientPortField.addFocusListener(new FocusListener() + formatPhoneNumber.addActionListener(new ActionListener() { - private String oldValue = null; - - public void focusLost(FocusEvent e) - { - try - { - int port = - Integer.valueOf(clientPortField.getText()); - - if(port <= 0 || port > 65535) - throw new NumberFormatException( - "Not a port number"); - - ConfigurationManager.setClientPort(port); - } - catch (NumberFormatException ex) - { - // not a number for port - String error = - Resources.getString( - "plugin.generalconfig.ERROR_PORT_NUMBER"); - GeneralConfigPluginActivator.getUIService(). - getPopupDialog().showMessagePopupDialog( - error, - error, - PopupDialog.ERROR_MESSAGE); - clientPortField.setText(oldValue); - } - } - - public void focusGained(FocusEvent e) + public void actionPerformed(ActionEvent e) { - oldValue = clientPortField.getText(); + ConfigurationManager.setNormalizePhoneNumber( + ((JCheckBox)e.getSource()).isSelected()); } }); - final JTextField clientSecurePortField = new JTextField(6); - clientSecurePortField.setText( - String.valueOf(ConfigurationManager.getClientSecurePort())); - valuePanel.add(clientSecurePortField); - clientSecurePortField.addFocusListener(new FocusListener() - { - private String oldValue = null; - - public void focusLost(FocusEvent e) - { - try - { - int port = - Integer.valueOf(clientSecurePortField.getText()); + StyledHTMLEditorPane checkBoxTextLabel = new StyledHTMLEditorPane(); - if(port <= 0 || port > 65535) - throw new NumberFormatException( - "Not a port number"); + checkBoxTextLabel.setContentType("text/html"); + checkBoxTextLabel.appendToEnd( + "" + GeneralConfigPluginActivator.getResources().getI18NString( + "plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS") + ""); - ConfigurationManager.setClientSecurePort(port); - } - catch (NumberFormatException ex) - { - // not a number for port - String error = - Resources.getString( - "plugin.generalconfig.ERROR_PORT_NUMBER"); - GeneralConfigPluginActivator.getUIService(). - getPopupDialog().showMessagePopupDialog( - error, - error, - PopupDialog.ERROR_MESSAGE); - clientSecurePortField.setText(oldValue); - } - } + checkBoxTextLabel.setBorder( + BorderFactory.createEmptyBorder(3, 0, 0, 0)); + checkBoxTextLabel.setOpaque(false); + checkBoxTextLabel.setEditable(false); - public void focusGained(FocusEvent e) - { - oldValue = clientSecurePortField.getText(); - } - }); + checkBoxPanel.add(formatPhoneNumber, BorderLayout.WEST); + checkBoxPanel.add(checkBoxTextLabel, BorderLayout.CENTER); - return callConfigPanel; + return checkBoxPanel; } - /** * Initializes the startup config panel. * @return the created component diff --git a/src/net/java/sip/communicator/plugin/generalconfig/SIPConfigForm.java b/src/net/java/sip/communicator/plugin/generalconfig/SIPConfigForm.java new file mode 100644 index 000000000..110320ba1 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/generalconfig/SIPConfigForm.java @@ -0,0 +1,138 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.generalconfig; + +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.util.swing.*; + +/** + * Implementation of the configuration form. + * + * @author Damian Minkov + */ +public class SIPConfigForm + extends TransparentPanel +{ + /** + * Creates the form. + */ + public SIPConfigForm() + { + super(new BorderLayout()); + + TransparentPanel sipClientPortConfigPanel = new TransparentPanel(); + sipClientPortConfigPanel.setLayout(new BorderLayout(10, 10)); + sipClientPortConfigPanel.setPreferredSize(new Dimension(250, 72)); + + add(sipClientPortConfigPanel, BorderLayout.NORTH); + + TransparentPanel labelPanel + = new TransparentPanel(new GridLayout(0, 1, 2, 2)); + TransparentPanel valuePanel + = new TransparentPanel(new GridLayout(0, 1, 2, 2)); + + sipClientPortConfigPanel.add(labelPanel, + BorderLayout.WEST); + sipClientPortConfigPanel.add(valuePanel, + BorderLayout.CENTER); + + labelPanel.add(new JLabel( + Resources.getString( + "plugin.generalconfig.SIP_CLIENT_PORT"))); + labelPanel.add(new JLabel( + Resources.getString( + "plugin.generalconfig.SIP_CLIENT_SECURE_PORT"))); + + final JTextField clientPortField = new JTextField(6); + clientPortField.setText( + String.valueOf(ConfigurationManager.getClientPort())); + valuePanel.add(clientPortField); + clientPortField.addFocusListener(new FocusListener() + { + private String oldValue = null; + + public void focusLost(FocusEvent e) + { + try + { + int port = + Integer.valueOf(clientPortField.getText()); + + if(port <= 0 || port > 65535) + throw new NumberFormatException( + "Not a port number"); + + ConfigurationManager.setClientPort(port); + } + catch (NumberFormatException ex) + { + // not a number for port + String error = + Resources.getString( + "plugin.generalconfig.ERROR_PORT_NUMBER"); + GeneralConfigPluginActivator.getUIService(). + getPopupDialog().showMessagePopupDialog( + error, + error, + PopupDialog.ERROR_MESSAGE); + clientPortField.setText(oldValue); + } + } + + public void focusGained(FocusEvent e) + { + oldValue = clientPortField.getText(); + } + }); + + final JTextField clientSecurePortField = new JTextField(6); + clientSecurePortField.setText( + String.valueOf(ConfigurationManager.getClientSecurePort())); + valuePanel.add(clientSecurePortField); + clientSecurePortField.addFocusListener(new FocusListener() + { + private String oldValue = null; + + public void focusLost(FocusEvent e) + { + try + { + int port + = Integer.valueOf(clientSecurePortField.getText()); + + if(port <= 0 || port > 65535) + throw new NumberFormatException( + "Not a port number"); + + ConfigurationManager.setClientSecurePort(port); + } + catch (NumberFormatException ex) + { + // not a number for port + String error = + Resources.getString( + "plugin.generalconfig.ERROR_PORT_NUMBER"); + GeneralConfigPluginActivator.getUIService(). + getPopupDialog().showMessagePopupDialog( + error, + error, + PopupDialog.ERROR_MESSAGE); + clientSecurePortField.setText(oldValue); + } + } + + public void focusGained(FocusEvent e) + { + oldValue = clientSecurePortField.getText(); + } + }); + } +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java b/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java index ae230943c..0e4d43e29 100644 --- a/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java +++ b/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java @@ -37,4 +37,12 @@ public interface PhoneNumberI18nService * numbers; otherwise, false */ public boolean phoneNumbersMatch(String aPhoneNumber, String bPhoneNumber); + + /** + * Indicates if the given string is possibly a phone number. + * + * @param possibleNumber the string to be verified + * @return + */ + public boolean isPhoneNumber(String possibleNumber); } diff --git a/src/net/java/sip/communicator/util/GuiUtils.java b/src/net/java/sip/communicator/util/GuiUtils.java index e451bb70a..e9e4d97bb 100644 --- a/src/net/java/sip/communicator/util/GuiUtils.java +++ b/src/net/java/sip/communicator/util/GuiUtils.java @@ -327,60 +327,6 @@ public static String formatTime(long time) return timeStrBuf.toString(); } - /** - * Formats the given call string by removing any special characters, such as - * intervals and brackets. Dashes are removed from number only strings. - * - * @param callString a string that would be called - * @return the formatted string, ready to be called - */ - public static String formatCallString(String callString) - { - boolean isDigitsOnly = isDigitsOnly(callString); - - StringBuffer normalizedCallString - = new StringBuffer(callString.length()); - char[] stringAsCharArray = callString.toCharArray(); - - for (char character : stringAsCharArray) - { - if ((character != ' ' - && character != '(' - && character != ')') - && (!isDigitsOnly || character != '-')) - { - normalizedCallString.append(character); - } - } - - return normalizedCallString.toString(); - } - - /** - * Indicates if the given string contains only digits. - * - * @param s the string to verify - * @return true if the given string contains only digits or - * false if the string contains also other characters - */ - public static boolean isDigitsOnly(String s) - { - char[] stringAsCharArray = s.toCharArray(); - - boolean digitsOnly = true; - for (char character : stringAsCharArray) - { - if (character != ' ' - && character != '(' - && character != ')' - && character != '-' - && DIGIT_MAPPINGS.get(Character.toUpperCase(character)) == null) - digitsOnly = false; - } - - return digitsOnly; - } - /** * Subtracts the two dates. * @param date1 the first date argument diff --git a/src/net/java/sip/communicator/util/StringUtils.java b/src/net/java/sip/communicator/util/StringUtils.java index 6d903b470..a4f4024ac 100644 --- a/src/net/java/sip/communicator/util/StringUtils.java +++ b/src/net/java/sip/communicator/util/StringUtils.java @@ -7,7 +7,6 @@ package net.java.sip.communicator.util; import java.io.*; -import java.util.*; /** * Utility class that helps to work with String class. @@ -195,4 +194,44 @@ public static boolean isNumber(String string) return true; } + + /** + * Indicates if the given string contains any letters. + * + * @param string the string to check for letters + * @return true if the given string contains letters, + * false - otherwise + */ + public static boolean containsLetters(String string) + { + for (int i = 0; i < string.length(); i++) + { + if (Character.isLetter(string.charAt(i))) + return true; + } + + return false; + } + + /** + * Removes all spaces from the given string and returns a concatenated + * result string. + * + * @param string the string to concatenate + * @return the concatenated string + */ + public static String concatenateWords(String string) + { + StringBuffer buff = new StringBuffer(); + char[] stringAsCharArray = string.toCharArray(); + + for (char character : stringAsCharArray) + { + if (character != ' ') + { + buff.append(character); + } + } + return buff.toString(); + } }