Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.jxcell.server
Class ChartServerComponent

    java.lang.Object
      com.jxcell.server.ChartServerComponent

public class ChartServerComponent
extends java.lang.Object

ChartServerComponent is a server based chart producing engine. This class handles image generation, image caching and resource management. There should be only one instance of this class per ServletContext

Constructor Summary
`ChartServerComponent()` Creates a new instance of image server component with properties initialized from the configuration file
`ChartServerComponent(JcImageServer icimageserver)` Internal constructor

Method Summary
`void` | `destroy()` Destroys the server component and all images stored in cache.
`void` | `finalize()`
`void` | `gc()` Runs the garbage collector that removes the expired images from memory or destroys the files.
`byte[]` | `getBytes(ChartDescription chartDescription)` Returns the actual bytes of the image based on its description.
`byte[]` | `getCachedBuffer(java.lang.String guid)` Returns the actual bytes of the image based on the unique image's id.
`java.lang.String` | `getCachedImageMap(java.lang.String guid)` Returns image map based on the unique image's id.
`static ChartServerComponent` | `getDefaultInstance(ServletContext servletcontext)` Returns server component instance for the servlet context.
`java.lang.String` | `getHtmlReport()` Returns a brief description of the component status in HTML format suitable for displaying in a browser
`int` | `getImageCount()` Returns the number of the currently cached images
`java.lang.String` | `getImageID(ChartDescription chartDescription)` Returns a unique image ID for the image description.
`java.lang.String` | `getImageTag(ChartDescription chartDescription, java.lang.String dsc)` Returns HTML tag with src attribute consisting of url with appended to it a unique image id.
`java.lang.String` | `getImageTag(ChartDescription chartDescription, java.lang.String hostname, java.lang.String attributes, boolean unique)` Returns HTML tag with src attribute consisting of url with appended to it a unique image id.
`java.lang.String` | `getImageTag(ChartDescription chartDescription, java.lang.String hostname, java.lang.String attributes, boolean unique, boolean https)` Returns HTML tag with src attribute consisting of url with appended to it a unique image id.
`long` | `getMemorySize()` Returns the amount of memory that cached images take
`ResourceRepository` | `getProperties()` Returns the current server settings.
`ChartDescription` | `newImageSpec()` Creates and returns a new chart specification structure
`void` | `saveBufferTo(ChartDescription chartDescription, java.lang.String path)` Produces the chart in the required format and saves it into a file.
`void` | `writeBufferTo(ChartDescription chartDescription, HttpServletResponse httpservletresponse)` This method obtains the image bytes using getBytes method, sets the content type based on the image type, writes the bytes into the response, and closes the output.
`void` | `writeCachedBufferTo(java.lang.String guid, HttpServletResponse httpservletresponse)` This method obtains the image bytes using getCachedBuffer method, sets the content type tbased on the image type, writes the bytes into the response, and closes the output.
`void` | `writeCachedBufferTo(java.lang.String guid, JspWriter jspwriter, HttpServletResponse httpservletresponse)` Used by the getImage.jsp to write cached bytes out - some servers will not allow us to getOutputStream from response and instead the writer should be used.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ChartServerComponent

    public ChartServerComponent()

  Creates a new instance of image server component with properties initialized from the configuration file

### ChartServerComponent

    public ChartServerComponent(JcImageServer icimageserver)

  Internal constructor

Parameters:
  `icimageserver` - server

Method Detail

### getDefaultInstance

    public static ChartServerComponent getDefaultInstance(ServletContext servletcontext)

  Returns server component instance for the servlet context. This function checks the context attribute "JCCHART" and if it is not defined, creates a new instance of MxServerComponent by using its default constructor. In addition this function automatically removes all unneeded images from the cache.

  Parameters:
    `servletcontext` - servlet context
  Returns:
    server component

### newImageSpec

    public ChartDescription newImageSpec()

  Creates and returns a new chart specification structure

  Returns:
    new image specification

### getImageTag

    public java.lang.String getImageTag(ChartDescription chartDescription,
                                        java.lang.String hostname,
                                        java.lang.String attributes,
                                        boolean unique,
                                        boolean https)

  Returns HTML tag with src attribute consisting of url with appended to it a unique image id. When the href field in the dsc structure is set, the HTML tag is appended to the return value. The generated image is placed in the cache and its reference count is incremented.

  Parameters:
    `chartDescription` - chart's description
    `hostname` - image retrieval url
    `attributes` - aditional HTML attributes
    `unique` - when set to true this function will produce a unique image with unique id even if the same image already exists in the cache
    `https` - use https in plugins codebases
  Returns:
    html code

### getImageTag

    public java.lang.String getImageTag(ChartDescription chartDescription,
                                        java.lang.String hostname,
                                        java.lang.String attributes,
                                        boolean unique)

  Returns HTML tag with src attribute consisting of url with appended to it a unique image id. When the href field in the dsc structure is set, the HTML tag is appended to the return value. The generated image is placed in the cache and its reference count is incremented.

  Parameters:
    `chartDescription` - chart's description
    `hostname` - image retrieval url
    `attributes` - aditional HTML attributes
    `unique` - when set to true this function will produce a unique image with unique id even if the same image already exists in the cache
  Returns:
    html code

