Example usage for com.liferay.portal.kernel.xml SAXReaderUtil read

List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil read

Introduction

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

Prototype

public static Document read(URL url) throws DocumentException 

Source Link

Usage

From source file:com.acs.DDMXSD.java

License:Open Source License

public String getHTML(PageContext pageContext, String xml, Fields fields, String namespace, String mode,
        boolean readOnly, Locale locale) throws Exception {

    Document document = SAXReaderUtil.read(xml);

    return getHTML(pageContext, document.getRootElement(), fields, namespace, mode, readOnly, locale);
}

From source file:com.acs.DDMXSD.java

License:Open Source License

public JSONArray getJSONArray(String xml) throws DocumentException, JSONException {

    return getJSONArray(SAXReaderUtil.read(xml));
}

From source file:com.beorn.onlinepayment.messaging.messageprocessor.RegisterMessageProcessor.java

License:Open Source License

public void processMessage(Message message, MessageContext messageContext) throws Exception {
    String applicationId = message.getStringProperty("applicationId");
    String data = message.getStringProperty("data");

    Document document = SAXReaderUtil.read(data);
    ServletContext servletContext = messageContext.getServletContext();
    ServiceContext serviceContext = ServiceContextUtil.getDefaultServiceContext();

    PaymentPlugin paymentPlugin = registerPaymentPlugin(document, applicationId, servletContext,
            serviceContext);/*from w  w  w  .j  a va 2 s .  co m*/
    registerPaymentMethods(document, paymentPlugin, serviceContext);
}

From source file:com.beorn.paymentapi.messaging.PaymentPluginSenderTest.java

License:Open Source License

/**
 * Verifies that the PaymentPluginSender uses correct keys to send a
 * register message/*  w  w w .  j a v a 2s.c  o m*/
 * 
 * @throws Exception
 */
@Test
public void testRegister() throws Exception {
    // Data

    String servletContextName = "servletContextName";
    String compactedDocumentString = "compactedDocumentString";

    // Mocks

    mockStatic(PaymentPluginUtil.class);
    mockStatic(SAXReaderUtil.class);

    ServletContext servletContext = mock(ServletContext.class);
    InputStream is = mock(InputStream.class);
    Document document = mock(Document.class);
    Message message = mock(Message.class);
    AsynchronousMessenger asynchronousMessenger = mock(AsynchronousMessenger.class);

    when(servletContext.getServletContextName()).thenReturn(servletContextName);
    when(PaymentPluginUtil.getPluginDescriptionStream(Mockito.eq(servletContext))).thenReturn(is);
    when(SAXReaderUtil.read(Mockito.eq(is))).thenReturn(document);
    when(document.compactString()).thenReturn(compactedDocumentString);

    when(_session.createMessage()).thenReturn(message);

    // Test

    PaymentPluginSender messageSender = spy(new PaymentPluginSender(servletContext));

    // when(messageSender.getSynchronousMessenger()) doesn't work here
    doReturn(asynchronousMessenger).when(messageSender).getAsynchronousMessenger();

    messageSender.start();

    messageSender.register();

    Mockito.verify(message).setStringProperty(Mockito.eq("method"), Mockito.eq("register"));
    Mockito.verify(message).setStringProperty(Mockito.eq("data"), Mockito.eq(compactedDocumentString));
    Mockito.verify(asynchronousMessenger).send(Mockito.eq(message));
}

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 ww w .j  a  v a  2  s.com*/
 * 
 * @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

public static ConfigDescription parseConfigDescription(String config)
        throws SystemException, InvalidConfigDescriptionException {

    if (Validator.isNull(config))
        return new ConfigDescription(new ArrayList<ConfigGroup>(0));

    try {//  www .  java  2s . c  o m
        Document document = SAXReaderUtil.read(config);
        return parseConfigDescription(document.selectSingleNode("/*"));

    } catch (DocumentException e) {
        throw new SystemException(e);
    }
}

From source file:com.beorn.paymentpluginapi.messaging.PaymentPluginSender.java

License:Open Source License

/**
 * Register the payment plugin into the payment system
 * /*from   ww w  .  j  av a 2  s .  co m*/
 * @throws PortalException
 * @throws SystemException
 */
public void register() throws PortalException, SystemException {
    ServletContext servletContext = getServletContext();

    try {
        Document pluginDescriptionDocument = SAXReaderUtil
                .read(PaymentPluginUtil.getPluginDescriptionStream(servletContext));

        Message message = createMessage();
        message.setStringProperty("method", "register");
        message.setStringProperty("applicationId", servletContext.getServletContextName());
        message.setStringProperty("data", pluginDescriptionDocument.compactString());

        getAsynchronousMessenger().send(message);

    } catch (DocumentException e) {
        throw new SystemException(e);

    } catch (JMSException e) {
        throw new SystemException(e);

    } catch (IOException e) {
        throw new PortalException(e);
    }
}

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
 * /*from w w  w . j  a va  2 s.  com*/
 * @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//w w  w.  ja v  a  2 s.  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//w w w .  j  ava  2s .co  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);
    }
}