All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.purej.vminspect.html.AbstractStatisticsView Maven / Gradle / Ivy

// Copyright (c), 2013, adopus consulting GmbH Switzerland, all rights reserved.
package com.purej.vminspect.html;

import java.io.IOException;
import com.purej.vminspect.data.statistics.Period;
import com.purej.vminspect.data.statistics.Range;

/**
 * Abstract class for statistics views.
 *
 * @author Stefan Mueller
 */
abstract class AbstractStatisticsView extends AbstractHtmlView {
  private final Range _range;

  /**
   * Creates a new instance of this view.
   */
  public AbstractStatisticsView(StringBuilder output, Range range) {
    super(output);
    _range = range;
  }

  protected String statisticsGraphParams(String graphName, int width, int height) {
    return addRangeParams(params("statsGraph=" + graphName, "statsWidth=" + width, "statsHeight=" + height), _range);
  }

  protected static String statisticsPageParams(String... additionalParams) {
    StringBuilder builder = new StringBuilder();
    builder.append("page=statistics");
    for (String param : additionalParams) {
      builder.append(PARAMS_SEPARATOR).append(param);
    }
    return builder.toString();
  }

  protected String addRangeParams(String otherParams) {
    return addRangeParams(otherParams, _range);
  }

  protected static String addRangeParams(String otherParams, Range range) {
    if (range.getPeriod() == Period.CUSTOM) {
      if (range.getStartDate() != null && range.getEndDate() != null) {
        String from = urlEncode(formatDate(range.getStartDate()));
        String to = urlEncode(formatDate(range.getEndDate()));
        return params(otherParams, "statsPeriod=custom", "statsFromDate=" + from, "statsToDate=" + to);
      }
      return params(otherParams, "statsPeriod=custom");
    }
    else {
      return params(otherParams, "statsPeriod=" + range.getPeriod().getCode());
    }
  }

  protected void writeChoosePeriodLinks(String statsDetailName, int width, int height) throws IOException {
    writeln("
"); String separator = "    "; String addParams = statsDetailName != null ? params("statsDetail=" + statsDetailName, "statsWidth=" + width, "statsHeight=" + height) : null; writeln(separator); writeln("Choice of period : "); for (Period myPeriod : Period.values()) { if (myPeriod == Period.CUSTOM) { writeln(""); writeln(img(myPeriod.getIconName(), "Customized") + " Customized"); } else { String periodParam = "statsPeriod=" + myPeriod.getCode(); String params = statsDetailName != null ? statisticsPageParams(addParams, periodParam) : statisticsPageParams(periodParam); write(lnk(params, img(myPeriod.getIconName(), "Choice of period " + myPeriod.getLabel()) + " " + myPeriod.getLinkLabel())); write("   "); } } writeln("
"); writeCustomPeriodDiv(statsDetailName, width, height); } private void writeCustomPeriodDiv(String graphDetailName, int statsWidth, int statsHeight) throws IOException { writeln(""); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy