Welcome to the Kelkoo Group Customer Service

Code Samples JAVA

Here some code sample in JAVA to help you read our feeds:

 

KFS FTP utils to get and check feeds

 

CSV parser (using OPENCSV library):

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import au.com.bytecode.opencsv.CSVReader;

public class CsvColumnReader {
   int NB_FIELDS_TO_RETRIEVE=18;

   public List<String> extract(File file) throws IOException {
      List<String> columns = new ArrayList<>();
      CSVReader csvReader = initCsvReader(file);
      String[] data;
      while ((data = csvReader.readNext()) != null && data.length > 0) {
         columns.add(data[NB_FIELDS_TO_RETRIEVE]);
      }
      csvReader.close();
      return columns;
   }

   private CSVReader initCsvReader(File file) throws FileNotFoundException {
      return new CSVReader(new FileReader(file), ";", "'",0);
   }

   public static void main(String args[]) {
      CsvColumnReader csvColumnReader=new CsvColumnReader();
      List<String> fields=csvColumnReader.extract(new File("MerchantFeed_fr.csv"));
      // read fields...
   }
}

 
XML parser:

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;

public class ReadXMLFile {

  public static void main(String argv[]) {

    try {

	File fXmlFile = new File("Offerfeed_11636313_fr.full.xml");
	DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
	DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
	Document doc = dBuilder.parse(fXmlFile);
	doc.getDocumentElement().normalize();

	NodeList nParentList = doc.getElementsByTagName("CatalogListings");
        NodeList offers=nParentList.item(0).getChildNodes();
	for (int temp = 0; temp < offers.getLength(); temp++) {
		Node offer = nList.item(temp);

		if (offer.getNodeType() == Node.ELEMENT_NODE) {
			Element offerElement = (Element) offer;

			String offerElement.getAttribute("id");
			offerElement.getElementsByTagName("Title").item(0).getTextContent();
                        // ...
		}
	}
    } catch (Exception e) {
	e.printStackTrace();
    }
  }

}