ToolboxConfiguration toolbox = new ToolboxConfiguration(); toolbox.setScope(Scope.APPLICATION); toolbox.addTool(localizationTool); factoryConfig.addToolbox(toolbox); velocityToolManager.configure(factoryConfig);
public void addTool(ToolConfiguration tool) { addChild(tool); }
public String toString() { StringBuilder out = new StringBuilder(); out.append("Toolbox '"); out.append(this.scope); out.append("' "); appendProperties(out); appendChildren(out, "tools: \n ", "\n "); return out.toString(); }
public EasyWrap<ToolboxConfiguration> toolbox(String scope) { ToolboxConfiguration toolbox = new ToolboxConfiguration(); toolbox.setScope(scope); addToolbox(toolbox); this.toolbox = new EasyWrap<ToolboxConfiguration>(toolbox, this); return this.toolbox; }
String scope = toolbox.getScope(); for (ToolConfiguration tool : toolbox.getTools()) Map<String,Object> newToolboxProps = toolbox.getPropertyMap(); putProperties(scope, newToolboxProps);
public EasyWrap tool(String key, String classname) { ToolConfiguration tool = new ToolConfiguration(); if (key != null) { tool.setKey(key); } tool.setClassname(classname); if (this.config instanceof ToolConfiguration) { ToolboxConfiguration toolbox = (ToolboxConfiguration)getParent(); toolbox.addTool(tool); return new EasyWrap(tool, toolbox); } else if (this.config instanceof ToolboxConfiguration) { ToolboxConfiguration toolbox = (ToolboxConfiguration)getConfiguration(); toolbox.addTool(tool); return new EasyWrap(tool, toolbox); } throw new IllegalStateException("Wrapping unknown "+Configuration.class.getName()+": "+getConfiguration()); } }
if (getScope() == 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()+"\")."); for (ToolConfiguration tool : getTools()) if (getScope().equals(invalidScope)) for (String validScope : validScopes) if (getScope().equals(validScope))
@Override public int compareTo(Configuration conf) { if (!(conf instanceof ToolboxConfiguration)) { throw new UnsupportedOperationException("ToolboxConfigurations can only be compared to other ToolboxConfigurations"); } ToolboxConfiguration toolbox = (ToolboxConfiguration)conf; return getScope().compareTo(toolbox.getScope()); }
public ToolConfiguration getTool(String key) { for (ToolConfiguration tool : getTools()) { if (key.equals(tool.getKey())) { return tool; } } return null; }
public Collection<ToolConfiguration> getTools() { return getChildren(); }
protected void readToolboxes(ExtProperties factory) { String[] scopes = factory.getStringArray("toolbox"); for (String scope : scopes) { ToolboxConfiguration toolbox = new ToolboxConfiguration(); toolbox.setScope(scope); addToolbox(toolbox); ExtProperties toolboxProps = factory.subset(scope); readTools(toolboxProps, toolbox); readProperties(toolboxProps, toolbox); } }
tool.setClassname(classname); tool.setKey(key); toolbox.addTool(tool);
public InvalidScopeException(ToolboxConfiguration toolbox, ToolConfiguration tool) { super(toolbox, "Toolbox with scope '" + toolbox.getScope() + "' may not contain a " + tool.getClassname() + '.'); this.tool = tool; }
public EasyWrap<C> restrictTo(String path) { if (this.config instanceof ToolConfiguration) { ToolConfiguration tool = (ToolConfiguration)this.config; tool.setRestrictTo(path); return this; } else if (this.config instanceof ToolboxConfiguration) { ToolboxConfiguration toolbox = (ToolboxConfiguration)this.config; for (ToolConfiguration tool : toolbox.getTools()) { tool.setRestrictTo(path); } return this; } throw new IllegalStateException("Wrapping unknown "+Configuration.class.getName()+": "+getConfiguration()); }
public ToolboxConfiguration getToolbox(String scope) { for (ToolboxConfiguration toolbox : getToolboxes()) { if (scope.equals(toolbox.getScope())) { return toolbox; } } return null; }
public void clean(ToolboxConfiguration toolbox) { cleanProperties(toolbox); // go thru tools to log and remove debug ones Iterator<ToolConfiguration> i = toolbox.getTools().iterator(); while (i.hasNext()) { ToolConfiguration tool = i.next(); cleanProperties(tool); try { tool.validate(); } catch (ConfigurationException ce) { if (LOG != null) { LOG.debug("ConfigurationCleaner : ", ce); LOG.warn("ConfigurationCleaner : Removing {}", tool); } i.remove(); } } //TODO: loop on validate() until all debug scoped tools are removed }