StringBuffer command = new StringBuffer();
byte buf[] = new byte[4096];
int len = 0, bIdx = 0;
char ch;
boolean inside = false;
SsiCommand ssiCommand = null;
String strCmd;
String[] strParamType;
String[] strParam;
if (buffered)
out = (OutputStream)new ServletOutputStreamWrapper();
else
out = res.getOutputStream();
if (ssiMediator == null)
ssiMediator = new SsiMediator(req, res, out, servletContext, debug, path, isVirtualWebappRelative);
else
ssiMediator.flush(req, res, out, servletContext, path, isVirtualWebappRelative);
while ((len = in.read(buf)) != -1)
soonOut.write(buf, 0, len);
soonOut.close();
byte[] unparsed = soonOut.toByteArray();
soonOut = null; buf = null;
while (bIdx < unparsed.length) {
if (!inside) {
if (unparsed[bIdx] == bStart[0]&& byteCmp(unparsed, bIdx, bStart)) {
inside = true;
bIdx += bStart.length;
command.delete(0, command.length());
continue;
}
out.write(unparsed[bIdx]);
bIdx++;
} else {
if (unparsed[bIdx] == bEnd[0]&& byteCmp(unparsed, bIdx, bEnd)) {
inside = false;
bIdx += bEnd.length;
try {
strCmd = parseCmd(command);
} catch (IndexOutOfBoundsException ex) {
out.write(ssiMediator.getError());
continue;
}
strCmd = parseCmd(command);
strParamType = parseParamType(command, strCmd.length());
strParam = parseParam(command, strCmd.length());
if(debug > 0)
log("Serving SSI resource: " + strCmd);
ssiCommand = ssiMediator.getCommand(strCmd);
if (ssiCommand != null && strParamType.length==strParam.length&& strParamType.length>0) {
if (ssiCommand.isPrintable()) {
out.write((ssiCommand.getStream(strParamType, strParam)).getBytes());
} else
ssiCommand.process(strParamType, strParam);
} else if(ignoreUnsupportedDirective && ssiCommand==null) {
;
} else {
out.write(ssiMediator.getError());
}