KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > tools > resourcemaker > KeyToLangFlgImgAssociation


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
/*
13  * ----- BEGIN LICENSE BLOCK -----
14  * Version: JCSL 1.0
15  *
16  * The contents of this file are subject to the Jahia Community Source License
17  * 1.0 or later (the "License"); you may not use this file except in
18  * compliance with the License. You may obtain a copy of the License at
19  * http://www.jahia.org/license
20  *
21  * Software distributed under the License is distributed on an "AS IS" basis,
22  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
23  * for the rights, obligations and limitations governing use of the contents
24  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
25  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
26  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
27  *
28  * The Shared Modifications are Jahia tools resource maker.
29  *
30  * The Developer of the Shared Modifications is Jahia Solution S�rl.
31  * Portions created by the Initial Developer are Copyright (C) 2002 by the
32  * Initial Developer. All Rights Reserved.
33  *
34  * Contributor(s):
35  * Sep 24 2002 Jahia Solutions S�rl: MAP Initial release.
36  *
37  * ----- END LICENSE BLOCK -----
38  */

39
40 package org.jahia.tools.resourcemaker;
41
42 import java.io.BufferedWriter JavaDoc;
43 import java.io.FileOutputStream JavaDoc;
44 import java.io.IOException JavaDoc;
45 import java.io.OutputStreamWriter JavaDoc;
46 import java.util.Locale JavaDoc;
47
48 /**
49  * <p>Title: Jahia tools resource maker</p>
50  * <p>Description: Generate the resource bundle file that can be merged to the
51  * Jahia resource bundle main file. This file contain the flag (on/off) resource
52  * image key followed by the path to the resource in question.</p>
53  *
54  * Usage example: In "./jahia/build/classes" directory type :
55  * # java org.jahia.tools.resourcemaker.KeyToLangFlgImgAssociation
56  * The output "lang_flg_resource_bundle.properties" file is generated and can be
57  * merged to "JahiaEnginesResources.properties" file.
58  *
59  * WARNING ! The image resource flag should exist in path
60  * "/jsp/jahia/engines/images/flags/".
61  *
62  * <p>Copyrights: MAP (Jahia Solution S�rl 2002)</p>
63  * <p>Company: Jahia Solutions S�rl 2002</p>
64  * @author MAP
65  * @version 1.0
66  */

67 public final class KeyToLangFlgImgAssociation {
68
69     public static void main(String JavaDoc[] args) {
70
71         Locale JavaDoc[] availableLocales = Locale.getAvailableLocales();
72         StringBuffer JavaDoc fileContent = new StringBuffer JavaDoc("");
73         for (int i=0; i < availableLocales.length; i++) {
74             Locale JavaDoc curLocale = availableLocales[i];
75             String JavaDoc country = curLocale.getCountry();
76             fileContent.append(curLocale.getLanguage() + (country.equals("") ? "" : "_" + country) +
77                                "FlagOn = " + _imagePath + curLocale.getLanguage() + "_on.gif\n");
78             fileContent.append(curLocale.getLanguage() + (country.equals("") ? "" : "_" + country) +
79                                "FlagOff = " + _imagePath + curLocale.getLanguage() + "_off.gif\n");
80         }
81         writeFile(_resourceFileName, fileContent.toString());
82     }
83
84     private static void writeFile(String JavaDoc fileName, String JavaDoc fileContent) {
85         try {
86             BufferedWriter JavaDoc out = new BufferedWriter JavaDoc(
87                     new OutputStreamWriter JavaDoc(
88                     new FileOutputStream JavaDoc(fileName)));
89             out.write(fileContent);
90             out.close();
91         } catch (IOException JavaDoc ie) {
92             System.out.println(ie.getMessage());
93         }
94     }
95
96     private static final String JavaDoc _imagePath = "/jsp/jahia/engines/images/flags/";
97     private static final String JavaDoc _resourceFileName = "lang_flg_resource_bundle.properties";
98 }
99
Popular Tags