1 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 ; 26 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingEnumeration ; 30 import javax.naming.NameClassPair ; 31 32 40 public class ThemeSupport { 41 43 45 public ThemeSupport() { 46 } 47 48 50 public static synchronized String getCurrentThemeLocalName() { 51 return Constants.DEFAULT_THEME_JNDI_NAME; 52 } 53 54 public static synchronized String getCurrentPathToThemeResource() { 55 String pathToThemeResources = null; 56 try { 57 pathToThemeResources = (String )InvokerFactory.getRemoteInvoker() 58 .invokeMethodOnTheme(getCurrentThemeLocalName(), 59 "getPathToThemeResource", 60 new Object [0]); 61 } catch(Exception e) { 62 pathToThemeResources = null; 64 } 65 return pathToThemeResources; 66 } 67 68 public static synchronized Vector getThemes() { 69 return findThemes(); 70 } 71 72 public static synchronized void changeTheme(String newTheme) { 73 Vector themes = findThemes(); 74 for (int i=0; i<themes.size(); i++) { 75 if (newTheme.compareTo((String )themes.elementAt(i))==0) { 76 Constants.DEFAULT_THEME_JNDI_NAME = newTheme; 77 return; 78 } 79 } 80 } 81 82 private static Vector findThemes() { 83 Vector themes = new Vector (); 84 Context context = null; 85 themes = new Vector (); 86 try { 88 context = za.org.coefficient.util.common.ContextUtil.getContext(); 89 for (NamingEnumeration ne = context.list(Constants.JNDI_CONTEXT + "/" + "themes"); ne.hasMore(); ) { 90 NameClassPair bind = (NameClassPair )ne.next(); 91 themes.add(bind.getName()); 92 } 93 context.close(); 94 } catch (Exception e) { 95 e.printStackTrace(); 96 } 97 return themes; 98 } 99 } 100 | Popular Tags |