Package freemarker.template

Examples of freemarker.template.TemplateModel


        getContext().put("date", new SimpleDate(new Date(), TemplateDateModel.DATETIME));       
       
    }
   
    protected Object internalPutInContext(String key, Object value) {
    TemplateModel model = null;
    try {
      model = getContext().get(key);
    }
    catch (TemplateModelException e) {
      throw new ExporterException("Could not get key " + key, e);
View Full Code Here


      getContext().put(key, value);
      return model;
    }
   
    protected Object internalRemoveFromContext(String key) {
      TemplateModel model = null;
    try {
      model = getContext().get(key);
    }
    catch (TemplateModelException e) {
      throw new ExporterException("Could not get key " + key, e);
View Full Code Here

   
    protected FreeMarkerPageContext() throws TemplateModelException
    {
        environment = Environment.getCurrentEnvironment();

        TemplateModel appModel = environment.getGlobalVariable(
                FreemarkerServlet.KEY_APPLICATION_PRIVATE);
        if(!(appModel instanceof ServletContextHashModel)) {
            appModel = environment.getGlobalVariable(
                    FreemarkerServlet.KEY_APPLICATION);
        }
        if(appModel instanceof ServletContextHashModel) {
            this.servlet = ((ServletContextHashModel)appModel).getServlet();
        }
        else {
            throw new  TemplateModelException("Could not find an instance of " +
                    ServletContextHashModel.class.getName() +
                    " in the data model under either the name " +
                    FreemarkerServlet.KEY_APPLICATION_PRIVATE + " or " +
                    FreemarkerServlet.KEY_APPLICATION);
        }
       
        TemplateModel requestModel =
            environment.getGlobalVariable(FreemarkerServlet.KEY_REQUEST_PRIVATE);
        if(!(requestModel instanceof HttpRequestHashModel)) {
            requestModel = environment.getGlobalVariable(
                    FreemarkerServlet.KEY_REQUEST);
        }
View Full Code Here

    public Object getAttribute(String name, int scope)
    {
        switch (scope) {
            case PAGE_SCOPE: {
                try {
                    TemplateModel m = environment.getGlobalNamespace().get(name);
                    if (m instanceof AdapterTemplateModel) {
                        return ((AdapterTemplateModel) m).getAdaptedObject(OBJECT_CLASS);
                    }
                    if (m instanceof WrapperTemplateModel) {
                        return ((WrapperTemplateModel)m).getWrappedObject();
View Full Code Here

        // Set cache policy
        setBrowserCachingPolicy(response);

        ServletContext servletContext = getServletContext();
        try {
            TemplateModel model = createModel(wrapper, servletContext, request, response);

            // Give subclasses a chance to hook into preprocessing
            if (preTemplateProcess(request, response, template, model)) {
                try {
                    // Process the template
View Full Code Here

        unlistedModels.put(key, model);
    }

    public TemplateModel get(String key) throws TemplateModelException {
        // Lookup in page scope
        TemplateModel model = super.get(key);
        if(model != null) {
            return model;
        }

        // Look in unlisted models
View Full Code Here

    }
   
    TemplateModel _getAsTemplateModel(Environment env)
            throws TemplateException
    {
        TemplateModel tm = target.getAsTemplateModel(env);
        String classname = null;
        try {
            classname = ((TemplateScalarModel) tm).getAsString();
        }
        catch (ClassCastException cce) {
View Full Code Here

        throws
        TemplateModelException
    {
        Class clazz = object.getClass();
        Map classInfo = wrapper.getClassKeyMap(clazz);
        TemplateModel retval = null;
       
        try
        {
            if(wrapper.isMethodsShadowItems())
            {
                Object fd = classInfo.get(key);
                if(fd != null)
                {
                    retval = invokeThroughDescriptor(fd, classInfo);
                } else {
                    retval = invokeGenericGet(classInfo, clazz, key);
                }
            }
            else
            {
                TemplateModel model = invokeGenericGet(classInfo, clazz, key);
                final TemplateModel nullModel = wrapper.wrap(null);
                if(model != nullModel && model != UNKNOWN)
                {
                    return model;
                }
                Object fd = classInfo.get(key);
View Full Code Here

        InvocationTargetException,
        TemplateModelException
    {
        // See if this particular instance has a cached implementation
        // for the requested feature descriptor
        TemplateModel member;
        synchronized(this) {
            if(memberMap != null) {
                member = (TemplateModel)memberMap.get(desc);
            }
            else {
                member = null;
            }
        }

        if(member != null)
            return member;

        TemplateModel retval = UNKNOWN;
        if(desc instanceof IndexedPropertyDescriptor)
        {
            Method readMethod =
                ((IndexedPropertyDescriptor)desc).getIndexedReadMethod();
            retval = member =
View Full Code Here

        // Otherwise it is a NOROOT_REL_URI, and has to be resolved relative
        // to current page... We have to obtain the request object to know what
        // is the URL of the current page (this assumes there's a
        // HttpRequestHashModel under name FreemarkerServlet.KEY_REQUEST in the
        // environment...) (JSP.7.6.3.2)
        TemplateModel reqHash =
            Environment.getCurrentEnvironment().getVariable(
                FreemarkerServlet.KEY_REQUEST_PRIVATE);
        if(reqHash instanceof HttpRequestHashModel) {
            HttpServletRequest req  =
                ((HttpRequestHashModel)reqHash).getRequest();
View Full Code Here

TOP

Related Classes of freemarker.template.TemplateModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.