|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface RequestHandler
A RequestHandler is used to process a request delivererd to the GraphServlet. These requests take the form of an InputSource (read from the servlet request), and are converted to a Graph by the process method.
Handlers are supplied to handle SOAP requests and raw XML. They are added to the
tag library in the same way as EmbedderFactory
, except the service
file is META-INF/services/org.faceless.graph2.tag.RequestHandlers
Method Summary | |
---|---|
boolean |
matches(String type)
Return true if this RequestHandler matches the specified type of request. |
void |
process(String type,
String imagepath,
GraphContext context,
InputSource source,
HttpServletRequest req,
HttpServletResponse res)
Process the input and convert it to a Graph. |
Method Detail |
---|
boolean matches(String type)
servlet/GraphServlet/myhandler
will match this RequestHandler if this method returns "myhandler".equals(type)
void process(String type, String imagepath, GraphContext context, InputSource source, HttpServletRequest req, HttpServletResponse res) throws IOException, SAXException
EmbeddedXMLGraph
class and an appropriate Embedder
. The generated Graph can be returned
immediately, or it can be stored in the GraphContext
and a link returned
to it for later retrieval.
Here's a simple example showing how to return a graph directly from this request
EmbeddedXMLGraph xml = new EmbeddedXMLGraph(); xml.parse(source); String format = xml.getRequestedFormat(); Embedder embedder = context.getEmbedderFactory(format).newEmbedder(format); ByteArrayOutputStream bout = new ByteArrayOutputStream(); xml.doEmbed(embedder, graphid, "", null, new StringWriter(), bout); bout.close(); res.setContentType(embedder.getMIMEType()); res.setContentLength(bout.size()); bout.writeTo(res.getOutputStream());and here's an example showing how to store a generated image for later retrieval. Note that we append the pageid (as returned from
GraphContext.nextPageId()
)
and a slash to the image path.
EmbeddedXMLGraph xml = new EmbeddedXMLGraph(); xml.parse(source); String format = xml.getRequestedFormat(); Embedder embedder = context.getEmbedderFactory(format).newEmbedder(format); String pageid = context.nextPageId(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); res.setContentType("text/html; charset="UTF-8"); imagepath += pageid + "/"; xml.doEmbed(embedder, "anything", imagepath, null, res.getWriter(), bout); bout.close(); context.putFile(pageid, embedder.getId(), bout.toByteArray(), embedder.getMIMEType());
type
- the type, as matched by the matches(java.lang.String)
methodimagepath
- the base URL of the Servlet that will be returning any files
generated by this method.context
- the GraphContext object, which may be used to store any generated filessource
- the InputSource containing the inputreq
- the HttpServletRequest, available if any additional information needs to
be readres
- the HttpServletResponse, which must be written to to return the necessary
data to the browser
IOException
SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |