1 17 package org.alfresco.web.config; 18 19 import java.util.Iterator ; 20 21 import org.alfresco.config.ConfigElement; 22 import org.alfresco.config.ConfigException; 23 import org.alfresco.config.xml.elementreader.ConfigElementReader; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.dom4j.Element; 27 28 33 public class ViewsElementReader implements ConfigElementReader 34 { 35 public static final String ELEMENT_VIEW = "view"; 36 public static final String ELEMENT_VIEWIMPL = "view-impl"; 37 public static final String ELEMENT_VIEWDEFAULTS = "view-defaults"; 38 public static final String ELEMENT_PAGESIZE = "page-size"; 39 public static final String ELEMENT_SORTCOLUMN = "sort-column"; 40 public static final String ELEMENT_SORTDIRECTION = "sort-direction"; 41 42 private static Log logger = LogFactory.getLog(ViewsElementReader.class); 43 44 47 @SuppressWarnings ("unchecked") 48 public ConfigElement parse(Element element) 49 { 50 ViewsConfigElement configElement = null; 51 52 if (element != null) 53 { 54 String name = element.getName(); 55 if (name.equals(ViewsConfigElement.CONFIG_ELEMENT_ID) == false) 56 { 57 throw new ConfigException("ViewsElementReader can only parse " + 58 ViewsConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + 59 name + "'"); 60 } 61 62 configElement = new ViewsConfigElement(); 63 64 Iterator <Element> renderers = element.elementIterator(ELEMENT_VIEWIMPL); 66 while (renderers.hasNext()) 67 { 68 Element renderer = renderers.next(); 69 configElement.addView(renderer.getTextTrim()); 70 } 71 72 Element viewDefaults = element.element(ELEMENT_VIEWDEFAULTS); 74 if (viewDefaults != null) 75 { 76 Iterator <Element> pages = viewDefaults.elementIterator(); 77 while (pages.hasNext()) 78 { 79 Element page = pages.next(); 80 String pageName = page.getName(); 81 82 Element defaultView = page.element(ELEMENT_VIEW); 84 if (defaultView != null) 85 { 86 String viewName = defaultView.getTextTrim(); 87 configElement.addDefaultView(pageName, viewName); 88 } 89 90 Element sortColumn = page.element(ELEMENT_SORTCOLUMN); 92 if (sortColumn != null) 93 { 94 String column = sortColumn.getTextTrim(); 95 configElement.addDefaultSortColumn(pageName, column); 96 } 97 98 Element sortDir = page.element(ELEMENT_SORTDIRECTION); 100 if (sortDir != null) 101 { 102 configElement.addSortDirection(pageName, sortDir.getTextTrim()); 103 } 104 105 processPageSizeElement(page.element(ELEMENT_PAGESIZE), 107 pageName, configElement); 108 } 109 } 110 } 111 112 return configElement; 113 } 114 115 122 @SuppressWarnings ("unchecked") 123 private void processPageSizeElement(Element pageSizeElement, String page, 124 ViewsConfigElement configElement) 125 { 126 if (pageSizeElement != null) 127 { 128 Iterator <Element> views = pageSizeElement.elementIterator(); 129 while (views.hasNext()) 130 { 131 Element view = views.next(); 132 String viewName = view.getName(); 133 String pageSize = view.getTextTrim(); 134 try 135 { 136 configElement.addDefaultPageSize(page, viewName, Integer.parseInt(pageSize)); 137 } 138 catch (NumberFormatException nfe) 139 { 140 if (logger.isWarnEnabled()) 141 { 142 logger.warn("Failed to set page size for view '" + viewName + 143 "' in page '" + page + "' as '" + pageSize + 144 "' is an invalid number!"); 145 } 146 } 147 } 148 } 149 } 150 } 151 | Popular Tags |