001: /*
002: * Coefficient - facilitates project based collaboration
003: * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
004: * PO Box 395
005: * Pretoria 0001, RSA
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package za.org.coefficient.html;
021:
022: import za.org.coefficient.core.Constants;
023: import za.org.coefficient.util.common.InvokerFactory;
024:
025: import java.util.Vector;
026:
027: import javax.naming.Context;
028: import javax.naming.InitialContext;
029: import javax.naming.NamingEnumeration;
030: import javax.naming.NameClassPair;
031:
032: /**
033: * The Theme object controls or affects the look and a feel of a page.
034: * The theme is like a set of color pens and other printing devices and
035: * the modules are what are added to the sheet of paper. Once
036: * everything is in place, the Page is sent to the web browser.
037: *
038: *
039: */
040: public class ThemeSupport {
041: //~ Static fields/initializers =============================================
042:
043: //~ Constructors ===========================================================
044:
045: public ThemeSupport() {
046: }
047:
048: //~ Methods ================================================================
049:
050: public static synchronized String getCurrentThemeLocalName() {
051: return Constants.DEFAULT_THEME_JNDI_NAME;
052: }
053:
054: public static synchronized String getCurrentPathToThemeResource() {
055: String pathToThemeResources = null;
056: try {
057: pathToThemeResources = (String) InvokerFactory
058: .getRemoteInvoker().invokeMethodOnTheme(
059: getCurrentThemeLocalName(),
060: "getPathToThemeResource", new Object[0]);
061: } catch (Exception e) {
062: // do nothing
063: pathToThemeResources = null;
064: }
065: return pathToThemeResources;
066: }
067:
068: public static synchronized Vector getThemes() {
069: return findThemes();
070: }
071:
072: public static synchronized void changeTheme(String newTheme) {
073: Vector themes = findThemes();
074: for (int i = 0; i < themes.size(); i++) {
075: if (newTheme.compareTo((String) themes.elementAt(i)) == 0) {
076: Constants.DEFAULT_THEME_JNDI_NAME = newTheme;
077: return;
078: }
079: }
080: }
081:
082: private static Vector findThemes() {
083: Vector themes = new Vector();
084: Context context = null;
085: themes = new Vector();
086: // Get the theme names
087: try {
088: context = za.org.coefficient.util.common.ContextUtil
089: .getContext();
090: for (NamingEnumeration ne = context
091: .list(Constants.JNDI_CONTEXT + "/" + "themes"); ne
092: .hasMore();) {
093: NameClassPair bind = (NameClassPair) ne.next();
094: themes.add(bind.getName());
095: }
096: context.close();
097: } catch (Exception e) {
098: e.printStackTrace();
099: }
100: return themes;
101: }
102: }
|