KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > html > ThemeSupport


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.html;
21
22 import za.org.coefficient.core.Constants;
23 import za.org.coefficient.util.common.InvokerFactory;
24
25 import java.util.Vector JavaDoc;
26
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.naming.NamingEnumeration JavaDoc;
30 import javax.naming.NameClassPair JavaDoc;
31
32 /**
33  * The Theme object controls or affects the look and a feel of a page.
34  * The theme is like a set of color pens and other printing devices and
35  * the modules are what are added to the sheet of paper. Once
36  * everything is in place, the Page is sent to the web browser.
37  *
38  *
39  */

40 public class ThemeSupport {
41     //~ Static fields/initializers =============================================
42

43     //~ Constructors ===========================================================
44

45     public ThemeSupport() {
46     }
47
48     //~ Methods ================================================================
49

50     public static synchronized String JavaDoc getCurrentThemeLocalName() {
51         return Constants.DEFAULT_THEME_JNDI_NAME;
52     }
53
54     public static synchronized String JavaDoc getCurrentPathToThemeResource() {
55         String JavaDoc pathToThemeResources = null;
56         try {
57             pathToThemeResources = (String JavaDoc)InvokerFactory.getRemoteInvoker()
58                 .invokeMethodOnTheme(getCurrentThemeLocalName(),
59                                      "getPathToThemeResource",
60                                      new Object JavaDoc[0]);
61         } catch(Exception JavaDoc e) {
62             // do nothing
63
pathToThemeResources = null;
64         }
65         return pathToThemeResources;
66     }
67
68     public static synchronized Vector JavaDoc getThemes() {
69         return findThemes();
70     }
71
72     public static synchronized void changeTheme(String JavaDoc newTheme) {
73         Vector JavaDoc themes = findThemes();
74         for (int i=0; i<themes.size(); i++) {
75             if (newTheme.compareTo((String JavaDoc)themes.elementAt(i))==0) {
76                 Constants.DEFAULT_THEME_JNDI_NAME = newTheme;
77                 return;
78             }
79         }
80     }
81
82     private static Vector JavaDoc findThemes() {
83         Vector JavaDoc themes = new Vector JavaDoc();
84         Context JavaDoc context = null;
85         themes = new Vector JavaDoc();
86         // Get the theme names
87
try {
88             context = za.org.coefficient.util.common.ContextUtil.getContext();
89             for (NamingEnumeration JavaDoc ne = context.list(Constants.JNDI_CONTEXT + "/" + "themes"); ne.hasMore(); ) {
90                 NameClassPair JavaDoc bind = (NameClassPair JavaDoc)ne.next();
91                 themes.add(bind.getName());
92             }
93             context.close();
94         } catch (Exception JavaDoc e) {
95             e.printStackTrace();
96         }
97         return themes;
98     }
99 }
100
Popular Tags