Subversion Repositories SmartDukaan

Rev

Rev 5638 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.util;

import in.shop2020.metamodel.core.Entity;
import in.shop2020.metamodel.util.CreationUtils;
import in.shop2020.metamodel.util.ExpandedEntity;

import java.util.Arrays;
import java.util.List;

public class ProductDocumentsGenerator {
        private String[] indentation = {"", "    ", "        ", "            ","                "};
        private List<Entity> entities;
        
        
        public ProductDocumentsGenerator(List<Entity> allValidEntities) {
                this.entities = allValidEntities;
        }

        public void generate() throws Exception {
                StringBuffer sb = new StringBuffer();
                for ( Entity entity : entities) {
                        ExpandedEntity ex = new ExpandedEntity(entity);
                        if(entity.getSlide(130088l) != null) {
                                String productName = EntityUtils.getProductName(ex);
                                String productUrl = productName.toLowerCase().replace(' ', '-');
                                productUrl = productUrl.replaceAll("/", "-").replaceAll("-+", "-");
                                productUrl = "/product-documents/" + productUrl + "-user-manual-software-updates-how-to-" + entity.getID();
                                sb.append("<div>\n");
                                sb.append(indentation[1] + "<a href='" + productUrl + "'>");
                                sb.append(productName + " User manual, Software updates and how to");
                                sb.append("</div>\n");
                                sb.append("</a>\n");
                        }
                }
                String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "product-documents.html";
                
                try     {
                        DBUtils.store(sb.toString(), indexFilename);
                        
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
        
        public static void main (String [] args) throws Exception {
                ProductDocumentsGenerator asg = new ProductDocumentsGenerator(Arrays.asList(CreationUtils.getEntity(1001715l), CreationUtils.getEntity(1001715l), CreationUtils.getEntity(1003884l)));
                asg.generate();
        }
}