KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > blueprints > ui > BpcatalogLocalizedResource


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.j2ee.blueprints.ui;
21
22 import java.net.URL JavaDoc;
23 import java.util.Locale JavaDoc;
24
25 /**
26  * @author Yutaka Yoshida
27  */

28 public class BpcatalogLocalizedResource {
29
30     private String JavaDoc orgpath;
31     private Locale JavaDoc defaultLocale;
32     private String JavaDoc lang;
33     private String JavaDoc country;
34     private String JavaDoc variant;
35     private int offset;
36     private URL JavaDoc articleURL;
37
38     /** Creates a new instance of BpcatalogHtmlResource */
39     public BpcatalogLocalizedResource(String JavaDoc resource, String JavaDoc suffix) {
40         orgpath = resource;
41         defaultLocale = Locale.getDefault();
42         lang = defaultLocale.getLanguage();
43         country = defaultLocale.getCountry();
44         variant = defaultLocale.getVariant();
45         offset = resource.indexOf("."+suffix);
46     }
47     
48     public URL JavaDoc getResourceURL() {
49         String JavaDoc path = getResourcePath();
50         articleURL = (URL JavaDoc)getClass().getResource(path);
51         return articleURL;
52     }
53     
54     public String JavaDoc getResourcePath() {
55         StringBuffer JavaDoc path = new StringBuffer JavaDoc(orgpath);
56         if (!variant.equals("")) {
57             if (!country.equals("")) {
58                 path.insert(offset, "_"+lang+"_"+country+"_"+variant);
59                 articleURL = getClass().getResource(path.toString());
60                 if (articleURL!=null) {
61                     return path.toString();
62                 }
63             }
64         }
65         if (!country.equals("")) {
66             // in case path was modified
67
path.replace(0, path.length(), orgpath);
68             path.insert(offset, "_"+lang+"_"+country);
69             articleURL = getClass().getResource(path.toString());
70             if (articleURL!=null) {
71                 return path.toString();
72             }
73         }
74         path.replace(0, path.length(), orgpath);
75         path.insert(offset, "_"+lang);
76         articleURL = getClass().getResource(path.toString());
77         if (articleURL!=null) {
78             return path.toString();
79         } else {
80             return orgpath;
81         }
82     }
83     
84 }
85
Popular Tags