| 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 | 0 | public Froogle(JammyjoesDatabase database) { |
| 20 | 0 | this.database = database; |
| 21 | 0 | } |
| 22 | |
|
| 23 | |
public void writeFile(String uploadDir, String filename) throws IOException { |
| 24 | 0 | FileWriter out = new FileWriter(new File(uploadDir, filename), false); |
| 25 | 0 | out.write("product_url\tname\tdescription\timage_url\tcategory\tprice\tbrand\n"); |
| 26 | 0 | Enumeration enumeration = |
| 27 | |
new ProductSearch(database, 9999, new Logger(null)).doSearch(new FroogleSearchCriteria(database)); |
| 28 | 0 | while (enumeration.hasMoreElements()) { |
| 29 | 0 | Product product = (Product) enumeration.nextElement(); |
| 30 | 0 | write(out, "http://www.jammyjoes.co.uk/jammyjoes/toys/" + product.getId().toString()+"\t"); |
| 31 | 0 | write(out, product.getName()+"\t"); |
| 32 | 0 | write(out, product.getDescription()+"\t"); |
| 33 | 0 | write(out, "http://www.jammyjoes.co.uk" + product.getPicture()+"\t"); |
| 34 | 0 | write(out, product.getType().getType()+"\t"); |
| 35 | 0 | write(out, JammyJoesContextUtil.getPriceDisplayWithoutPound(product.getRetailpriceincvat())+"\t"); |
| 36 | 0 | write(out, product.getManufacturer().getName()); |
| 37 | 0 | out.write("\n"); |
| 38 | 0 | } |
| 39 | 0 | out.close(); |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
private void write(FileWriter out, String thing) throws IOException { |
| 43 | 0 | if (thing != null) { |
| 44 | 0 | out.write(thing.replaceAll("\n"," ").replaceAll("\r"," ")); |
| 45 | |
} |
| 46 | 0 | } |
| 47 | |
} |