Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common
  * Development and Distribution License("CDDL") (collectively, the
  * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * Contributor(s):
  *
  * The Original Software is NetBeans. The Initial Developer of the Original
  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  * Microsystems, Inc. All Rights Reserved.
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
 
 
 package org.netbeans.modules.i18n;
 
 import java.util.List;
Utilities class for I18N module.

Author(s):
Peter Zavadsky
 
 public final class I18nUtil {

    
Help ID for i18n module in general.
 
     public static final String HELP_ID_I18N = "internation.internation"// NOI18N
     
Help ID for I18N dialog.
 
     public static final String HELP_ID_AUTOINSERT = "internation.autoinsert"// NOI18N
     
Help ID for Insert I18N dialog.
 
     public static final String HELP_ID_MANINSERT = "internation.maninsert"// NOI18N
     
Help ID for I18N form property editor. You can see it in Component inspector.
 
     public static final String HELP_ID_FORMED = "internation.formed"// NOI18N
     
Help ID for I18N test wizard.
 
     public static final String HELP_ID_TESTING = "internation.testing"// NOI18N
     
Help ID for I18N wizard.
 
     public static final String HELP_ID_WIZARD = "internation.wizard"// NOI18N
     
Help ID for I18N options.
 
     public static final String HELP_ID_CUSTOM = "internation.custom"// NOI18N
     
Help ID for parameters dialog.
 
     public static final String HELP_ID_ADDPARAMS = "internation.addparams"// NOI18N
     
Help ID for replacing format.
 
     public static final String HELP_ID_REPLFORMAT = "internation.replformat"// NOI18N
     
Help ID for Locale execution.
 
     public static final String HELP_ID_RUNLOCALE = "internation.runlocale"// NOI18N
     
    
Help ID for property editor
 
     public static final String PE_REPLACE_CODE_HELP_ID = "i18n.pe.replacestring"// NOI18N
     
Help ID for property editor
 
     public static final String PE_I18N_REGEXP_HELP_ID = "i18n.pe.i18nregexp";   // NOI18N
     
Help ID for property editor
 
     public static final String PE_BUNDLE_CODE_HELP_ID = "i18n.pe.bundlestring"// NOI18N
     
Help ID for property editor
 
     public static final String PE_TEST_REGEXP_HELP_ID = "i18n.pe.testregexp";   // NOI18N
     
Help ID for javaI18nString. It is a universal one for all subclasses.
 
     public static final String PE_I18N_STRING_HELP_ID = "i18n.pe.i18nString";   // NOI18N
 
     private static final String DEFAULT_STANDARD_REPLACE_FORMAT = "java.util.ResourceBundle.getBundle(\"{bundleNameSlashes}\").getString(\"{key}\")"// NOI18N
     private static final String DEFAULT_NETBEANS_REPLACE_FORMAT = "org.openide.util.NbBundle.getMessage({sourceFileName}.class, \"{key}\")"// NOI18N
    
    
Items for init format customizer.
 
     private static List<StringinitFormatItems;

    
Help description for init format customizer.
    private static List<StringinitHelpItems;

    
Items for replace format customizer.
    private static List<StringreplaceFormatItems;

    
Help description for replace format customizer.
    private static List<StringreplaceHelpItems;

    
Items for regular expression customizer.
    private static List<StringregExpItems;

    
Help description for regular expression customizer.
    private static List<StringregExpHelpItems;
    
    
Items for i18n regular expression customizer.
    private static List<Stringi18nRegExpItems;

    
Gets initFormatItems.
    public static List<StringgetInitFormatItems() { 
        if( == null) {
             = new ArrayList<String>(2);
            .add("java.util.ResourceBundle.getBundle(\"{bundleNameSlashes}\")"); // NOI18N
            .add("org.openide.util.NbBundle.getBundle({sourceFileName}.class)"); // NOI18N
        }
              
        return ;
    }

    
Gets InitHelpFormats.
    public static List<StringgetInitHelpItems() {
        if( == null) {
            ResourceBundle bundle = getBundle();
             = new ArrayList<String>(3);
            .add(bundle.getString("TXT_PackageNameSlashes")); // NOI18N
            .add(bundle.getString("TXT_PackageNameDots")); // NOI18N
            .add(bundle.getString("TXT_SourceDataObjectName")); // NOI18N
        }
         
        return ;
    }

    
Gets replaceFormatItems.
    public static List<StringgetReplaceFormatItems() {
        if( == null) {
             = new ArrayList<String>(7);
            .add("{identifier}.getString(\"{key}\")"); // NOI18N
            .add("Utilities.getString(\"{key}\")"); // NOI18N
            .add("org.openide.util.NbBundle.getBundle({sourceFileName}.class).getString(\"{key}\")"); // NOI18N
            .add("java.text.MessageFormat.format(java.util.ResourceBundle.getBundle(\"{bundleNameSlashes}\").getString(\"{key}\"), {arguments})"); // NOI18N
            .add("org.openide.util.NbBundle.getMessage({sourceFileName}.class, \"{key}\", {arguments})"); // NOI18N
        }
            
        return ;
    }

    
Gets default replace format - based on whether the project type is a NB module project or not. (Module projects use NbBundle preferentially.)
    public static String getDefaultReplaceFormat(boolean nbProject) {
        return nbProject ?  : ;
    }

    
Gets replaceHeplItems
    public static List<StringgetReplaceHelpItems() {
        if( == null) {
            ResourceBundle bundle = getBundle();
             = new ArrayList<String>(6);
            .add(bundle.getString("TXT_FieldIdentifier")); // NOI18N
            .add(bundle.getString("TXT_KeyHelp")); // NOI18N
            .add(bundle.getString("TXT_PackageNameSlashes")); // NOI18N
            .add(bundle.getString("TXT_PackageNameDots")); // NOI18N
            .add(bundle.getString("TXT_SourceDataObjectName")); // NOI18N
            .add(bundle.getString("TXT_Arguments")); // NOI18N
        }
            
        return ;
    }

    
Gets regExpItems. [:alnum:]=any character of [:digit:] or [:alpha:] class [:alpha:]=any letter. [:blank:]=space or tab. [:cntrl:]=any character with octal codes 000 through 037, or DEL (octal code 177). [:digit:]=any digit. [:graph:]=any character that is not a [:alnum:] or [:punct:] class. [:lower:]=any lower case letter. [:print:]=any character from the [:space:] class, and any character that is not in the [:graph:] class. [:punct:]=any one of ! \" # $ % & ' ( ) * + , - . / : ; < = > ?

:
[ \\ ] ^ _ ` { | } ~ [:space:]=any character of CR FF HT NL VT SPACE. [:upper:]=any upper case letter. [:xdigit:]=any hexa digit character.
    public static List<StringgetRegExpItems() {
        if( == null) {
             = new ArrayList<String>(4);
            //XXX Only first array item taken into account when checking, rest are not used
            .add("(getString|getBundle)[:space:]*\\([:space:]*{hardString}|//[:space:]*NOI18|getMessage[:space:]*\\(([:alnum:]|[:punct:]|[:space:])*,[:space:]*{hardString}"); // NOI18N
            .add("(getString|getBundle)[:space:]*\\([:space:]*{hardString}"); // NOI18N
            .add("//[:space:]*NOI18N"); // NOI18N
            .add("(getString|getBundle)[:space:]*\\([:space:]*|getMessage[:space:]*\\(([:alnum:]|[:punct:]|[:space:])*,[:space:]*{hardString}|//[:space:]*NOI18N"); // NOI18N
        }
            
        return ;
    }
    
    
Gets i18nRegExpItems.
    public static List<StringgetI18nRegExpItems() {
        if( == null) {
             = new ArrayList<String>(2);
            .add("getString[:space:]*\\([:space:]*{hardString}"); // NOI18N
            .add("(getString[:space:]*\\([:space:]*|getMessage[:space:]*\\(([:alnum:]|[:punct:]|[:space:])*,[:space:]*){hardString}"); // NOI18N
        }
            
        return ;
    }

    
Indicates if folder or its subfolders contains data object that is supported by any internationalization factory.
    public static boolean containsAcceptedDataObject(DataFolder folder) {
        DataObject[] children = folder.getChildren();
        DataObject[] folders = new DataObject[children.length];
        int ifoldersCount = 0;
        for (DataObject child : children) {
            if (child instanceof DataFolder) {  
                folders[foldersCount++] = child;
            } else if (FactoryRegistry.hasFactory(child.getClass())) {
                return true;
            }
        }
        for (i = 0; i < foldersCounti++) {
            if (containsAcceptedDataObject((DataFolderchildren[i])) {
                return true;
            }
        }
        return false;
    }
    
    
Recursivelly get all accepted data objects starting from given folder.
    public static List<DataObjectgetAcceptedDataObjects(DataObject.Container folder) {
        List<DataObjectaccepted = new ArrayList<DataObject>();
        
        final VisibilityQuery visQuery = VisibilityQuery.getDefault();
        DataObject[] children = folder.getChildren();
        for (DataObject child : children) {
            if (!visQuery.isVisible(child.getPrimaryFile())) {
                continue;
            }
            if(child instanceof DataObject.Container) {
                accepted.addAll(getAcceptedDataObjects((DataObject.Container)child));
            } else {
                if(FactoryRegistry.hasFactory(child.getClass()))
                    accepted.add(child);
            }
        }
        return accepted;
    }
    
    
Gets resource bundle for i18n module.
    public static ResourceBundle getBundle() {
        return NbBundle.getBundle(I18nUtil.class);
    }
    
    
Gets i18n options.
    public static I18nOptions getOptions() {
        return I18nOptions.getDefault();
    }
    
New to GrepCode? Check out our FAQ X