Package freemarker.template

Examples of freemarker.template.TemplateModelException


     */
    public String getAsString() throws TemplateModelException {
        try {
            return property.getString();
        } catch (RepositoryException e) {
            throw new TemplateModelException(e);
        }
    }
View Full Code Here


     */
    public TemplateModel get(int index) throws TemplateModelException {
        try {
            return new SimpleScalar(values[index].getString());
        } catch (RepositoryException e) {
            throw new TemplateModelException(e);
        }
    }
View Full Code Here

     */
    public TemplateModel get(int index) throws TemplateModelException {
        try {
            return new NodeModel(nodes.get(index));
        } catch (RepositoryException e) {
            throw new TemplateModelException(e);
        }
    }
View Full Code Here

    @Override
    public Object exec(final List arguments) throws TemplateModelException {

        if (arguments.size() != ARG_SIZE) {
            LOGGER.debug("FillTagArticles with wrong arguments!");
            throw new TemplateModelException("Wrong arguments!");
        }

        final String tagTitle = (String) arguments.get(0);
        final int currentPageNum = Integer.parseInt((String) arguments.get(1));
        final int pageSize = Integer.parseInt((String) arguments.get(2));
View Full Code Here

        }
        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);
        }
        if(requestModel instanceof HttpRequestHashModel) {
            HttpRequestHashModel reqHash = (HttpRequestHashModel)requestModel;
            this.request = reqHash.getRequest();
            this.session = request.getSession(false);
            this.response = reqHash.getResponse();
            this.wrapper = reqHash.getObjectWrapper();
        }
        else  {
            throw new  TemplateModelException("Could not find an instance of " +
                    HttpRequestHashModel.class.getName() +
                    " in the data model under either the name " +
                    FreemarkerServlet.KEY_REQUEST_PRIVATE + " or " +
                    FreemarkerServlet.KEY_REQUEST);
        }
View Full Code Here

                (HttpRequestParametersHashModel) request.getAttribute(
                    ATTR_REQUEST_PARAMETERS_MODEL);
            params.putUnlistedModel(KEY_REQUEST_PARAMETERS, requestParametersModel);
            return params;
        } catch (ServletException e) {
            throw new TemplateModelException(e);
        } catch (IOException e) {
            throw new TemplateModelException(e);
        }
    }
View Full Code Here

            introspectClass(clazz);
            Map classInfo = (Map)classCache.get(clazz);
            Object ctors = classInfo.get(CONSTRUCTORS);
            if(ctors == null)
            {
                throw new TemplateModelException("Class " + clazz.getName() +
                        " has no public constructors.");
            }
            Constructor ctor = null;
            Object[] objargs;
            if(ctors instanceof SimpleMemberModel)
            {
                SimpleMemberModel smm = (SimpleMemberModel)ctors;
                ctor = (Constructor)smm.getMember();
                objargs = smm.unwrapArguments(arguments, this);
            }
            else if(ctors instanceof MethodMap)
            {
                MethodMap methodMap = (MethodMap)ctors;
                MemberAndArguments maa =
                    methodMap.getMemberAndArguments(arguments);
                objargs = maa.getArgs();
                ctor = (Constructor)maa.getMember();
            }
            else
            {
                // Cannot happen
                throw new Error();
            }
            return ctor.newInstance(objargs);
        }
        catch (TemplateModelException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw new TemplateModelException(
                    "Could not create instance of class " + clazz.getName(), e);
        }
    }
View Full Code Here

        }
        boolean varArg = MethodUtilities.isVarArgs(member);
        int typeLen = argTypes.length;
        if(varArg) {
            if(typeLen - 1 > arguments.size()) {
                throw new TemplateModelException("Method " + member +
                        " takes at least " + (typeLen - 1) +
                        " arguments");
            }
        }
        else if(typeLen != arguments.size()) {
            throw new TemplateModelException("Method " + member +
                    " takes exactly " + typeLen + " arguments");
        }
        
        Object[] args = unwrapArguments(arguments, argTypes, wrapper);
        if(args != null) {
View Full Code Here

    private static Object unwrapArgument(TemplateModel model, Class type, BeansWrapper w)
    throws TemplateModelException {
        Object val = w.unwrap(model, type);
        if(val == BeansWrapper.CAN_NOT_UNWRAP) {
            throw new TemplateModelException("Can not unwrap argument " +
                    model + " to " + type.getName());
        }
        return val;
    }
View Full Code Here

//                throw new TemplateModelException("Index out of bounds: " + index);
            }
        }
        else
        {
            throw new TemplateModelException("Underlying collection is not a list, it's " + object.getClass().getName());
        }
    }
View Full Code Here

TOP

Related Classes of freemarker.template.TemplateModelException

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.