Package org.faceless.graph2.tag
Class GraphContext
- java.lang.Object
-
- org.faceless.graph2.tag.GraphContext
-
public class GraphContext extends Object
The GraphContext is the equivalent of theServletContext
, and manages the generated graphs, their resources and the Embedders/RequestHandlers that are used to create and serve them. Unless you're creating your ownRequestHandler
you will not need to access this class.- Since:
- 2.4
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Destroy this GraphContext - must be called when the ServletContext is reloaded.EmbedderFactory
getEmbedderFactory(String type)
Get the EmbedderFactory that closest matches the specified type, which may be a default EmbedderFactory if no direct match is found.byte[]
getFile(String pageid, String graphid)
Return a generated file saved withputFile()
String
getFileType(String pageid, String graphid)
Return the MIME-type of the generated file saved withputFile()
static GraphContext
getGraphContext(ServletContext sc)
Retrieve the GraphContext object for the specified ServletContext.static GraphContext
getGraphContext(ServletContext sc, HttpServletRequest req)
Retrieve the GraphContext object for the specified context.RequestHandler
getRequestHandler(String type)
Get a RequestHandler that matches the specified type, ornull
if no matching handlers are found.Map<URL,Object>
getResources()
Return a context-wide Map that can be used to save general resourcesString
nextPageId()
Return a new unique ID for the next page - guaranteed to be uniquevoid
putFile(String pageid, String graphid, byte[] data, String mimetype)
Store a generated Imagevoid
setStoreSize(int storesize)
Set the maximum number of pages to keep around before they're freed.
-
-
-
Method Detail
-
getGraphContext
public static GraphContext getGraphContext(ServletContext sc)
Retrieve the GraphContext object for the specified ServletContext. CallsgetGraphContext(sc, null)
- Parameters:
sc
- the Servlet Context
-
getGraphContext
public static GraphContext getGraphContext(ServletContext sc, HttpServletRequest req)
Retrieve the GraphContext object for the specified context. One is created if it doesn't exist.
Which context is used (the session or the ServletContext) depends on the
org.faceless.graph2.tag.UseSession
init-parameter. If this is set totrue
, graphs will be stored in the session. This is required for clustered load-balancing.- Parameters:
sc
- the Servlet Contextreq
- the HTTP request - only required if graphs are to be stored in the session context
-
destroy
public void destroy()
Destroy this GraphContext - must be called when the ServletContext is reloaded.
-
setStoreSize
public void setStoreSize(int storesize)
Set the maximum number of pages to keep around before they're freed. This isn't exactly the same as the number of graphs - a page may have more than one graph on it. The default is "50"- Parameters:
storesize
- the size of the page store
-
getRequestHandler
public RequestHandler getRequestHandler(String type)
Get a RequestHandler that matches the specified type, ornull
if no matching handlers are found.- Parameters:
type
- the type
-
getEmbedderFactory
public EmbedderFactory getEmbedderFactory(String type)
Get the EmbedderFactory that closest matches the specified type, which may be a default EmbedderFactory if no direct match is found.- Parameters:
type
- the type
-
nextPageId
public String nextPageId()
Return a new unique ID for the next page - guaranteed to be unique
-
putFile
public void putFile(String pageid, String graphid, byte[] data, String mimetype)
Store a generated Image- Parameters:
pageid
- the page idgraphid
- the graph id - must be unique on the specified pagedata
- the datamimetype
- the MIME-type of the image
-
getFile
public byte[] getFile(String pageid, String graphid)
Return a generated file saved withputFile()
- Parameters:
pageid
- the page idgraphid
- the graph id
-
getFileType
public String getFileType(String pageid, String graphid)
Return the MIME-type of the generated file saved withputFile()
- Parameters:
pageid
- the page idgraphid
- the graph id
-
-