本文整理匯總了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