package $JAVA_PACKAGE_NAME$;

import com.novell.emframe.dev.*;
import com.novell.emframe.dev.config.SystemConfig;
import com.novell.emframe.dev.config.ConfigException;

import javax.servlet.http.HttpServletRequest;
import java.util.Properties;

public class $JAVA_CLASS_NAME$ extends Task
{
   public boolean execute(TaskContext context, Properties resultStrings)
   {
      HttpServletRequest req = context.getRequest();
      String nextState = req.getParameter("nextState");

      SystemConfig systemConfig = SystemConfig.getSystemConfig(context);

      if(nextState==null || nextState.equals("initialState"))
      {
         resultStrings.put("ConfigurationExample_Name", systemConfig.getSetting("ConfigurationExample_Name","Joe"));
         resultStrings.put("ConfigurationExample_Color", systemConfig.getSetting("ConfigurationExample_Color","Blue"));

         setUIPage("$MODULE_NAME$/$JAVA_CLASS_NAME$.jsp");
      }
      else if(nextState.equals("save"))
      {
         try
         {
            systemConfig.setSetting("ConfigurationExample_Name", req.getParameter("ConfigurationExample_Name"));
            systemConfig.setSetting("ConfigurationExample_Color", req.getParameter("ConfigurationExample_Color"));

            systemConfig.writeSettings();
         }
         catch (ConfigException e)
         {
            eMFrameUtils.setMessage("error","Configuration Store Example","Your settings could not be saved.",context);
         }

         eMFrameUtils.setMessage("success","Configuration Store Example","Your settings have been saved.",context);
      }

      return true;
   }
}