|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.core.util;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import java.util.Date;  | 
  |  20 |     | 
     | 
  |  21 |     | 
   import org.jdom.CDATA;  | 
  |  22 |     | 
   import org.jdom.Element;  | 
  |  23 |     | 
   import org.jdom.Namespace;  | 
  |  24 |     | 
     | 
  |  25 |     | 
     | 
  |  26 |     | 
     | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  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 |     | 
   }  |