/** * Gets the value of a {@link Template}-scope attribute from the given {@link Template}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_TEMPLATE}. * @throws NullPointerException * If {@code template} is null */ public final Object get(Template template) { if (scope != SCOPE_TEMPLATE) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) template).getCustomAttribute(key, this); }
/** * Gets the value of a {@link Configuration}-scope attribute from the given {@link Configuration}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_CONFIGURATION}. * @throws NullPointerException * If {@code cfg} is null * * @since 2.3.22 */ public final Object get(Configuration cfg) { if (scope != SCOPE_CONFIGURATION) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) cfg).getCustomAttribute(key, this); }
/** * Retrieves a named custom attribute for this configurable. If the * attribute is not present in the configurable, and the configurable has * a parent, then the parent is looked up as well. * * @param name the name of the custom attribute * * @return the value of the custom attribute. Note that if the custom attribute * was created with <tt><#ftl attributes={...}></tt>, then this value is already * unwrapped (i.e. it's a <code>String</code>, or a <code>List</code>, or a * <code>Map</code>, ...etc., not a FreeMarker specific class). */ public Object getCustomAttribute(String name) { Object retval; synchronized (customAttributes) { retval = customAttributes.get(name); if (retval == null && customAttributes.containsKey(name)) { return null; } } if (retval == null && parent != null) { return parent.getCustomAttribute(name); } return retval; }
/** * Gets the attribute from the appropriate scope that's accessible through the specified {@link Environment}. If * the attribute has {@link #SCOPE_ENVIRONMENT} scope, it will be get from the given {@link Environment} directly. * If the attribute has {@link #SCOPE_TEMPLATE} scope, it will be get from the parent of the given * {@link Environment} (that is, in {@link Environment#getParent()}) directly). If the attribute has * {@link #SCOPE_CONFIGURATION} scope, it will be get from {@link Environment#getConfiguration()}. * * @throws NullPointerException * If {@code env} is null * * @return The new value of the attribute (possibly {@code null}), or {@code null} if the attribute doesn't exist. * * @since 2.3.22 */ public final Object get(Environment env) { return getScopeConfigurable(env).getCustomAttribute(key, this); }
/** * Same as {@link #get(Environment)}, but uses {@link Environment#getCurrentEnvironment()} to fill the 2nd argument. * * @throws IllegalStateException * If there is no current {@link Environment}, which is usually the case when the current thread isn't * processing a template. */ public final Object get() { return getScopeConfigurable(getRequiredCurrentEnvironment()).getCustomAttribute(key, this); }
/** * @return the value of a template-scope attribute in the context of a * given template. * @throws UnsupportedOperationException if this custom attribute is not a * template-scope attribute * @throws NullPointerException if t is null */ public final Object get(Template t) { if(scope != SCOPE_TEMPLATE) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable)t).getCustomAttribute(key, this); }
/** * Gets the value of a {@link Configuration}-scope attribute from the given {@link Configuration}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_CONFIGURATION}. * @throws NullPointerException * If {@code cfg} is null * * @since 2.3.22 */ public final Object get(Configuration cfg) { if (scope != SCOPE_CONFIGURATION) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) cfg).getCustomAttribute(key, this); }
/** * Gets the value of a {@link Template}-scope attribute from the given {@link Template}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_TEMPLATE}. * @throws NullPointerException * If {@code template} is null */ public final Object get(Template template) { if (scope != SCOPE_TEMPLATE) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) template).getCustomAttribute(key, this); }
/** * Gets the value of a {@link Template}-scope attribute from the given {@link Template}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_TEMPLATE}. * @throws NullPointerException * If {@code template} is null */ public final Object get(Template template) { if (scope != SCOPE_TEMPLATE) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) template).getCustomAttribute(key, this); }
/** * Gets the value of a {@link Configuration}-scope attribute from the given {@link Configuration}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_CONFIGURATION}. * @throws NullPointerException * If {@code cfg} is null * * @since 2.3.22 */ public final Object get(Configuration cfg) { if (scope != SCOPE_CONFIGURATION) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) cfg).getCustomAttribute(key, this); }
/** * @return the value of the attribute in the context of the current environment. * @throws IllegalStateException if there is no current environment (and * hence also no current template and configuration), therefore the * attribute's current scope object can't be resolved. */ public final Object get() { return getScopeConfigurable().getCustomAttribute(key, this); }
/** * Retrieves a named custom attribute for this configurable. If the * attribute is not present in the configurable, and the configurable has * a parent, then the parent is looked up as well. * * @param name the name of the custom attribute * * @return the value of the custom attribute. Note that if the custom attribute * was created with <tt><#ftl attributes={...}></tt>, then this value is already * unwrapped (i.e. it's a <code>String</code>, or a <code>List</code>, or a * <code>Map</code>, ...etc., not a FreeMarker specific class). */ public Object getCustomAttribute(String name) { Object retval; synchronized (customAttributes) { retval = customAttributes.get(name); if (retval == null && customAttributes.containsKey(name)) { return null; } } if (retval == null && parent != null) { return parent.getCustomAttribute(name); } return retval; }
/** * Retrieves a named custom attribute for this configurable. If the * attribute is not present in the configurable, and the configurable has * a parent, then the parent is looked up as well. * * @param name the name of the custom attribute * * @return the value of the custom attribute. Note that if the custom attribute * was created with <tt><#ftl attributes={...}></tt>, then this value is already * unwrapped (i.e. it's a <code>String</code>, or a <code>List</code>, or a * <code>Map</code>, ...etc., not a FreeMarker specific class). */ public Object getCustomAttribute(String name) { Object retval; synchronized (customAttributes) { retval = customAttributes.get(name); if (retval == null && customAttributes.containsKey(name)) { return null; } } if (retval == null && parent != null) { return parent.getCustomAttribute(name); } return retval; }
/** * Retrieves a named custom attribute for this configurable. If the * attribute is not present in the configurable, and the configurable has * a parent, then the parent is looked up as well. * * @param name the name of the custom attribute * * @return the value of the custom attribute. Note that if the custom attribute * was created with <tt><#ftl attributes={...}></tt>, then this value is already * unwrapped (i.e. it's a <code>String</code>, or a <code>List</code>, or a * <code>Map</code>, ...etc., not a FreeMarker specific class). */ public Object getCustomAttribute(String name) { Object retval; synchronized(customAttributes) { retval = customAttributes.get(name); if(retval == null && customAttributes.containsKey(name)) { return null; } } if(retval == null && parent != null) { return parent.getCustomAttribute(name); } return retval; }
/** * Gets the attribute from the appropriate scope that's accessible through the specified {@link Environment}. If * the attribute has {@link #SCOPE_ENVIRONMENT} scope, it will be get from the given {@link Environment} directly. * If the attribute has {@link #SCOPE_TEMPLATE} scope, it will be get from the parent of the given * {@link Environment} (that is, in {@link Environment#getParent()}) directly). If the attribute has * {@link #SCOPE_CONFIGURATION} scope, it will be get from {@link Environment#getConfiguration()}. * * @throws NullPointerException * If {@code env} is null * * @return The new value of the attribute (possibly {@code null}), or {@code null} if the attribute doesn't exist. * * @since 2.3.22 */ public final Object get(Environment env) { return getScopeConfigurable(env).getCustomAttribute(key, this); }
/** * Gets the attribute from the appropriate scope that's accessible through the specified {@link Environment}. If * the attribute has {@link #SCOPE_ENVIRONMENT} scope, it will be get from the given {@link Environment} directly. * If the attribute has {@link #SCOPE_TEMPLATE} scope, it will be get from the parent of the given * {@link Environment} (that is, in {@link Environment#getParent()}) directly). If the attribute has * {@link #SCOPE_CONFIGURATION} scope, it will be get from {@link Environment#getConfiguration()}. * * @throws NullPointerException * If {@code env} is null * * @return The new value of the attribute (possibly {@code null}), or {@code null} if the attribute doesn't exist. * * @since 2.3.22 */ public final Object get(Environment env) { return getScopeConfigurable(env).getCustomAttribute(key, this); }
/** * Same as {@link #get(Environment)}, but uses {@link Environment#getCurrentEnvironment()} to fill the 2nd argument. * * @throws IllegalStateException * If there is no current {@link Environment}, which is usually the case when the current thread isn't * processing a template. */ public final Object get() { return getScopeConfigurable(getRequiredCurrentEnvironment()).getCustomAttribute(key, this); }
/** * Same as {@link #get(Environment)}, but uses {@link Environment#getCurrentEnvironment()} to fill the 2nd argument. * * @throws IllegalStateException * If there is no current {@link Environment}, which is usually the case when the current thread isn't * processing a template. */ public final Object get() { return getScopeConfigurable(getRequiredCurrentEnvironment()).getCustomAttribute(key, this); }