本文整理汇总了Java中freemarker.core.Environment类的典型用法代码示例。如果您正苦于以下问题:Java Environment类的具体用法?Java Environment怎么用?Java Environment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Environment类属于freemarker.core包,在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTagRenderer
import freemarker.core.Environment; //导入依赖的package包/类
@Override
@SuppressWarnings("nls")
protected TagRenderer createTagRenderer(HtmlMutableListState state, Environment env, Map<?, ?> params,
TemplateDirectiveBody body, TemplateModel[] loopVars) throws TemplateModelException
{
String tag = "div";
if( params.containsKey("tag") )
{
tag = ((SimpleScalar) params.get("tag")).getAsString();
}
boolean hideDisabledOptions = false;
if( params.containsKey("hideDisabledOptions") )
{
hideDisabledOptions = ((TemplateBooleanModel) params.get("hideDisabledOptions")).getAsBoolean();
}
return new ButtonListTagRenderer(tag, (HtmlListState) state, env, body, loopVars, hideDisabledOptions);
}
示例2: ButtonListTagRenderer
import freemarker.core.Environment; //导入依赖的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);
}
示例3: getSectionWriter
import freemarker.core.Environment; //导入依赖的package包/类
public SectionWriter getSectionWriter()
{
try
{
AdapterTemplateModel model = (AdapterTemplateModel) Environment.getCurrentEnvironment().getGlobalVariable(
"_info");
if( model != null )
{
return (SectionWriter) model.getAdaptedObject(SectionWriter.class);
}
return null;
}
catch( TemplateModelException e )
{
throw new SectionsRuntimeException(e);
}
}
示例4: getSectionWriter
import freemarker.core.Environment; //导入依赖的package包/类
public SectionWriter getSectionWriter()
{
try
{
return (SectionWriter) ((AdapterTemplateModel) Environment.getCurrentEnvironment().getGlobalVariable(
"_info")) //$NON-NLS-1$
.getAdaptedObject(SectionWriter.class);
}
catch( TemplateModelException e )
{
throw new SectionsRuntimeException(e);
}
}
示例5: execute
import freemarker.core.Environment; //导入依赖的package包/类
@Override
public synchronized void execute(Environment env, @SuppressWarnings("rawtypes") Map params,
TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
entered++;
notifyAll();
final long startTime = System.currentTimeMillis();
while (!released) {
// To avoid blocking the CI server forever is something goes wrong:
if (System.currentTimeMillis() - startTime > BLOCKING_TEST_TIMEOUT) {
LOG.error("JUnit test timed out");
}
try {
wait(1000);
} catch (InterruptedException e) {
LOG.error("JUnit test was interrupted");
}
}
LOG.debug("Blocker released");
}
示例6: execute
import freemarker.core.Environment; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
Long productCategoryId = FreemarkerUtils.getParameter(PRODUCT_CATEGORY_ID_PARAMETER_NAME, Long.class, params);
ProductCategory productCategory = productCategoryService.find(productCategoryId);
List<ProductCategory> productCategories;
if (productCategoryId != null && productCategory == null) {
productCategories = new ArrayList<ProductCategory>();
} else {
boolean useCache = useCache(env, params);
String cacheRegion = getCacheRegion(env, params);
Integer count = getCount(params);
if (useCache) {
productCategories = productCategoryService.findParents(productCategory, count, cacheRegion);
} else {
productCategories = productCategoryService.findParents(productCategory, count);
}
}
setLocalVariable(VARIABLE_NAME, productCategories, env, body);
}
示例7: execute
import freemarker.core.Environment; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
try {
SimpleNumber pFor = (SimpleNumber) params.get("for");
Number forMillis = null;
if (pFor != null) {
forMillis = pFor.getAsNumber();
try {
Thread.sleep(forMillis.longValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
示例8: execPush
import freemarker.core.Environment; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Object execPush(List args, boolean setLast) throws TemplateModelException {
if (args == null || args.size() != 2) {
throw new TemplateModelException("Invalid number of arguments (expected: 2)");
}
TemplateModel nameModel = (TemplateModel) args.get(0);
if (!(nameModel instanceof TemplateScalarModel)) {
throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)");
}
TemplateModel valueModel = (TemplateModel) args.get(1);
Environment env = CommonFtlUtil.getCurrentEnvironment();
ContextFtlUtil.pushRequestStack(LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)), valueModel, setLast, env);
return new SimpleScalar("");
}
示例9: getDirectiveRenderExceptionMode
import freemarker.core.Environment; //导入依赖的package包/类
/**
* Special helper for directives to check what the render mode is going to be when exception is caught.
* This can be used for alternate output.
* WARN: this must be maintained carefully so it matches behavior of our modified OFBizTemplateExceptionHandler
* and methods above.
*/
public static RenderExceptionMode getDirectiveRenderExceptionMode(Environment env, RenderExceptionMode liveExMode) {
MapStack<String> context = null;
CmsPageContext pageContext = null;
try {
context = CmsRenderUtil.getRenderContextAlways(env);
pageContext = CmsRenderUtil.getPageContextAlways(context);
} catch(Throwable t) {
Debug.logError(t, "Cms: isDirectiveCaughtRenderExceptionMode: internal error: could not fetch all page context info from environment", module);
}
boolean isPreview = false;
if (pageContext != null) {
isPreview = pageContext.isPreview();
}
if (!isPreview && liveExMode != null) return liveExMode;
return UtilRender.getRenderExceptionMode(pageContext != null ? pageContext.getRequest() : null);
}
示例10: makeOptions
import freemarker.core.Environment; //导入依赖的package包/类
public static WrappingOptions makeOptions(String wrapper, String mode, Environment env) throws TemplateModelException {
ObjectWrapper targetWrapper = ObjectWrapperUtil.getObjectWrapperByName(wrapper, env);
if (targetWrapper == null) {
throw new TemplateModelException("Unrecognized wrapper name: " + wrapper);
}
if (wrapper == null) {
wrapper = "";
}
RewrapMode rewrapMode = RewrapMode.ALWAYS_DEEP;
if (mode != null && !mode.isEmpty()) {
rewrapMode = RewrapMode.fromString(mode);
if (rewrapMode == null) {
throw new TemplateModelException("Unrecognized rewrapping mode: " + mode);
}
}
return new WrappingOptions(wrapper, ObjectWrapperUtil.getObjectWrapperByName(wrapper, env),
rewrapMode, env.getObjectWrapper());
}
示例11: getRequestStackSize
import freemarker.core.Environment; //导入依赖的package包/类
static Integer getRequestStackSize(String name, HttpServletRequest request,
Map<String, Object> context, Environment env) throws TemplateModelException {
if (request != null) {
return getStackSize(getRequestVarMapFromReqAttribs(request), name);
}
else {
Map<String, Object> globalContext = getGlobalContext(context, env);
if (globalContext != null) {
return getStackSize(getRequestVarMapFromGlobalContext(globalContext), name);
}
else if (env != null) {
return getStackSize(getRequestVarMapFromFtlGlobals(env), name);
}
else {
return null;
}
}
}
示例12: execute
import freemarker.core.Environment; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
Long productCategoryId = FreemarkerUtils.getParameter(PRODUCT_CATEGORY_ID_PARAMETER_NAME, Long.class, params);
ProductCategory productCategory = productCategoryService.find(productCategoryId);
List<ProductCategory> productCategories;
if (productCategoryId != null && productCategory == null) {
productCategories = new ArrayList<ProductCategory>();
} else {
boolean useCache = useCache(env, params);
String cacheRegion = getCacheRegion(env, params);
Integer count = getCount(params);
if (useCache) {
productCategories = productCategoryService.findChildren(productCategory, count, cacheRegion);
} else {
productCategories = productCategoryService.findChildren(productCategory, count);
}
}
setLocalVariable(VARIABLE_NAME, productCategories, env, body);
}
示例13: getWrappedObject
import freemarker.core.Environment; //导入依赖的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);
}
示例14: createEnvironmentMap
import freemarker.core.Environment; //导入依赖的package包/类
public static Map<String, Object> createEnvironmentMap(Environment env) {
Map<String, Object> templateRoot = new HashMap<String, Object>();
Set<String> varNames = null;
try {
varNames = UtilGenerics.checkSet(env.getKnownVariableNames());
} catch (TemplateModelException e1) {
Debug.logError(e1, "Error getting FreeMarker variable names, will not put pass current context on to sub-content", module);
}
if (varNames != null) {
for (String varName: varNames) {
//freemarker.ext.beans.StringModel varObj = (freemarker.ext.beans.StringModel) varNameIter.next();
//Object varObj = varNameIter.next();
//String varName = varObj.toString();
templateRoot.put(varName, FreeMarkerWorker.getWrappedObject(varName, env));
}
}
return templateRoot;
}
示例15: handleTemplateException
import freemarker.core.Environment; //导入依赖的package包/类
/**
* Only prints errors when the configuration-property
* 'core/dev/print_errors' is set to true.
*/
public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException {
try {
// Make sure that the error message is not swallowed somewhere
// unnoticed
// in dev-mode. This way it is clearly visible in the console.
if (false /* app.isDevPrintErrorMessages() */) {
// Print stack trace if we are in debug mode.
te.printStackTrace();
// Print message to template if we are in debug mode.
out.write("[ERROR: " + te.getMessage() + "]");
}
} catch (IOException e) {
e.printStackTrace();
// throw new TemplateException("Failed to print error message.
// Cause: " + e, env);
}
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:22,代码来源:FreemarkerExceptionHandler.java