Android Open Source - BehatReporter Item Parser






From Project

Back to project page BehatReporter.

License

The source code is released under:

Copyright (C) 2013 Fabian Kiss <headrevision@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software...

If you think the Android project BehatReporter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package headrevision.BehatReporter.report;
/*from w w w .  j  a  va 2s.  c o  m*/
import headrevision.BehatReporter.json.Parser;
import headrevision.BehatReporter.json.ParserException;

import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import com.fasterxml.jackson.databind.JsonNode;

public abstract class ItemParser extends Parser {

  private ItemParserFactory subItemParserFactory;

  public ItemParser(JsonNode item, ItemParserFactory subItemParserFactory) {
    super(item);
    this.subItemParserFactory = subItemParserFactory;
  }

  public abstract boolean hasTitle() throws ParserException;

  public String parseTitle() throws ParserException {
    throw (new ParserException(new UnsupportedOperationException()));
  }

  public Result parseResult() throws ParserException {
    if (has("result")) {
      return parseResultDirectly(parseText("result"));
    } else {
      return parseResultRecursively();
    }
  }

  public boolean hasSubItems() {
    String subItemsKey;
    try {
      subItemsKey = subItemParserFactory.getItemsKey();
    } catch (NullPointerException e) {
      return false;
    }
    return hasSubItems(subItemsKey);
  }

  public List<JsonNode> parseSubItems() throws ParserException {
    String subItemsKey;
    try {
      subItemsKey = subItemParserFactory.getItemsKey();
    } catch (NullPointerException e) {
      throw(new ParserException(e));
    }
    return parseSubItems(subItemsKey);
  }

  protected boolean hasSubItems(String subItemsKey) {
    List<JsonNode> subItems = null;
    try {
      subItems = parseSubItems(subItemsKey);
    } catch (ParserException e) {
      return false;
    }
    return subItems.size() > 0;
  }

  protected List<JsonNode> parseSubItems(String subItemsKey) throws ParserException {
    return parseArray(subItemsKey);
  }

  private Result parseResultDirectly(String resultText)
      throws ParserException {
    try {
      return Result.valueOf(resultText.toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
      throw (new ParserException(e));
    }
  }

  private Result parseResultRecursively() throws ParserException {
    Result result = Result.PASSED;

    if (hasSubItems()) {
      List<JsonNode> subItems = parseSubItems();
      Iterator<JsonNode> subItemIterator = subItems.iterator();
      while (subItemIterator.hasNext()) {
        result = addSubItemResult(subItemIterator.next(), result);
      }
    }

    return result;
  }

  private Result addSubItemResult(JsonNode subItem, Result itemResult) throws ParserException {
    ItemParser subItemParser = subItemParserFactory.getItemParser(subItem);
    Result subItemResult = subItemParser.parseResult();
    if (itemResult.getPriority() < subItemResult.getPriority()) {
      itemResult = subItemResult;
    }
    return itemResult;
  }

}




Java Source Code List

headrevision.BehatReporter.ItemHandler.java
headrevision.BehatReporter.ListHandler.java
headrevision.BehatReporter.MainActivity.java
headrevision.BehatReporter.ReportHandler.java
headrevision.BehatReporter.json.ParserException.java
headrevision.BehatReporter.json.Parser.java
headrevision.BehatReporter.json.ReaderException.java
headrevision.BehatReporter.json.Reader.java
headrevision.BehatReporter.report.FeatureParserFactory.java
headrevision.BehatReporter.report.FeatureParser.java
headrevision.BehatReporter.report.FeaturesAdapterFactory.java
headrevision.BehatReporter.report.FeaturesAdapter.java
headrevision.BehatReporter.report.ItemParserFactory.java
headrevision.BehatReporter.report.ItemParser.java
headrevision.BehatReporter.report.ItemsAdapterFactory.java
headrevision.BehatReporter.report.ItemsAdapter.java
headrevision.BehatReporter.report.LoaderException.java
headrevision.BehatReporter.report.LoaderTaskListener.java
headrevision.BehatReporter.report.LoaderTask.java
headrevision.BehatReporter.report.Loader.java
headrevision.BehatReporter.report.OutlineExampleParser.java
headrevision.BehatReporter.report.OutlineParser.java
headrevision.BehatReporter.report.ReportParser.java
headrevision.BehatReporter.report.Result.java
headrevision.BehatReporter.report.ScenarioOrOutlineParserFactory.java
headrevision.BehatReporter.report.ScenarioParser.java
headrevision.BehatReporter.report.ScenariosAndOutlinesAdapterFactory.java
headrevision.BehatReporter.report.ScenariosAndOutlinesAdapter.java
headrevision.BehatReporter.report.StepOrOutlineExampleParserFactory.java
headrevision.BehatReporter.report.StepParserFactory.java
headrevision.BehatReporter.report.StepParser.java
headrevision.BehatReporter.report.StepsAdapterFactory.java
headrevision.BehatReporter.report.StepsAdapter.java
headrevision.BehatReporter.report.StepsAndOutlineExamplesAdapterFactory.java
headrevision.BehatReporter.report.StepsAndOutlineExamplesAdapter.java
headrevision.BehatReporter.store.ItemTitles.java
headrevision.BehatReporter.store.ReportJson.java
headrevision.BehatReporter.store.ReportUrl.java
headrevision.BehatReporter.ui.ItemDepth.java
headrevision.BehatReporter.ui.Message.java
headrevision.BehatReporter.ui.OptionsMenu.java
headrevision.BehatReporter.ui.ResultColor.java
headrevision.BehatReporter.ui.SetReportDialogListener.java
headrevision.BehatReporter.ui.SetReportDialog.java