Coverage Report - org.kuali.rice.kew.xml.GroupNamespaceURITransformationFilterPOC
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupNamespaceURITransformationFilterPOC
0%
0/25
N/A
1
 
 1  
 /*
 2  
  * Copyright 2007-2010 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.xml;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.rice.core.util.KeyValue;
 24  
 import org.xml.sax.SAXException;
 25  
 
 26  
 /**
 27  
  * This XML Filter is used to rename elements of concern in a pre-1.0.3 Group XML document
 28  
  * to their 1.0.3-compliant names. As an example:
 29  
  *
 30  
  *   -- Example from GroupXmlImportTest.xml as filtered by GroupNamespaceURIEliminationFilterPOC -- 
 31  
  *   <members>
 32  
  *       <principalName>ewestfal</principalName>
 33  
  *       <principalName>rkirkend</principalName>
 34  
  *       <principalId>2015</principalId>
 35  
  *   </members>
 36  
  *   
 37  
  *   -- Resulting transformation --
 38  
  *   <members>
 39  
  *       <memberId>ewestfal</memberId>
 40  
  *       <memberId>rkirkend</memberId>
 41  
  *       <memberId>2015</memberId>
 42  
  *   </members>
 43  
  *   
 44  
  * Note: This filter has methods for transforming the attributes of elements, but all they
 45  
  *       do is return "new AttributesImpl()". If it is necessary to transform attributes of
 46  
  *       pre-1.0.3 elements, we can build those methods out.
 47  
  * 
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  *
 50  
  */
 51  
 public class GroupNamespaceURITransformationFilterPOC extends AbstractTransformationFilter {
 52  
 
 53  
         // The URI of a Group 1.0.0 schema 
 54  
     public static final String GROUP_URI="ns:workflow/Group";    
 55  
     
 56  
         // The Map containing element transformation values
 57  
         private Map<String,String> elementTransformationMap;
 58  
     
 59  
         public GroupNamespaceURITransformationFilterPOC(){
 60  0
                 super();
 61  
                 
 62  
                 // Initialize the element transformation map
 63  0
                 setElementTransformationMap();                
 64  0
         }
 65  
 
 66  
         /*
 67  
          * Build a Map that maps elements we intend to transform to their corresponding transformed value.
 68  
          * The keys in this Map are "hierarchically-qualified" representations of the elements of concern.
 69  
          * 
 70  
          * For example, if "group" is a child of "groups", which is in turn a child of the root
 71  
          * element "data", then it is represented as "data.groups.group" in the Map.
 72  
          */
 73  
         private void setElementTransformationMap(){
 74  0
                 Map<String,String> elementTransformationMap = new HashMap<String,String>();
 75  0
                 elementTransformationMap.put("group.name", "groupName");
 76  0
                 elementTransformationMap.put("group.namespace", "namespaceCode");
 77  0
                 elementTransformationMap.put("group.description", "groupDescription");
 78  0
                 elementTransformationMap.put("group.members.principalName", "memberId");
 79  0
                 elementTransformationMap.put("group.members.principalId", "memberId");
 80  0
                 this.elementTransformationMap = elementTransformationMap;
 81  0
         }
 82  
 
 83  
 
 84  
         /**
 85  
          * This overridden method ...
 86  
          * 
 87  
          * @see org.kuali.rice.kew.xml.AbstractTransformationFilter#getElementTransformationList()
 88  
          */        
 89  
         public List<KeyValue> getElementTransformationList() {
 90  0
                 List<KeyValue> rList = new ArrayList<KeyValue>();
 91  
 
 92  0
                 rList.add(new KeyValue("group.name", GROUP_URI));
 93  0
                 rList.add(new KeyValue("group.namespace", GROUP_URI));
 94  0
                 rList.add(new KeyValue("group.description", GROUP_URI));
 95  0
                 rList.add(new KeyValue("group.members.principalName", GROUP_URI));
 96  0
                 rList.add(new KeyValue("group.members.principalId", GROUP_URI));                
 97  
 
 98  0
                 return rList;
 99  
         }
 100  
 
 101  
 
 102  
         /**
 103  
          * This overridden method ...
 104  
          * 
 105  
          * @see org.kuali.rice.kew.xml.AbstractTransformationFilter#getStartingElementPath()
 106  
          */        
 107  
         public String getStartingElementPath() {
 108  
                 
 109  0
                 return "data.groups";
 110  
         }
 111  
 
 112  
         
 113  
         /**
 114  
          * This overridden method ...
 115  
          * 
 116  
          * @see org.kuali.rice.kew.xml.AbstractTransformationFilter#transformStartElement(org.kuali.rice.kew.xml.AbstractTransformationFilter.CurrentElement)
 117  
          */
 118  
         public CurrentElement transformStartElement(CurrentElement currentElement) throws SAXException{
 119  0
                 String transformedLocalName = elementTransformationMap.get(this.getTrimmedCurrentElementKey(currentElement.getNameKey()));
 120  0
                 String transformedQualifiedName = transformedLocalName;
 121  
                 
 122  0
                 return new CurrentElement(currentElement.getNameKey(),currentElement.getUri(), transformedLocalName, transformedQualifiedName, currentElement.getAttributes());
 123  
         }
 124  
         
 125  
         
 126  
         /**
 127  
          * This overridden method ...
 128  
          * 
 129  
          * @see org.kuali.rice.kew.xml.AbstractTransformationFilter#transformEndElement(org.kuali.rice.kew.xml.AbstractTransformationFilter.CurrentElement)
 130  
          */
 131  
         public CurrentElement transformEndElement(CurrentElement currentElement) throws SAXException {
 132  0
                 String transformedLocalName = elementTransformationMap.get(this.getTrimmedCurrentElementKey(currentElement.getNameKey()));
 133  0
                 String transformedQualifiedName = transformedLocalName;
 134  
                                                                 
 135  0
                 return new CurrentElement(currentElement.getNameKey(),currentElement.getUri(), transformedLocalName, transformedQualifiedName);
 136  
         }
 137  
         
 138  
 
 139  
         
 140  
 
 141  
 }