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.InputStream;
18  import java.io.OutputStream;
19  
20  import java.util.Map;
21  
22  /**
23   * <a href="SanitizerUtil.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Zsolt Balogh
26   * @author Brian Wing Shun Chan
27   */
28  public class SanitizerUtil {
29  
30      public static Sanitizer getSanitizer() {
31          return _sanitizer;
32      }
33  
34      public static byte[] sanitize(
35              long companyId, long groupId, long userId, String className,
36              long classPK, String contentType, byte[] byteArray)
37          throws SanitizerException {
38  
39          return sanitize(
40              companyId, groupId, userId, className, classPK, contentType,
41              Sanitizer.MODE_ALL, byteArray, null);
42      }
43  
44      public static void sanitize(
45              long companyId, long groupId, long userId, String className,
46              long classPK, String contentType, InputStream inputStream,
47              OutputStream outputStream)
48          throws SanitizerException {
49  
50          sanitize(
51              companyId, groupId, userId, className, classPK, contentType,
52              Sanitizer.MODE_ALL, inputStream, outputStream, null);
53      }
54  
55      public static String sanitize(
56              long companyId, long groupId, long userId, String className,
57              long classPK, String contentType, String s)
58          throws SanitizerException {
59  
60          return sanitize(
61              companyId, groupId, userId, className, classPK, contentType,
62              Sanitizer.MODE_ALL, s, null);
63      }
64  
65      public static byte[] sanitize(
66              long companyId, long groupId, long userId, String className,
67              long classPK, String contentType, String mode, byte[] byteArray,
68              Map<String, Object> options)
69          throws SanitizerException {
70  
71          return sanitize(
72              companyId, groupId, userId, className, classPK, contentType,
73              new String[] {mode}, byteArray, options);
74      }
75  
76      public static void sanitize(
77              long companyId, long groupId, long userId, String className,
78              long classPK, String contentType, String mode,
79              InputStream inputStream, OutputStream outputStream,
80              Map<String, Object> options)
81          throws SanitizerException {
82  
83          sanitize(
84              companyId, groupId, userId, className, classPK, contentType,
85              new String[] {mode}, inputStream, outputStream, options);
86      }
87  
88      public static String sanitize(
89              long companyId, long groupId, long userId, String className,
90              long classPK, String contentType, String mode, String s,
91              Map<String, Object> options)
92          throws SanitizerException {
93  
94          return sanitize(
95              companyId, groupId, userId, className, classPK, contentType,
96              new String[] {mode}, s, options);
97      }
98  
99      public static byte[] sanitize(
100             long companyId, long groupId, long userId, String className,
101             long classPK, String contentType, String[] modes, byte[] byteArray,
102             Map<String, Object> options)
103         throws SanitizerException {
104 
105         return getSanitizer().sanitize(
106             companyId, groupId, userId, className, classPK, contentType, modes,
107             byteArray, options);
108     }
109 
110     public static void sanitize(
111             long companyId, long groupId, long userId, String className,
112             long classPK, String contentType, String[] modes,
113             InputStream inputStream, OutputStream outputStream,
114             Map<String, Object> options)
115         throws SanitizerException {
116 
117         getSanitizer().sanitize(
118             companyId, groupId, userId, className, classPK, contentType, modes,
119             inputStream, outputStream, options);
120     }
121 
122     public static String sanitize(
123             long companyId, long groupId, long userId, String className,
124             long classPK, String contentType, String[] modes, String s,
125             Map<String, Object> options)
126         throws SanitizerException {
127 
128         return getSanitizer().sanitize(
129             companyId, groupId, userId, className, classPK, contentType, modes,
130             s, options);
131     }
132 
133     public void setSanitizer(Sanitizer sanitizer) {
134         _sanitizer = sanitizer;
135     }
136 
137     private static Sanitizer _sanitizer;
138 
139 }