Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Outputter.java

00001 package edu.virtualschool.jwaa.xml;
00002 
00003 import java.io.IOException;
00004 import java.io.StringWriter;
00005 import java.util.List;
00006 
00007 import org.jdom.Element;
00008 import org.jdom.output.Format;
00009 import org.jdom.output.XMLOutputter;
00010 
00011 public class Outputter 
00012 {
00013   final XMLOutputter outputter;
00014   final StringWriter writer = new StringWriter();
00015   
00016   public Outputter(boolean enableTrim) 
00017   {
00018     Format f = enableTrim ? Format.getPrettyFormat() : Format.getRawFormat();
00019     this.outputter = new XMLOutputter(f);
00020 //    outputter.setTextNormalize(f);
00021 //    outputter.setTextTrim(enableTrim);
00022 //    outputter.setTrimAllWhite(enableTrim);
00023 //    outputter.setIndent(" ");
00024   }
00025   public String output(Element element)
00026     throws ValidationFault
00027   {
00028     try
00029     {
00030       outputter.output(element, writer);
00031       String string = writer.toString();
00032       writer.getBuffer().setLength(0);
00033       return string;
00034     }
00035     catch (IOException e)
00036     {
00037       throw new ValidationFault("IOFault in "+element);
00038     }
00039   }
00040   public String output(List list)
00041     throws ValidationFault
00042   {
00043     try
00044     {
00045       outputter.output(list, writer);
00046       String string = writer.toString();
00047       writer.getBuffer().setLength(0);
00048       return string;
00049     }
00050     catch (IOException e)
00051     {
00052       throw new ValidationFault("IOFault in "+list);
00053     }
00054   }
00055 
00056 }