net.groupbuy.template.directive.CurrentMemberDirective.java Source code

Java tutorial

Introduction

Here is the source code for net.groupbuy.template.directive.CurrentMemberDirective.java

Source

/*
 * Copyright 2005-2013 shopxx.net. All rights reserved.
 * Support: http://www.shopxx.net
 * License: http://www.shopxx.net/license
 */
package net.groupbuy.template.directive;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import javax.annotation.Resource;

import net.groupbuy.entity.Member;
import net.groupbuy.service.MemberService;

import org.springframework.stereotype.Component;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * ? - ?
 * 
 * @author SHOP++ Team
 * @version 3.0
 */
@Component("currentMemberDirective")
public class CurrentMemberDirective extends BaseDirective {

    /** ???? */
    private static final String VARIABLE_NAME = "currentMember";

    @Resource(name = "memberServiceImpl")
    private MemberService memberService;

    @SuppressWarnings("rawtypes")
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
            throws TemplateException, IOException {
        Member currentMember = memberService.getCurrent();
        if (body != null) {
            setLocalVariable(VARIABLE_NAME, currentMember, env, body);
        } else {
            if (currentMember != null) {
                Writer out = env.getOut();
                out.write(currentMember.getUsername());
            }
        }
    }

}