001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.sanitizer;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import java.io.InputStream;
020    import java.io.OutputStream;
021    
022    import java.util.Map;
023    
024    /**
025     * @author Zsolt Balogh
026     * @author Brian Wing Shun Chan
027     */
028    public class SanitizerUtil {
029    
030            public static Sanitizer getSanitizer() {
031                    PortalRuntimePermission.checkGetBeanProperty(SanitizerUtil.class);
032    
033                    return _sanitizer;
034            }
035    
036            public static byte[] sanitize(
037                            long companyId, long groupId, long userId, String className,
038                            long classPK, String contentType, byte[] bytes)
039                    throws SanitizerException {
040    
041                    return sanitize(
042                            companyId, groupId, userId, className, classPK, contentType,
043                            Sanitizer.MODE_ALL, bytes, null);
044            }
045    
046            public static void sanitize(
047                            long companyId, long groupId, long userId, String className,
048                            long classPK, String contentType, InputStream inputStream,
049                            OutputStream outputStream)
050                    throws SanitizerException {
051    
052                    sanitize(
053                            companyId, groupId, userId, className, classPK, contentType,
054                            Sanitizer.MODE_ALL, inputStream, outputStream, null);
055            }
056    
057            public static String sanitize(
058                            long companyId, long groupId, long userId, String className,
059                            long classPK, String contentType, String s)
060                    throws SanitizerException {
061    
062                    return sanitize(
063                            companyId, groupId, userId, className, classPK, contentType,
064                            Sanitizer.MODE_ALL, s, null);
065            }
066    
067            public static byte[] sanitize(
068                            long companyId, long groupId, long userId, String className,
069                            long classPK, String contentType, String mode, byte[] bytes,
070                            Map<String, Object> options)
071                    throws SanitizerException {
072    
073                    return sanitize(
074                            companyId, groupId, userId, className, classPK, contentType,
075                            new String[] {mode}, bytes, options);
076            }
077    
078            public static void sanitize(
079                            long companyId, long groupId, long userId, String className,
080                            long classPK, String contentType, String mode,
081                            InputStream inputStream, OutputStream outputStream,
082                            Map<String, Object> options)
083                    throws SanitizerException {
084    
085                    sanitize(
086                            companyId, groupId, userId, className, classPK, contentType,
087                            new String[] {mode}, inputStream, outputStream, options);
088            }
089    
090            public static String sanitize(
091                            long companyId, long groupId, long userId, String className,
092                            long classPK, String contentType, String mode, String s,
093                            Map<String, Object> options)
094                    throws SanitizerException {
095    
096                    return sanitize(
097                            companyId, groupId, userId, className, classPK, contentType,
098                            new String[] {mode}, s, options);
099            }
100    
101            public static byte[] sanitize(
102                            long companyId, long groupId, long userId, String className,
103                            long classPK, String contentType, String[] modes, byte[] bytes,
104                            Map<String, Object> options)
105                    throws SanitizerException {
106    
107                    return getSanitizer().sanitize(
108                            companyId, groupId, userId, className, classPK, contentType, modes,
109                            bytes, options);
110            }
111    
112            public static void sanitize(
113                            long companyId, long groupId, long userId, String className,
114                            long classPK, String contentType, String[] modes,
115                            InputStream inputStream, OutputStream outputStream,
116                            Map<String, Object> options)
117                    throws SanitizerException {
118    
119                    getSanitizer().sanitize(
120                            companyId, groupId, userId, className, classPK, contentType, modes,
121                            inputStream, outputStream, options);
122            }
123    
124            public static String sanitize(
125                            long companyId, long groupId, long userId, String className,
126                            long classPK, String contentType, String[] modes, String s,
127                            Map<String, Object> options)
128                    throws SanitizerException {
129    
130                    return getSanitizer().sanitize(
131                            companyId, groupId, userId, className, classPK, contentType, modes,
132                            s, options);
133            }
134    
135            public void setSanitizer(Sanitizer sanitizer) {
136                    PortalRuntimePermission.checkSetBeanProperty(getClass());
137    
138                    _sanitizer = sanitizer;
139            }
140    
141            private static Sanitizer _sanitizer;
142    
143    }