Class DefaultFormatter

java.lang.Object
com.nomagic.magicreport.format.DefaultFormatter
All Implemented Interfaces:
IFormatter
Direct Known Subclasses:
DocBookFormatter, DOCXFormatter, HTMLFormatter, LaTeXFormatter, PPTXFormatter, RTFFormatter, TextFormatter, XLSXFormatter, XMLFormatter

@OpenApiAll public class DefaultFormatter extends Object implements IFormatter
This class provides default implementation for any output format.
Since:
Jun 11, 2007 10:49:57 PM
Version:
1.0 Jun 11, 2007
  • Field Details

    • properties

      protected Properties properties
      Engine properties.
    • styledDocument

      protected StyledDocument styledDocument
      Styled document.
  • Constructor Details

    • DefaultFormatter

      public DefaultFormatter()
      Create a default formatter without properties.
    • DefaultFormatter

      public DefaultFormatter(Properties properties)
      Create a default formatter with specific properties.
      Parameters:
      properties - a template properties
  • Method Details

    • registerObjectFormatter

      public void registerObjectFormatter(Class<?> targetType, IFormatter formatter)
      Register an object formatter to be used to format values of a given target class.
      Specified by:
      registerObjectFormatter in interface IFormatter
      Parameters:
      targetType - the Class object of the type to be formatted
      formatter - the instance of object of the IFormatter class. If this is null, then any existing definition will be removed.
    • getObjectFormater

      public IFormatter getObjectFormater(Class<?> targetType)
      Returns the formatter for the target type class or current formatter if target type class is not registered.
      Specified by:
      getObjectFormater in interface IFormatter
      Parameters:
      targetType - the Class object of the type to be formatted
      Returns:
      the instance of object of the IFormatter class.
    • setProperties

      public void setProperties(Properties properties)
      Passes along the properties from the template engine indicating the properties to be used in formatter.
      Parameters:
      properties - Properties
    • getProperties

      public Properties getProperties()
      Return a properties.
      Returns:
      the properties
    • setStyledDocument

      public void setStyledDocument(StyledDocument styledDocument)
      Set a StyledDocument to be used with this formatter.
      Specified by:
      setStyledDocument in interface IFormatter
      Parameters:
      styledDocument - A {link StyledDocument}
    • writeImage

      protected void writeImage(Image image, String imageFormat, OutputStream outputStream, boolean forceWrite) throws IOException
      Write an image into output stream.
      Parameters:
      image - Image
      imageFormat - output image format
      outputStream - output stream
      forceWrite - force to write the image to output stream
      Throws:
      IOException - if an error occurs during writing.
    • writeImage

      protected void writeImage(Image image, String imageFormat, OutputStream outputStream, boolean forceWrite, boolean skipDPI) throws IOException
      Write an image into output stream.
      Parameters:
      image - Image
      imageFormat - output image format
      outputStream - output stream
      forceWrite - force to write the image to output stream
      skipDPI - skip change dpi metadata
      Throws:
      IOException - if an error occurs during writing.
    • writeImage

      protected void writeImage(Image image, String imageFormat, File outputFile, boolean forceWrite) throws IOException
      Write an image into output file.
      Parameters:
      image - Image
      imageFormat - output image format
      outputFile - output file
      forceWrite - force to write the image to output stream
      Throws:
      IOException - if an error occurs during writing.
    • format

      public Object format(Object value)
      Convert an Object value into default format. This method always convert all value into String.
      Specified by:
      format in interface IFormatter
      Parameters:
      value - converting value
      Returns:
      object in default format.
    • getImageFlag

      public static int getImageFlag(String autoImageOption)
      Convert auto image option from TemplateConstants.TEMPLATE_AUTO_IMAGE into transformation flag.
      Parameters:
      autoImageOption - auto image option; (value 0, 1, 2, 3)
      Returns:
      transformation flag