1 package org.paneris.jammyjoes.upload; 2 3 import java.io.File; 4 import java.io.FileWriter; 5 import java.io.IOException; 6 import java.util.Enumeration; 7 8 import org.paneris.jammyjoes.controller.Logger; 9 import org.paneris.jammyjoes.controller.FroogleSearchCriteria; 10 import org.paneris.jammyjoes.controller.ProductSearch; 11 import org.paneris.jammyjoes.model.JammyjoesDatabase; 12 import org.paneris.jammyjoes.model.Product; 13 import org.paneris.jammyjoes.util.JammyJoesContextUtil; 14 15 public class AmazonExport { 16 17 JammyjoesDatabase database; 18 19 public AmazonExport(JammyjoesDatabase database) { 20 this.database = database; 21 } 22 23 public void writeFile(String uploadDir, String filename) throws IOException { 24 FileWriter out = new FileWriter(new File(uploadDir, filename), false); 25 out.write("jammyjoes_id\tsupplier_code\tproduct_url\tname\tdescription\timage_url\tcategory\tprice\tbrand\tstock_level\n"); 26 Enumeration enumeration = 27 new ProductSearch(database, 9999, new Logger(null)).doSearch(new FroogleSearchCriteria(database)); 28 while (enumeration.hasMoreElements()) { 29 Product product = (Product) enumeration.nextElement(); 30 write(out, product.getId().toString()+"\t"); 31 write(out, product.getSuppliercode()+"\t"); 32 write(out, "http://www.jammyjoes.co.uk/jammyjoes/toys/" + product.getId().toString()+"\t"); 33 write(out, product.getName()+"\t"); 34 write(out, product.getDescription()+"\t"); 35 write(out, "http://www.jammyjoes.co.uk" + product.getPicture()+"\t"); 36 write(out, product.getType().getType()+"\t"); 37 write(out, JammyJoesContextUtil.getPriceDisplayWithoutPound(product.getRetailpriceincvat())+"\t"); 38 write(out, product.getManufacturer().getName()+"\t"); 39 write(out, product.getStocklevel().toString()); 40 out.write("\n"); 41 } 42 out.close(); 43 } 44 45 private void write(FileWriter out, String thing) throws IOException { 46 if (thing != null) { 47 out.write(thing.replaceAll("\n"," ").replaceAll("\r"," ")); 48 } 49 } 50 }