Example usage for com.liferay.portal.kernel.xml Node selectSingleNode

List of usage examples for com.liferay.portal.kernel.xml Node selectSingleNode

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Node selectSingleNode.

Prototype

public Node selectSingleNode(String xPathExpression);

Source Link

Usage

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  a  v  a 2s .  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  va2 s .co  m
    }

    return map;
}

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 all the payment method handlers as defined in this plugin's
 * payment-plugin.xml/*from www.  j av a  2  s . c  om*/
 * 
 * @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//w ww . j  a v  a2  s  . c o m
 * 
 * @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);
    }
}