All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.template.velocity.impl.TemplateContextAdapter Maven / Gradle / Ivy

The newest version!
package org.zodiac.template.velocity.impl;

import org.apache.velocity.VelocityContext;
import org.zodiac.sdk.toolkit.constants.ArrayPool;
import org.zodiac.template.base.TemplateContext;

/**
 * 将TemplateContext适配到velocity context的适配器。
 *
 */
public class TemplateContextAdapter extends VelocityContext {

    private static final long serialVersionUID = 7058778446941818969L;

    private final TemplateContext context;

    public TemplateContextAdapter(TemplateContext context) {
        this.context = context;
    }

    public TemplateContext getTemplateContext() {
        return context;
    }

    @Override
    public Object internalGet(String key) {
        return context.get(key);
    }

    @Override
    public Object internalPut(String key, Object value) {
        Object oldValue = context.get(key);
        context.put(key, value);
        return oldValue;
    }

    @Override
    public boolean internalContainsKey(String key) {
        if (key instanceof String) {
            return context.containsKey((String)key);
        } else {
            return false;
        }
    }

    @Override
    public String[] internalGetKeys() {
        return context.keySet().toArray(ArrayPool.EMPTY_STRING_ARRAY);
    }

    @Override
    public Object internalRemove(String key) {
        if (key instanceof String) {
            Object oldValue = context.get((String)key);
            context.remove((String)key);
            return oldValue;
        } else {
            return null;
        }
    }

    @Override
    public String toString() {
        return "TemplateContextAdapter[" + context + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy