public static Object getJavaObject(HttpServletRequest pRequest, String pFullClassName) throws Exception { HttpSession session = pRequest.getSession(); CleanwiseUser appUser = (CleanwiseUser) session.getAttribute(Constants.APP_USER); StoreData storeD = appUser.getUserStore(); AccountData accountD = appUser.getUserAccount(); int storeId = 0; int accountId = 0; if (storeD != null) storeId = storeD.getBusEntity().getBusEntityId(); if (accountD != null) accountId = accountD.getBusEntity().getBusEntityId(); String key = storeId + "@" + accountId + "@" + pFullClassName; Object javaObj = session.getAttribute(key); if (javaObj == null) { ArrayList prefAL = new ArrayList(); String path = ""; PropertyData storePrefixPD = storeD.getPrefix(); if (storePrefixPD != null) { path = Utility.strNN(storePrefixPD.getValue()); } String accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER); if (Utility.isSet(accountDir)) { path += "/" + accountDir; } path = path.replace('\\', '/').toLowerCase(); String[] pathDirA = Utility.parseStringToArray(path, "/"); String pathInc = null; for (int ii = 0; ii < pathDirA.length; ii++) { String ss = pathDirA[ii]; if (Utility.isSet(ss)) { if (pathInc == null) { pathInc = "." + ss; } else { pathInc += "." + ss; } pathDirA[ii] = pathInc; } else { pathDirA[ii] = null; } } int ll = pFullClassName.lastIndexOf("."); String defaultPath = pFullClassName.substring(0, ll); String className = pFullClassName.substring(ll); Class clazz = null; for (int ii = pathDirA.length - 1; ii >= 0; ii--) { if (pathDirA[ii] != null) { String fullClassNameTest = defaultPath + pathDirA[ii] + className; try { clazz = Class.forName(fullClassNameTest); if (clazz != null) { break; } } catch (Exception exc) { } } } if (clazz == null) { clazz = Class.forName(pFullClassName); } if (clazz != null) { javaObj = clazz.newInstance(); session.setAttribute(key, javaObj); } } return javaObj; }
public static String getStoreFilePath( HttpServletRequest pRequest, String pPortal, String pFileName) { if (pFileName == null) { return ""; } pFileName = pFileName.trim(); HttpSession session = pRequest.getSession(); HashMap filePathHM = (HashMap) session.getAttribute("store.files"); if (filePathHM == null) { filePathHM = new HashMap(); session.setAttribute("store.files", filePathHM); } if (pPortal == null) pPortal = "store"; // Make key int storeId = 0; int accountId = 0; CleanwiseUser user = (CleanwiseUser) session.getAttribute(Constants.APP_USER); String accountDir = ""; if (user != null) { StoreData storeD = user.getUserStore(); if (storeD != null) { storeId = storeD.getBusEntity().getBusEntityId(); } AccountData accountD = user.getUserAccount(); if (accountD != null) { accountId = accountD.getBusEntity().getBusEntityId(); accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER); } } Locale locale = ClwI18nUtil.getUserLocale(pRequest); String key = pPortal + "@" + locale + "@" + pFileName + "@" + storeId + "@" + accountId; String resultFilePath = (String) filePathHM.get(key); if (resultFilePath != null) { return resultFilePath; } String storeDir = (String) session.getAttribute("store.dir") + ".clw"; String storePrefix = (String) session.getAttribute("pages.store.prefix"); if (storePrefix == null) storePrefix = ""; // String webDir = System.getProperty("webdeploy"); String webDir = (String) session.getAttribute("webdeploy"); if (webDir == null) webDir = ""; int ind = webDir.indexOf("deploy"); if (ind < 0) { (new Exception("Invalid current directory: " + webDir)).printStackTrace(); return ""; } // trying to find file String storeAcctPrefix = (Utility.isSet(accountDir)) ? storePrefix + "/" + accountDir : storePrefix; StringTokenizer tok = new StringTokenizer(storeAcctPrefix, "/"); String[] storeAcctPrefixA = new String[tok.countTokens() + 1]; storeAcctPrefixA[0] = ""; ind = 1; while (tok.hasMoreTokens()) { String nextToken = tok.nextToken(); if (ind == 1) { storeAcctPrefixA[ind] = nextToken; } else { storeAcctPrefixA[ind] = storeAcctPrefixA[ind - 1] + "/" + nextToken; } ind++; } String absPath = ""; String filePath = ""; boolean foundFl = false; for (int ii = storeAcctPrefixA.length - 1; ii >= 0; ii--) { filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + locale + "/" + pFileName; absPath = webDir + filePath; File tf = new File(absPath); if (tf.exists()) { foundFl = true; break; } if (Utility.isSet(locale.getLanguage())) { filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + locale.getLanguage() + "/" + pFileName; absPath = webDir + filePath; tf = new File(absPath); if (tf.exists()) { foundFl = true; break; } } filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + pFileName; absPath = webDir + filePath; tf = new File(absPath); if (tf.exists()) { foundFl = true; break; } /* filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + pFileName; absPath = webDir + filePath; tf = new File(absPath); if(tf.exists()) { foundFl = true; break; } */ } if (foundFl) { filePathHM.put(key, filePath); } return filePath; }
/** * Returns the store specific/account specific path for the image. @see storeFileImagePath * and @see getSIP */ private static String getSIP( String pPortal, String pFileName, String storePrefix, Locale locale, HashMap filePathHM, StoreData storeD, AccountData accountD, String webDir, String rootDir, boolean absolutePath) { if (pFileName == null) { return ""; } pFileName = pFileName.trim(); // guess at some values if not provided if (locale == null) { if (accountD != null && Utility.isSet(accountD.getBusEntity().getLocaleCd())) { locale = Utility.parseLocaleCode(accountD.getBusEntity().getLocaleCd()); } if (storeD != null && Utility.isSet(storeD.getBusEntity().getLocaleCd())) { locale = Utility.parseLocaleCode(storeD.getBusEntity().getLocaleCd()); } } if (filePathHM == null) { filePathHM = new HashMap(); } if (rootDir == null) { rootDir = ClwCustomizerMyFax.getStoreDir(); } if (!Utility.isSet(storePrefix)) { storePrefix = storeD.getPrefix().getValue(); } if (!Utility.isSet(webDir)) { webDir = System.getProperty("webdeploy"); } if (pPortal == null) pPortal = "store"; // Make key int storeId = 0; int accountId = 0; String accountDir = ""; if (storeD != null) { storeId = storeD.getBusEntity().getBusEntityId(); } if (accountD != null) { accountId = accountD.getBusEntity().getBusEntityId(); accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER); } String key = pPortal + "@" + locale + "@" + pFileName + "@" + storeId + "@" + accountId + "@" + absolutePath; String resultFilePath = (String) filePathHM.get(key); if (resultFilePath != null) { return resultFilePath; } if (storePrefix == null) storePrefix = ""; // String webDir = System.getProperty("webdeploy"); if (webDir == null) webDir = ""; int ind = webDir.indexOf("deploy"); if (ind < 0) { (new Exception("Invalid current directory: " + webDir)).printStackTrace(); return ""; } // trying to find file String storeAcctPrefix = (Utility.isSet(accountDir)) ? storePrefix + "/" + accountDir : storePrefix; StringTokenizer tok = new StringTokenizer(storeAcctPrefix, "/"); String[] storeAcctPrefixA = new String[tok.countTokens() + 1]; storeAcctPrefixA[0] = ""; ind = 1; while (tok.hasMoreTokens()) { String nextToken = tok.nextToken(); if (ind == 1) { storeAcctPrefixA[ind] = nextToken; } else { storeAcctPrefixA[ind] = storeAcctPrefixA[ind - 1] + "/" + nextToken; } ind++; } String absPath = ""; String filePath = ""; boolean foundFl = false; for (int ii = storeAcctPrefixA.length - 1; ii >= 0; ii--) { filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + locale + "/" + "images/" + pFileName; absPath = webDir + filePath; File tf = new File(absPath); if (tf.exists()) { foundFl = true; break; } filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + "images/" + pFileName; absPath = webDir + filePath; tf = new File(absPath); if (tf.exists()) { foundFl = true; break; } filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + "images/" + pFileName; absPath = webDir + filePath; tf = new File(absPath); if (tf.exists()) { foundFl = true; break; } /* filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + "images/"+ pFileName; absPath = webDir + filePath; tf = new File(absPath); if(tf.exists()) { foundFl = true; break; } */ } if (absolutePath) { filePath = absPath; } else { filePath = "/" + rootDir + filePath; } if (foundFl) { filePathHM.put(key, filePath); } return filePath; }
public void generatePdf( UserShopForm sForm, List pItems, StoreData pStore, OutputStream pOut, String pImageName, boolean personal, boolean pCatalogOnly, String catalogLocaleCd) throws IOException { mSkuTag = ClwI18nUtil.getMessage(mRequest, "shop.og.text.ourSkuNum", null); try { catalogOnly = pCatalogOnly; initColumnsAdnWidths(sForm.getAppUser()); mSiteData = sForm.getAppUser().getSite(); AccountData mAccount = sForm.getAppUser().getUserAccount(); String ogInvDisplay = mAccount.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.INVENTORY_OG_LIST_UI); boolean modernShoppingFl = mSiteData.hasModernInventoryShopping(); // loop through the items to check if the footer needs to have the pack // Disclaimer printed on each page. boolean printProblemPackDisclaimer = false, invItems = false, invAutoOrderItems = false, nonInvItems = false, addNewPage = false; for (int i = 0; i < pItems.size(); i++) { ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i); if (sci.getProduct().isPackProblemSku()) { printProblemPackDisclaimer = true; } if (sci.getIsaInventoryItem()) { invItems = true; if (null != mSiteData && mSiteData.isAnInventoryAutoOrderItem(sci.getProduct().getProductId())) { invAutoOrderItems = true; } } else { nonInvItems = true; if (invItems) addNewPage = true; } } Phrase headPhrase = new Phrase(makeChunk("", heading, true)); if (catalogOnly) { String catalogStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.catalog", null); headPhrase.add(makeChunk(catalogStr, heading, true)); } else { if (sForm.getAppUser().getSite() != null && sForm.getAppUser().getSite().getBSC() != null && sForm.getAppUser().getSite().getBSC().getBusEntityData() != null && sForm.getAppUser().getSite().getBSC().getBusEntityData().getShortDesc() != null) { String subname = sForm.getAppUser().getSite().getBSC().getBusEntityData().getShortDesc() + " "; headPhrase.add(makeChunk(subname, heading, true)); headPhrase.add(makeChunk(" ", heading, true)); } String orderGuideStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderGuide", null); headPhrase.add(makeChunk(orderGuideStr, heading, true)); headPhrase.add(makeChunk(" ", heading, true)); headPhrase.add( makeChunk( sForm.getAppUser().getUserAccount().getBusEntity().getShortDesc(), heading, true)); } HeaderFooter header = new HeaderFooter(headPhrase, true); header.setAlignment(HeaderFooter.ALIGN_RIGHT); // setup the document // pageSize, marginLeft, marginRight, marginTop, marginBottom Document document = new Document(PageSize.A4, 10, 15, 30, 15); PdfWriter writer = PdfWriter.getInstance(document, pOut); String addr = pStore.getPrimaryAddress().getAddress1() + " " + pStore.getPrimaryAddress().getAddress2(); Chunk disclaimer = null; String fmsg = ""; if (invItems) { fmsg += ClwI18nUtil.getMessage(mRequest, "shop.og.text.i-inventoryItem", null) + " "; } if (invAutoOrderItems) { fmsg += ClwI18nUtil.getMessage(mRequest, "shop.og.text.a-autoOrderItem", null) + " "; } if (printProblemPackDisclaimer) { fmsg += ClwI18nUtil.getMessage(mRequest, "shop.og.text.*packAndOrUomMayDifferByRegion", null); } if (fmsg.length() > 0) { disclaimer = makeChunk(fmsg, smallItalic, true); } Phrase footPhrase = makeStoreFooter(pStore, disclaimer, null); HeaderFooter footer = new HeaderFooter(footPhrase, false); footer.setAlignment(HeaderFooter.ALIGN_CENTER); // setup the borders from the header header.setBorder(borderType); footer.setBorder(HeaderFooter.TOP); document.setHeader(header); document.setFooter(footer); document.open(); // voc message String vocMessage = ClwI18nUtil.getMessage(mRequest, "shop.message.vocNotIncluded", null); document.add(makePhrase(vocMessage, smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); drawOGHeader(document, sForm, pImageName, personal); if (modernShoppingFl && !"SEPARATED LIST".equals(ogInvDisplay)) { drawHeader( document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true); String prevCat = null; for (int i = 0; i < pItems.size(); i++) { ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i); Table itmTable = makeItemElement(sci); // if the item data will not fit onto the page, // make a new page, and redraw the header. if (writer.fitsPage(itmTable, document.bottomMargin() + 10)) { if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) { if (null == prevCat || !prevCat.equals(sci.getCategoryPath())) { document.add(makePhrase(sci.getCategoryPath(), smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); } prevCat = sci.getCategoryPath(); } } if (!writer.fitsPage(itmTable, document.bottomMargin() + 10)) { document.newPage(); pageNumber = pageNumber + 1; drawHeader( document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true); if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) { document.add(makePhrase(sci.getCategoryPath(), smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); prevCat = sci.getCategoryPath(); } } document.add(itmTable); } } else { if (invItems) { drawHeader( document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true); String prevCat = null; for (int i = 0; i < pItems.size(); i++) { ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i); if (sci.getIsaInventoryItem() == false) { continue; } if (sci.getInventoryParValuesSum() <= 0) { // This is an inventory item that is not // allowed for this location. continue; } Table itmTable = makeItemElement(sci); // if the item data will not fit onto the page, // make a new page, and redraw the header. if (writer.fitsPage(itmTable, document.bottomMargin() + 10)) { if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) { if (null == prevCat || !prevCat.equals(sci.getCategoryPath())) { document.add(makePhrase(sci.getCategoryPath(), smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); } prevCat = sci.getCategoryPath(); } } if (!writer.fitsPage(itmTable, document.bottomMargin() + 10)) { document.newPage(); pageNumber = pageNumber + 1; drawHeader( document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true); if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) { document.add(makePhrase(sci.getCategoryPath(), smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); prevCat = sci.getCategoryPath(); } } document.add(itmTable); } } if (nonInvItems) { if (addNewPage) { document.newPage(); pageNumber = pageNumber + 1; } drawHeader( document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, false); document.add(makeBlankLine()); String prevCat = null; for (int i = 0; i < pItems.size(); i++) { ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i); if (sci.getIsaInventoryItem()) { continue; } Table itmTable = makeItemElement(sci); // Check to see if the category needs to be put out. if (writer.fitsPage(itmTable, document.bottomMargin() + 10)) { if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) { if (null == prevCat || !prevCat.equals(sci.getCategoryPath())) { document.add(makePhrase(sci.getCategoryPath(), smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); } prevCat = sci.getCategoryPath(); } } // if the item data will not fit onto the page, // make a new page, and redraw the header. if (!writer.fitsPage(itmTable, document.bottomMargin() + 10)) { document.newPage(); pageNumber = pageNumber + 1; drawHeader( document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, false); if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) { document.add(makePhrase(sci.getCategoryPath(), smallHeading, true)); document.add(makePhrase(null, smallHeading, true)); prevCat = sci.getCategoryPath(); } } document.add(itmTable); } } } // close out the document document.close(); } catch (DocumentException e) { e.printStackTrace(); throw new IOException(e.getMessage()); } }