Process SSI directives in the given resource. @param req the HTTP servlet request @param res the HTTP servlet response @param resource the URL of the resource to process @throws IOException if an I/O error occurs
(HttpServletRequest req, HttpServletResponse res, URL resource)
| 185 | * @throws IOException if an I/O error occurs |
| 186 | */ |
| 187 | protected void processSSI(HttpServletRequest req, HttpServletResponse res, URL resource) throws IOException { |
| 188 | SSIExternalResolver ssiExternalResolver = new SSIServletExternalResolver(getServletContext(), req, res, |
| 189 | isVirtualWebappRelative, debug, inputEncoding); |
| 190 | SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver, debug, allowExec); |
| 191 | PrintWriter printWriter; |
| 192 | StringWriter stringWriter = null; |
| 193 | if (buffered) { |
| 194 | stringWriter = new StringWriter(); |
| 195 | printWriter = new PrintWriter(stringWriter); |
| 196 | } else { |
| 197 | printWriter = res.getWriter(); |
| 198 | } |
| 199 | |
| 200 | URLConnection resourceInfo = resource.openConnection(); |
| 201 | InputStream resourceInputStream = resourceInfo.getInputStream(); |
| 202 | String encoding = resourceInfo.getContentEncoding(); |
| 203 | if (encoding == null) { |
| 204 | encoding = inputEncoding; |
| 205 | } |
| 206 | InputStreamReader isr; |
| 207 | if (encoding == null) { |
| 208 | isr = new InputStreamReader(resourceInputStream); |
| 209 | } else { |
| 210 | isr = new InputStreamReader(resourceInputStream, encoding); |
| 211 | } |
| 212 | |
| 213 | try (BufferedReader bufferedReader = new BufferedReader(isr)) { |
| 214 | long lastModified = ssiProcessor.process(bufferedReader, resourceInfo.getLastModified(), printWriter); |
| 215 | if (lastModified > 0) { |
| 216 | res.setDateHeader("last-modified", lastModified); |
| 217 | } |
| 218 | if (stringWriter != null) { |
| 219 | printWriter.flush(); |
| 220 | String text = stringWriter.toString(); |
| 221 | res.getWriter().write(text); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
no test coverage detected