1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }