Example usage for com.liferay.portal.kernel.deploy.hot HotDeployEvent getServletContext

List of usage examples for com.liferay.portal.kernel.deploy.hot HotDeployEvent getServletContext

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.deploy.hot HotDeployEvent getServletContext.

Prototype

public ServletContext getServletContext() 

Source Link

Usage

From source file:com.liferay.application.list.deploy.hot.LegacyPortletPanelAppHotDeployListener.java

License:Open Source License

protected List<Dictionary<String, Object>> getPropertiesList(HotDeployEvent hotDeployEvent)
        throws DocumentException, IOException {

    ServletContext servletContext = hotDeployEvent.getServletContext();

    String xml = _http.URLtoString(servletContext.getResource("/WEB-INF/liferay-portlet.xml"));

    if (xml == null) {
        return Collections.emptyList();
    }/*w  ww  .j  a v  a 2 s.c o m*/

    List<Dictionary<String, Object>> propertiesList = new ArrayList<>();

    Document document = UnsecureSAXReaderUtil.read(xml, true);

    Element rootElement = document.getRootElement();

    Iterator<Element> iterator = rootElement.elementIterator("portlet");

    while (iterator.hasNext()) {
        Element portletElement = iterator.next();

        String controlPanelEntryCategory = portletElement.elementText("control-panel-entry-category");

        if (Validator.isNull(controlPanelEntryCategory)) {
            continue;
        }

        controlPanelEntryCategory = PortletCategoryUtil.getPortletCategoryKey(controlPanelEntryCategory);

        Dictionary<String, Object> properties = new HashMapDictionary<>();

        String portletName = portletElement.elementText("portlet-name");

        String portletId = getPortletId(hotDeployEvent.getServletContextName(), portletName);

        properties.put("panel.app.portlet.id", portletId);

        properties.put("panel.category.key", controlPanelEntryCategory);

        String controlPanelEntryWeight = portletElement.elementText("control-panel-entry-weight");

        if (Validator.isNotNull(controlPanelEntryWeight)) {
            int panelAppOrder = (int) Math.ceil(GetterUtil.getDouble(controlPanelEntryWeight) * 100);

            properties.put("panel.app.order", panelAppOrder);
        }

        propertiesList.add(properties);
    }

    return propertiesList;
}

From source file:eu.ibacz.extlet.deploy.hot.ExtletPropsUtils.java

License:Open Source License

protected static Properties getExtletProperties(HotDeployEvent event) throws HotDeployException {
    for (String propertiesLocation : EXTLET_PROPERTIES) {
        if (_log.isDebugEnabled()) {
            _log.debug("Loading extlet properties: " + propertiesLocation);
        }/*from   ww  w.  j  a va  2 s.  c  o m*/
        URL properties;
        try {
            properties = event.getServletContext().getResource(propertiesLocation);
        } catch (MalformedURLException e) {
            throw new HotDeployException("Cannot open property file", e);
        }

        if (_log.isDebugEnabled()) {
            _log.debug("Loading extlet properties from " + properties);
        }
        InputStream is = null;

        try {
            if (properties != null) {
                is = properties.openStream();
            }

            if (is != null) {
                String propertiesString = StringUtil.read(is);

                if (_log.isDebugEnabled()) {
                    _log.debug("Extlet properties loaded from " + properties);
                }
                return PropertiesUtil.load(propertiesString);
            }

        } catch (Exception e) {
            _log.error(event.getServletContextName() + ": " + e.toString(), e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ioe) {
                    if (_log.isDebugEnabled()) {
                        _log.debug(ioe);
                    }
                }
            }
        }
    }

    if (_log.isDebugEnabled()) {
        _log.debug(event.getServletContextName() + " does not have any of these: "
                + Arrays.asList(EXTLET_PROPERTIES));
    }

    return null;
}

From source file:info.bonjean.jrebel.liferay.postcmd.ResourceReloader.java

License:Open Source License

public void register(HotDeployEvent hotDeployEvent) {
    ServletContext servletContext = hotDeployEvent.getServletContext();
    String servletContextPath = servletContext.getContextPath();

    // store a list of servlet registered contexts
    log.infoEcho("register context " + servletContextPath);
    registeredContexts.add(servletContextPath);

    // monitor portlet resources
    ServletIntegration servletIntegration = ServletIntegrationFactory.getInstance();
    RebelSource[] rebelSources = servletIntegration.getRebelSources((RebelServletContext) servletContext);
    for (RebelSource rebelSource : rebelSources)
        ResourceIntegrationFactory.getInstance().addFileListener(rebelSource.getFile(), this);
}