| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GroupNamespaceURIMemberTransformationFilterPOC |
|
| 2.3333333333333335;2.333 |
| 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 org.kuali.rice.kim.xml.KimNamespaceConstants; | |
| 19 | import org.xml.sax.Attributes; | |
| 20 | import org.xml.sax.SAXException; | |
| 21 | import org.xml.sax.helpers.AttributesImpl; | |
| 22 | import org.xml.sax.helpers.XMLFilterImpl; | |
| 23 | ||
| 24 | /** | |
| 25 | * This XML Filter is used to transform the <member> section generated in GroupNamespaceURIMemberTransformationFilterPOC. | |
| 26 | * such that the transformation from the pre-filtered pre-1.0.3 XML document looks like this: | |
| 27 | * | |
| 28 | * -- Example from GroupXmlImportTest.xml as filtered by GroupNamespaceURIMemberTransformationFilterPOC -- | |
| 29 | * <members> | |
| 30 | * <memberId>ewestfal</memberId> | |
| 31 | * <memberId>rkirkend</memberId> | |
| 32 | * <memberId>2015</memberId> | |
| 33 | * </members> | |
| 34 | * | |
| 35 | * -- Resulting transformation -- | |
| 36 | * <members> | |
| 37 | * <member> | |
| 38 | * <memberId>ewestfal</memberId> | |
| 39 | * <memberTypeCode>P</memberTypeCode> | |
| 40 | * </member> | |
| 41 | * <member> | |
| 42 | * <memberId>rkirkend</memberId> | |
| 43 | * <memberTypeCode>P</memberTypeCode> | |
| 44 | * </member> | |
| 45 | * <member> | |
| 46 | * <memberId>2015</memberId> | |
| 47 | * <memberTypeCode>P</memberTypeCode> | |
| 48 | * </member> | |
| 49 | * </members> | |
| 50 | * | |
| 51 | * Note 1: This filter assumes that <memberTypeCode> should be defaulted to "P" for all members. | |
| 52 | * | |
| 53 | * Note 2: As is the case with GroupNamespaceURIMemberTransformationFilterPOC, this filter has methods for transforming | |
| 54 | * the attributes of elements, but all they do is return "new AttributesImpl()". If it is necessary to transform | |
| 55 | * attributes of pre-1.0.3 elements, we can build those methods out. | |
| 56 | * | |
| 57 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 58 | * | |
| 59 | */ | |
| 60 | public class GroupNamespaceURIMemberTransformationFilterPOC extends XMLFilterImpl { | |
| 61 | ||
| 62 | // The URI of a Group 1.0.3 schema | |
| 63 | public static final String GROUP_URI_OLD = "ns:workflow/Group"; | |
| 64 | public static final String GROUP_URI_NEW = KimNamespaceConstants.GROUP; | |
| 65 | ||
| 66 | public GroupNamespaceURIMemberTransformationFilterPOC(){ | |
| 67 | 0 | super(); |
| 68 | 0 | } |
| 69 | ||
| 70 | public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { | |
| 71 | 0 | if (localName.equals("memberId") && GROUP_URI_OLD.equals(uri)){ |
| 72 | 0 | super.startElement(GROUP_URI_NEW, "member", "member", new AttributesImpl()); |
| 73 | 0 | super.startElement(GROUP_URI_NEW, localName, qName, atts); |
| 74 | } | |
| 75 | else { | |
| 76 | // Pass all elements through as they are | |
| 77 | 0 | super.startElement(uri, localName, qName, atts); |
| 78 | } | |
| 79 | 0 | } |
| 80 | ||
| 81 | public void endElement(String uri, String localName, String qName) throws SAXException { | |
| 82 | // Append a <memberTypeCode> element to each <memberId> element | |
| 83 | 0 | if (localName.equals("memberId") && GROUP_URI_OLD.equals(uri)){ |
| 84 | 0 | super.endElement(GROUP_URI_NEW, "memberId", "memberId"); |
| 85 | 0 | super.startElement(GROUP_URI_NEW, "memberTypeCode", "memberTypeCode", new AttributesImpl()); |
| 86 | 0 | String memberTypeCode = "P"; |
| 87 | 0 | characters(memberTypeCode.toCharArray(), 0, 1); |
| 88 | 0 | super.endElement(GROUP_URI_NEW, "memberTypeCode", "memberTypeCode"); |
| 89 | 0 | super.endElement(GROUP_URI_NEW, "member", "member"); |
| 90 | 0 | } |
| 91 | else { | |
| 92 | // Pass other elements through as they are | |
| 93 | 0 | super.endElement(uri, localName, qName); |
| 94 | } | |
| 95 | 0 | } |
| 96 | } |