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

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

Introduction

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

Prototype

public String getServletContextName() 

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();
    }/*from www .  ja  v a2  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   w w  w.  j  ava  2s  . com*/
        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;
}