1 9 10 package com.opensymphony.module.sitemesh.mapper; 11 12 import com.opensymphony.module.sitemesh.Decorator; 13 14 import javax.naming.Context ; 15 import javax.naming.InitialContext ; 16 import javax.naming.NamingException ; 17 import javax.servlet.http.HttpServletRequest ; 18 19 43 public final class EnvEntryDecoratorMapper extends ConfigDecoratorMapper { 44 50 public Decorator getNamedDecorator(HttpServletRequest request, String name) { 51 String resourceValue = getStringResource(name); 52 if (resourceValue == null) { 53 return super.getNamedDecorator(request, name); 54 } 55 else { 56 return new DefaultDecorator(name, resourceValue, null); 57 } 58 } 59 60 64 public static String getStringResource(String name) { 65 String value = null; 66 Context ctx = null; 67 try { 68 ctx = new InitialContext (); 69 Object o = ctx.lookup("java:comp/env/" + name); 70 if (o != null) { 71 value = o.toString(); 72 } 73 } 74 catch (NamingException ne) { 75 } 76 finally { 77 try { 78 if (ctx != null) ctx.close(); 79 } 80 catch (NamingException ne) { 81 } 82 } 83 return value; 84 } 85 } | Popular Tags |