Skip to content
Snippets Groups Projects
Commit b23527df authored by HongKee Moon's avatar HongKee Moon
Browse files

Create the remote xml file only once and keep it ready as a String

parent e148512c
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
public class CellHandler extends ContextHandler
{
......@@ -42,6 +43,9 @@ public class CellHandler extends ContextHandler
private final String dataSetURL;
// Cached XML string for provideXML()
private String remoteXmlString = null;
public CellHandler( final String baseUrl, final String xmlFilename ) throws SpimDataException
{
final SpimDataMinimal spimData = new XmlIoSpimDataMinimal().load( xmlFilename );
......@@ -122,8 +126,9 @@ public class CellHandler extends ContextHandler
}
}
// TODO: create the remote xml file only once and keep it ready as a String
public void provideXML( final Request baseRequest, final HttpServletResponse response ) throws IOException, ServletException
{
if ( null == remoteXmlString )
{
try
{
......@@ -132,47 +137,26 @@ public class CellHandler extends ContextHandler
final SequenceDescriptionMinimal seq = spimData.getSequenceDescription();
seq.setImgLoader( new RemoteImageLoader( dataSetURL ) );
final Document doc = new Document( io.toXml( spimData, spimData.getBasePath() ) );
response.setContentType( "application/xml" );
response.setStatus( HttpServletResponse.SC_OK );
baseRequest.setHandled( true );
final XMLOutputter xout = new XMLOutputter( Format.getPrettyFormat() );
xout.output( doc, response.getOutputStream() );
// xout.output( doc, System.out );
final StringWriter sw = new StringWriter();
xout.output( doc, sw );
remoteXmlString = sw.toString();
}
catch ( final Exception e )
catch ( final SpimDataException e )
{
throw new ServletException( e );
}
// final SAXBuilder sax = new SAXBuilder();
// Document doc;
// try
// {
// doc = sax.build( xmlFile );
// }
// catch ( final Exception e )
// {
// throw new ServletException( e );
// }
// final Element root = doc.getRootElement();
// final Element SequenceDescription = root.getChild( "SequenceDescription" );
// final Element ImageLoader = SequenceDescription.getChild( "ImageLoader" );
//
// ImageLoader.setAttribute( "format", "bdv.remote" );
//
// ImageLoader.removeChild( "hdf5" );
//
// final Element baseUrl = new Element( "baseUrl" );
// baseUrl.setText( dataSetURL );
// ImageLoader.setContent( baseUrl );
//
// response.setContentType( "application/xml" );
// response.setStatus( HttpServletResponse.SC_OK );
// baseRequest.setHandled( true );
// final PrintWriter ow = response.getWriter();
// ow.write( new XMLOutputter().outputString( doc ) );
// ow.close();
}
response.setContentType( "application/xml" );
response.setStatus( HttpServletResponse.SC_OK );
baseRequest.setHandled( true );
final PrintWriter ow = response.getWriter();
ow.write( remoteXmlString );
ow.close();
}
public String getXmlFile()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment