javaruntimes/midp/runtime/javasrc/com/nokia/mj/impl/rt/midp/StorageAccessor.java
changeset 79 2f468c1958d0
parent 61 bf7ee68962da
equal deleted inserted replaced
76:4ad59aaee882 79:2f468c1958d0
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   194                         {
   194                         {
   195                             // Try to parse the rest of attribute name (after "MIDlet-")
   195                             // Try to parse the rest of attribute name (after "MIDlet-")
   196                             // into an int.
   196                             // into an int.
   197                             midletN = Integer.parseInt(nameStr.substring(7));
   197                             midletN = Integer.parseInt(nameStr.substring(7));
   198                         }
   198                         }
   199                         catch (NumberFormatException ne) 
   199                         catch (NumberFormatException ne)
   200                         {
   200                         {
   201                         }
   201                         }
   202                     }
   202                     }
   203                 }
   203                 }
   204 
   204 
   205                 // Set the localized name of the MIDlet.
   205                 // Set the localized name of the MIDlet.
   206                 String localizedName = midletInfo.getAttribute("Nokia-MIDlet-Localized-" + midletN);
   206                 setLocalizedName(midletInfo, midletN);
   207                 if (localizedName == null)
       
   208                 {
       
   209                     localizedName = midletInfo.getName();
       
   210                 }
       
   211 
       
   212                 midletInfo.setLocalizedName(localizedName);
       
   213             }
   207             }
   214         }
   208         }
   215         finally
   209         finally
   216         {
   210         {
   217             // Closing the session.
   211             // Closing the session.
   221                 mSession.destroySession();
   215                 mSession.destroySession();
   222                 mSession = null;
   216                 mSession = null;
   223             }
   217             }
   224         }
   218         }
   225     }
   219     }
       
   220 
       
   221     /**
       
   222      * Sets localized name for the midlet basing on current
       
   223      * microedition.locale system property value and midlet's
       
   224      * JAD/Manifest attributes.
       
   225      *
       
   226      * @param midletInfo midlet info.
       
   227      * @param midletIndex index of the midlet in the suite.
       
   228      */
       
   229     private static void setLocalizedName(MidletInfo midletInfo, int midletIndex)
       
   230     {
       
   231         // Values for locales are of form
       
   232         // <language_code>[-<country_code>[-<variant>]]
       
   233         // for example 'es-MX' or 'en-US-Iron'.
       
   234         String currentLocale = System.getProperty("microedition.locale");
       
   235         String localizedName = null;
       
   236         if (currentLocale != null)
       
   237         {
       
   238             int idxMinus = -1;
       
   239             do
       
   240             {
       
   241                 localizedName = midletInfo.getAttribute(
       
   242                     "Nokia-MIDlet-" + midletIndex + "-" + currentLocale);
       
   243                 if (localizedName != null)
       
   244                 {
       
   245                     // Localized name found.
       
   246                     break;
       
   247                 }
       
   248                 // Localized name not found, now strip the most specific part,
       
   249                 // for example <-variant>, from the locale and do this again
       
   250                 // until there are no more parts or MIDlet name has been
       
   251                 // localized.
       
   252                 idxMinus = currentLocale.lastIndexOf('-');
       
   253                 if (idxMinus != -1)
       
   254                 {
       
   255                     currentLocale = currentLocale.substring(0, idxMinus);
       
   256                 }
       
   257             }
       
   258             while (localizedName == null && idxMinus != -1);
       
   259         }
       
   260 
       
   261         if (localizedName == null)
       
   262         {
       
   263             localizedName = midletInfo.getName();
       
   264         }
       
   265         midletInfo.setLocalizedName(localizedName);
       
   266     }
   226 }
   267 }