KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > actions > ActionUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.ui.actions;
21
22 /**
23  *
24  * @author Petr Kuzel
25  */

26 public final class ActionUtils {
27
28     private ActionUtils() {
29     }
30
31     /**
32      * Removes an ampersand from a text string; commonly used to strip out unneeded mnemonics.
33      * Replaces the first occurence of <samp>&amp;?</samp> by <samp>?</samp> or <samp>(&amp;??</samp> by the empty string
34      * where <samp>?</samp> is a wildcard for any character.
35      * <samp>&amp;?</samp> is a shortcut in English locale.
36      * <samp>(&amp;?)</samp> is a shortcut in Japanese locale.
37      * Used to remove shortcuts from workspace names (or similar) when shortcuts are not supported.
38      * <p>The current implementation behaves in the same way regardless of locale.
39      * In case of a conflict it would be necessary to change the
40      * behavior based on the current locale.
41      * @param text a localized label that may have mnemonic information in it
42      * @return string without first <samp>&amp;</samp> if there was any
43      */

44     public static String JavaDoc cutAmpersand(String JavaDoc text) {
45         // => need API request should be filled.
46
int i;
47         String JavaDoc result = text;
48
49         /* First check of occurence of '(&'. If not found check
50           * for '&' itself.
51           * If '(&' is found then remove '(&??'.
52           */

53         i = text.indexOf("(&"); // NOI18N
54

55         if ((i >= 0) && ((i + 3) < text.length()) && /* #31093 */
56                 (text.charAt(i + 3) == ')')) { // NOI18N
57
result = text.substring(0, i) + text.substring(i + 4);
58         } else {
59             //Sequence '(&?)' not found look for '&' itself
60
i = text.indexOf('&');
61
62             if (i < 0) {
63                 //No ampersand
64
result = text;
65             } else if (i == (text.length() - 1)) {
66                 //Ampersand is last character, wrong shortcut but we remove it anyway
67
result = text.substring(0, i);
68             } else {
69                 //Remove ampersand from middle of string
70
//Is ampersand followed by space? If yes do not remove it.
71
if (" ".equals(text.substring(i + 1, i + 2))) { // NOI18N
72
result = text;
73                 } else {
74                     result = text.substring(0, i) + text.substring(i + 1);
75                 }
76             }
77         }
78
79         return result;
80     }
81     
82 }
83
Popular Tags