當前位置: 首頁>>代碼示例>>Java>>正文


Java BeansWrapper類代碼示例

本文整理匯總了Java中freemarker.ext.beans.BeansWrapper的典型用法代碼示例。如果您正苦於以下問題:Java BeansWrapper類的具體用法?Java BeansWrapper怎麽用?Java BeansWrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BeansWrapper類屬於freemarker.ext.beans包,在下文中一共展示了BeansWrapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testShowItIsPossibleToPassInBeansWrappedObject

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
public void testShowItIsPossibleToPassInBeansWrappedObject() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    String txt = "<#if (classInfo.getMethods().size() > 0) >The size is greater than 0.</#if>";
    os.write(txt.getBytes());
    os.close();       
    
    
    StringWriter w = new StringWriter();
                    
    Map<String,Object> parameters = Collections.<String,Object>singletonMap(
        "classInfo", BeansWrapper.getDefaultInstance().wrap(new ClassInfo())
    );
    apply(fo, w, parameters);
    assertEquals("The size is greater than 0.", w.toString());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ProcessorTest.java

示例2: ButtonListTagRenderer

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
@SuppressWarnings("nls")
public ButtonListTagRenderer(String tag, HtmlListState state, Environment env, TemplateDirectiveBody body,
	TemplateModel[] loopVars, boolean hideDisabledOptions)
{
	super(tag, state); //$NON-NLS-1$
	this.wrapper = (BeansWrapper) env.getObjectWrapper();
	this.listState = state;
	this.body = body;
	this.loopVars = loopVars;
	this.hideDisabledOptions = hideDisabledOptions;

	this.hiddenId = new AppendedElementId(state, "_hid");
	ScriptVariable valVar = new ScriptVariable("val");
	JSStatements changeBody = new AssignStatement(new ElementValueExpression(hiddenId), valVar);

	JSHandler lsChangeHandler = state.getHandler(JSHandler.EVENT_CHANGE);
	if( lsChangeHandler != null )
	{
		changeBody = StatementBlock.get(changeBody, lsChangeHandler);
	}
	clickFunc = new SimpleFunction(JSHandler.EVENT_CHANGE, state, changeBody, valVar);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:ButtonListDirective.java

示例3: makeSimpleMapAdapter

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
/**
 * Adapts a map to a TemplateHashModelEx using an appropriate simple adapter, normally 
 * DefaultMapAdapter (or SimpleMapModel for BeansWrapper compatibility).
 * <p>
 * The ObjectWrapper is expected to implement at least ObjectWrapperWithAPISupport.
 * <p>
 * WARN: If impossible, it will duplicate the map using SimpleHash; but because this may result
 * in loss of ordering, a log warning will be printed.
 */
public static TemplateHashModelEx makeSimpleMapAdapter(Map<?, ?> map, ObjectWrapper objectWrapper, boolean permissive) throws TemplateModelException {
    // COMPATIBILITY MODE: check if exactly BeansWrapper, or a class that we know extends it WITHOUT extending DefaultObjectWrapper
    if (objectWrapper instanceof ScipioBeansWrapper || BeansWrapper.class.equals(objectWrapper.getClass())) {
        return new SimpleMapModel(map, (BeansWrapper) objectWrapper);
    } else if (objectWrapper instanceof ObjectWrapperWithAPISupport) {
        return DefaultMapAdapter.adapt(map, (ObjectWrapperWithAPISupport) objectWrapper);
    } else {
        if (permissive) {
            Debug.logWarning("Scipio: adaptSimpleMap: Unsupported Freemarker object wrapper (expected to implement ObjectWrapperWithAPISupport or BeansWrapper); forced to adapt map"
                    + " using SimpleHash; this could cause loss of map insertion ordering; please switch renderer setup to a different ObjectWrapper", module);
            return new SimpleHash(map, objectWrapper);
        } else {
            throw new TemplateModelException("Tried to wrap a Map using an adapter class,"
                    + " but our ObjectWrapper does not implement ObjectWrapperWithAPISupport or BeansWrapper"
                    + "; please switch renderer setup to a different ObjectWrapper");
        }
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:28,代碼來源:LangFtlUtil.java

示例4: toSimpleMapRewrapAdapters

import freemarker.ext.beans.BeansWrapper; //導入依賴的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: toSimpleMapRewrapAny

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
/**
 * Converts map to a simple wrapper, if applicable, by rewrapping
 * any map wrappers that implement <code>WrapperTemplateModel</code>.
 * <p>
 * This method is very permissive: anything that wraps a Map is accepted.
 * Other types of hashes are returned as-is.
 * <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 toSimpleMapRewrapAny(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (object instanceof WrapperTemplateModel) {
        // 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,代碼行數:38,代碼來源:LangFtlUtil.java

示例6: getWrapper

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
@Override
public ObjectWrapper getWrapper(Environment env) {
    ObjectWrapper curr = env.getObjectWrapper();
    if (curr instanceof ScipioExtendedObjectWrapper) {
        if (curr instanceof ScipioBeansWrapper) {
            if (((BeansWrapper) curr).isSimpleMapWrapper()) {
                return FreeMarkerWorker.getDefaultOfbizSimpleMapWrapper();
            } else {
                return FreeMarkerWorker.getDefaultOfbizWrapper();
            }
        } else {
            return FreeMarkerWorker.getDefaultOfbizSimpleMapWrapper();
        }
    } else {
        return curr;
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:18,代碼來源:ObjectWrapperUtil.java

示例7: unwrapParameters

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
protected Map unwrapParameters(Map params) {
    Map map = new HashMap(params.size());
    BeansWrapper objectWrapper = BeansWrapper.getDefaultInstance();
    for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();

        Object value = entry.getValue();

        if (value != null) {
            // the value should ALWAYS be a decendant of TemplateModel
            if (value instanceof TemplateModel) {
                try {
                    map.put(entry.getKey(), objectWrapper.unwrap((TemplateModel) value));
                } catch (TemplateModelException e) {
                    LOG.error("failed to unwrap [{}] it will be ignored", value.toString(), e);
                }
            }
            // if it doesn't, we'll do it the old way by just returning the toString() representation
            else {
                map.put(entry.getKey(), value.toString());
            }
        }
    }
    return map;
}
 
開發者ID:txazo,項目名稱:struts2,代碼行數:26,代碼來源:TagModel.java

示例8: getParam

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> T getParam(String name, Class<?> type, Object defaultValue) {
    try {
        Object o = params.get(name);

        if (o != null) {
            if (o instanceof TemplateModel) {
                return (T) eval(BeansWrapper.getDefaultInstance().unwrap((TemplateModel) o), type, defaultValue);
            } else {
                return (T) eval(o, type, defaultValue);
            }
        } else {
            TemplateModel tm = hash().get(name);

            if (tm != null) {
                return (T) eval(BeansWrapper.getDefaultInstance().unwrap(tm), type, defaultValue);
            }
        }
    } catch (TemplateModelException e) {
        throw new RuntimeException(e);
    }

    return null;
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:26,代碼來源:FreemarkerWidgetContext.java

示例9: prepareParams

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
protected static Map<String, Object> prepareParams(Map<String, ?> parameterValues) {
    Map<String, Object> parameterValuesWithStats = new HashMap<>(parameterValues);
    parameterValuesWithStats.put("statics", BeansWrapper.getDefaultInstance().getStaticModels());

    @SuppressWarnings("unchecked")
    Map<String, Object> params = LazyMap.lazyMap(parameterValuesWithStats, propertyName -> {
        for (String appProperty : AppContext.getPropertyNames()) {
            if (appProperty.replace(".", "_").equals(propertyName)) {
                return AppContext.getProperty(propertyName);
            }
        }
        return null;
    });

    return params;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:17,代碼來源:TemplateHelper.java

示例10: freemarkerConfig

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
/**
 * FreeMarker (ftl) configuration
 */
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
	final FreeMarkerConfigurer result = new FreeMarkerConfigurer();

	// template path
	result.setTemplateLoaderPath("/WEB-INF/ftl/");
	result.setDefaultEncoding("UTF-8");

	// static access
	final Version version = freemarker.template.Configuration.getVersion();
	final BeansWrapper wrapper = new BeansWrapper(version);
	final TemplateHashModel statics = wrapper.getStaticModels();
	final Map<String, Object> shared = new HashMap<>();
	for (final Class<?> clazz : ElFunctions.staticClasses) {
		shared.put(clazz.getSimpleName(), statics.get(clazz.getName()));
	}
	result.setFreemarkerVariables(shared);

	return result;
}
 
開發者ID:Katharsas,項目名稱:GMM,代碼行數:24,代碼來源:ApplicationConfiguration.java

示例11: getRoot

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
public Map<String, Object> getRoot(HttpServletRequest request) throws ServletException {
	Map<String, Object> root = new HashMap<String, Object>();
	root.put("basePath", this.getBasePath());

	try {
		BeansWrapper beansWrapper = new BeansWrapperBuilder(Configuration.VERSION_2_3_21).build();
		TemplateHashModel staticModels = beansWrapper.getStaticModels();
		TemplateHashModel stringUtils = (TemplateHashModel) staticModels.get(StringUtils.class.getCanonicalName());
		TemplateHashModel planInvocationHelper = (TemplateHashModel) staticModels.get(PlanInvocationHelper.class
				.getCanonicalName());
		root.put("StringUtils", stringUtils);
		root.put("PlanInvocationHelper", planInvocationHelper);
	} catch (TemplateModelException e) {
		throw new ServletException(e);
	}

	root.put(ERRORS, request.getSession().getAttribute(ERRORS));
	root.put(SUCCESSES, request.getSession().getAttribute(SUCCESSES));
	request.getSession().setAttribute(ERRORS, new ArrayList<String>());
	request.getSession().setAttribute(SUCCESSES, new ArrayList<String>());
	return root;
}
 
開發者ID:CloudCycle2,項目名稱:CSAR_Repository,代碼行數:23,代碼來源:AbstractServlet.java

示例12: FreemarkerStatementModel

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
public FreemarkerStatementModel(TableMetadata<?> tableMetadata, DatabaseDialect dialect, Object value) throws TemplateModelException {
    this.wrapper = BeansWrapper.getDefaultInstance();
    items.put("dialect", wrapper.wrap(dialect));
    items.put("table", wrapper.wrap(tableMetadata));
    items.put("value", new UnresolvedMapModel("value"));
    items.put("old", new UnresolvedMapModel("old"));
    items.put("new", new UnresolvedMapModel("new"));
    items.put("qualify", new DatabaseIdentifierQualifierMethod(dialect));
    items.put("isNotGenerated", new NonGeneratedColumnFilterMethod(tableMetadata));
    items.put("isGenerated", new GeneratedColumnFilterMethod(tableMetadata));
    items.put("isNotReference", new NonForeignKeyFilterMethod());
    items.put("isReference", new ForeignKeyFilterMethod());
    items.put("isSet", new ValueColumnSelectorMethod(value));
    items.put("isVersion", new VersionColumnSelectorMethod());
    items.put("isNotVersion", new NonVersionColumnSelectorMethod());
    items.put("escape", new EscapeMethod(dialect.getIdentifierEscapeCharacter()));
    items.put("quote", new QuoteMethod(dialect.getStringEscapeCharacter()));
    items.put("type", new TypeResolverMethod(dialect));
    items.put("column", new ColumnPickerMethod(tableMetadata));
}
 
開發者ID:mmnaseri,項目名稱:dragonfly,代碼行數:21,代碼來源:FreemarkerStatementModel.java

示例13: addStatics

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
/**
 * Sets up the static and common template objects including static methods
 * of math and constant classes. These are placed into a map for use by
 * the templates.
 * 
 * @param map The map to be populated by this method
 * @throws freemarker.template.TemplateException If there is an error creating the objects
 */
protected void addStatics(Map<String, Object> map) throws TemplateException
{
    BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
    TemplateHashModel staticModels = wrapper.getStaticModels();
    TemplateHashModel constantStatics =
            (TemplateHashModel) staticModels.get("com.alvermont.terraj.stargen.Constants");

    map.put("constants", constantStatics);

    TemplateHashModel mathStatics = 
            (TemplateHashModel) staticModels.get("java.lang.Math");
    
    map.put("math", mathStatics);
    
    TemplateHashModel uiStatics = 
            (TemplateHashModel) staticModels.get("com.alvermont.terraj.stargen.ui.UIUtils");
    
    map.put("uiutils", uiStatics);
    
    map.put("enviro", new Enviro());       
    
    map.put("imageroot", "images/");
}
 
開發者ID:madebyjeffrey,項目名稱:TerraJ,代碼行數:32,代碼來源:DetailsFromTemplate.java

示例14: testSpeedOfFreemarker

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
public void testSpeedOfFreemarker() throws Exception {
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(getWorkDir());
    cfg.setObjectWrapper(new BeansWrapper());
    Template templ = cfg.getTemplate("template.txt");
    
    for(int i = 0; i < whereTo.length; i++) {
        Writer out = new BufferedWriter(new FileWriter(whereTo[i]));
        templ.process(parameters, out);
        out.close();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:SpeedTest.java

示例15: useStaticPackage

import freemarker.ext.beans.BeansWrapper; //導入依賴的package包/類
public static TemplateHashModel useStaticPackage(String key) {
    try {
        BeansWrapper wrapper = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel statics = (TemplateHashModel) staticModels.get(key);
        return statics;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:13,代碼來源:FreemarkerStaticModels.java


注:本文中的freemarker.ext.beans.BeansWrapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。