Code with Finding: |
class SSIFrame {
public Reply handle(Request request)
throws ProtocolException
{
if (fresource == null)
return null;
if(SSIFrame.debug)
System.out.println("@@@@ handle: "+
(request.isInternal()
? "internal" : "external") ) ;
fresource.checkContent() ;
Integer depth =
(Integer) request.getState(STATE_DEPTH) ;
if(depth == null) depth = new Integer(0) ;
int unparsedSize = 0 ;
Segment[] segments = getSegments() ;
if(segments == null) {
parseFirstTime() ;
if( (segments = getSegments()) == null )
return null ; // Last resort: fall back to superclass
}
Reply reply = null ;
try {
// Obtain a command registry
updateRegistry() ;
vars = (Dictionary)
request.getState(STATE_VARIABLES) ;
// Initialize the registry-dependent variables:
vars = commReg.initVariables(this,request,vars) ;
// Add our "very global" variables
vars.put("secure",getValue(ATTR_SECURE,Boolean.TRUE)) ;
vars.put("maxDepth",getValue(ATTR_MAX_DEPTH,new Integer(10))) ;
vars.put("depth",depth) ;
vars.put("registry",commReg) ;
// Prepare the initial reply
// (which represents the unparsed parts of the document)
// and a prototype reply for segments that return null.
reply = createDefaultReply(request,HTTP.OK) ;
Reply defSegReply = createDefaultReply(request,HTTP.OK) ;
int unpSize = getUnparsedSize() ;
if(unpSize == -1)
reply.setHeaderValue(Reply.H_CONTENT_LENGTH,null) ;
else
reply.setContentLength(unpSize) ;
defSegReply.setHeaderValue(Reply.H_CONTENT_LENGTH,null) ;
long ims = request.getIfModifiedSince() ;
long cmt = fresource.getFileStamp() ;
// used to be getLastModified()
// should be something better
// than either
if(SSIFrame.debug)
System.out.println("@@@@ IMS: "+cmt+" vs "+ims) ;
if(ims != -1 && cmt != -1 && cmt <= ims) {
reply.setStatus(HTTP.NOT_MODIFIED) ;
defSegReply.setStatus(HTTP.NOT_MODIFIED) ;
} else if(ims != -1) {
if(SSIFrame.debug)
System.out.println("@@@@ Removed NOT MODIFIED") ;
}
if(cmt != -1)
defSegReply.setLastModified(cmt) ;
// For each segment:
// . obtain a reply,
// . merge its headers with the global reply's headers,
Reply[] partReps = new Reply[segments.length] ;
for(int i=0;i<segments.length;i++) {
if(!segments[i].isUnparsed()) {
if(SSIFrame.debug)
System.out.println("@@@@ Analyzing segment " +
segments[i]) ;
partReps[i] = segments[i].init(this, request,
vars, commReg, i);
if(SSIFrame.debug) {
if (partReps[i] == null)
System.out.println("@@@@ (null segment)") ;
System.out.println("@@@@ cacheReplies : "+
cacheReplies());
}
merge(reply,
partReps[i] != null ? partReps[i] : defSegReply) ;
}
}
// Set a stream, unless we're not supposed to.
// Also handle the case of no command segments.
switch(reply.getStatus()) {
default:
reply.setStream
(new SSIStream(cacheReplies(),
segments,
partReps,
new RandomAccessFile(fresource.getFile(),
"r"))) ;
case HTTP.NO_CONTENT:
case HTTP.NOT_MODIFIED:
}
if(SSIFrame.debug)
System.out.println("@@@@ Last-modified: " +
reply.getLastModified()) ;
reply.setDate(System.currentTimeMillis()) ;
return reply ;
} catch(SSIException ex) {
reply = createDefaultReply(request,HTTP.INTERNAL_SERVER_ERROR) ;
reply.setContent("SSIFrame is misconfigured: "+
ex.getMessage());
throw new HTTPException(reply) ;
} catch(Exception ex) {
ex.printStackTrace() ;
if(SSIFrame.debug) {
if(SSIFrame.debug)
System.out.println("@@@@ Fallback to FileResource") ;
}
return null ; // Last resort: fall back to superclass
}
}
}
|