/*
 * Decompiled with CFR 0_110.
 *
 * Could not load the following classes:
 *  org.pageseeder.berlioz.BerliozException
 *  org.pageseeder.berlioz.content.ContentGenerator
 *  org.pageseeder.berlioz.content.ContentRequest
 *  org.pageseeder.xmlwriter.XMLWriter
 */
package org.pageseeder.berlioz.flint;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.pageseeder.berlioz.BerliozException;
import org.pageseeder.berlioz.content.ContentGenerator;
import org.pageseeder.berlioz.content.ContentRequest;
import org.pageseeder.berlioz.flint.model.FlintConfig;
import org.pageseeder.berlioz.flint.model.IndexMaster;
import org.pageseeder.flint.MultipleIndexReader;
import org.pageseeder.flint.api.Index;
import org.pageseeder.xmlwriter.XMLWriter;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public abstract class IndexGenerator implements ContentGenerator {
  public static final String INDEX_PARAMETER = "index";

  @Override
  public void process(ContentRequest req, XMLWriter xml) throws BerliozException, IOException {
    String name = req.getParameter(INDEX_PARAMETER);
    if (name == null) {
      this.processSingle(FlintConfig.get().getMaster(), req, xml);
    } else {
      ArrayList<IndexMaster> indexes = new ArrayList<IndexMaster>();
      for (String aname : name.split(",")) {
        IndexMaster amaster = FlintConfig.get().getMaster(aname.trim());
        if (amaster == null) continue;
        indexes.add(amaster);
      }
      if (indexes.size() == 1) this.processSingle(indexes.get(0), req, xml);
      else this.processMultiple(indexes, req, xml);
    }
  }

  public String buildIndexEtag(ContentRequest req) {
    String names = req.getParameter(INDEX_PARAMETER);
    FlintConfig config = FlintConfig.get();
    if (names == null) return String.valueOf(config.getMaster().lastModified());
    StringBuilder etag = new StringBuilder();
    for (String name : names.split(",")) {
      IndexMaster master = config.getMaster(name.trim());
      if (master != null) {
        etag.append(name).append('-').append(master.lastModified());
      }
    }
    return etag.length() > 0 ? etag.toString() : null;
  }

  public MultipleIndexReader buildMultiReader(Collection<IndexMaster> masters) {
    List<Index> indexes = new ArrayList<>();
    for (IndexMaster master : masters)
      indexes.add(master.getIndex());
    return FlintConfig.get().getManager().getMultipleIndexReader(indexes);
  }

  public abstract void processSingle(IndexMaster master, ContentRequest req, XMLWriter xml) throws BerliozException, IOException;

  public abstract void processMultiple(Collection<IndexMaster> masters, ContentRequest req, XMLWriter xml) throws BerliozException, IOException;
}

@@ -561,24 +561,77 @@
 entRequest;%0A
+import org.pageseeder.berlioz.content.ContentStatus;%0A
 import org.p
@@ -724,24 +724,82 @@
 ndexMaster;%0A
+import org.pageseeder.berlioz.flint.util.GeneratorErrors;%0A
 import org.p
@@ -1333,35 +1333,37 @@
 %7B%0A      
-this.processSingle(
+IndexMaster master = 
 FlintCon
@@ -1383,16 +1383,205 @@
 Master()
+;%0A      if (master == null)%0A        GeneratorErrors.error(req, xml, %22configuration%22, %22No default index found!%22, ContentStatus.INTERNAL_SERVER_ERROR);%0A      else%0A        processSingle(master
 , req, x
@@ -1893,21 +1893,16 @@
 ) == 1) 
-this.
 processS
@@ -1949,13 +1949,8 @@
 lse 
-this.
 proc
@@ -2166,22 +2166,101 @@
 = null) 
-return
+%7B%0A      IndexMaster master = config.getMaster();%0A      return master == null ? null :
  String.
@@ -2267,34 +2267,22 @@
 valueOf(
-config.getM
+m
 aster
-()
 .lastMod
@@ -2287,24 +2287,30 @@
 odified());%0A
+    %7D%0A
     StringBu

Handle case when no default index is defined