Source Code Cross Referenced for RetailProCatalogConverter.java in  » Content-Management-System » openedit » org » openedit » store » retailproconvert » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » openedit » org.openedit.store.retailproconvert 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Sep 15, 2004
003:         */
004:        package org.openedit.store.retailproconvert;
005:
006:        import java.io.File;
007:        import java.io.FileFilter;
008:        import java.io.FileInputStream;
009:        import java.io.FileOutputStream;
010:        import java.io.IOException;
011:        import java.io.InputStreamReader;
012:        import java.io.Reader;
013:        import java.util.ArrayList;
014:        import java.util.Arrays;
015:        import java.util.Collections;
016:        import java.util.Enumeration;
017:        import java.util.Iterator;
018:        import java.util.List;
019:        import java.util.zip.ZipEntry;
020:        import java.util.zip.ZipFile;
021:
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:        import org.dom4j.Document;
025:        import org.dom4j.Element;
026:        import org.dom4j.io.OutputFormat;
027:        import org.dom4j.io.SAXReader;
028:        import org.dom4j.io.XMLWriter;
029:        import org.openedit.money.Money;
030:        import org.openedit.store.CatalogConverter;
031:        import org.openedit.store.Category;
032:        import org.openedit.store.InventoryItem;
033:        import org.openedit.store.Option;
034:        import org.openedit.store.Price;
035:        import org.openedit.store.PriceTier;
036:        import org.openedit.store.Product;
037:        import org.openedit.store.Store;
038:        import org.openedit.store.StoreException;
039:        import org.openedit.store.convert.ConvertStatus;
040:
041:        import com.openedit.util.OutputFiller;
042:        import com.openedit.util.ZipUtil;
043:
044:        /**
045:         * A catalog converter that converts RetailPro XML zip files (G*.zip, N*.zip,
046:         * etc.) to a set of OpenEdit catalogs and products.
047:         * 
048:         * @author cburkey
049:         */
050:        public class RetailProCatalogConverter extends CatalogConverter {
051:            String INDEX = "index";
052:            protected OutputFiller fieldOutputFiller;
053:
054:            private static final Log log = LogFactory
055:                    .getLog(RetailProCatalogConverter.class);
056:
057:            public synchronized void convert(Store inStore,
058:                    ConvertStatus inErrorLog) throws Exception {
059:                File uploadHome = new File(inStore.getStoreDirectory(),
060:                        "/upload");
061:                if (!uploadHome.exists()) {
062:                    inErrorLog.add("No upload directory");
063:                    return;
064:                }
065:                File[] zipFiles = uploadHome.listFiles(getStyleZipFileFilter());
066:
067:                File inputHome = new File(inStore.getStoreDirectory(), "/tmp/");
068:                inputHome.mkdirs();
069:
070:                //First clean out the  store upload directory
071:                if (zipFiles == null || zipFiles.length == 0) {
072:                    inErrorLog.add("No input files found");
073:                    log.info("No style inputs found");
074:                } else {
075:                    List inputs = new ArrayList(Arrays.asList(zipFiles));
076:                    Collections.sort(inputs);
077:                    for (Iterator iter = inputs.iterator(); iter.hasNext();) {
078:                        clearStoreUploadDir(inputHome); //DELETES from /store/tmp
079:                        List outputAllProducts = new ArrayList();
080:                        File file = (File) iter.next();
081:
082:                        unzip(new File[] { file }, inputHome);
083:                        //there may be more than one styles page in there
084:
085:                        List styles = listStyleXmls(inputHome);
086:
087:                        for (Iterator siter = styles.iterator(); siter
088:                                .hasNext();) {
089:                            File style = (File) siter.next();
090:
091:                            Document page = cleanXml(style);
092:                            log.info("Converting styles...");
093:                            convertStyles(inStore, page, outputAllProducts);
094:                            inErrorLog.add("Completed "
095:                                    + outputAllProducts.size() + " products");
096:                            boolean hadAvailability = updateInventoryLevels(
097:                                    inStore, page, outputAllProducts);
098:                            log.info("Completed " + outputAllProducts.size()
099:                                    + " products. Avail: " + hadAvailability
100:                                    + " file size:" + style.length());
101:                            if (style.length() > 5000000 && !hadAvailability) //was a large file with no availability must be a full dump
102:                            {
103:                                log
104:                                        .info("Marking remaining products not available");
105:                                markRemainingProductsUnavailable(inStore,
106:                                        outputAllProducts);
107:                            }
108:                            inErrorLog.setReindex(true);
109:
110:                        }
111:                        convertCatTree(inStore, inputHome);
112:                        inStore.clearProducts();
113:                        moveUploadFile(file); //to completed
114:                    }
115:                }
116:                log.info("Moving images...");
117:                //move the photos
118:                File[] imagezips = uploadHome
119:                        .listFiles(getImagesZipFileFilter());
120:                if (imagezips != null && imagezips.length > 0) {
121:                    List sortedImages = new ArrayList(Arrays.asList(imagezips));
122:                    Collections.sort(sortedImages);
123:                    for (Iterator iter = sortedImages.iterator(); iter
124:                            .hasNext();) {
125:                        File zip = (File) iter.next();
126:                        copyPhotos(inStore, zip);
127:                        moveUploadFile(zip);
128:                        inErrorLog.setReindex(true);
129:                    }
130:                    inStore.clearProducts();
131:                }
132:                File[] customerZips = uploadHome
133:                        .listFiles(getCustomerZipFileFilter());
134:                if (customerZips != null && customerZips.length > 0) {
135:                    unzip(customerZips, inputHome);
136:
137:                    //Handle The user management part
138:                    CustomerListConverter users = new CustomerListConverter();
139:                    users.setCustomerArchive(inStore.getCustomerArchive());
140:                    users.convert(inStore, inErrorLog);
141:
142:                    for (int i = 0; i < customerZips.length; i++) {
143:                        moveUploadFile(customerZips[i]);
144:                        inErrorLog.setReindex(true);
145:                    }
146:                }
147:            }
148:
149:            private void convertStyles(Store inStore, Document page,
150:                    List outputAllProducts) throws Exception {
151:                int count = 0;
152:                for (Iterator iter = page.getRootElement().elementIterator(
153:                        "Style"); iter.hasNext();) {
154:                    Element styleE = (Element) iter.next();
155:                    String id = styleE.attributeValue("fldStyleSID");
156:                    log.info("Converting style " + id);
157:                    Product newproduct = inStore.getProduct(id); //Need to maintain keywords in xconf
158:                    if (newproduct == null) {
159:                        newproduct = new Product();
160:                        newproduct.setId(id);
161:                    } else {
162:                        //newproduct.clearCatalogs();
163:                        newproduct.clearItems();
164:
165:                    }
166:                    newproduct.setPriceSupport(null);
167:                    newproduct.clearOptions();
168:                    String name = styleE.attributeValue("fldStyleName");
169:                    if (name == null) {
170:                        //??
171:                        name = "no name";
172:                    }
173:                    name = cleanText(name);
174:                    newproduct.setId(styleE.attributeValue("fldStyleSID"));
175:                    newproduct.setName(name);
176:                    populateItems(newproduct, styleE);
177:
178:                    //fldProdAvail="Sell Always"  fldOutStockMsg_i="3" fldOutStockMsg="Please Allow 6-8 Weeks for Delivery" 
179:                    String mesg = styleE.attributeValue("fldProdAvail");
180:                    if (mesg != null && mesg.equals("Sell Always")) {
181:                        String fldOutStockMsg = styleE
182:                                .attributeValue("fldOutStockMsg");
183:                        if (fldOutStockMsg != null
184:                                && fldOutStockMsg.length() > 0) {
185:                            //loop over all the items and set them to 100 inventory levels
186:                            //save message in product
187:                            newproduct.putAttribute("outOfStockMsg",
188:                                    fldOutStockMsg);
189:                        }
190:                    }
191:
192:                    String desc = styleE.attributeValue("fldStyleLongDesc");
193:                    if (desc == null) {
194:                        desc = "no description available";
195:                    }
196:                    String val = parseDescription(desc);
197:
198:                    val = val.replace('\\', '/');//need to replace \ with /
199:
200:                    val = val.replaceAll("R:/Web Pics/", inStore.getStoreHome()
201:                            + "/products/images/extras/");
202:                    newproduct.setDescription(val);
203:
204:                    newproduct.putAttribute("fldDesc1", styleE
205:                            .attributeValue("fldDesc1"));
206:                    newproduct.putAttribute("fldDesc2", styleE
207:                            .attributeValue("fldDesc2"));
208:                    newproduct.putAttribute("fldDesc3", styleE
209:                            .attributeValue("fldDesc3"));
210:                    newproduct.putAttribute("fldDesc4", styleE
211:                            .attributeValue("fldDesc4"));
212:
213:                    String taxable = styleE.attributeValue("fldTaxCd");
214:                    if (taxable != null
215:                            && !taxable.trim().equalsIgnoreCase("Taxable")) {
216:                        newproduct.setTaxExempt(true);
217:                    }
218:                    String handlingAmount = styleE
219:                            .attributeValue("fldHandAmount");
220:                    if (handlingAmount != null) {
221:                        // The product-level handling charge trumps any item-level
222:                        // charges.
223:                        Option handlingCharge = createHandlingOption(new Money(
224:                                handlingAmount));
225:                        newproduct.addOption(handlingCharge);
226:                    }
227:                    //product
228:                    count++;
229:                    newproduct.setOrdering(count);
230:                    //newproduct.setAvailable(newproduct.isInStock());
231:                    newproduct.setAvailable(true);
232:                    outputAllProducts.add(id);
233:                    newproduct.clearKeywords();
234:                    String keyword = parseKeywords(desc);
235:                    if (keyword != null) {
236:                        keyword = keyword.replaceAll("CLSFD", "classified");
237:                        keyword = keyword.trim();
238:                        if (keyword.indexOf("classified") >= 0) {
239:                            newproduct.setShippingMethodId("electronic");
240:                        }
241:                        newproduct.addKeyword(keyword);
242:                    }
243:                    //inStore.saveProduct(newproduct);
244:                    inStore.getProductArchive().saveProduct(newproduct);
245:                    String fdesc = newproduct.getDescription();
246:                    inStore.getProductArchive().saveProductDescription(
247:                            newproduct, fdesc);
248:
249:                    inStore.getProductArchive().clearProduct(newproduct);
250:                    log.info("Completed style " + id);
251:                }
252:                //<Style_Avail  fldStyleSID="GHHKIOIHIJCELOHM"> 
253:                //<Item_Avail  fldItemNum="8563" fldItemSID="PAAAIABDHPBHNEAI" AvailQuantity="30" Availability="1" />
254:            }
255:
256:            private String cleanText(String inName) {
257:                StringBuffer done = new StringBuffer(inName.length());
258:                for (int i = 0; i < inName.length(); i++) {
259:                    char c = inName.charAt(i);
260:                    if (c > 31 && c < 127) {
261:                        done.append(c);
262:                    }
263:                }
264:                return done.toString();
265:            }
266:
267:            private boolean updateInventoryLevels(Store inStore, Document page,
268:                    List outputAllProducts) throws StoreException {
269:                boolean hasAvailability = false;
270:                for (Iterator iter = page.getRootElement().elementIterator(
271:                        "Style_Avail"); iter.hasNext();) {
272:                    hasAvailability = true;
273:                    Element styleE = (Element) iter.next();
274:                    //Item_Avail
275:                    String id = styleE.attributeValue("fldStyleSID");
276:                    Product aproduct = inStore.getProduct(id);
277:                    if (aproduct != null) {
278:                        for (Iterator iterator = styleE
279:                                .elementIterator("Item_Avail"); iterator
280:                                .hasNext();) {
281:                            Element element = (Element) iterator.next();
282:                            String sku = styleE.attributeValue("fldItemNum");
283:                            InventoryItem item = aproduct
284:                                    .getInventoryItemBySku(sku);
285:                            if (item != null) {
286:                                item
287:                                        .setQuantityInStock(Integer
288:                                                .parseInt(element
289:                                                        .attributeValue("AvailQuantity")));
290:                            }
291:                        }
292:                        aproduct.setAvailable(true);
293:                        outputAllProducts.add(id);
294:                        inStore.getProductArchive().saveProduct(aproduct);
295:                    }
296:
297:                }
298:                return hasAvailability;
299:            }
300:
301:            private Document cleanXml(File input) throws Exception {
302:                SAXReader reader = new SAXReader();
303:
304:                ///http://en.wikipedia.org/wiki/ISO-8859-1
305:                FileInputStream fi = new FileInputStream(input);
306:                Reader stream = new InputStreamReader(fi, "ISO-8859-1");
307:                Document page = reader.read(stream);
308:                fi.close();
309:
310:                //Write out a clean version of it
311:                FileOutputStream out = new FileOutputStream(input);
312:                OutputFormat format = OutputFormat.createPrettyPrint();
313:                format.setEncoding("ISO-8859-1");
314:                XMLWriter writer = new XMLWriter(out, format);
315:                writer.write(page);
316:                return page;
317:
318:            }
319:
320:            protected Option createHandlingOption(Money inHandlingAmount) {
321:                Option handlingCharge = new Option();
322:                handlingCharge.addTierPrice(1, new Price(inHandlingAmount));
323:                handlingCharge.setId("handling");
324:                handlingCharge.setName("Handling charge");
325:                handlingCharge.setRequired(true);
326:                return handlingCharge;
327:            }
328:
329:            /**
330:             * 
331:             */
332:            protected void markRemainingProductsUnavailable(Store inStore,
333:                    List inGoodProducts) throws StoreException {
334:                //loop over all known products
335:                List ids = inStore.listAllKnownProductIds();
336:                for (Iterator iter = ids.iterator(); iter.hasNext();) {
337:                    String id = (String) iter.next();
338:                    if (findProductIn(id, inGoodProducts)) {
339:                        //already saved
340:                    } else {
341:                        //Mark it unavailable
342:                        Product product = inStore.getProduct(id);
343:                        if (product != null && product.isAvailable()) {
344:                            product.setAvailable(false);
345:
346:                            inStore.getProductArchive().saveProduct(product);
347:                            String fdesc = product.getDescription();
348:                            inStore.getProductArchive().saveProductDescription(
349:                                    product, fdesc);
350:                            inStore.getProductArchive().clearProduct(product);
351:                        }
352:                    }
353:                }
354:            }
355:
356:            protected boolean findProductIn(String inId, List inList) {
357:                for (Iterator iter = inList.iterator(); iter.hasNext();) {
358:                    String product = (String) iter.next();
359:                    if (product.equals(inId)) {
360:                        return true;
361:                    }
362:                }
363:                return false;
364:            }
365:
366:            protected void clearStoreUploadDir(File inputdir) {
367:                File[] files = inputdir.listFiles();
368:                for (int i = 0; i < files.length; i++) {
369:                    if (!files[i].delete()) {
370:                        log
371:                                .error("Could not delete file "
372:                                        + files[i].getName());
373:                    }
374:                }
375:            }
376:
377:            protected void moveUploadFile(File inInputFile) {
378:                if (!inInputFile.exists()) {
379:                    return;
380:                }
381:                //File[] zipFiles = inInputDir.listFiles( inType );
382:                File tmpDir = new File(inInputFile.getParentFile(), "completed");
383:                tmpDir.mkdirs();
384:                /*		for ( int i = 0; i < zipFiles.length; i++ )
385:                 {
386:                 */
387:                String name = inInputFile.getName();
388:                File newFile = new File(tmpDir, name);
389:                if (newFile.exists()) {
390:                    newFile.delete();
391:                }
392:                inInputFile.renameTo(newFile);
393:                //}
394:            }
395:
396:            protected void unzip(File[] zipFiles, File workingDir)
397:                    throws Exception {
398:                //Unzip from 
399:                //	File uploadHome = new File( inStore.getStoreDirectory().getParentFile(), "/upload");
400:
401:                ZipUtil util = new ZipUtil();
402:
403:                for (int i = 0; i < zipFiles.length; i++) {
404:                    try {
405:                        util.unzip(zipFiles[i], workingDir);
406:                    } catch (Exception ex) {
407:                        log.error("Could not unzip file. Deleting it "
408:                                + zipFiles[i]);
409:                        zipFiles[i].delete();
410:                    }
411:                }
412:            }
413:
414:            protected FileFilter getStyleZipFileFilter() {
415:                return new FileFilter() {
416:                    public boolean accept(File pathname) {
417:                        String p = pathname.getName();
418:                        if (p.startsWith("N00") && p.endsWith(".zip")) {
419:                            return true;
420:                        }
421:                        return false;
422:                    }
423:                };
424:            }
425:
426:            protected FileFilter getImagesZipFileFilter() {
427:                return new FileFilter() {
428:                    public boolean accept(File pathname) {
429:                        String p = pathname.getName();
430:                        if (p.startsWith("G00") && p.endsWith(".zip")) {
431:                            return true;
432:                        }
433:                        return false;
434:                    }
435:                };
436:            }
437:
438:            protected FileFilter getCustomerZipFileFilter() {
439:                return new FileFilter() {
440:                    public boolean accept(File pathname) {
441:                        String p = pathname.getName();
442:                        if (p.startsWith("S00") && p.endsWith(".zip")) {
443:                            return true;
444:                        }
445:                        return false;
446:                    }
447:                };
448:            }
449:
450:            protected FileFilter getEcsStyleZipFileFilter() {
451:                return new FileFilter() {
452:                    public boolean accept(File pathname) {
453:                        String p = pathname.getName().toLowerCase();
454:                        if (p.startsWith("ecstyle_") && p.endsWith(".xml")) {
455:                            return true;
456:                        }
457:                        return false;
458:                    }
459:                };
460:            }
461:
462:            /**
463:             * This will create the AllCatalogs.xml file that will be used by the XMLCatalogArchive
464:             * @throws Exception
465:             */
466:            protected void convertCatTree(Store inStore, File inInputDir)
467:                    throws Exception {
468:                File input = new File(inInputDir, "CatTree.xml");
469:
470:                if (input.exists()) {
471:                    SAXReader reader = new SAXReader();
472:                    FileInputStream stream = new FileInputStream(input);
473:                    Document document = reader.read(stream);
474:
475:                    CatalogWithProducts temproot = new CatalogWithProducts(
476:                            "index", "Index");
477:                    temproot.setProperty("sortfield", "priceOrderingUp");
478:                    createCatalog(document.getRootElement(), temproot);
479:
480:                    inStore.getCatalogArchive().setRootCatalog(temproot);
481:                    inStore.getCatalogArchive().saveCatalogs();
482:                    inStore.getCatalogArchive().reloadCatalogs();
483:                    clearProductFromAllCategories(inStore);
484:                    updateProductsIn(inStore, temproot);
485:                }
486:                //remove coupons listing
487:                Category coupons = inStore.getCatalog("AMADAAAADJONALBD");
488:                if (coupons != null) {
489:                    inStore.getCatalogArchive().deleteCatalog(coupons);
490:                }
491:            }
492:
493:            protected void clearProductFromAllCategories(Store inStore)
494:                    throws Exception {
495:                List ids = inStore.listAllKnownProductIds();
496:                for (Iterator iter = ids.iterator(); iter.hasNext();) {
497:                    String id = (String) iter.next();
498:                    Product product = inStore.getProduct(id);
499:                    if (product != null) {
500:                        product.clearCatalogs();
501:                        inStore.getProductArchive().saveProduct(product);
502:                        inStore.getProductArchive().clearProduct(product);
503:                    }
504:                }
505:            }
506:
507:            protected void createCatalog(Element inRootElement,
508:                    CatalogWithProducts inParent) throws StoreException {
509:                //add the products
510:                for (Iterator iter = inRootElement.elementIterator("Style"); iter
511:                        .hasNext();) {
512:                    Element element = (Element) iter.next();
513:                    String ordering = element.attributeValue("OrderNo");
514:                    Style style = new Style();
515:                    if (ordering != null && ordering.length() > 0) {
516:                        style.setOrdering(Integer.parseInt(ordering));
517:                    }
518:                    style.setId(element.attributeValue("SID"));
519:                    inParent.addStyle(style);
520:                }
521:                for (Iterator iter = inRootElement.elementIterator("TreeNode"); iter
522:                        .hasNext();) {
523:                    Element element = (Element) iter.next();
524:                    String id = element.attributeValue("SID");
525:                    String name = element.attributeValue("Caption");
526:                    CatalogWithProducts child = new CatalogWithProducts(id,
527:                            name);
528:                    inParent.addChild(child);
529:                    createCatalog(element, child);
530:                }
531:            }
532:
533:            /**
534:             * @param inProducts
535:             * @throws StoreException
536:             */
537:            protected void updateProductsIn(Store inStore,
538:                    CatalogWithProducts inCatalog) throws StoreException {
539:                if (inCatalog.hasStyles()) {
540:                    for (Iterator iter = inCatalog.getStyles().iterator(); iter
541:                            .hasNext();) {
542:                        Style pid = (Style) iter.next();
543:                        Product product = inStore.getProduct(pid.getId());
544:                        if (product != null) {
545:                            if (product.getOrdering() != pid.getOrdering()
546:                                    || !product.isInCatalog(inCatalog)) {
547:
548:                                product.setOrdering(pid.getOrdering());
549:                                product.addCatalog(inCatalog);
550:
551:                                inStore.getProductArchive()
552:                                        .saveProduct(product);
553:                                String fdesc = product.getDescription();
554:                                inStore.getProductArchive()
555:                                        .saveProductDescription(product, fdesc);
556:
557:                                inStore.getProductArchive().clearProduct(
558:                                        product);
559:                            }
560:                        } else {
561:                            log.error("CatTree specified invalid product  "
562:                                    + pid.getId());
563:                        }
564:                    }
565:                }
566:                for (Iterator iter = inCatalog.getChildren().iterator(); iter
567:                        .hasNext();) {
568:                    CatalogWithProducts child = (CatalogWithProducts) iter
569:                            .next();
570:                    updateProductsIn(inStore, child);
571:                }
572:
573:            }
574:
575:            /**
576:             * @throws IOException
577:             *  
578:             */
579:            protected void copyPhotos(Store inStore, File inZip)
580:                    throws IOException {
581:                //Copy from / store/upload/images/ / store/products/images/thumb and
582:
583:                File newImages = new File(inStore.getStoreDirectory(),
584:                        "products/images");
585:
586:                File largedir = new File(newImages, "original");
587:                largedir.mkdirs();
588:
589:                File meddir = new File(newImages, "medium");
590:                meddir.mkdirs();
591:
592:                File thumbdir = new File(newImages, "thumb");
593:                thumbdir.mkdirs();
594:
595:                OutputFiller filler = new OutputFiller();
596:                ZipFile zip = new ZipFile(inZip);
597:                for (Enumeration iter = zip.entries(); iter.hasMoreElements();) {
598:                    ZipEntry entry = (ZipEntry) iter.nextElement();
599:                    String fileName = entry.getName();
600:                    if (fileName.endsWith("t.jpg")) {
601:                        String baseName = fileName.substring(0, fileName
602:                                .indexOf("t.jpg"));
603:                        File outputFile = new File(thumbdir, baseName
604:                                + "-100.jpg");
605:                        FileOutputStream fos = new FileOutputStream(outputFile);
606:                        filler.fill(zip.getInputStream(entry), fos);
607:                        fos.flush();
608:                        fos.close();
609:                    } else {
610:                        String baseName = fileName.substring(0, fileName
611:                                .indexOf(".jpg"));
612:                        File outputFile = new File(largedir, baseName
613:                                + "-100.jpg");
614:                        //File outputFile = new File(largedir, fileName);
615:                        FileOutputStream fos = new FileOutputStream(outputFile);
616:                        filler.fill(zip.getInputStream(entry), fos);
617:                        fos.flush();
618:                        fos.close();
619:                        File medFile = new File(meddir, baseName + "-100.jpg");
620:                        //copy the large to the med
621:                        filler.fill(outputFile, medFile);
622:                    }
623:                }
624:            }
625:
626:            public OutputFiller getOutputFiller() {
627:                if (fieldOutputFiller == null) {
628:                    fieldOutputFiller = new OutputFiller();
629:                }
630:                return fieldOutputFiller;
631:            }
632:
633:            protected FileFilter largeImageFilter() {
634:                return new FileFilter() {
635:                    public boolean accept(File inArg0) {
636:                        if (inArg0.getName().endsWith("jpg")
637:                                && !inArg0.getName().endsWith("t.jpg")) {
638:                            return true;
639:                        }
640:                        return false;
641:                    }
642:                };
643:            }
644:
645:            protected FileFilter thumbnailFilter() {
646:                return new FileFilter() {
647:                    public boolean accept(File inArg0) {
648:                        if (inArg0.getName().endsWith("t.jpg")) {
649:                            return true;
650:                        }
651:                        return false;
652:                    }
653:                };
654:            }
655:
656:            /**
657:             * @param inNewproduct
658:             * @param inProductE
659:             */
660:            private void populateItems(Product inNewproduct, Element inProductE) {
661:                //TODO: Add keywords for desc medium
662:
663:                for (Iterator iter = inProductE.elementIterator("Item"); iter
664:                        .hasNext();) {
665:                    Element eitem = (Element) iter.next();
666:                    InventoryItem newItem = createItem(eitem);
667:                    newItem.setProduct(inNewproduct);
668:                    inNewproduct.addInventoryItem(newItem);
669:                    /*
670:                     * Look over the price structures and look for each type of price we track
671:                     * On the first item we find
672:                     */
673:                    //Set pricing each time
674:                }
675:            }
676:
677:            public InventoryItem createItem(Element inItemElem) {
678:                InventoryItem newItem = new InventoryItem();
679:
680:                int q = Integer.parseInt(inItemElem
681:                        .attributeValue("AvailQuantity"));
682:                if (q < 1) {
683:                    String att = inItemElem.attributeValue("fldTotOnHnd");
684:                    if (att != null && att.length() > 0) {
685:                        q = Integer.parseInt(att);
686:                    }
687:                }
688:                newItem.setQuantityInStock(q);
689:                newItem.setColor(inItemElem.attributeValue("fldAttr"));
690:                newItem.setSize(inItemElem.attributeValue("fldSize"));
691:                newItem.setSku(inItemElem.attributeValue("fldItemNum"));
692:                //newItem.put("RTP_item_no", );
693:                newItem.put("RTP_sid", inItemElem.attributeValue("fldItemSID"));
694:                String itemHandlingAmountStr = inItemElem
695:                        .attributeValue("fldHandAmount");
696:                if (itemHandlingAmountStr != null) {
697:                    Money itemHandlingAmount = new Money(itemHandlingAmountStr);
698:                    newItem.addOption(createHandlingOption(itemHandlingAmount));
699:                }
700:                newItem.setPriceSupport(null);
701:                for (Iterator iterator = inItemElem.elementIterator("Price"); iterator
702:                        .hasNext();) {
703:
704:                    Price price = null;
705:                    PriceTier tprice = newItem.getTier(0);
706:                    if (tprice == null) {
707:                        price = new Price();
708:                    } else {
709:                        price = tprice.getPrice();
710:                    }
711:                    Element priceElement = (Element) iterator.next();
712:                    if (priceElement != null) {
713:                        String level = priceElement.attributeValue("Level");
714:                        String value = priceElement.attributeValue("Value");
715:                        if (value != null && value.trim().length() > 0) {
716:                            if ("3".equals(level)) {
717:                                price.setRetailPrice(new Money(value));
718:                            }
719:                            //1 retail price
720:                            //2 retail sale price
721:                            //3 web regular retail sale
722:                            //4 web sale price
723:
724:                            if ("4".equals(level)) {
725:                                Money sale = new Money(value);
726:                                if (!sale.isZero()) {
727:                                    price.setSalePrice(sale);
728:                                }
729:                            }
730:                        }
731:                        newItem.addTierPrice(1, price);
732:                    } else {
733:                        //inErrorLog.add("No price found for " + inNewproduct.getName() + " " + inNewproduct.getId());
734:                    }
735:                }
736:                return newItem;
737:            }
738:
739:            /**
740:             * @return
741:             */
742:            protected List listStyleXmls(File inPutHome) {
743:                //search
744:                File[] listinputs = inPutHome
745:                        .listFiles(getEcsStyleZipFileFilter());
746:                List sorted = new ArrayList(Arrays.asList(listinputs));
747:                Collections.sort(sorted);
748:                return sorted;
749:
750:            }
751:
752:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.