Coverage Report - org.kuali.rice.core.api.util.xml.XmlRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlRenderer
0%
0/27
0%
0/12
1.75
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.core.api.util.xml;
 17  
 
 18  
 import org.jdom.CDATA;
 19  
 import org.jdom.Element;
 20  
 import org.jdom.Namespace;
 21  
 import org.kuali.rice.core.api.util.RiceConstants;
 22  
 
 23  
 import java.util.Date;
 24  
 
 25  
 /**
 26  
  * A helper class which helps with building the XML for objects.
 27  
  *
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  
 public class XmlRenderer {
 31  
 
 32  
     private Namespace namespace;
 33  
     
 34  0
     public XmlRenderer() {}
 35  
     
 36  0
     public XmlRenderer(Namespace namespace) {
 37  0
         this.namespace = namespace;
 38  0
     }
 39  
     
 40  
     public Element renderElement(Element parent, String elementName) {
 41  0
         Element element = new Element(elementName, namespace);
 42  0
         if (parent != null) {
 43  0
             parent.addContent(element);
 44  
         }
 45  0
         return element;
 46  
     }
 47  
     
 48  
     public Element renderTextElement(Element parent, String elementName, String text) {
 49  0
         Element element = null;
 50  0
         if (text != null) {
 51  0
             element = renderElement(parent, elementName);
 52  0
             element.setText(text);
 53  
         }
 54  0
         return element;
 55  
     }
 56  
     
 57  
     public Element renderBooleanElement(Element parent, String elementName, Boolean bool, boolean defaultValue) {
 58  0
         if (bool == null) {
 59  0
             bool = new Boolean(defaultValue);
 60  
         }
 61  0
         return renderTextElement(parent, elementName, (bool.booleanValue() ? "true" : "false"));   
 62  
     }
 63  
     
 64  
     public Element renderDateElement(Element parent, String elementName, Date date) {
 65  0
         Element element = null;
 66  0
         if (date != null) {
 67  0
             element = renderTextElement(parent, elementName, RiceConstants.getDefaultDateFormat().format(date));
 68  
         }
 69  0
         return element;
 70  
     }
 71  
     
 72  
     public void renderAttribute(Element element, String attributeName, String attributeValue) {
 73  0
         element.setAttribute(attributeName, attributeValue);
 74  0
     }
 75  
     
 76  
     public Element renderCDATAElement(Element parent, String elementName, String data) {
 77  0
             Element element = null;
 78  0
         if (data != null) {
 79  0
             element = renderElement(parent, elementName);
 80  0
             element.addContent(new CDATA(data));
 81  
         }
 82  0
         return element;
 83  
     }
 84  
 
 85  
 }