1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.sanitizer;
16  
17  import java.io.ByteArrayInputStream;
18  import java.io.ByteArrayOutputStream;
19  import java.io.InputStream;
20  import java.io.OutputStream;
21  
22  import java.util.Map;
23  
24  /**
25   * <a href="BaseSanitizer.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Zsolt Balogh
28   * @author Brian Wing Shun Chan
29   */
30  public abstract class BaseSanitizer implements Sanitizer {
31  
32      public byte[] sanitize(
33              long companyId, long groupId, long userId, String className,
34              long classPK, String contentType, String[] modes, byte[] byteArray,
35              Map<String, Object> options)
36          throws SanitizerException {
37  
38          ByteArrayOutputStream byteArrayOutputStream =
39              new ByteArrayOutputStream();
40  
41          sanitize(
42              companyId, groupId, userId, className, classPK, contentType,
43              modes, new ByteArrayInputStream(byteArray), byteArrayOutputStream,
44              options);
45  
46          return byteArrayOutputStream.toByteArray();
47      }
48  
49      public abstract void sanitize(
50              long companyId, long groupId, long userId, String className,
51              long classPK, String contentType, String[] modes,
52              InputStream inputStream, OutputStream outputStream,
53              Map<String, Object> options)
54          throws SanitizerException;
55  
56      public String sanitize(
57              long companyId, long groupId, long userId, String className,
58              long classPK, String contentType, String[] modes, String s,
59              Map<String, Object> options)
60          throws SanitizerException {
61  
62          ByteArrayOutputStream byteArrayOutputStream =
63              new ByteArrayOutputStream();
64  
65          sanitize(
66              companyId, groupId, userId, className, classPK, contentType,
67              modes, new ByteArrayInputStream(s.getBytes()),
68              byteArrayOutputStream, options);
69  
70          return byteArrayOutputStream.toString();
71      }
72  
73  }