package org.jfox.framework.management.http;

import java.util.Properties;

import org.jfox.framework.ComponentName;
import org.jfox.framework.Registry;

/**
 * @author <a href="mailto:yangyong@ufsoft.com.cn">Young Yang</a>
 */

public class UnregisterComponentCommand implements Command {

    public String doGet(Registry registry, Properties queryMap) throws Exception {
        String compName = queryMap.getProperty("compname");
        registry.unregisterComponent(ComponentName.parseString(compName));

        StringBuffer sb = new StringBuffer();
        sb.append(PageUtil.head("unregister view"));
        sb.append(PageUtil.banner("Unregister View"));
        sb.append(unregisterTable(compName));
        sb.append(linkTable());
        sb.append(PageUtil.foot());
        return sb.toString();

    }

    private static String unregisterTable(String compName) {
        StringBuffer sb = new StringBuffer();
        sb.append("<table width=\"780\" align=\"center\">\n" +
                "  <tr>\n" +
                "    <td width=\"180\"><b>Operation Name: </b></td><td>")
                .append("unregister ")
                .append("</td>\n" +
                "  </tr>\n" +
                "  <tr>\n" +
                "    <td width=\"180\"><b>Component Name: </b></td><td>")
                .append(compName)
                .append("</td>\n" +
                "  </tr>\n" +
                "  <tr>\n" +
                "    <td width=\"180\" valign=\"top\"><b>Operation Result: </b></td><td>")
                .append("sucess")
                .append("</td>\n" +
                "  </tr>\n" +

                "  </tr>\n" +
                "\n" +
                "</table><br>\n" +
                "");
        return sb.toString();

    }

    private static String linkTable() {
        StringBuffer sb = new StringBuffer();
        sb.append("<table width=\"780\" align=\"center\">\n" +
                "  <tr>\n" +
                "    <td>")
                .append("<a href=\"?action=Index")
                .append("\"> &lt;&lt;Return To Index</a>")
                .append("</td>\n" +
                "  </tr>\n" +
                "</table>\n");
        return sb.toString();
    }

    public static void main(String[] args) {

    }
}

