Package freemarker.ext.beans

Examples of freemarker.ext.beans.BeanModel


            }

            public void close() throws IOException
                try {                             
                    Environment env = Environment.getCurrentEnvironment();
                    BeanModel req = (BeanModel) env.getVariable("request");
                    BeanModel res = (BeanModel) env.getVariable("response");
                    Object prefix = env.getVariable("urlPrefix");
                    if (req != null) {
                        HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                        ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
                        HttpServletResponse response = null;
                        if (res != null) {
                            response = (HttpServletResponse) res.getWrappedObject();
                        }
                                           
                        // make the link
                        RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
                        out.write(rh.makeLink(request, response, buf.toString(), fullPath, secure, encode));
View Full Code Here


    public static final String module = JpCacheIncludeTransform.class.getName();
    protected static UtilCache pageCache = new UtilCache("webapp.JpInclude", 0, 0, 0, false, false);

    public Writer getWriter(final Writer writer, Map args) throws TemplateModelException, IOException {
        Environment env = Environment.getCurrentEnvironment();
        BeanModel req = (BeanModel) env.getVariable("request");
        BeanModel jpr = (BeanModel) env.getVariable("pages");

        final HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
        final ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
        final RepositoryWrapper wrapper = (RepositoryWrapper) jpr.getWrappedObject();
        final String contextName = ctx.getServletContextName();
        final long expireTime = this.getExpireTime(args);
        final String include = this.getInclude(args);

        return new Writer(writer) {
View Full Code Here

                    if (Debug.verboseOn()) Debug.logVerbose("parms: " + amount + " " + format + " " + locale, module);
                    Locale localeObj = null;
                    if (locale.length() < 1) {
                        // Load the locale from the session
                        Environment env = Environment.getCurrentEnvironment();
                        BeanModel req = (BeanModel) env.getVariable("request");
                        if (req != null) {
                            HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                            localeObj = UtilHttp.getLocale(request);
                        } else {
                            localeObj = env.getLocale();
                        }
                    } else {
View Full Code Here

            throw new TemplateModelException("First argument not an instance of TemplateScalarModel");
        if (!(args.get(1) instanceof BeanModel) && !(args.get(1) instanceof TemplateNumberModel) && !(args.get(1) instanceof TemplateScalarModel))
            throw new TemplateModelException("Second argument not an instance of BeanModel nor TemplateNumberModel nor TemplateScalarModel");
                         
        Environment env = Environment.getCurrentEnvironment();
        BeanModel req = (BeanModel)env.getVariable("request");
        HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
       
        String name = ((TemplateScalarModel) args.get(0)).getAsString();
        Object value = null;
        if (args.get(1) instanceof TemplateScalarModel)
            value = ((TemplateScalarModel) args.get(1)).getAsString();
View Full Code Here

                try {
                    if (Debug.verboseOn()) Debug.logVerbose("parms: " + amount + " " + isoCode + " " + locale, module);
                    if (locale.length() < 1) {
                        // Load the locale from the session
                        Environment env = Environment.getCurrentEnvironment();
                        BeanModel req = (BeanModel) env.getVariable("request");
                        if (req != null) {
                            HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                            out.write(UtilFormatOut.formatCurrency(amount, isoCode, UtilHttp.getLocale(request), rounding)); // we set the max to 10 digits as an hack to not round numbers in the ui
                        } else {
                            out.write(UtilFormatOut.formatCurrency(amount, isoCode, env.getLocale(), rounding)); // we set the max to 10 digits as an hack to not round numbers in the ui
                        }
                    } else {
View Full Code Here

            throw new IllegalArgumentException(
                "Object to be included must be passed to this directive via the 'object' parameter"
            );
        }

        BeanModel objectModel = (BeanModel) params.get( "object" );

        if ( objectModel == null ) {
            throw new IllegalArgumentException(
                "Object passed to this directive via the 'object' parameter must not be null"
            );
        }

        if ( !( objectModel.getWrappedObject() instanceof Writable ) ) {
            throw new IllegalArgumentException( "Given object isn't a ModelElement:" + objectModel.getWrappedObject() );
        }

        return (Writable) objectModel.getWrappedObject();
    }
View Full Code Here

    public void write(FreeMarkerWritable writable, Context context, Writer writer) throws Exception {
        Configuration configuration = context.get( Configuration.class );
        Template template = configuration.getTemplate( writable.getTemplateName() );
        template.process(
            new ExternalParamsTemplateModel(
                new BeanModel( writable, BeansWrapper.getDefaultInstance() ),
                new SimpleMapModel( context.get( Map.class ), BeansWrapper.getDefaultInstance() )
            ),
            writer
        );
    }
View Full Code Here

  public TemplateModel wrap(Object obj) throws TemplateModelException {
    if (obj instanceof Artifact) {
      return new ArtifactWrapper((Artifact) obj, this);
    }
    else if (obj instanceof WebResult) {
      return new BeanModel(obj, this);
    }
    else {
      return super.wrap(obj);
    }
  }
View Full Code Here

    /** {@inheritDoc} */
    @Override
    protected Configuration createConfiguration() {
        Configuration configuration = super.createConfiguration();

        BeanModel tilesBeanModel = new BeanModel(new TilesFMModelRepository(),
                BeansWrapper.getDefaultInstance());
        configuration.setSharedVariable("tiles", tilesBeanModel);
        return configuration;
    }
View Full Code Here

    /** {@inheritDoc} */
    @Override
    protected Configuration createConfiguration() {
        Configuration configuration = super.createConfiguration();

        BeanModel tilesBeanModel = new BeanModel(new TilesFMModelRepository(),
                BeansWrapper.getDefaultInstance());
        configuration.setSharedVariable("tiles", tilesBeanModel);
        return configuration;
    }
View Full Code Here

TOP

Related Classes of freemarker.ext.beans.BeanModel

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.