com.xmlmind.fo.graphic
Class GraphicUtil

java.lang.Object
  extended by com.xmlmind.fo.graphic.GraphicUtil

public final class GraphicUtil
extends Object

A collection of functions (static methods) useful to implement GraphicFactories.


Method Summary
static String createTempFile(GraphicEnv graphicEnv, String suffix)
          Not for public use: needed to implement GraphicFactories.cs.
static String extensionToFormat(File file)
          Equivalent to extensionToFormat(file.getPath()).
static String extensionToFormat(String path)
          Returns the MIME type corresponding to the extension of the specified filename, when this extension is known.
static String formatToExtension(String format)
          Returns the filename extension corresponding to specified MIME type.
static String formatToSuffix(String format)
          Similar to formatToExtension(java.lang.String) except that it prepends "." to the filename extension and that it never returns null (the fallback suffix is ".img").
static void saveGraphic(Graphic graphic, File outFile)
          Saves specified graphic to specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extensionToFormat

public static String extensionToFormat(File file)
Equivalent to extensionToFormat(file.getPath()).


extensionToFormat

public static String extensionToFormat(String path)
Returns the MIME type corresponding to the extension of the specified filename, when this extension is known. Returns null otherwise.

For example, returns "image/jpeg" for "/tmp/foo.jpg".


formatToExtension

public static String formatToExtension(String format)
Returns the filename extension corresponding to specified MIME type. For example, returns: "jpg" for "image/jpeg" and "bar" for "application/x-bar+xml".

Parameters:
format - a MIME type
Returns:
a suitable filename extension or null if such extension cannot be determined.

formatToSuffix

public static String formatToSuffix(String format)
Similar to formatToExtension(java.lang.String) except that it prepends "." to the filename extension and that it never returns null (the fallback suffix is ".img").


saveGraphic

public static void saveGraphic(Graphic graphic,
                               File outFile)
                        throws IOException
Saves specified graphic to specified file.

This function supports graphics having a "data:" location.

Parameters:
graphic - graphic to be saved
outFile - save file
Throws:
IOException - if an I/O error occurs during the operation
See Also:
URLUtil.openStream(java.lang.String)

createTempFile

public static String createTempFile(GraphicEnv graphicEnv,
                                    String suffix)
                             throws Exception
Not for public use: needed to implement GraphicFactories.cs.

Throws:
Exception