01 import java.io.*;
02 import javax.servlet.*;
03 import javax.servlet.http.*;
04
05 public class ServletFilter extends HttpServlet {
06
07 public void doGet(HttpServletRequest req, HttpServletResponse res)
08 throws ServletException, IOException {
09
10 String contentType = req.getContentType();
11 if (contentType == null) return;
12 res.setContentType(contentType);
13 PrintWriter out = res.getWriter();
14 BufferedReader in = req.getReader();
15
16 String line = null;
17 while ((line = in.readLine()) != null) {
18 line = replace(line, "<plaintext>", "");
19 line = replace(line, "</plaintext>", "");
20 out.println(line);
21 }
22 }
23
24 public void doPost(HttpServletRequest req, HttpServletResponse res)
25 throws ServletException, IOException {
26 doGet(req, res);
27 }
28
29 private String replace(String line, String oldString, String newString) {
30 int index = 0;
31 while ((index = line.indexOf(oldString, index)) >= 0) {
32 // starý reťazec nahradíme novým
33 line = line.substring(0, index) + newString + line.substring(index + oldString.length());
34 index += newString.length();
35 }
36 return line;
37 }
38 }
|