public String generateXhtml(String contextRoot) { String contextRootWithoutSlash = contextRoot.replace("\\", "").replace("/", ""); StringBuffer strBuf = new StringBuffer(); // for ease of debugging String descriptionString = ""; if (this.getDescription() != null && !this.getDescription().equals("")) { descriptionString = " (" + this.getDescription() + ")"; } strBuf.append("// File: " + this.getName() + descriptionString + "\n"); strBuf.append( "// Last Generated: " + FormatUtil.formatDate(FormatUtil.getEngSlashSimpleDateTimeFormat(), new Date()) + "\n"); strBuf.append( CommonUtil.includeContextRootInPathsForCss(getContent(), contextRootWithoutSlash)); return strBuf.toString(); }
@Override public Calendar getFirstExecutionTime() { Calendar cal = Calendar.getInstance(); // if we set this timezone we get randomness because GMT is ambiguous (ie it changes for BST and // can mean UTC or UC1) // cal.setTimeZone(TimeZone.getTimeZone("GMT")); FormatUtil.resetTime(cal); cal.set(Calendar.HOUR_OF_DAY, 14); cal.set(Calendar.MINUTE, 26); return cal; }
@Override public void addContentJDynamiTeValues(JDynamiTe jDynamiTe, Transaction transaction) { super.addContentJDynamiTeValues(jDynamiTe, transaction); jDynamiTe.setVariable( "CUSTOMER_FULLNAME", transaction.getEcommerceShoppingCart().getCustomer().getDisplayName()); CompanyDetails companyDetails = CommonConfiguration.getCommonConfiguration().getDefaultCompanyDetails(); jDynamiTe.setVariable("COMPANY_NAME", companyDetails.getAddress().getContactFirstName()); if (companyDetails.getLogoDetails() != null) { jDynamiTe.setVariable("COMPANY_LOGO", companyDetails.getLogoDetails().getFilename()); } jDynamiTe.setVariable("COMPANY_WEBSITE", companyDetails.getWeb()); jDynamiTe.setVariable("ORDER_NUMBER", transaction.getId().toString()); jDynamiTe.setVariable("DISPATCH_DATETIME", new Date().toString()); String shippingMethodName = ""; if (transaction.getEcommerceShoppingCart().getAvailableShippingService() != null) { shippingMethodName = transaction .getEcommerceShoppingCart() .getAvailableShippingService() .getCachedServiceName(); } jDynamiTe.setVariable("SHIPPING_METHOD_NAME", shippingMethodName); jDynamiTe.setVariable( "SHIPPING_ADDRESS_STRING", transaction.getShippingAddress().getAddressString()); jDynamiTe.setVariable("ORDER_STATUS", transaction.getTransactionStatus().getLabel()); List<ShoppingCartItem> shoppingCartItems = transaction.getEcommerceShoppingCart().getItems(); for (int i = 0, n = shoppingCartItems.size(); i < n; i++) { EcommerceShoppingCartItem shoppingItem = (EcommerceShoppingCartItem) shoppingCartItems.get(i); jDynamiTe.setVariable( "PRODUCT_CODE_REPEATED", CommonUtil.getStringOrEmpty(shoppingItem.getItemCode())); jDynamiTe.setVariable("PRODUCT_SIZE_REPEATED", shoppingItem.getProductSize()); jDynamiTe.setVariable("PRODUCT_BRAND_AND_NAME_REPEATED", shoppingItem.getItemName()); jDynamiTe.setVariable( "PRODUCT_QUANTITY_REPEATED", FormatUtil.formatTwoDigit(shoppingItem.getQuantity())); jDynamiTe.parseDynElem("productList"); } jDynamiTe.setVariable( "COMPLETE_OR_CONTINUE", "This dispatch completes your order. We hope you will be very happy with your purchases."); jDynamiTe.setVariable("PART_OR_Y", "Y"); }
private void addBasicCmsContentUrls( StringBuffer sitemapStrBuf, BasicCmsContentFeDmb basicCmsContentFeDmb, CmsPageRevision cmsPageRevision) { basicCmsContentFeDmb.createBasicCmsContents(); List<BasicCmsContent> basicCmsContentList = basicCmsContentFeDmb.getBasicCmsContents(); for (int i = 0, n = basicCmsContentList.size(); i < n; i++) { sitemapStrBuf.append("<url>"); sitemapStrBuf.append("<loc>"); sitemapStrBuf.append( StringEscapeUtils.escapeXml( basicCmsContentFeDmb.getBasicCmsContentLink( basicCmsContentList.get(i), cmsPageRevision))); sitemapStrBuf.append("</loc>"); sitemapStrBuf.append("<lastmod>"); sitemapStrBuf.append( FormatUtil.formatDateForDB(basicCmsContentList.get(i).getDateLastModified())); sitemapStrBuf.append("</lastmod>"); sitemapStrBuf.append("</url>"); } }
public void generateSiteMap(File file) { List<CmsPage> cmsPages = new BeanDao(CmsPage.class).getAll(); StringBuffer sitemapStrBuf = new StringBuffer(); sitemapStrBuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sitemapStrBuf.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"); CmsPageRevision tempCmsPageRevision; removeUnusedPages(cmsPages, getUnusedMenu().getChildren()); removeUnusedPages(cmsPages, getErrorMenu().getChildren()); for (int i = 0, n = cmsPages.size(); i < n; i++) { tempCmsPageRevision = cmsPages.get(i).getLatestRevision(); if (tempCmsPageRevision != null && cmsPages.get(i).getClass().equals(CmsPage.class)) { sitemapStrBuf.append("<url>"); sitemapStrBuf.append("<loc>"); CmsPageUrl cmsPageUrl = new CmsPageUrl(cmsPages.get(i)); cmsPageUrl.setHost(this); sitemapStrBuf.append(cmsPageUrl.toString()); sitemapStrBuf.append("</loc>"); sitemapStrBuf.append("<lastmod>"); sitemapStrBuf.append(FormatUtil.formatDateForDB(tempCmsPageRevision.getDateLastModified())); sitemapStrBuf.append("</lastmod>"); sitemapStrBuf.append("<priority>"); sitemapStrBuf.append(cmsPages.get(i).getSiteMapPriority()); sitemapStrBuf.append("</priority>"); sitemapStrBuf.append("</url>"); for (CmsAtom tempCmsAtom : tempCmsPageRevision.getCmsAtomList()) { if (tempCmsAtom instanceof BasicCmsContentAtom) { addBasicCmsContentUrls( sitemapStrBuf, (BasicCmsContentFeDmb) ((BasicCmsContentAtom) tempCmsAtom).getFrontendModuleBacking(), tempCmsPageRevision); } } } } List<BlogEntry> blogEntryList = new BeanDao(BlogEntry.class).getAll(); for (int i = 0, n = blogEntryList.size(); i < n; i++) { sitemapStrBuf.append("<url>"); sitemapStrBuf.append("<loc>"); sitemapStrBuf.append( StringEscapeUtils.escapeXml( BlogFeDmb.getBlogEntryUrl( blogEntryList.get(i), CmsConfiguration.getCmsConfiguration().getBlogCpr()))); sitemapStrBuf.append("</loc>"); sitemapStrBuf.append("<lastmod>"); sitemapStrBuf.append(FormatUtil.formatDateForDB(blogEntryList.get(i).getDateLastModified())); sitemapStrBuf.append("</lastmod>"); sitemapStrBuf.append("</url>"); } sitemapStrBuf.append("</urlset>"); try { file.createNewFile(); FileWriter writer = new FileWriter(file); writer.write(sitemapStrBuf.toString()); writer.flush(); writer.close(); } catch (IOException ioex) { ApplicationUtil.handleError(ioex); } }
@Override public Boolean executeCall() throws Exception { String[] cols = { "Category", "Manufacturer", // * fields marked with * are mandatory and MUST be filled in "Title", // * "Product Description", // "Link", // * "Image", // "SKU", // * "Stock", // they only update the feed every 2-3 days "Condition", // New, Open Box, Refurbished, OEM, Used "Shipping Weight", // in pounds "Shipping Cost", // expects lowest available, value not required but useful if free shipping // offered "Bid", "Promotional Description", "EAN/UPC", // only really applies to entertainment goods "Price" // * }; List<String[]> rows = new ArrayList<String[]>(); BeanDao realizedProductDao = new BeanDao(RealizedProduct.class); if (EcommerceConfiguration.getEcommerceSettingsStatic().isProductListGroupByColour()) { realizedProductDao.setWhereCriteria("bean.productInfo.defaultRealizedProduct.id=bean.id"); } realizedProductDao.addWhereCriteria("bean.productInfo.product.isShowingOnWebsite=1"); List<RealizedProduct> realizedProducts = realizedProductDao.setIsReturningActiveBeans(true).getAll(); Map<ProductInfo, ArrayList<ProductColour>> coloursCovered = new HashMap<ProductInfo, ArrayList<ProductColour>>(); for (RealizedProduct realizedProduct : realizedProducts) { if (!EcommerceConfiguration.getEcommerceSettingsStatic().isProductListGroupByColour()) { ArrayList<ProductColour> currentColours = coloursCovered.get(realizedProduct.getProductInfo()); if (currentColours == null) { currentColours = new ArrayList<ProductColour>(); } if (!currentColours.contains(realizedProduct.getProductColour())) { currentColours.add(realizedProduct.getProductColour()); coloursCovered.put(realizedProduct.getProductInfo(), currentColours); } else { // we dont want multiple where there are several sizes for this // colour/p.info combination continue; } } List<ProductType> productTypes = realizedProduct.getProductInfo().getProduct().getProductTypes(); String category = "Misc."; String typeForUrl = null; for (ProductType type : productTypes) { typeForUrl = type.getMapping(); if (typeForUrl == null || typeForUrl.equals("")) { typeForUrl = type.getMapping(); if (typeForUrl == null || typeForUrl.equals("")) { typeForUrl = CommonUtil.makeSafeUrlMapping(type.getName()); } } } String manufacturerName; // ordinarily we would use something like 'menswear' or 'sportswear' here not brand but // we cant determine it here so need to improvise to keep correct format and still make sense // to a user (for seo) String manufacturerNameForUrl; if (realizedProduct.getProductInfo().getProduct().getProductBrand() != null) { manufacturerName = realizedProduct.getProductInfo().getProduct().getProductBrand().getMapping(); if (manufacturerName == null || manufacturerName.equals("")) { manufacturerName = realizedProduct.getProductInfo().getProduct().getProductBrand().getName(); } manufacturerNameForUrl = CommonUtil.makeSafeUrlMapping(manufacturerName); } else { manufacturerName = ""; manufacturerNameForUrl = CommonUtil.makeSafeUrlMapping(websiteName); } String title = realizedProduct.getProductInfo().getProduct().getName(); String productDescription = CommonUtil.getStringOrEmpty(realizedProduct.getProductInfo().getShortDescription()); if (!serverUrl.startsWith("http")) { serverUrl = "http://" + serverUrl; } if (!serverUrl.endsWith("/")) { serverUrl = serverUrl + "/"; } if (contextPath.startsWith("/")) { contextPath = contextPath.substring(1); } if (!contextPath.endsWith("/")) { contextPath = contextPath + "/"; } String serverContext = serverUrl + contextPath; serverContext = serverContext.replaceAll("//", "/"); serverContext = serverContext.replaceAll("http:/", "http://"); String urlToProductView = serverContext + manufacturerNameForUrl + "/" + typeForUrl + "/" + realizedProduct.getProductInfo().getMappingOrId() + ".aplos?type=product"; String imageDetailsId = "missing"; FileDetails largeImage = realizedProduct.getImageDetailsByKey("LARGE_IMAGE"); if (largeImage != null) { imageDetailsId = String.valueOf(largeImage.getId()); } else if (realizedProduct.getDefaultImageDetails() != null) { imageDetailsId = String.valueOf(realizedProduct.getDefaultImageDetails().getId()); } else if (realizedProduct.getImageDetailsList() != null && realizedProduct.getImageDetailsList().size() > 0) { imageDetailsId = String.valueOf(realizedProduct.getImageDetailsList().get(0).getId()); } String urlToImage = ""; if (!imageDetailsId.equals("missing")) { urlToImage = serverContext + "media/?filename=realizedProductImages/" + imageDetailsId + "_large.jpg&provideDefaultIfMissing=true"; } String sku = realizedProduct.determineItemCode(); if (sku == null || sku.equals("")) { // not all sites use item codes but we have to pass one, so invent one sku = realizedProduct.getProductInfo().getId() + "SKU"; sku += realizedProduct.getId(); if (!EcommerceConfiguration.getEcommerceSettingsStatic().isProductListGroupByColour() && realizedProduct.getProductColour() != null) { sku += "C" + realizedProduct.getProductColour().getId(); } } String stock = ""; String condition = "New"; String shippingWeight = FormatUtil.formatTwoDigit(realizedProduct.determineWeight()); // there's way too many factors to consider for shipping cost, so i'm only going to pass a // value String shippingCost = ""; if (isFreeShippingAvailable(realizedProduct.getProductInfo())) { shippingCost = "0"; } String bid = ""; String promotionalDescription = ""; String eanUpc = String.valueOf( realizedProduct .getProductInfo() .getId()); // we might want to use isbn etc if this were a book String price; if (realizedProduct.getSitewideDiscount() != null) { price = FormatUtil.formatTwoDigit( realizedProduct .getPrice() .subtract( realizedProduct .getPrice() .divide(new BigDecimal(100)) .multiply(realizedProduct.getSitewideDiscount()))); } else { price = realizedProduct.getPriceStr(); } rows.add( new String[] { category, manufacturerName, title, productDescription, urlToProductView, urlToImage, sku, stock, condition, shippingWeight, shippingCost, bid, promotionalDescription, eanUpc, price }); } try { // this is relative to webroot - so that it can be accessed as a feed String filename = "tab-delimited-feed.txt"; FileIoUtil.generateTabDelimitedFile(filename, cols, rows); } catch (InputMismatchException ime) { ime.printStackTrace(); } return true; }