Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package freemarker.ext.jsp;
  
  import java.util.Iterator;
  
  import  javax.el.ArrayELResolver;
  import  javax.el.BeanELResolver;
  import  javax.el.CompositeELResolver;
  import  javax.el.ELContext;
 import  javax.el.ELContextEvent;
 import  javax.el.ELContextListener;
 import  javax.el.ELResolver;
 import  javax.el.ExpressionFactory;
 import  javax.el.FunctionMapper;
 import  javax.el.ListELResolver;
 import  javax.el.MapELResolver;
 import  javax.el.ResourceBundleELResolver;
 import  javax.el.ValueExpression;
 import  javax.el.VariableMapper;
 import  javax.servlet.jsp.JspApplicationContext;
 import  javax.servlet.jsp.el.ImplicitObjectELResolver;
 import  javax.servlet.jsp.el.ScopedAttributeELResolver;
 

Author(s):
Attila Szegedi
Version:
$Id: $
 
 class FreeMarkerJspApplicationContext implements JspApplicationContext
 {
     private static final Logger logger = Logger.getLogger("freemarker.jsp");
     private static final ExpressionFactory expressionFactoryImpl = findExpressionFactoryImplementation();
     
     private final LinkedList listeners = new LinkedList();
     private final CompositeELResolver elResolver = new CompositeELResolver();
     private final CompositeELResolver additionalResolvers = new CompositeELResolver();
     {
         .add(new ImplicitObjectELResolver());
         .add();
         .add(new MapELResolver());
         .add(new ResourceBundleELResolver());
         .add(new ListELResolver());
         .add(new ArrayELResolver());
         .add(new BeanELResolver());
         .add(new ScopedAttributeELResolver());
     }
     
     public void addELContextListener(ELContextListener listener) {
         synchronized() {
             .addLast(listener);
         }
     }
 
     private static ExpressionFactory findExpressionFactoryImplementation() {
         ExpressionFactory ef = tryExpressionFactoryImplementation("com.sun");
         if(ef == null) {
             ef = tryExpressionFactoryImplementation("org.apache");
             if(ef == null) {
                 .warn("Could not find any implementation for " + 
                         ExpressionFactory.class.getName());
             }
         }
         return ef;
     }
 
     private static ExpressionFactory tryExpressionFactoryImplementation(String packagePrefix) {
         String className = packagePrefix + ".el.ExpressionFactoryImpl";
         try {
             Class cl = ClassUtil.forName(className);
             if(ExpressionFactory.class.isAssignableFrom(cl)) {
                 .info("Using " + className + " as implementation of " + 
                         ExpressionFactory.class.getName());
                 return (ExpressionFactory)cl.newInstance();
             }
             .warn("Class " + className + " does not implement " + 
                     ExpressionFactory.class.getName());
         }
         catch(ClassNotFoundException e) {
         }
         catch(Exception e) {
             .error("Failed to instantiate " + classNamee);
         }
         return null;
     }
 
     public void addELResolver(ELResolver resolver) {
         .add(resolver);
     }
 
     public ExpressionFactory getExpressionFactory() {
         return ;
     }
     
     ELContext createNewELContext(final FreeMarkerPageContext pageCtx) {
         ELContext ctx = new FreeMarkerELContext(pageCtx);
         ELContextEvent event = new ELContextEvent(ctx);
         synchronized() {
            for (Iterator iter = .iterator(); iter.hasNext();) {
                ELContextListener l = (ELContextListener) iter.next();
                l.contextCreated(event);
            }
        }
        return ctx;
    }
    private class FreeMarkerELContext extends ELContext {
        private final FreeMarkerPageContext pageCtx;
        
        FreeMarkerELContext(FreeMarkerPageContext pageCtx) {
            this. = pageCtx;
        }
        
        public ELResolver getELResolver() {
            return ;
        }
        public FunctionMapper getFunctionMapper() {
            return null;
        }
        public VariableMapper getVariableMapper() {
            return new VariableMapper() {
                public ValueExpression resolveVariable(String name) {
                    Object obj = .findAttribute(name);
                    if(obj == null) {
                        return null;
                    }
                    return .createValueExpression(obj
                            obj.getClass());
                }
                public ValueExpression setVariable(String name
                        ValueExpression value) {
                    ValueExpression prev = resolveVariable(name);
                    .setAttribute(namevalue.getValue(
                            FreeMarkerELContext.this));
                    return prev;
                }
            };
        }
    }
New to GrepCode? Check out our FAQ X