01 import java.io.*;
02 import javax.servlet.*;
03 import javax.servlet.http.*;
04
05 import com.oroinc.text.perl.*;
06
07 public class ServletFilterPerl extends HttpServlet {
08
09 /* Vytvoríme objekt Perl5Util, potrebný na vytvorenie
10 regulárneho výrazu, porovnávanie a nahrádzanie reazcov */
11 Perl5Util perl = new Perl5Util();
12
13 public void doGet(HttpServletRequest req, HttpServletResponse res)
14 throws ServletException, IOException {
15
16 String contentType = req.getContentType();
17 if (contentType == null) return;
18 res.setContentType(contentType);
19
20 PrintWriter out = res.getWriter();
21
22 BufferedReader in = req.getReader();
23
24 try {
25 String line = null;
26 while ((line = in.readLine()) != null) {
27 // porovnáme a ak je výsledok true nahradíme
28 if (perl.match("#</?plaintext>#i", line))
29 line = perl.substitute("s#</?plaintext>##ig", line);
30 out.println(line);
31 }
32 }
33 catch(MalformedPerl5PatternException e) {
34 log("Problem with regular expresion: " + e.getMessage());
35 }
36 }
37
38 public void doPost(HttpServletRequest req, HttpServletResponse res)
39 throws ServletException, IOException {
40 doGet(req, res);
41 }
42 }
|