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

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

Introduction

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

Prototype

public static Document read(URL url, boolean validate) throws DocumentException 

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   w  w  w.  j av a  2s  .  co 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;
}