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-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.core.api.util.xml;
 18  
 
 19  
 import org.jdom.CDATA;
 20  
 import org.jdom.Element;
 21  
 import org.jdom.Namespace;
 22  
 import org.kuali.rice.core.api.util.RiceConstants;
 23  
 
 24  
 import java.util.Date;
 25  
 
 26  
 /**
 27  
  * A helper class which helps with building the XML for objects.
 28  
  *
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  
 public class XmlRenderer {
 32  
 
 33  
     private Namespace namespace;
 34  
     
 35  0
     public XmlRenderer() {}
 36  
     
 37  0
     public XmlRenderer(Namespace namespace) {
 38  0
         this.namespace = namespace;
 39  0
     }
 40  
     
 41  
     public Element renderElement(Element parent, String elementName) {
 42  0
         Element element = new Element(elementName, namespace);
 43  0
         if (parent != null) {
 44  0
             parent.addContent(element);
 45  
         }
 46  0
         return element;
 47  
     }
 48  
     
 49  
     public Element renderTextElement(Element parent, String elementName, String text) {
 50  0
         Element element = null;
 51  0
         if (text != null) {
 52  0
             element = renderElement(parent, elementName);
 53  0
             element.setText(text);
 54  
         }
 55  0
         return element;
 56  
     }
 57  
     
 58  
     public Element renderBooleanElement(Element parent, String elementName, Boolean bool, boolean defaultValue) {
 59  0
         if (bool == null) {
 60  0
             bool = new Boolean(defaultValue);
 61  
         }
 62  0
         return renderTextElement(parent, elementName, (bool.booleanValue() ? "true" : "false"));   
 63  
     }
 64  
     
 65  
     public Element renderDateElement(Element parent, String elementName, Date date) {
 66  0
         Element element = null;
 67  0
         if (date != null) {
 68  0
             element = renderTextElement(parent, elementName, RiceConstants.getDefaultDateFormat().format(date));
 69  
         }
 70  0
         return element;
 71  
     }
 72  
     
 73  
     public void renderAttribute(Element element, String attributeName, String attributeValue) {
 74  0
         element.setAttribute(attributeName, attributeValue);
 75  0
     }
 76  
     
 77  
     public Element renderCDATAElement(Element parent, String elementName, String data) {
 78  0
             Element element = null;
 79  0
         if (data != null) {
 80  0
             element = renderElement(parent, elementName);
 81  0
             element.addContent(new CDATA(data));
 82  
         }
 83  0
         return element;
 84  
     }
 85  
 
 86  
 }