### getImageTag

    public java.lang.String getImageTag(ChartDescription chartDescription,
                                        java.lang.String dsc)

  Returns HTML tag with src attribute consisting of url with appended to it a unique image id. When the href field in the dsc structure is set, the HTML tag is appended to the return value. The generated image is placed in the cache and its reference count is incremented.

  Parameters:
    `chartDescription` - - chart's description
    `dsc` - - chart's description
  Returns:
    html code

### getImageID

    public java.lang.String getImageID(ChartDescription chartDescription)

  Returns a unique image ID for the image description. This function generates the image if the image with such attributes does not exist in the cache. The generated image is placed in the cache and its reference count is incremented

  Parameters:
    `chartDescription` - chart's description
  Returns:
    html code

### getCachedBuffer

    public byte[] getCachedBuffer(java.lang.String guid)

  Returns the actual bytes of the image based on the unique image's id. The reference count for the image is decremented.

  Parameters:
    `guid` - unique image ID returned by getID() function or ID that was embedded into the image tag by getImageTag function
  Returns:
    image bytes

### getCachedImageMap

    public java.lang.String getCachedImageMap(java.lang.String guid)

  Returns image map based on the unique image's id.

  Parameters:
    `guid` - - unique image ID
  Returns:
    image map or null

### getBytes

    public byte[] getBytes(ChartDescription chartDescription)

  Returns the actual bytes of the image based on its description. The generated image is placed in the cache, but the reference count is not incremented

  Parameters:
    `chartDescription` - chartDescription
  Returns:
    image bytes

### saveBufferTo

    public void saveBufferTo(ChartDescription chartDescription,
                             java.lang.String path)

  Produces the chart in the required format and saves it into a file. The generated image is placed in the cache, but the reference count is not incremented.

  Parameters:
    `chartDescription` - - chart description
    `path` - - file path

### gc

    public void gc()

  Runs the garbage collector that removes the expired images from memory or destroys the files. This function will return immediately if the last call to the garbage collector was made within the interval specified by the MxServerProperties gcInterval member. This function does not invoke Java garbage collector and merely removes the unwanted images from the cache

### destroy

    public void destroy()

  Destroys the server component and all images stored in cache. This function is called by finalization and rarely should be used directly

### finalize

    public void finalize()
                  throws java.lang.Throwable

  Throws:
    `java.lang.Throwable`

### getImageCount

    public int getImageCount()

  Returns the number of the currently cached images

  Returns:
    number of images

### getMemorySize

    public long getMemorySize()

  Returns the amount of memory that cached images take

  Returns:
    memory size

### getHtmlReport

    public java.lang.String getHtmlReport()

  Returns a brief description of the component status in HTML format suitable for displaying in a browser

  Returns:
    html description

### writeBufferTo

    public void writeBufferTo(ChartDescription chartDescription,
                              HttpServletResponse httpservletresponse)
                       throws java.io.IOException

  This method obtains the image bytes using getBytes method, sets the content type based on the image type, writes the bytes into the response, and closes the output. See also notes for writeCachedBufferTo regarding some server limitations

  Parameters:
    `chartDescription` - discription
    `httpservletresponse` - response
  Throws:
    `java.io.IOException` - exception

### writeCachedBufferTo

    public void writeCachedBufferTo(java.lang.String guid,
                                    HttpServletResponse httpservletresponse)
                             throws java.io.IOException

  This method obtains the image bytes using getCachedBuffer method, sets the content type tbased on the image type, writes the bytes into the response, and closes the output. An example of this method invocation is: getServerComponent().writeCachedBufferTo(guid,response) NOTE. This function set the cache-control and expired headers when no_cache attribute of the description is set to true The implementation of this method tries to obtain the ServletOutputStream from the response object. Some JSP servers do not permit it inside the JSP pages, since the JSPWriter have been already retrieved by the time this function is called. If this happens, you might try to write the bytes to the JSPWriter by creating a new String from the bytes

  Parameters:
    `guid` - - unique image ID returned by getImageID function or embedded into HTML fragment by getImageTag function
    `httpservletresponse` - servlet response stream
  Throws:
    `java.io.IOException` - exception

### writeCachedBufferTo

    public void writeCachedBufferTo(java.lang.String guid,
                                    JspWriter jspwriter,
                                    HttpServletResponse httpservletresponse)
                             throws java.io.IOException

  Used by the getImage.jsp to write cached bytes out - some servers will not allow us to getOutputStream from response and instead the writer should be used. This function decrements the image reference count. This is a work around for the servers that will not allow us to obtain the output stream because it was already opened. This function in such case writes the image to the JspWriter.

  Parameters:
    `guid` - id
    `jspwriter` - jspwriter
    `httpservletresponse` - response
  Throws:
    `java.io.IOException` - exception

### getProperties

    public ResourceRepository getProperties()

  Returns the current server settings.

  Returns:
    properties

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD