当前位置: 首页>>代码示例>>Java>>正文


Java BeanModel类代码示例

本文整理汇总了Java中freemarker.ext.beans.BeanModel的典型用法代码示例。如果您正苦于以下问题:Java BeanModel类的具体用法?Java BeanModel怎么用?Java BeanModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeanModel类属于freemarker.ext.beans包,在下文中一共展示了BeanModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeMiddle

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@SuppressWarnings({"nls"})
@Override
protected void writeMiddle(SectionWriter writer) throws IOException
{
	List<Option<?>> options = listState.getOptions();
	for( Option<?> option : options )
	{
		writer.writeTag("li");
		writer.writeTag("input", "type", "hidden", "name", listState.getName(), "value", option.getValue());
		loopVars[0] = new BeanModel(option, wrapper);
		try
		{
			body.render(writer);
		}
		catch( TemplateException e )
		{
			SectionUtils.throwRuntime(e);
		}
		writer.endTag("li");
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:ListRendererDirective.java

示例2: writeMiddle

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@Override
protected void writeMiddle(SectionWriter writer) throws IOException
{
	List<ListOption<Object>> optionList = renderer.renderOptionList(writer);
	for( ListOption<Object> listOption : optionList )
	{
		Option<Object> option = listOption.getOption();
		HtmlBooleanState state = listOption.getBooleanState();
		state.setLabel(new TextLabel(option.getName(), true));
		loopVars[0] = new BeanModel(option, wrapper);
		loopVars[1] = new BeanModel(state, wrapper);
		try
		{
			body.render(writer);
		}
		catch( TemplateException e )
		{
			throw Throwables.propagate(e);
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:BooleanListDirective.java

示例3: getWrappedObject

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
/**
* Gets BeanModel from FreeMarker context and returns the object that it wraps.
* @param varName the name of the variable in the FreeMarker context.
* @param env the FreeMarker Environment
*/
public static <T> T getWrappedObject(String varName, Environment env) {
    Object obj = null;
    try {
        obj = env.getVariable(varName);
        if (obj != null) {
            if (obj == TemplateModel.NOTHING) {
                obj = null;
            } else if (obj instanceof BeanModel) {
                BeanModel bean = (BeanModel) obj;
                obj = bean.getWrappedObject();
            } else if (obj instanceof SimpleScalar) {
                obj = obj.toString();
            }
        }
    } catch (TemplateModelException e) {
        Debug.logInfo(e.getMessage(), module);
    }
    return UtilGenerics.<T>cast(obj);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:25,代码来源:FreeMarkerWorker.java

示例4: toSimpleMapRewrapAdapters

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
/**
 * Converts map to a simple wrapper, if applicable, by rewrapping
 * known complex map wrappers that implement <code>WrapperTemplateModel</code>.
 * <p>
 * If the specified ObjectWrapper is a BeansWrapper, this forces rewrapping as a SimpleMapModel.
 * If it isn't we assume caller specified an objectWrapper that will rewrap the map with
 * a simple model (we have no way of knowing).
 * <p>
 * WARN: Bypasses auto-escaping for complex maps; caller must decide how to handle
 * (e.g. the object wrapper used to rewrap the result).
 * Other types of maps are not altered.
 * 
 * @deprecated don't use
 */
@Deprecated
private static TemplateHashModel toSimpleMapRewrapAdapters(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (object instanceof SimpleMapModel || object instanceof BeanModel || object instanceof DefaultMapAdapter) {
        // Permissive
        Map<?, ?> wrappedObject = (Map<?, ?>) ((WrapperTemplateModel) object).getWrappedObject();
        if (objectWrapper instanceof BeansWrapper) {
            // Bypass the beanswrapper wrap method and always make simple wrapper
            return new SimpleMapModel(wrappedObject, (BeansWrapper) objectWrapper);
        } else {
            // If anything other than BeansWrapper, assume caller is aware and his wrapper will create a simple map
            return (TemplateHashModel) objectWrapper.wrap(wrappedObject);
        }
    }
    else if (object instanceof TemplateHashModel) {
        return (TemplateHashModel) object;
    }
    else {
        throw new TemplateModelException("object is not a recognized map type");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:35,代码来源:LangFtlUtil.java

示例5: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguements");
    if (!(args.get(0) instanceof TemplateScalarModel))
        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();
    if (args.get(1) instanceof TemplateNumberModel)
        value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    if (args.get(1) instanceof BeanModel)
        value = ((BeanModel) args.get(1)).getWrappedObject();

    request.setAttribute(name, value);
    return new SimpleScalar("");
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:26,代码来源:SetRequestAttributeMethod.java

示例6: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguements");
    if (!(args.get(0) instanceof TemplateScalarModel))
        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("context");
    Map context = (Map) req.getWrappedObject();

    String name = ((TemplateScalarModel) args.get(0)).getAsString();
    Object value = null;
    if (args.get(1) instanceof TemplateScalarModel)
        value = ((TemplateScalarModel) args.get(1)).getAsString();
    if (args.get(1) instanceof TemplateNumberModel)
        value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    if (args.get(1) instanceof BeanModel)
        value = ((BeanModel) args.get(1)).getWrappedObject();

    context.put(name, value);
    return new SimpleScalar("");
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:26,代码来源:SetContextFieldTransform.java

示例7: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException
{
    String result = null;
    
    if (args.size() == 2)
    {
        Object arg0 = args.get(0);
        Object arg1 = args.get(1);
        
        if (arg0 instanceof BeanModel && arg1 instanceof TemplateNumberModel)
        {
            Object wrapped = ((BeanModel)arg0).getWrappedObject();
            if (wrapped instanceof TemplateContentData)
            {
                int bytes = ((TemplateNumberModel)arg1).getAsNumber().intValue();
                
                try 
                {
            	    result = ((TemplateContentData)wrapped).getContentAsText(bytes);
                } 
                catch (ContentIOException e)
                {
                   logger.warn("unable to getContentAsText", e);
            	   /*
                    * Unable to extract content - return empty text instead.
                    * Probably here through a transformation failure.
                    * This method is called from FreeMarker so throwing the 
                    * exception causes problems.
                    */
                   result = "";
                }
            }
        }
    }
    
    return result != null ? result : "";
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:41,代码来源:CropContentMethod.java

示例8: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException
{
    int result = 0;
    
    if (args.size() == 2)
    {
        // arg 0 must be a wrapped TemplateNode object
        BeanModel arg0 = (BeanModel)args.get(0);
        
        // arg 1 can be either wrapped QName object or a String 
        String arg1String = null;
        Object arg1 = args.get(1);
        if (arg1 instanceof BeanModel)
        {
            arg1String = ((BeanModel)arg1).getWrappedObject().toString();
        }
        else if (arg1 instanceof TemplateScalarModel)
        {
            arg1String = ((TemplateScalarModel)arg1).getAsString();
        }
        if (arg0.getWrappedObject() instanceof TemplateNode)
        {
            // test to see if this node has the aspect
            if ( ((TemplateNode)arg0.getWrappedObject()).hasAspect(arg1String) )
            {
                result = 1;
            }
        }
    }
    
    return Integer.valueOf(result);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:HasAspectMethod.java

示例9: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException
{
    int result = 0;
    
    if (args.size() == 2)
    {
        // arg 0 must be a wrapped TemplateNode object
        BeanModel arg0 = (BeanModel)args.get(0);
        
        // arg 1 must be a String permission name
        String permission;
        Object arg1 = args.get(1);
        if (arg1 instanceof TemplateScalarModel)
        {
            permission = ((TemplateScalarModel)arg1).getAsString();
            
            if (arg0.getWrappedObject() instanceof TemplateNode)
            {
                // test to see if this node has the permission
                if ( ((TemplateNode)arg0.getWrappedObject()).hasPermission(permission) )
                {
                    result = 1;
                }
            }
        }
    }
    
    return Integer.valueOf(result);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:33,代码来源:HasPermissionMethod.java

示例10: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException
{
    String result = null;
    
    if (args.size() == 1)
    {
        // arg 0 can be either wrapped QName object or a String 
        String arg0String = null;
        Object arg0 = args.get(0);
        if (arg0 instanceof BeanModel)
        {
            arg0String = ((BeanModel)arg0).getWrappedObject().toString();
        }
        else if (arg0 instanceof TemplateScalarModel)
        {
            arg0String = ((TemplateScalarModel)arg0).getAsString();
        }

        try
        {
        result = createQName(arg0String).toPrefixString(services.getNamespaceService());
    }
        catch (NamespaceException e) 
        {
            // not valid qname -> return original value
            result = arg0String;
        }
    }
    
    return result != null ? result : "";
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:35,代码来源:ShortQNameMethod.java

示例11: extractRestrictableDateFrom

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
private Optional<RestrictableDate> extractRestrictableDateFrom(final Map parameters) {

        return Optional.ofNullable(parameters.get(DATE_PARAM_NAME))
            .map(parameter -> (StringModel) parameter)
            .map(BeanModel::getWrappedObject)
            .map(wrappedObject -> (RestrictableDate)wrappedObject);
    }
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:8,代码来源:RestrictableDateFormatterDirective.java

示例12: createFunction

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@Override
public Object createFunction(Function<List, Object> func) {
    return (TemplateMethodModelEx) arguments ->
            func.apply((List)arguments.stream().map(arg -> {
                if (arg instanceof BeanModel) {
                    return ((StringModel) arg).getWrappedObject();
                } else {
                    return arg;
                }
            }).collect(Collectors.toList()));
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:12,代码来源:FreemarkerTemplateEngine.java

示例13: unwrap

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T unwrap(Object o) {
    Object returnObj = null;

    if (o == TemplateModel.NOTHING) {
        returnObj = null;
    } else if (o instanceof SimpleScalar) {
        returnObj = o.toString();
    } else if (o instanceof BeanModel) {
        returnObj = ((BeanModel) o).getWrappedObject();
    }

    return (T) returnObj;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:15,代码来源:FreeMarkerWorker.java

示例14: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguements");
    if (!(args.get(0) instanceof TemplateScalarModel))
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel");
    // SCIPIO: This is too limiting...
    //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 = FreeMarkerWorker.getCurrentEnvironment();
    BeanModel req = (BeanModel)env.getVariable("request");
    HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();

    // SCIPIO: name should not be escaped
    //String name = ((TemplateScalarModel) args.get(0)).getAsString();
    String name = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
    Object valueModel = args.get(1);
    Object value = null;
    // SCIPIO: Let DeepUnwrap handle this...
    //if (args.get(1) instanceof TemplateScalarModel)
    //    value = ((TemplateScalarModel) args.get(1)).getAsString();
    //if (args.get(1) instanceof TemplateNumberModel)
    //    value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    //if (args.get(1) instanceof BeanModel)
    //    value = ((BeanModel) args.get(1)).getWrappedObject();
    // SCIPIO: NOTE: Unlike this above, this call will avoid the auto-escaping as implemented by Ofbiz (sensitive to DeepUnwrap implementation)
    value = LangFtlUtil.unwrapAlwaysUnlessNull(valueModel);
    
    request.setAttribute(name, value);
    return new SimpleScalar("");
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:33,代码来源:SetRequestAttributeMethod.java

示例15: exec

import freemarker.ext.beans.BeanModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguements");
    if (!(args.get(0) instanceof TemplateScalarModel))
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel");
    // SCIPIO: This is too limiting...
    //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 = FreeMarkerWorker.getCurrentEnvironment();
    BeanModel req = (BeanModel)env.getVariable("context");
    Map context = (Map) req.getWrappedObject();

    // SCIPIO: name should not be escaped
    //String name = ((TemplateScalarModel) args.get(0)).getAsString();
    String name = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
    Object valueModel = args.get(1);
    Object value = null;
    // SCIPIO: Let DeepUnwrap handle this...
    //if (args.get(1) instanceof TemplateNumberModel)
    //    value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    //if (args.get(1) instanceof BeanModel)
    //    value = ((BeanModel) args.get(1)).getWrappedObject();
    // SCIPIO: NOTE: Unlike this above, this call will avoid the auto-escaping as implemented by Ofbiz (sensitive to DeepUnwrap implementation)
    value = LangFtlUtil.unwrapAlwaysUnlessNull(valueModel);
            
    context.put(name, value);
    return new SimpleScalar("");
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:31,代码来源:SetContextFieldTransform.java


注:本文中的freemarker.ext.beans.BeanModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。