KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > api > MessagesSelector


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.api;
7
8 import java.sql.SQLException JavaDoc;
9 import java.util.*;
10
11 import com.raptus.owxv3.*;
12
13 /**
14  *
15  * <hr>
16  * <table width="100%" border="0">
17  * <tr>
18  * <td width="24%"><b>Filename</b></td><td width="76%">MessagesSelector.java</td>
19  * </tr>
20  * <tr>
21  * <td width="24%"><b>Author</b></td><td width="76%">Guy Zürcher (gzuercher@raptus.com)</td>
22  * </tr>
23  * <tr>
24  * <td width="24%"><b>Date</b></td><td width="76%">1st of May 2001</td>
25  * </tr>
26  * </table>
27  * <hr>
28  * <table width="100%" border="0">
29  * <tr>
30  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
31  * </tr>
32  * </table>
33  * <hr>
34  */

35 public class MessagesSelector extends Object JavaDoc
36 {
37     /**
38      *
39      */

40     protected Locale[] availLocales = null;
41
42     /**
43      *
44      */

45     protected Hashtable localizedMsgs = null;
46
47     /**
48      *
49      */

50     public MessagesSelector(String JavaDoc[] locales)
51     {
52         reset();
53
54         availLocales = new Locale[locales.length];
55         for(int i = 0; i < locales.length; i ++)
56         {
57             PairOfObjects po = LocaleManager.stripLocaleString(locales[i]);
58             if(po != null && po.isValid())
59                 availLocales[i] = new Locale((String JavaDoc) po.getObjectOne(),
60                                              (String JavaDoc) po.getObjectTwo());
61         }
62     }
63
64     /**
65      *
66      */

67     public void reset()
68     {
69         localizedMsgs = new Hashtable();
70     }
71
72     /**
73      *
74      */

75     public void loadMessages(GlobalResources gres, String JavaDoc tableId, int rowId, String JavaDoc field)
76                 throws SQLException JavaDoc
77     {
78         for(int i = 0; i < availLocales.length; i ++)
79         {
80             String JavaDoc msg = gres.loadMessage(tableId, rowId, field, availLocales[i]);
81             if(msg != null)
82                 localizedMsgs.put(availLocales[i].toString() + "_" + field, msg);
83         }
84     }
85
86     /**
87      *
88      */

89     public void saveMessages(GlobalResources gres, String JavaDoc tableId, int rowId, String JavaDoc field)
90                 throws SQLException JavaDoc
91     {
92         for(int i = 0; i < availLocales.length; i ++)
93         {
94             String JavaDoc msg = (String JavaDoc) localizedMsgs.get(availLocales[i].toString() + "_" + field);
95             gres.saveMessage(tableId,rowId, field, availLocales[i], msg);
96         }
97     }
98
99     /**
100      *
101      */

102     public String JavaDoc getMessage(String JavaDoc field, Locale locale)
103     {
104         return (String JavaDoc) localizedMsgs.get(locale.toString() + "_" + field);
105     }
106
107     /**
108      *
109      */

110     public void setMessage(String JavaDoc field, Locale locale, String JavaDoc msg)
111     {
112         if(msg != null)
113             localizedMsgs.put(locale.toString() + "_" + field, msg);
114         else
115             LoggingManager.log("Cannot link NULL message: " + field + "/" + locale.toString(), this);
116     }
117
118     /**
119      *
120      */

121     public Locale[] getLocales() { return availLocales; }
122     public void setLocales(Locale[] l) { this.availLocales = l; }
123 }
124
125 // eof
126
Popular Tags