1 19 20 21 package org.netbeans.modules.i18n; 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.ResourceBundle ; 26 27 28 import org.openide.loaders.DataFolder; 29 import org.openide.loaders.DataObject; 30 import org.openide.util.NbBundle; 31 import org.openide.util.SharedClassObject; 32 import org.netbeans.api.queries.VisibilityQuery; 33 34 39 public final class I18nUtil { 40 41 42 public static final String HELP_ID_I18N = "internation.internation"; 44 public static final String HELP_ID_AUTOINSERT = "internation.autoinsert"; 46 public static final String HELP_ID_MANINSERT = "internation.maninsert"; 48 public static final String HELP_ID_FORMED = "internation.formed"; 50 public static final String HELP_ID_TESTING = "internation.testing"; 52 public static final String HELP_ID_WIZARD = "internation.wizard"; 54 public static final String HELP_ID_CUSTOM = "internation.custom"; 56 public static final String HELP_ID_ADDPARAMS = "internation.addparams"; 58 public static final String HELP_ID_REPLFORMAT = "internation.replformat"; 60 public static final String HELP_ID_RUNLOCALE = "internation.runlocale"; 62 63 public static final String PE_REPLACE_CODE_HELP_ID = "i18n.pe.replacestring"; 65 public static final String PE_I18N_REGEXP_HELP_ID = "i18n.pe.i18nregexp"; 67 public static final String PE_BUNDLE_CODE_HELP_ID = "i18n.pe.bundlestring"; 69 public static final String PE_TEST_REGEXP_HELP_ID = "i18n.pe.testregexp"; 71 public static final String PE_I18N_STRING_HELP_ID = "i18n.pe.i18nString"; 73 74 75 private static List initFormatItems; 76 77 78 private static List initHelpItems; 79 80 81 private static List replaceFormatItems; 82 83 84 private static List replaceHelpItems; 85 86 87 private static List regExpItems; 88 89 90 private static List regExpHelpItems; 91 92 93 private static List i18nRegExpItems; 94 95 96 public static List getInitFormatItems() { 97 if(initFormatItems == null) { 98 initFormatItems = new ArrayList (2); 99 initFormatItems.add("java.util.ResourceBundle.getBundle(\"{bundleNameSlashes}\")"); initFormatItems.add("org.openide.util.NbBundle.getBundle({sourceFileName}.class)"); } 102 103 return initFormatItems; 104 } 105 106 107 public static List getInitHelpItems() { 108 if(initHelpItems == null) { 109 ResourceBundle bundle = getBundle(); 110 initHelpItems = new ArrayList (3); 111 initHelpItems.add("{bundleNameSlashes} - "+ bundle.getString("TXT_PackageNameSlashes")); initHelpItems.add("{bundleNameDots} - " + bundle.getString("TXT_PackageNameDots")); initHelpItems.add("{sourceFileName} - " + bundle.getString("TXT_SourceDataObjectName")); } 115 116 return initHelpItems; 117 } 118 119 120 public static List getReplaceFormatItems() { 121 if(replaceFormatItems == null) { 122 replaceFormatItems = new ArrayList (7); 123 replaceFormatItems.add("{identifier}.getString(\"{key}\")"); replaceFormatItems.add("Utilities.getString(\"{key}\")"); replaceFormatItems.add("java.util.ResourceBundle.getBundle(\"{bundleNameSlashes}\").getString(\"{key}\")"); replaceFormatItems.add("org.openide.util.NbBundle.getBundle({sourceFileName}.class).getString(\"{key}\")"); replaceFormatItems.add("java.text.MessageFormat.format(java.util.ResourceBundle.getBundle(\"{bundleNameSlashes}\").getString(\"{key}\"), {arguments})"); replaceFormatItems.add("org.openide.util.NbBundle.getMessage({sourceFileName}.class, \"{key}\")"); replaceFormatItems.add("org.openide.util.NbBundle.getMessage({sourceFileName}.class, \"{key}\", {arguments})"); } 131 132 return replaceFormatItems; 133 } 134 135 138 public static String getDefaultReplaceFormat(boolean nbProject) { 139 return (String ) getReplaceFormatItems().get(nbProject ? 5 : 2); 140 } 141 142 143 public static List getReplaceHelpItems() { 144 if(replaceHelpItems == null) { 145 ResourceBundle bundle = getBundle(); 146 replaceHelpItems = new ArrayList (6); 147 replaceHelpItems.add("{identifier} - " + bundle.getString("TXT_FieldIdentifier")); replaceHelpItems.add("{key} - " + bundle.getString("TXT_KeyHelp")); replaceHelpItems.add("{bundleNameSlashes} - " + bundle.getString("TXT_PackageNameSlashes")); replaceHelpItems.add("{bundleNameDots} - " + bundle.getString("TXT_PackageNameDots")); replaceHelpItems.add("{sourceFileName} - " + bundle.getString("TXT_SourceDataObjectName")); replaceHelpItems.add("{arguments} - " + bundle.getString("TXT_Arguments")); } 154 155 return replaceHelpItems; 156 } 157 158 159 public static List getRegExpItems() { 160 if(regExpItems == null) { 161 regExpItems = new ArrayList (4); 162 regExpItems.add("(getString|getBundle)[:space:]*\\([:space:]*{hardString}|// *NOI18N"); regExpItems.add("(getString|getBundle)[:space:]*\\([:space:]*{hardString}"); regExpItems.add("// *NOI18N"); regExpItems.add("(getString|getBundle)[:space:]*\\([:space:]*|getMessage[:space:]*\\(([:alnum:]|[:punct:]|[:space:])*,[:space:]*{hardString}|// *NOI18N"); } 167 168 return regExpItems; 169 } 170 171 172 public static List getI18nRegExpItems() { 173 if(i18nRegExpItems == null) { 174 i18nRegExpItems = new ArrayList (2); 175 i18nRegExpItems.add("getString[:space:]*\\([:space:]*{hardString}"); i18nRegExpItems.add("(getString[:space:]*\\([:space:]*|getMessage[:space:]*\\(([:alnum:]|[:punct:]|[:space:])*,[:space:]*){hardString}"); } 178 179 return i18nRegExpItems; 180 } 181 182 183 public static List getRegExpHelpItems() { 184 if(regExpHelpItems == null) { 185 ResourceBundle bundle = getBundle(); 186 regExpHelpItems = new ArrayList (13); 187 regExpHelpItems.add("{hardString} - " + bundle.getString("TXT_HardString")); regExpHelpItems.add("[:alnum:] - " + bundle.getString("TXT_Alnum")); regExpHelpItems.add("[:alpha:] - " + bundle.getString("TXT_Alpha")); regExpHelpItems.add("[:blank:] - " + bundle.getString("TXT_Blank")); regExpHelpItems.add("[:cntrl:] - " + bundle.getString("TXT_Cntrl")); regExpHelpItems.add("[:digit:] - " + bundle.getString("TXT_Digit")); regExpHelpItems.add("[:graph:] - " + bundle.getString("TXT_Graph")); regExpHelpItems.add("[:lower:] - " + bundle.getString("TXT_Lower")); regExpHelpItems.add("[:print:] - " + bundle.getString("TXT_Print")); regExpHelpItems.add("[:punct:] - " + bundle.getString("TXT_Punct")); regExpHelpItems.add("[:space:] - " + bundle.getString("TXT_Space")); regExpHelpItems.add("[:upper:] - " + bundle.getString("TXT_Upper")); regExpHelpItems.add("[:xdigit:] - " + bundle.getString("TXT_Xdigit")); } 203 204 return regExpHelpItems; 205 } 206 207 211 public static boolean containsAcceptedDataObject(DataFolder folder) { 212 DataObject[] children = folder.getChildren(); 213 DataObject[] folders = new DataObject[children.length]; 214 int i, foldersCount = 0; 215 216 for (i = 0; i < children.length; i++) { 217 if (children[i] instanceof DataFolder) { 218 folders[foldersCount++] = children[i]; 219 } else if (FactoryRegistry.hasFactory(children[i].getClass())) { 220 return true; 221 } 222 } 223 for (i = 0; i < foldersCount; i++) { 224 if (containsAcceptedDataObject((DataFolder) children[i])) { 225 return true; 226 } 227 } 228 return false; 229 } 230 231 234 public static List getAcceptedDataObjects(DataObject.Container folder) { 235 List accepted = new ArrayList (); 236 237 final VisibilityQuery visQuery = VisibilityQuery.getDefault(); 238 239 DataObject[] children = folder.getChildren(); 240 241 for(int i = 0; i < children.length; i++) { 242 if (!visQuery.isVisible(children[i].getPrimaryFile())) { 243 continue; 244 } 245 if(children[i] instanceof DataObject.Container) { 246 accepted.addAll(getAcceptedDataObjects((DataObject.Container)children[i])); 247 } else { 248 if(FactoryRegistry.hasFactory(children[i].getClass())) 249 accepted.add(children[i]); 250 } 251 } 252 253 return accepted; 254 } 255 256 257 public static ResourceBundle getBundle() { 258 return NbBundle.getBundle(I18nUtil.class); 259 } 260 261 262 public static I18nOptions getOptions() { 263 return I18nOptions.getDefault(); 264 } 265 266 267 } 268 | Popular Tags |