|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.yworks.yfiles.server.tiles.servlet.BaseServlet
com.yworks.yfiles.server.tiles.servlet.LoaderServlet
This servlet loads graphs from server side files, caches them and allows the download of cached graphs. See
handlePostRequest(HttpServletRequest,HttpServletResponse)
for more details.
Subclasses can customize the behavior of this servlet by providing custom implementations of
getGraphResourceStream(String)
, getIoHandler(String)
,
customizeGraphMLIOHandler(GraphMLIOHandler, Graph2D)
or loadableGraphs(HttpServletResponse)
.
Field Summary | |
protected String |
INIT_PARAM_CONFIGURE_REALIZERS
|
protected String |
LOADABLE_GRAPHS_LIST
"/resources/graphs/loadable-graphs.json": resource containing a list of graphs, which can be loaded. |
Fields inherited from class com.yworks.yfiles.server.tiles.servlet.BaseServlet |
EDGE_DESCRIPTION_KEY, EDGE_URL_KEY, NODE_DESCRIPTION_KEY, NODE_URL_KEY |
Constructor Summary | |
LoaderServlet()
|
Method Summary | |
protected void |
customizeGraphMLIOHandler(GraphMLIOHandler ioh,
Graph2D graph)
customization hook for subclasses. |
protected InputStream |
getGraphResourceStream(String requestedPath)
returns an input stream for reading a requested graph. |
protected IOHandler |
getIoHandler(String format)
returns an IO handler suitable for handling the requested graph format. |
protected void |
handleGetRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
calls handlePostRequest(HttpServletRequest,HttpServletResponse) . |
protected void |
handlePostRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
handles "downloadableFormats", "downloadGraph", "loadGraph" and "loadableGraphs" requests. |
void |
initialize()
initializes this servlet. |
protected void |
loadableGraphs(javax.servlet.http.HttpServletResponse response)
writes the symbolic names of the loadable graphs as a JSON string to the given response. |
Methods inherited from class com.yworks.yfiles.server.tiles.servlet.BaseServlet |
addViewConfigurator, cachedGraphs, cacheGraph, doGet, doPost, getEdgeDescription, getEdgeURL, getForId, getGraph, getGraphBounds, getGraphContentBounds, getId, getId, getId, getId, getNodeDescription, getNodeURL, getReadWriteLock, getSessionMonitor, getViewConfigurators, getWriter, hasDescriptions, hasURLs, init, isUseJSONPrefixing, lookupId, lookupId, lookupId, lookupId, newGraph, readLock, registerLicense, removeViewConfigurator, setEdgeDescription, setEdgeURL, setNodeDescription, setNodeURL, uncacheGraph, unlockRead, unlockWrite, updateEdgePaths, validateIds, writeContentBounds, writeLock, writeWorldBounds |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected String LOADABLE_GRAPHS_LIST
loadableGraphs(javax.servlet.http.HttpServletResponse)
.
protected final String INIT_PARAM_CONFIGURE_REALIZERS
Constructor Detail |
public LoaderServlet()
Method Detail |
public void initialize() throws javax.servlet.ServletException
initialize
in class BaseServlet
javax.servlet.ServletException
protected void handlePostRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
handles "downloadableFormats", "downloadGraph", "loadGraph" and "loadableGraphs" requests.
The "downloadableFormats" request returns a list of available formats for downloading a graph in JSON format.
The "downloadGraph" request has a mandatory parameter "path" and an optional parameter "format". The parameter "path" contains the name of the graph to be downloaded. The parameter "format" specifies the format for the download. It defaults to "ygf". Useful values are filename extensions of yFiles for Java graph formats; "ygf", "gml", "graphml", "graphmlz" and "tgf". Moreover some image formats are supported: "gif", "jpg", "png" and "bmp". The response for this request is a binary stream containing the graph in the requested format.
The "loadableGraphs" request takes no parameters and returns a list of file names of graphs from the "resources/graphs" directory in comment-filtered JSON format.
The "loadGraph" request has a mandatory parameter "path". If the value of the parameter "path" is "foo.ygf", and there is not yet a graph cached for the name "foo.ygf" in the session of the request, then the graph is loaded from the file "foo.ygf" from the directory "resources/graphs" in the web application, to which this servlet belongs, and cached using the name "foo.ygf". Reloading a graph which is already cached can be forced by setting the optional parameter "reload" to "true".
Subclasses can customize the behavior of this servlet by providing custom implementations of
getIoHandler(String)
, customizeGraphMLIOHandler(GraphMLIOHandler, Graph2D)
,
getGraphResourceStream(String)
or loadableGraphs(HttpServletResponse)
.
handlePostRequest
in class BaseServlet
request
- the requestresponse
- the response to write to, the status is set set to 200 on success and to 404 otherwise
javax.servlet.ServletException
IOException
protected IOHandler getIoHandler(String format)
null
.
format
- the requested format as a filename extension or null
IOHandler
suitable for the requested format or null
protected void loadableGraphs(javax.servlet.http.HttpServletResponse response) throws IOException
writes the symbolic names of the loadable graphs as a JSON string to the given response. This method handles
the "loadableGraphs" request. This implementation returns the list stored in
LOADABLE_GRAPHS_LIST
. Subclasses can customize this method.
The format of the string written to the response is like in the following example.
/*[ "aGraph.ygf", "anotherGraph.graphml" ]*/
response
- the response to write to
IOException
- if there are problems reading input list or writing the responsegetGraphResourceStream(String)
protected void customizeGraphMLIOHandler(GraphMLIOHandler ioh, Graph2D graph)
getIoHandler(String)
method, since there is no access to the graph. The default
implementation adds the string attributes "url" and "description" for nodes and edges, which are
also supported by yEd and for which there is further support in the BaseServlet
(e.g. BaseServlet.getNodeURL(Graph2D, Node)
). It is safe not to call this implementation,
if you overwrite this method in a subclass and the "url" and "description" attributes are not needed.
ioh
- the handler to be used for reading or writing the graphgraph
- the graph to be read or written, after this method has completedgetIoHandler(String)
protected InputStream getGraphResourceStream(String requestedPath)
/resources/graphs
directory of the web application using
ServletContext.getResourceAsStream(String)
.
requestedPath
- the name for the graph resource
null
protected void handleGetRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
handlePostRequest(HttpServletRequest,HttpServletResponse)
.
handleGetRequest
in class BaseServlet
request
- the requestresponse
- the response to write to
javax.servlet.ServletException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |