// Copyright (C) 2006-2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.enterprise.connector.dctm;

import java.net.MalformedURLException;
import java.util.Iterator;

import com.google.enterprise.connector.pusher.DocPusher;
import com.google.enterprise.connector.pusher.FeedException;
import com.google.enterprise.connector.pusher.GsaFeedConnection;
import com.google.enterprise.connector.pusher.PushException;

import com.google.enterprise.connector.spi.Document;
import com.google.enterprise.connector.spi.DocumentList;
import com.google.enterprise.connector.spi.SpiConstants;
import com.google.enterprise.connector.spi.TraversalManager;
import com.google.enterprise.connector.spi.RepositoryException;

import com.google.enterprise.connector.traversal.FileSizeLimitInfo;

public class DctmTraversalUtil {
  public static void runTraversal(TraversalManager queryTraversalManager,
      int batchHint) throws RepositoryException, PushException, FeedException {
    DctmTraversalManager dctmTM = (DctmTraversalManager) queryTraversalManager;
    dctmTM.setBatchHint(batchHint);
    System.out.println(batchHint);

    DocumentList documentList = dctmTM.startTraversal();
    // int nb = resultSet.size();
    // System.out.println("nb vaut " + nb);
    // The real connector manager will not always start from the beginning.
    // It will start from the beginning if it receives an explicit admin
    // command to do so, or if it thinks that it has never run this
    // connector
    // before. It decides whether it has run a connector before by storing
    // every checkpoint it receives from
    // the connector. If it can find no stored checkpoint, it assumes that
    // it has never run this connector before and starts from the beginning,
    // as here.
    if (documentList == null) {
      // in this test program, we will stop in this situation. The real
      // connector manager might wait for a while, then try again
      return;
    }

    DocPusher push = null;
    try {
      push = new DocPusher(new GsaFeedConnection(
          // "8.6.49.36"
          // "swp-gsa-demo"
          "gogol.vizdom.com"                                                 
          , 19900), "dctm", new FileSizeLimitInfo());

    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    int counter = 0;

    while (true) {
      counter = 0;
      Document pm = null;
      while ((pm = documentList.nextDocument()) != null) {
        System.out.println("pm change");
        counter++;

        if (counter == batchHint) {
          System.out.println("counter == batchhint !!!!");
          // this test program only takes batchHint results from each
          // resultSet. The real connector manager may take fewer -
          // for example, if it receives a shutdown request
          break;
        }
        Iterator iteri = pm.getPropertyNames().iterator();
        int k = 0;
        while (iteri.hasNext()) {
          iteri.next();
          k++;
        }
        System.out.println("counter " + counter + " " + k);
        System.out.println(pm.findProperty(
            SpiConstants.PROPNAME_DISPLAYURL).nextValue());
        push.take(pm);

      }
      String checkpoint = "";
      if (counter != 0) {
        System.out.println("appel checkpoint");
        checkpoint = documentList.checkpoint();
        System.out.println("appel checkpoint " + checkpoint);
      }
      dctmTM.resumeTraversal(checkpoint);
    }
  }
}

@@ -10,21 +10,12 @@
 ght 
-(C) 2006-2009
+2007
  Goo
@@ -634,75 +634,8 @@
 m;%0A%0A
-import java.net.MalformedURLException;%0Aimport java.util.Iterator;%0A%0A
 impo
@@ -866,33 +866,32 @@
 .PushException;%0A
-%0A
 import com.googl
@@ -1166,17 +1166,16 @@
 eption;%0A
-%0A
 import c
@@ -1233,16 +1233,155 @@
 mitInfo;
+%0Aimport com.google.enterprise.connector.util.filter.DocumentFilterChain;%0A%0Aimport java.net.MalformedURLException;%0Aimport java.util.Iterator;
 %0A%0Apublic
@@ -2647,159 +2647,44 @@
 ion(
-%0A          // %228.6.49.36%22%0A          // %22swp-gsa-demo%22%0A          %22gogol.vizdom.com%22                                                 %0A          , 19900),
+null, %22gogol%22, 19900, -1),%0A         
  %22dc
@@ -2711,16 +2711,43 @@
 itInfo()
+, new DocumentFilterChain()
 );%0A%0A    
@@ -3728,20 +3728,25 @@
 .take(pm
+, null
 );%0A
-%0A
       %7D%0A

Fix the tests to compile against connector manager 2.8 (but not yet the 2.8.x branch as of 2.8.0-M3).