Source Code Cross Referenced for LangManager.java in  » XML-UI » xui32 » com » xoetrope » carousel » langed » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » xui32 » com.xoetrope.carousel.langed 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.langed;
002:
003:        import java.io.BufferedReader;
004:        import java.io.IOException;
005:        import java.io.InputStreamReader;
006:        import java.net.URL;
007:        import java.sql.Connection;
008:        import java.sql.DriverManager;
009:        import java.sql.ResultSet;
010:        import java.sql.Statement;
011:        import java.util.StringTokenizer;
012:        import java.util.Vector;
013:
014:        import java.awt.Frame;
015:        import java.awt.event.ActionEvent;
016:        import java.awt.event.ActionListener;
017:        import javax.swing.JButton;
018:        import javax.swing.JList;
019:
020:        /**
021:         * LangManager
022:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
023:         * the GNU Public License (GPL), please see license.txt for more details. If
024:         * you make commercial use of this software you must purchase a commercial
025:         * license from Xoetrope.</p>
026:         * <p> $Revision: 1.7 $</p>
027:         */
028:        public class LangManager {
029:            public LangManager(boolean _bIsStandalone) {
030:                bIsStandalone = _bIsStandalone;
031:            }
032:
033:            /*
034:             * @deprecated uses an old file format
035:             public void init( URL _url, String defLang )  throws IOException
036:             {
037:             url = _url;
038:             langList = new Vector( 5 );
039:             subStrings = new Language();
040:
041:             BufferedReader is;
042:             is = new BufferedReader( new InputStreamReader( _url.openStream()));
043:
044:             String s = is.readLine();
045:             StringTokenizer token = new StringTokenizer( s, "|" );
046:             int numLangs = Integer.parseInt( token.nextToken());
047:
048:             langList.ensureCapacity( numLangs );
049:             for ( int i = 0; i < numLangs; i++ ) {
050:             s = is.readLine();
051:             token = new StringTokenizer( s, "|" );
052:             LangName ln = new LangName();
053:             ln.id = Integer.parseInt( token.nextToken());
054:             ln.code = token.nextToken();
055:             ln.name = token.nextToken();
056:
057:             langList.addElement( ln );
058:             }
059:
060:             read( defLang.length() > 0 ? defLang : ((LangName)langList.elementAt( 0 )).code );
061:             }
062:             */
063:
064:            /**
065:             * Loads a language and sets it as the default language.
066:             * This function is intended primarily for internal use by the
067:             * catalogue viewer.
068:             * @param langName the code name for the language.
069:             */
070:            /*  
071:             * @deprecated uses an old file format
072:             public void changeLang( String langName )
073:             {
074:             int items = langList.size();
075:             for ( int i = 0; i < items; i++ ) {
076:             if ( ((LangName)langList.elementAt( i )).name.compareTo( langName ) == 0 ) {
077:             Language backup = currentLang;
078:             try {
079:             String langCode = ((LangName)langList.elementAt( i )).code;
080:             read( langCode );
081:             }
082:             catch ( IOException e ) {
083:             currentLang = backup;
084:             }
085:             break;
086:             }
087:             }
088:             }
089:             */
090:
091:            /**
092:             * @deprecated uses an old file format   
093:            public void read( String code ) throws IOException
094:            {
095:              currentLang = new Language();
096:
097:              String file = url.toString();
098:              String fs = System.getProperty( "file.separator" );
099:              int index = file.lastIndexOf( fs );
100:              if ( index == -1 ) {
101:                index = file.lastIndexOf( "/" );
102:                if ( index == -1 )
103:                  index = file.lastIndexOf( "\\" );
104:              }
105:              file = file.substring( 0, index + 1 );
106:              code += ".jln";
107:              BufferedReader is;
108:              //file += "lang/";
109:              file += code;
110:              URL url2 = new URL( file );
111:              is = new BufferedReader( new InputStreamReader( url2.openStream()));
112:
113:              currentLang.read( is, false );
114:              is.close();
115:
116:              // Read the substrings
117:              if ( index == -1 ) {
118:                index = file.lastIndexOf( "/" );
119:                if ( index == -1 )
120:                  index = file.lastIndexOf( "\\" );
121:              }
122:              file = file.substring( 0, index + 1 );
123:              file += "sub.jln";
124:              URL url3 = new URL( file );
125:              is = new BufferedReader( new InputStreamReader( url3.openStream()));
126:              subStrings.read( is, true );
127:              is.close();
128:            }*/
129:
130:            public void read(String driver, String url, String userName,
131:                    String password, String code, String tableName,
132:                    boolean doSubstitutions) {
133:                try {
134:                    currentLang = new Language();
135:
136:                    // Try to load the driver.
137:                    Class.forName(driver.trim());
138:
139:                    Connection conn = DriverManager.getConnection(url,
140:                            userName, password);
141:                    Statement stmt = conn.createStatement();
142:                    ResultSet rs = stmt.executeQuery("SELECT ID, " + code
143:                            + " FROM " + tableName);
144:
145:                    while (rs.next()) {
146:                        LangItem li = new LangItem(doSubstitutions);
147:                        li.id = rs.getInt(1);
148:                        li.langStr = rs.getString(2);
149:                        currentLang.langStrings.put(li, li);
150:                    }
151:                } catch (Exception e) {
152:                    e.printStackTrace();
153:                }
154:            }
155:
156:            /**
157:             * Gets a string from the language.
158:             * @param id the ID of the requird string.
159:             * @return the requested string complete with substitutions or else "" if not found.
160:             */
161:            public String getString(int id) {
162:                if (currentLang != null)
163:                    return currentLang.getString(id);
164:                return "";
165:            }
166:
167:            /**
168:             * Gets the number of strings in the current language.
169:             */
170:            public int getNumStrings() {
171:                if (currentLang != null)
172:                    return currentLang.getNumStrings();
173:                return 0;
174:            }
175:
176:            /**
177:             * Gets a string from the language, calls getString.
178:             * @param id the ID of the required string.
179:             * @return the requested string complete with substitutions or else "" if not found.
180:             */
181:            public String getSubString(int id) {
182:                if (currentLang != null)
183:                    return currentLang.getString(id);
184:                return "";
185:            }
186:
187:            /**
188:             * Gets a string from the language, calls getString.
189:             * @param subString the substitution string.
190:             * @return the requested string from the current language.
191:             */
192:            public String getSubString(String substitution) {
193:                if (currentLang != null) {
194:                    int idx = substitution.indexOf('@');
195:                    int endIdx = 0;
196:                    int lastIdx = 0;
197:                    if (idx > -1) {
198:                        String keyStr;
199:                        endIdx = substitution.indexOf('@', idx + 1);
200:                        lastIdx = substitution.length() - 1;
201:                        if ((idx == 0) && (endIdx == lastIdx))
202:                            keyStr = substitution;
203:                        else
204:                            keyStr = substitution.substring(idx, endIdx + 1);
205:
206:                        int subStrId = subStrings.findString(keyStr);
207:                        if (subStrId >= 0) {
208:                            String retStr = currentLang.getString(subStrId);
209:                            if (retStr.length() != 0) {
210:                                if ((idx == 0) && (endIdx == lastIdx))
211:                                    return retStr;
212:                                else {
213:                                    String x = substitution.substring(0, idx);
214:                                    x += retStr;
215:                                    if (endIdx < lastIdx)
216:                                        x += substitution.substring(endIdx + 1);
217:                                    return x;
218:                                }
219:                            }
220:                        }
221:                    }
222:                    /* 04/10/2001 while(
223:                    int subStrId = subStrings.FindString( subString );
224:                    if ( subStrId >= 0 ) {
225:                    String retStr = currentLang.GetString( subStrId );
226:                    if ( retStr.length() != 0 )
227:                    return retStr;
228:                    }*/
229:                }
230:                return substitution;
231:            }
232:
233:            /*  
234:             * @deprecated uses an old file format
235:             public void pickLang()
236:             {
237:               LangPicker lp = new LangPicker( this, langList );
238:               lp.init();
239:             }
240:             */
241:
242:            public String getLangName() {
243:                if (langName != null)
244:                    return langName;
245:                int items = langList.size();
246:                if (items > 0)
247:                    return ((LangName) langList.elementAt(0)).name;
248:
249:                return "";
250:            }
251:
252:            private Language currentLang;
253:            private Language subStrings;
254:            private Vector langList;
255:            private String langName;
256:            private boolean bIsStandalone;
257:            private URL url;
258:        }
259:
260:        class LangName {
261:            public int id;
262:            public String code;
263:            public String name;
264:
265:            public LangName() {
266:            }
267:
268:            public String toString() {
269:                return name;
270:            }
271:        }
272:
273:        /* class LangPicker extends Frame
274:         * @deprecated uses an old file format
275:         {
276:         public LangPicker( LangManager _langMgr, Vector v )
277:         {
278:         setLayout( null );
279:         langMgr = _langMgr;
280:         elementList = v;
281:
282:         okBtn = new JButton( "OK" );
283:         okBtn.addActionListener( new ActionListener() {
284:         public void actionPerformed( ActionEvent e )
285:         {
286:         ChangeLang();
287:         dispose();
288:         }
289:         });
290:
291:         cancelBtn = new JButton( "Cancel" );
292:         cancelBtn.addActionListener( new ActionListener() {
293:         public void actionPerformed( ActionEvent e )
294:         {
295:         dispose();
296:         }
297:         });
298:
299:         langListbox = new JList( elementList );
300:
301:         add( okBtn );
302:         add( cancelBtn );
303:         add( langListbox );
304:
305:         langListbox.setSelectedIndex( 0 );
306:
307:         okBtn.setBounds( 110, 140, 100, 30 );
308:         cancelBtn.setBounds( 10, 140, 100, 30 );
309:
310:         setSize( 220, 180 );
311:         setVisible( true );
312:         }
313:
314:
315:         public void init()
316:         {
317:         langListbox.setBounds( 10, 30, 200, 100 );
318:         }
319:
320:         public void  ChangeLang()
321:         {
322:         String str = ((LangName)elementList.elementAt( langListbox.getSelectedIndex())).name;
323:         langMgr.changeLang( str );
324:         }
325:
326:         private JButton okBtn;
327:         private JButton cancelBtn;
328:         private JList langListbox;
329:         private Vector elementList;
330:         LangManager langMgr;
331:         }*/
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.