Search in sources :

Example 6 with DashboardsConfigElement

use of org.alfresco.web.config.DashboardsConfigElement in project acs-community-packaging by Alfresco.

the class Column method fromXML.

/**
 * Deserialise this PageConfig instance from the specified XML stream.
 *
 * @param xml
 */
public void fromXML(DashboardsConfigElement config, String xml) {
    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(new StringReader(xml));
        Element rootElement = document.getRootElement();
        // walk the pages found in xml
        Iterator itrPages = rootElement.elementIterator(ELEMENT_PAGE);
        while (itrPages.hasNext()) {
            Element pageElement = (Element) itrPages.next();
            String layoutId = pageElement.attributeValue(ATTR_LAYOUTID);
            LayoutDefinition layoutDef = config.getLayoutDefinition(layoutId);
            if (layoutDef != null) {
                // found the layout now build the page and read the columns
                Page page = new Page(pageElement.attributeValue(ATTR_ID), layoutDef);
                Iterator itrColumns = pageElement.elementIterator(ELEMENT_COLUMN);
                while (itrColumns.hasNext()) {
                    Column column = new Column();
                    // read and resolve the dashlet definitions for this column
                    Element columnElement = (Element) itrColumns.next();
                    Iterator itrDashlets = columnElement.elementIterator(ELEMENT_DASHLET);
                    while (itrDashlets.hasNext()) {
                        String dashletId = ((Element) itrDashlets.next()).attributeValue(ATTR_REFID);
                        DashletDefinition dashletDef = config.getDashletDefinition(dashletId);
                        if (dashletDef != null) {
                            column.addDashlet(dashletDef);
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("Failed to resolve Dashboard Dashlet Definition ID: " + dashletId);
                        }
                    }
                    // add the column of dashlets to the page
                    page.addColumn(column);
                }
                // add the page to this config instance
                this.addPage(page);
            } else if (logger.isWarnEnabled()) {
                logger.warn("Failed to resolve Dashboard Layout Definition ID: " + layoutId);
            }
        }
    } catch (DocumentException docErr) {
    // if we cannot parse, then we simply revert to default
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader) Iterator(java.util.Iterator) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) Document(org.dom4j.Document) LayoutDefinition(org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)

Aggregations

DashboardsConfigElement (org.alfresco.web.config.DashboardsConfigElement)6 LayoutDefinition (org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)4 DashletDefinition (org.alfresco.web.config.DashboardsConfigElement.DashletDefinition)3 ArrayList (java.util.ArrayList)2 FacesContext (javax.faces.context.FacesContext)2 StringReader (java.io.StringReader)1 Iterator (java.util.Iterator)1 UISelectMany (javax.faces.component.UISelectMany)1 UISelectOne (javax.faces.component.UISelectOne)1 SelectItem (javax.faces.model.SelectItem)1 UIListItem (org.alfresco.web.ui.common.component.UIListItem)1 UIDescription (org.alfresco.web.ui.common.component.description.UIDescription)1 Document (org.dom4j.Document)1 DocumentException (org.dom4j.DocumentException)1 Element (org.dom4j.Element)1 SAXReader (org.dom4j.io.SAXReader)1 ConfigService (org.springframework.extensions.config.ConfigService)1