/**
 * $RCSfile$
 * Copyright 2002-2003 by Robert Simmons Jr., All Rights Reserved
 * 
 * Last Checked in by: $Author$
 * Last Checked in on: $Date$
 * Currently Locked By: $Locker$
 * Working Tag: $Name$
 * 
 * End: Mirror Standard Header.
***** DO NOT EDIT ABOVE THIS LINE *****/
package jconfer.client.xmlclient.commands;

import java.util.Collection;
import java.util.Iterator;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import jconfer.client.xmlclient.XMLClientCommand;
import jconfer.data.Smiley;
import mirror.datafetch.DataFetch;
import mirror.datafetch.DataFetchHome;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/** Handles a command for getting an admin screen for forum smileys.
 *
 * <p><b><small>Current CVS Tag:  $Name$</b></small></p>
 * @version $Revision$
 * @author $author$
 */
public class SmileyAdminView extends XMLClientCommand {

  /** Creates a new instance of SmileyAdminView */
  public SmileyAdminView() throws NamingException {
    super();
  }

  /** {@inheritDoc} */
  public Element executeCommand(final HttpServletRequest request, 
                                final Document doc)
    throws Exception {
    DataFetchHome dfHome = (DataFetchHome)jndiLookup(DataFetchHome.class, 
                                                     "JConfer/DataFetch");
    DataFetch dataFetch = dfHome.create();
    Collection smileys = dataFetch.performQuery(Smiley.class, null, null, null, 
                                                null, "code ascending");
    // --
    Iterator iter = smileys.iterator();
    Smiley tgtSmiley = null;
    Element result = doc.createElement("smiley-admin-view");
    Element node = null;
    while (iter.hasNext()) {
      tgtSmiley = (Smiley)iter.next();
      node = doc.createElement("smiley");
      node.setAttribute("code", tgtSmiley.getCode());
      node.setAttribute("description", tgtSmiley.getDescription());
      result.appendChild(node);
    }
    return result;
  }
}

