org.apache.velocity.tools.Scope Java Examples
The following examples show how to use
org.apache.velocity.tools.Scope.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderTool.java From velocity-tools with Apache License 2.0 | 6 votes |
/** * Looks for deprecated parse depth and catch.exceptions properties, * as well as any 'forceThreadSafe' setting. */ protected void configure(ValueParser parser) { // look for deprecated parse.depth key Integer depth = parser.getInteger(KEY_PARSE_DEPTH); if (depth != null) { setParseDepth(depth); } // look for deprecated catch.exceptions key Boolean catchEm = parser.getBoolean(KEY_CATCH_EXCEPTIONS); if (catchEm != null) { setCatchExceptions(catchEm); } // check if they want thread-safety manually turned off this.forceThreadSafe = parser.getBoolean(KEY_FORCE_THREAD_SAFE, forceThreadSafe); // if we're request-scoped, then there's no point in forcing the issue if (Scope.REQUEST.equals(parser.getString("scope"))) { this.forceThreadSafe = false; } }
Example #2
Source File: ToolboxFactory.java From velocity-tools with Apache License 2.0 | 5 votes |
public boolean hasTools(String scope) { Map<String,ToolInfo> tools = scopedToolInfo.get(scope); if (tools != null && !tools.isEmpty()) { return true; } else if (data != null && Scope.APPLICATION.equals(scope)) { return true; } return false; }
Example #3
Source File: ToolboxFactory.java From velocity-tools with Apache License 2.0 | 5 votes |
public Toolbox createToolbox(String scope) { Map<String,ToolInfo> tools = scopedToolInfo.get(scope); Map properties = scopedProperties.get(scope); Toolbox toolbox; if (properties == null) { if (globalProperties == null) { toolbox = new Toolbox(tools); } else { toolbox = new Toolbox(tools, globalProperties); } } else { //TODO: this will waste cycles on subsequent retrievals // of the same toolbox. consider improving... if (globalProperties != null) { properties.putAll(globalProperties); } toolbox = new Toolbox(tools, properties); } // if application scoped or if there's only one toolbox, // then automatically include data, if we have any. if (data != null && (scopedToolInfo.size() == 1 || scope.equals(Scope.APPLICATION))) { toolbox.cacheData(getData()); } return toolbox; }
Example #4
Source File: ConfigTests.java From velocity-tools with Apache License 2.0 | 5 votes |
protected FactoryConfiguration getBaseConfig() { FactoryConfiguration base = new FactoryConfiguration(); Data datum = new Data(); datum.setKey("version"); datum.setType("number"); datum.setValue("2.0"); base.addData(datum); ToolboxConfiguration toolbox = new ToolboxConfiguration(); toolbox.setScope(Scope.REQUEST); toolbox.setProperty("locale", Locale.US); ToolConfiguration tool = new ToolConfiguration(); tool.setClass(ResourceTool.class); toolbox.addTool(tool); base.addToolbox(toolbox); toolbox = new ToolboxConfiguration(); toolbox.setScope(Scope.APPLICATION); tool = new ToolConfiguration(); tool.setKey("calc"); tool.setClass(MathTool.class); toolbox.addTool(tool); tool = new ToolConfiguration(); tool.setClass(NumberTool.class); tool.setProperty("locale", Locale.FRENCH); toolbox.addTool(tool); base.addToolbox(toolbox); return base; }
Example #5
Source File: ToolboxConfiguration.java From velocity-tools with Apache License 2.0 | 4 votes |
@Override public void validate() { super.validate(); if (getScope() == null) { throw new ConfigurationException(this, "Toolbox scope cannot be null"); } if (!Scope.exists(getScope())) { throw new ConfigurationException(this, "Scope '"+getScope()+"' is not recognized. Please correct or add your new custom scope with "+Scope.class.getName()+".add(\""+getScope()+"\")."); } // validate that all tools are allowed in this scope for (ToolConfiguration tool : getTools()) { // check if this toolbox's scope has been declared invalid for (String invalidScope : tool.getInvalidScopes()) { if (getScope().equals(invalidScope)) { throw new InvalidScopeException(this, tool); } } // if the set of valid scopes has been limited, check to be // sure that this toolbox's scope is in the set String[] validScopes = tool.getValidScopes(); if (validScopes != null && validScopes.length > 0) { boolean found = false; for (String validScope : validScopes) { if (getScope().equals(validScope)) { found = true; break; } } if (!found) { throw new InvalidScopeException(this, tool); } } } }
Example #6
Source File: ViewToolManager.java From velocity-tools with Apache License 2.0 | 4 votes |
public boolean hasSessionTools() { return hasTools(Scope.SESSION); }
Example #7
Source File: ViewToolManager.java From velocity-tools with Apache License 2.0 | 4 votes |
protected Toolbox getSessionToolbox() { return createToolbox(Scope.SESSION); }