javacommons/utils/javasrc/com/nokia/mj/impl/utils/ResourceLoader.java
changeset 76 4ad59aaee882
parent 48 e0d6e9bd3ca7
child 72 1f0034e370aa
child 83 26b2b12093af
equal deleted inserted replaced
69:773449708c84 76:4ad59aaee882
    32  *       horizontalSpan, labelStyle);
    32  *       horizontalSpan, labelStyle);
    33  *
    33  *
    34  *   Label noteLabel = createLabel(
    34  *   Label noteLabel = createLabel(
    35  *       res.string("note"), horizontalSpan, labelStyle);
    35  *       res.string("note"), horizontalSpan, labelStyle);
    36  * </pre>
    36  * </pre>
    37  *
       
    38  * @author Nokia Corporation
       
    39  * @version 1.0
       
    40  */
    37  */
    41 public class ResourceLoader
    38 public class ResourceLoader
    42 {
    39 {
    43     /** AVKON UI identifier. */
    40     /** AVKON UI identifier. */
    44     public static final int AVKON = 1;
    41     public static final int AVKON = 1;
    65     public static ResourceLoader getInstance(String avkonFileName,
    62     public static ResourceLoader getInstance(String avkonFileName,
    66                                              String avkonPrefix,
    63                                              String avkonPrefix,
    67                                              String qtFileName,
    64                                              String qtFileName,
    68                                              String qtPrefix)
    65                                              String qtPrefix)
    69     {
    66     {
    70         // Avkon name prefix pair is used as key and this is same between platforms.
    67         // Construct key from filenames and prefixes, this is the same
    71         String key = avkonFileName + ":" + avkonPrefix;
    68         // between platforms.
       
    69         String key = (new StringBuffer()).append(avkonFileName).append(":")
       
    70             .append(avkonPrefix).append(":").append(qtFileName).append(":")
       
    71             .append(qtPrefix).toString();
    72         ResourceLoader result = (ResourceLoader)resourceLoaders.get(key);
    72         ResourceLoader result = (ResourceLoader)resourceLoaders.get(key);
    73 
    73 
    74         if (result == null)
    74         if (result == null)
    75         {
    75         {
    76             result = new ResourceLoader(avkonFileName, avkonPrefix, qtFileName, qtPrefix);
    76             result = new ResourceLoader(avkonFileName, avkonPrefix, qtFileName, qtPrefix);
   144      * @param resourceName name of the resource
   144      * @param resourceName name of the resource
   145      * @param aPrefix prefix added before each id when retrieving
   145      * @param aPrefix prefix added before each id when retrieving
   146      */
   146      */
   147     public ResourceLoader(String resourceName, String aPrefix)
   147     public ResourceLoader(String resourceName, String aPrefix)
   148     {
   148     {
       
   149         locType = AVKON;
   149         prefix = aPrefix;
   150         prefix = aPrefix;
   150         loadFile(resourceName, true);  // Avkon
   151         loadFile(resourceName, true);  // Avkon
   151     }
   152     }
   152 
   153 
   153     /**
   154     /**
   157      * @return formatter instance
   158      * @return formatter instance
   158      * @see Formatter
   159      * @see Formatter
   159      */
   160      */
   160     public Formatter format(String id)
   161     public Formatter format(String id)
   161     {
   162     {
   162         return new Formatter(string(id));
   163         return new Formatter(string(id), locType);
   163     }
   164     }
   164 
   165 
   165     /**
   166     /**
   166      * Get a string formatter of a given resource id.
   167      * Get a string formatter of a given resource id.
   167      *
   168      *
   172      */
   173      */
   173     public Formatter format(String avkonId, String qtId)
   174     public Formatter format(String avkonId, String qtId)
   174     {
   175     {
   175         if (locType == AVKON)
   176         if (locType == AVKON)
   176         {
   177         {
   177             return new Formatter(string(avkonId));
   178             return new Formatter(string(avkonId), locType);
   178         }
   179         }
   179         else
   180         else
   180         {
   181         {
   181             return new Formatter(string(qtId));        
   182             return new Formatter(string(qtId), locType);
   182         }
   183         }
   183     }
   184     }
   184 
   185 
   185     /**
   186     /**
   186      * Formats localised text with specified parameters from an array.
   187      * Formats localised text with specified parameters from an array.
   193      */
   194      */
   194     public String format(String avkonId, String qtId, Object[] textParameters)
   195     public String format(String avkonId, String qtId, Object[] textParameters)
   195     {
   196     {
   196         if (locType == AVKON)
   197         if (locType == AVKON)
   197         {
   198         {
   198             return new Formatter(string(avkonId)).format(textParameters);
   199             return new Formatter(string(avkonId), locType).format(textParameters);
   199         }
   200         }
   200         else
   201         else
   201         {
   202         {
   202             return new Formatter(string(qtId)).format(textParameters);
   203             return new Formatter(string(qtId), locType).format(textParameters);
   203         }
   204         }
   204     }
   205     }
   205 
   206 
   206     /**
   207     /**
   207      * Get a string formatter of a given resource id.
   208      * Get a string formatter of a given resource id.
   210      * @return formatter instance
   211      * @return formatter instance
   211      * @see Formatter
   212      * @see Formatter
   212      */
   213      */
   213     public Formatter format(Id id)
   214     public Formatter format(Id id)
   214     {
   215     {
   215         return new Formatter(id.getString(locType));
   216         return new Formatter(id.getString(locType), locType);
   216     }
   217     }
   217 
   218 
   218     /**
   219     /**
   219      * Formats localised text with specified parameters from an array.
   220      * Formats localised text with specified parameters from an array.
   220      *
   221      *
   223      * @return localised text formatted with the provided parameters
   224      * @return localised text formatted with the provided parameters
   224      * @see Formatter
   225      * @see Formatter
   225      */
   226      */
   226     public String format(String id, Object[] textParameters)
   227     public String format(String id, Object[] textParameters)
   227     {
   228     {
   228         return new Formatter(string(id)).format(textParameters);
   229         return new Formatter(string(id), locType).format(textParameters);
   229     }
   230     }
   230 
   231 
   231     /**
   232     /**
   232      * Formats localised text with specified parameters from an array.
   233      * Formats localised text with specified parameters from an array.
   233      *
   234      *
   236      * @return localised text formatted with the provided parameters
   237      * @return localised text formatted with the provided parameters
   237      * @see Formatter
   238      * @see Formatter
   238      */
   239      */
   239     public String format(Id id, Object[] textParameters)
   240     public String format(Id id, Object[] textParameters)
   240     {
   241     {
   241         return new Formatter(string(id.getString(locType))).format(textParameters);
   242         return new Formatter(string(id.getString(locType)), locType).format(textParameters);
   242     }
   243     }
   243 
   244 
   244 
   245 
   245     /**
   246     /**
   246      * Get a plain string resource with a given resource id.
   247      * Get a plain string resource with a given resource id.
   329         InputStream is = null;
   330         InputStream is = null;
   330 
   331 
   331         if (!avkon)  // Qt resources.
   332         if (!avkon)  // Qt resources.
   332         {
   333         {
   333             String langName = getLocaleIdQt();
   334             String langName = getLocaleIdQt();
   334            
   335 
   335             // Emulator returns falsely en_GB as engineering English locale name.
   336             // Emulator returns falsely en_GB as engineering English locale name.
   336             if (langName.equals("en_GB"))
   337             if (langName.equals("en_GB"))
   337             {
   338             {
   338                 langName = "en";
   339                 langName = "en";
   339             }
   340             }
   340             
   341 
   341             // Load with real locale id
   342             // Load with real locale id
   342             is = this.getClass().getResourceAsStream(
   343             is = this.getClass().getResourceAsStream(
   343                 LOC_RESOURCE_BASE + resourceName + "_" + langName + ".loc");
   344                 LOC_RESOURCE_BASE + resourceName + "_" + langName + ".loc");
   344 
   345 
   345             if (is == null)
   346             if (is == null)