org.ujoframework.core
Class UjoManagerCSV<UJO extends Ujo>

java.lang.Object
  extended by org.ujoframework.core.UjoService<UJO>
      extended by org.ujoframework.core.UjoManagerCSV<UJO>

public class UjoManagerCSV<UJO extends Ujo>
extends UjoService<UJO>

A Manager for CSV import / export. If you need take a control of a non UJO property object serialization then use a UjoTextable object list.

Sample of usage

  List<Person> people = new ArrayList<Person>(0);
  UjoManagerCSV<Person> manager = UjoManagerCSV.getInstance(Person.class);

  // Save CSV:
  manager.saveCSV(new File("file.csv"), people, "SaveContext");

  // Load CSV:
  people = manager.loadCSV(new File("file.csv"), "LoadContext");
 

Author:
Pavel Ponec
See Also:
UjoTextable

Field Summary
 
Fields inherited from class org.ujoframework.core.UjoService
UNDEFINED, UTF_8
 
Constructor Summary
UjoManagerCSV(java.lang.Class<UJO> ujoClass, UjoProperty... properties)
          Creates a new instance of UjoManagerCSV
 
Method Summary
protected  java.lang.String getHeaderTitle(UjoProperty p)
          Header label for a required Property.
static
<UJO extends Ujo>
UjoManagerCSV<UJO>
getInstance(java.lang.Class<UJO> ujoClass)
          Create new instance
static
<UJO extends Ujo>
UjoManagerCSV<UJO>
getInstance(java.lang.Class<UJO> ujoClass, UjoProperty... properties)
          Create new instance
 java.lang.String getNewLine()
          New Line
 char getSeparator()
           
 boolean isPrintHeader()
          Print CSV Header
 java.util.List<UJO> loadCSV(java.io.File file, java.lang.Object context)
          Load an Ujo from CSV format by UTF-8 code Page.
 java.util.List<UJO> loadCSV(java.util.Scanner inp, java.lang.Object context)
          Load an Ujo from Java resource bundle
protected  void printValue(java.io.Writer out, java.lang.String value)
          Print Text
 void saveCSV(java.io.File file, java.util.List<UJO> ujoList, java.lang.Object context)
          Save Ujo into CSV format by codepage UTF-8.
 void saveCSV(java.io.OutputStream out, java.nio.charset.Charset cs, java.util.List<UJO> ujoList, java.lang.Object context)
          Save Ujo into CSV format.
 void saveCSV(java.io.Writer out, java.util.List<UJO> ujoList, java.lang.Object context)
          Save Ujo into CSV format
 void setNewLine(java.lang.String newLine)
          New Line character sequence.
 UjoManagerCSV setPrintHeader(boolean printHeader)
          Print CSV Header
 UjoManagerCSV setSeparator(char separator)
           
protected  void writeValue(UJO ujo, java.lang.StringBuilder value, int propPointer, int lineCounter, UjoAction action)
          Write value to UJO
 
Methods inherited from class org.ujoframework.core.UjoService
getInputStream, getOutputStream, getProperties, getText, getUjoClass, getUjoManager, isTextable, setText, setUjoManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UjoManagerCSV

public UjoManagerCSV(java.lang.Class<UJO> ujoClass,
                     UjoProperty... properties)
Creates a new instance of UjoManagerCSV

Parameters:
ujoClass - Exported Ujo Class
properties - Exported properties of class, if value is null than all properties are used.
Method Detail

saveCSV

public void saveCSV(java.io.File file,
                    java.util.List<UJO> ujoList,
                    java.lang.Object context)
             throws java.io.IOException,
                    java.lang.InstantiationException,
                    java.lang.IllegalAccessException
Save Ujo into CSV format by codepage UTF-8.

Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException

saveCSV

public void saveCSV(java.io.OutputStream out,
                    java.nio.charset.Charset cs,
                    java.util.List<UJO> ujoList,
                    java.lang.Object context)
             throws java.io.IOException,
                    java.lang.InstantiationException,
                    java.lang.IllegalAccessException
Save Ujo into CSV format.

Parameters:
out - Output Stream.
cs - Character set
ujoList - List of UJO objects
context -
Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException

saveCSV

public void saveCSV(java.io.Writer out,
                    java.util.List<UJO> ujoList,
                    java.lang.Object context)
             throws java.io.IOException,
                    java.lang.InstantiationException,
                    java.lang.IllegalAccessException
Save Ujo into CSV format

Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException

getHeaderTitle

protected java.lang.String getHeaderTitle(UjoProperty p)
Header label for a required Property. You can overwrite the method in case you want to localize header titles.

Parameters:
p - Property
Returns:
Default implementation returns UjoProperty.getName() .

loadCSV

public java.util.List<UJO> loadCSV(java.io.File file,
                                   java.lang.Object context)
                                        throws java.io.IOException,
                                               java.lang.InstantiationException,
                                               java.lang.IllegalAccessException
Load an Ujo from CSV format by UTF-8 code Page.

Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException

loadCSV

public java.util.List<UJO> loadCSV(java.util.Scanner inp,
                                   java.lang.Object context)
                                        throws java.lang.InstantiationException,
                                               java.lang.IllegalAccessException
Load an Ujo from Java resource bundle

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

writeValue

protected void writeValue(UJO ujo,
                          java.lang.StringBuilder value,
                          int propPointer,
                          int lineCounter,
                          UjoAction action)
                   throws java.lang.IllegalArgumentException
Write value to UJO

Throws:
java.lang.IllegalArgumentException

printValue

protected void printValue(java.io.Writer out,
                          java.lang.String value)
                   throws java.io.IOException
Print Text

Throws:
java.io.IOException

getSeparator

public char getSeparator()

setSeparator

public UjoManagerCSV setSeparator(char separator)

getNewLine

public java.lang.String getNewLine()
New Line


setNewLine

public void setNewLine(java.lang.String newLine)
New Line character sequence. It is allowed a combination of characters (\\r or \\n).


isPrintHeader

public boolean isPrintHeader()
Print CSV Header


setPrintHeader

public UjoManagerCSV setPrintHeader(boolean printHeader)
Print CSV Header


getInstance

public static <UJO extends Ujo> UjoManagerCSV<UJO> getInstance(java.lang.Class<UJO> ujoClass)
Create new instance


getInstance

public static <UJO extends Ujo> UjoManagerCSV<UJO> getInstance(java.lang.Class<UJO> ujoClass,
                                                               UjoProperty... properties)
Create new instance



Copyright © 2010. All Rights Reserved.