Package at.kugel.tool.buildtray.action

Source Code of at.kugel.tool.buildtray.action.RefreshCommand

package at.kugel.tool.buildtray.action;

import java.io.IOException;
import java.text.ParseException;

import at.kugel.tool.buildtray.action.http.MultiUrlReader;
import at.kugel.tool.buildtray.config.MultiConfig;
import at.kugel.tool.buildtray.parser.MultiRegexBusyParser;
import at.kugel.tool.buildtray.parser.MultiRegexStatusParser;
import at.kugel.tool.buildtray.parser.RegexParser;
import at.kugel.tool.buildtray.status.SetStatusAble;
import at.kugel.tool.buildtray.status.Status;

/**
* Refresh the status and set it into the tray.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
class RefreshCommand extends ActionCommand {

   private final MultiConfig configs;

   public RefreshCommand(MultiConfig confs, SetStatusAble statusDisplay) {
      super(confs.getFirstConfig(), statusDisplay);
      configs = confs;
   }

   @Override
   protected void workTemplate() throws IOException, ParseException {
      updateBuildResult();
   }

   private void updateBuildResult() throws IOException, ParseException {
      String[] contents = downloadBuildStatuses();

      if (handleBusyProjects(contents)) {
         return;
      }

      handleRegularProjects(contents);
   }

   private String[] downloadBuildStatuses() throws IOException {
      return new MultiUrlReader(configs).readPages();
   }

   private boolean handleBusyProjects(String[] contents) {
      MultiRegexBusyParser busyParser = new MultiRegexBusyParser(configs, contents);
      if (busyParser.isBusy()) {
         if (busyParser.isUpdateStatus()) {
            updateStatusFrom(busyParser);
         }
         return true;
      }
      return false;
   }

   private void updateStatusFrom(RegexParser parser) {
      Status status = parser.getStatus();
      String projectName = parser.getProjectName();
      String buildDate = parser.getBuildDate();
      statusDisplay.setStatus(status, projectName, buildDate);
   }

   private void handleRegularProjects(String[] contents) throws ParseException {
      MultiRegexStatusParser statusParser = new MultiRegexStatusParser(configs, contents);
      statusParser.parse();
      updateStatusFrom(statusParser);
   }

}
TOP

Related Classes of at.kugel.tool.buildtray.action.RefreshCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.