001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.sys.spring.datadictionary;
017    
018    import java.util.ArrayList;
019    
020    import org.kuali.rice.kns.datadictionary.WorkflowProperty;
021    import org.kuali.rice.kns.datadictionary.WorkflowPropertyGroup;
022    import org.springframework.beans.factory.support.BeanDefinitionBuilder;
023    import org.springframework.beans.factory.xml.ParserContext;
024    import org.springframework.util.StringUtils;
025    import org.w3c.dom.Element;
026    import org.w3c.dom.Node;
027    import org.w3c.dom.NodeList;
028    
029    public class WorkflowPropertiesBeanDefinitionParser extends KualiBeanDefinitionParserBase {
030    
031        @Override
032        protected String getBaseBeanTypeParent(Element element) {
033            return "WorkflowProperties";
034        }
035        
036        @Override
037        protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder bean) {
038            // get all attributes
039            handleAbstractAttribute(element, bean);
040            
041            // parse groups
042            NodeList children = element.getChildNodes();
043            ArrayList<WorkflowPropertyGroup> groups = new ArrayList<WorkflowPropertyGroup>();
044            for ( int i = 0; i < children.getLength(); i++ ) {
045                Node child = children.item(i);
046                if ( child.getLocalName() != null && child.getLocalName().equals("group") ) {
047                    WorkflowPropertyGroup group = new WorkflowPropertyGroup();
048                    Element groupElement = (Element)child;                
049                    String basePath = groupElement.getAttribute("basePath");
050                    if ( StringUtils.hasText(basePath) ) {
051                        group.setBasePath(basePath);
052                    }
053                    groups.add( group );
054                    // parse group paths
055                    NodeList groupChildren = groupElement.getChildNodes();
056                    for ( int j = 0 ; j < groupChildren.getLength(); j++ ) {
057                        Node groupChild = groupChildren.item(j);
058                        if ( groupChild.getLocalName() != null && groupChild.getLocalName().equals("path") ) {
059                            Element pathElement = (Element)groupChild;                
060                            String path = pathElement.getAttribute("path");
061                            if ( StringUtils.hasText( path ) ) {
062                                WorkflowProperty prop = new WorkflowProperty();
063                                prop.setPath(path);
064                                group.getWorkflowProperties().add( prop );
065                            }
066                        }
067                        
068                    }
069                }
070            }        
071            bean.addPropertyValue("workflowPropertyGroups", groups);
072        }
073    
074        
075    }