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 Froogle { 16 17 JammyjoesDatabase database; 18 19 public Froogle(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("product_url\tname\tdescription\timage_url\tcategory\tprice\tbrand\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, "http://www.jammyjoes.co.uk/jammyjoes/toys/" + product.getId().toString()+"\t"); 31 write(out, product.getName()+"\t"); 32 write(out, product.getDescription()+"\t"); 33 write(out, "http://www.jammyjoes.co.uk" + product.getPicture()+"\t"); 34 write(out, product.getType().getType()+"\t"); 35 write(out, JammyJoesContextUtil.getPriceDisplayWithoutPound(product.getRetailpriceincvat())+"\t"); 36 write(out, product.getManufacturer().getName()); 37 out.write("\n"); 38 } 39 out.close(); 40 } 41 42 private void write(FileWriter out, String thing) throws IOException { 43 if (thing != null) { 44 out.write(thing.replaceAll("\n"," ").replaceAll("\r"," ")); 45 } 46 } 47 }