List of usage examples for com.liferay.portal.kernel.xml Node getStringValue
public String getStringValue();
From source file:com.beorn.onlinepayment.messaging.messageprocessor.RegisterMessageProcessor.java
License:Open Source License
private void registerPaymentMethods(Document document, PaymentPlugin paymentPlugin, ServiceContext serviceContext) throws PortalException, SystemException { List<PaymentMethod> paymentMethods = new ArrayList<PaymentMethod>(); List<Node> methodNodes = document.selectNodes("/plugin/methods/method"); for (Node methodNode : methodNodes) { Node methodKeyNode = methodNode.selectSingleNode("key"); String methodKey = methodKeyNode.getStringValue(); Node methodNameNode = methodNode.selectSingleNode("name"); Map<Locale, String> methodNameMap = getLocalizationMap(methodNameNode); PaymentMethod paymentMethod;/*from ww w.j av a 2 s.c o m*/ try { paymentMethod = PaymentMethodLocalServiceUtil.getPaymentMethodByKey(methodKey); methodNameMap = mergeLocalizationMaps(paymentMethod.getNameMap(), methodNameMap); paymentMethod = PaymentMethodLocalServiceUtil.updatePaymentMethod( paymentMethod.getPaymentMethodId(), methodKey, methodNameMap, serviceContext); } catch (NoSuchMethodException e) { paymentMethod = PaymentMethodLocalServiceUtil.addPaymentMethod(serviceContext.getUserId(), methodKey, methodNameMap, serviceContext); } paymentMethods.add(paymentMethod); } PaymentPluginLocalServiceUtil.updatePaymentPluginPaymentMethods(paymentPlugin.getPaymentPluginId(), paymentMethods); }
From source file:com.beorn.onlinepayment.messaging.messageprocessor.RegisterMessageProcessor.java
License:Open Source License
private Map<Locale, String> getLocalizationMap(Node node) { List<Node> children = node.selectNodes("*"); if (children.isEmpty()) return LocalizationUtil.getLocalizationMap(node.getStringValue()); Locale[] locales = LanguageUtil.getAvailableLocales(); Map<Locale, String> map = new HashMap<Locale, String>(); for (Locale locale : locales) { String languageId = LocaleUtil.toLanguageId(locale); Node languageNode = node.selectSingleNode(languageId); if (languageNode == null) continue; String localization = languageNode.getStringValue(); if (Validator.isNull(localization)) continue; map.put(locale, localization);// w w w . j a v a 2s. co m } return map; }
From source file:com.beorn.paymentappapi.util.PaymentAppUtil.java
License:Open Source License
/** * Retrieve the notification listener as defined in this app's * payment-app.xml/*from w ww. j a va2s .c o m*/ * * @param servletContext * this webapp's servlet context * @return the notification listener * @throws PortalException * @throws SystemException */ public static NotificationListener getNotificationListener(ServletContext servletContext) throws PortalException, SystemException { try { InputStream is = getAppDescriptionStream(servletContext); if (is == null) return null; try { Document document = SAXReaderUtil.read(is); Node notificationListenerClassNode = document .selectSingleNode("/plugin/notification-listener-class"); if (notificationListenerClassNode == null) return null; String className = notificationListenerClassNode.getStringValue(); try { NotificationListener notificationListener = (NotificationListener) Class.forName(className) .newInstance(); return notificationListener; } catch (Exception e) { throw new PortalException("Could not initialize notification listener for {app:" + servletContext.getServletContextName() + ", classname:" + className + "}", e); } } catch (Exception e) { throw new PortalException(e); } finally { is.close(); } } catch (IOException e1) { throw new SystemException(e1); } }
From source file:com.beorn.paymentpluginapi.config.ConfigDescriptionUtil.java
License:Open Source License
private static String getRequiredValue(Node node, String key) throws InvalidConfigDescriptionException { Node valueNode = node.selectSingleNode(key); if (valueNode == null) throw new InvalidConfigDescriptionException("Missing key \"" + key + "\""); return valueNode.getStringValue(); }
From source file:com.beorn.paymentpluginapi.config.ConfigDescriptionUtil.java
License:Open Source License
private static String getOptionalValue(Node node, String key, String defaultValue) { Node valueNode = node.selectSingleNode(key); if (valueNode == null) return defaultValue; return valueNode.getStringValue(); }
From source file:com.beorn.paymentpluginapi.util.PaymentPluginUtil.java
License:Open Source License
/** * Retrieve this plugin's name as defined in its payment-plugin.xml * // ww w . ja va 2 s. c om * @param servletContext * this webapp's servlet context * @return this plugin's name * @throws PortalException * @throws IOException */ public static String getPluginName(ServletContext servletContext) throws PortalException, IOException { InputStream is = getPluginDescriptionStream(servletContext); try { Document document = SAXReaderUtil.read(is); Node nameNode = document.selectSingleNode("/plugin/name"); return nameNode.getStringValue(); } catch (Exception e) { throw new PortalException(e); } finally { is.close(); } }
From source file:com.beorn.paymentpluginapi.util.PaymentPluginUtil.java
License:Open Source License
/** * Retrieve all the payment method handlers as defined in this plugin's * payment-plugin.xml/*from ww w .ja v a2s.c o m*/ * * @param servletContext * this webapp's servlet context * @return the supported payment method handlers * @throws PortalException * @throws SystemException */ public static Map<String, MethodHandler> getPluginMethodHandlers(ServletContext servletContext) throws PortalException, SystemException { try { InputStream is = getPluginDescriptionStream(servletContext); try { Document document = SAXReaderUtil.read(is); Map<String, MethodHandler> methodHandlers = new HashMap<String, MethodHandler>(); List<Node> methodNodes = document.selectNodes("/plugin/methods/method"); for (Node methodNode : methodNodes) { Node keyNode = methodNode.selectSingleNode("key"); Node classNameNode = methodNode.selectSingleNode("class"); String key = keyNode.getStringValue(); String className = classNameNode.getStringValue(); try { MethodHandler methodHandler = (MethodHandler) Class.forName(className).newInstance(); methodHandler.initialize(servletContext); methodHandlers.put(key, methodHandler); } catch (Exception e) { _log.error("Could not initialize method handler for {plugin:" + servletContext.getServletContextName() + ", key:" + key + ", classname:" + className + "}", e); } } return methodHandlers; } catch (Exception e) { throw new PortalException(e); } finally { is.close(); } } catch (IOException e1) { throw new SystemException(e1); } }
From source file:com.beorn.paymentpluginapi.util.PaymentPluginUtil.java
License:Open Source License
/** * Retrieve the config validator as defined in this plugin's * payment-plugin.xml//from ww w .java2 s . c om * * @param servletContext * this webapp's servlet context * @param key * kind of config to retrieve * @return the payment method config validator * @throws PortalException * @throws SystemException */ public static ConfigValidator getConfigValidator(ServletContext servletContext, String key) throws PortalException, SystemException { try { InputStream is = getPluginDescriptionStream(servletContext); if (is == null) return null; try { Document document = SAXReaderUtil.read(is); Node configNode = document.selectSingleNode("/plugin/" + key); if (configNode == null) return null; Node classNameNode = configNode.selectSingleNode("./validatorClass"); if (classNameNode == null) return null; String className = classNameNode.getStringValue(); try { ConfigDescription configDescription = ConfigDescriptionUtil.parseConfigDescription(configNode); ConfigValidator configValidator = (ConfigValidator) Class.forName(className).newInstance(); configValidator.setConfigDescription(configDescription); return configValidator; } catch (Exception e) { throw new PortalException( "Could not initialize validator for {plugin:" + servletContext.getServletContextName() + ", key:" + key + ", classname:" + className + "}", e); } } catch (Exception e) { throw new PortalException(e); } finally { is.close(); } } catch (IOException e1) { throw new SystemException(e1); } }
From source file:com.rivetlogic.ecommerce.cart.ShoppingCartItemUtil.java
License:Open Source License
public static void setCartItemDetails(String productId, ThemeDisplay themeDisplay, ShoppingCartItem shoppingCartItem) { long groupId = themeDisplay.getScopeGroupId(); Document document = getItemContent(productId, groupId); if (null != document) { Node itemTitleNode = document.selectSingleNode(ShoppingCartItem.PRODUCT_TITLE); Node itemListPriceNode = document.selectSingleNode(ShoppingCartItem.LIST_PRICE); Node itemSalePriceNode = document.selectSingleNode(ShoppingCartItem.SALE_PRICE); Node imagesNode = document.selectSingleNode(ShoppingCartItem.PRODUCT_IMAGES); shoppingCartItem.setItemTitle(itemTitleNode.getStringValue()); shoppingCartItem.setSalePrice(itemSalePriceNode.getStringValue()); shoppingCartItem.setListPrice(itemListPriceNode.getStringValue()); shoppingCartItem.setItemImage(themeDisplay.getPortalURL() + imagesNode.getStringValue()); }/*from w ww .j ava 2 s.c om*/ shoppingCartItem.setItemLink(themeDisplay.getPortalURL() + WEB_PAGE_PATH + themeDisplay.getScopeGroup().getFriendlyURL() + VIEW_PAGE_PATH + shoppingCartItem.getProductId()); }
From source file:com.rivetlogic.ecommerce.portlet.ShoppingCartPortlet.java
License:Open Source License
private void addCartDetailsOnResponse(ResourceRequest request, ResourceResponse response, String itemId) throws SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Map<String, Integer> cartItemsCountMap = new HashMap<String, Integer>(); String itemToDetailProductId = itemId; boolean returnItemDetails = (null != itemId && !itemId.isEmpty()); if (!themeDisplay.isSignedIn()) { List<String> itemsProductIdsList = getOrderItemsIdsFromSession(request); if (itemsProductIdsList == null && returnItemDetails) { itemsProductIdsList = new ArrayList<String>(); itemsProductIdsList.add(itemId); }/*from w w w. j a v a 2 s.c om*/ if (null != itemsProductIdsList) { for (String productId : itemsProductIdsList) { if (!cartItemsCountMap.containsKey(productId)) { cartItemsCountMap.put(productId, 1); } else { cartItemsCountMap.put(productId, cartItemsCountMap.get(productId) + 1); } } } } else { ShoppingOrder activeShoppingOrder = ShoppingOrderLocalServiceUtil.getUserActiveOrder( themeDisplay.getUserId(), themeDisplay.getCompanyGroupId(), themeDisplay.getCompanyId(), Boolean.FALSE); if (null != activeShoppingOrder) { List<ShoppingOrderItem> orderItemsList = ShoppingOrderItemLocalServiceUtil .findByOrderId(activeShoppingOrder.getOrderId()); if (null != orderItemsList) { for (ShoppingOrderItem shoppingOrderItem : orderItemsList) { cartItemsCountMap.put(shoppingOrderItem.getProductId(), shoppingOrderItem.getQuantity()); if (returnItemDetails && itemId.equals(String.valueOf(shoppingOrderItem.getItemId()))) { itemToDetailProductId = shoppingOrderItem.getProductId(); } } } } } double total = 0; float itemTotal = 0; int quantity = 0, itemQuantity = 0; for (Entry<String, Integer> mapEntry : cartItemsCountMap.entrySet()) { Document document = getItemContent(mapEntry.getKey(), themeDisplay.getScopeGroupId()); if (null != document) { Node itemListPriceNode = document.selectSingleNode(ShoppingCartItem.LIST_PRICE); Node itemSalePriceNode = document.selectSingleNode(ShoppingCartItem.SALE_PRICE); Float salePrice = !itemSalePriceNode.getStringValue().isEmpty() ? Float.valueOf(itemSalePriceNode.getStringValue()) : 0; Float listPrice = !itemListPriceNode.getStringValue().isEmpty() ? Float.valueOf(itemListPriceNode.getStringValue()) : 0; total += (salePrice != 0 ? salePrice * (float) mapEntry.getValue() : listPrice * (float) mapEntry.getValue()); quantity += mapEntry.getValue(); if (returnItemDetails && itemToDetailProductId.equals(mapEntry.getKey())) { itemQuantity = mapEntry.getValue(); itemTotal = (salePrice != 0 ? salePrice * (float) mapEntry.getValue() : listPrice * (float) mapEntry.getValue()); } } } DecimalFormat totalFormat = new DecimalFormat(ShoppingCartPortletConstants.DECIMAL_FORMAT); JSONObject jsonResponse = JSONFactoryUtil.createJSONObject(); JSONObject cartDetailsJson = JSONFactoryUtil.createJSONObject(); cartDetailsJson.put(ShoppingCartPortletConstants.CART_DETAILS_TOTAL, totalFormat.format(total)); cartDetailsJson.put(ShoppingCartPortletConstants.CART_DETAILS_QUANTITY, quantity); jsonResponse.put(ShoppingCartPortletConstants.CART_DETAILS, cartDetailsJson); if (returnItemDetails) { JSONObject itemDetailsJson = JSONFactoryUtil.createJSONObject(); itemDetailsJson.put(ShoppingCartPortletConstants.CART_DETAILS_TOTAL, totalFormat.format(itemTotal)); itemDetailsJson.put(ShoppingCartPortletConstants.CART_DETAILS_QUANTITY, itemQuantity); jsonResponse.put(ShoppingCartPortletConstants.ITEM_DETAILS, itemDetailsJson); } printJsonResponse(jsonResponse.toString(), null, response); }