package templateadaptor;
import adaptorlib.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Logger;
/** Demonstrates what code is necessary
 *  for putting public content onto a GSA.
 *  The key operations are A) pushing document ids
 *  and B) providing the bytes of documents. */
// TODO: Link to configuration steps.
class TemplateAdaptor extends Adaptor {
  private static Logger LOG = Logger.getLogger(Adaptor.class.getName());

  /** Acquires and pushes document ids to GSA.  It's OK to push
   *  the same document ids multiple times because the operation
   *  is fast. */
  public void pushDocIds() {
    LOG.info("about to get doc ids");
    List<DocId> handles = getDocIds();
    LOG.info("about to push " + handles.size() + " doc ids");
    GsaCommunicationHandler.pushDocIds("testfeed", handles);
    LOG.info("done pushing doc ids");
  }

  /** Provides a couple mock ids.  Replace with code 
   *  that lists your repository. */
  private List<DocId> getDocIds() {
    ArrayList<DocId> mockDocIds = new ArrayList<DocId>();
    mockDocIds.add(new DocId("1001"));
    mockDocIds.add(new DocId("1002"));
    return mockDocIds;
  }

  /** Gives the bytes of a document referenced with id. Returns
   *  null if such a document doesn't exist. */
  public byte []getDocContent(DocId id) {
    if ("1001".equals(id.getUniqueId())) {
      return "Document 1001 says hello and apple orange"
          .getBytes(Config.getGsaCharacterEncoding());
    } else if ("1002".equals(id.getUniqueId())) {
      return "Document 1002 says hello and banana strawberry"
          .getBytes(Config.getGsaCharacterEncoding());
    } else {
      return null;
    }
  }

  /** An example main for an adaptor. */
  public static void main(String a[]) {
    final Adaptor adaptor = new TemplateAdaptor();

    // Setup providing content:
    GsaCommunicationHandler gsa = new GsaCommunicationHandler(adaptor);
    try {
      gsa.beginListeningForContentRequests();
    } catch (IOException e) {
      throw new RuntimeException("could not start", e);
    }
    LOG.info("doc content serving started");

    // Uncomment next line to push once at program start.
    // adaptor.pushDocIds();

    // Setup regular pushing of doc ids:
    ScheduleIterator everyNite = new ScheduleOncePerDay(/*hour*/3,
        /*minute*/0, /*second*/0);
    gsa.beginPushingDocIds(everyNite);
    LOG.info("doc id pushing has been put on schedule");
  }
}

// TODO: Write SecuredByAclTemplateAdaptor.
// TODO: Write SecuredByRequestTemplateAdaptor.

@@ -83,58 +83,18 @@
 ava.
-io.UnsupportedEncodingException;%0Aimport java.
 util.
+Array
 List
@@ -104,37 +104,32 @@
 mport java.util.
-Array
 List;%0Aimport jav
@@ -1803,14 +1803,8 @@
     
-final 
 Adap
@@ -1843,41 +1843,8 @@
 r();
-%0A%0A    // Setup providing content:
 %0A   
@@ -1911,16 +1911,49 @@
 daptor);
+%0A%0A    // Setup providing content:
 %0A    try
@@ -1997,24 +1997,71 @@
 Requests();%0A
+      LOG.info(%22doc content serving started%22);%0A
     %7D catch 
@@ -2127,16 +2127,24 @@
 ot start
+ serving
 %22, e);%0A 
@@ -2151,53 +2151,8 @@
    %7D
-%0A    LOG.info(%22doc content serving started%22);
 %0A%0A  

Remove unused import.