001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.sanitizer;
016    
017    import java.io.ByteArrayInputStream;
018    import java.io.ByteArrayOutputStream;
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 abstract class BaseSanitizer implements Sanitizer {
029    
030            public byte[] sanitize(
031                            long companyId, long groupId, long userId, String className,
032                            long classPK, String contentType, String[] modes, byte[] byteArray,
033                            Map<String, Object> options)
034                    throws SanitizerException {
035    
036                    ByteArrayOutputStream byteArrayOutputStream =
037                            new ByteArrayOutputStream();
038    
039                    sanitize(
040                            companyId, groupId, userId, className, classPK, contentType,
041                            modes, new ByteArrayInputStream(byteArray), byteArrayOutputStream,
042                            options);
043    
044                    return byteArrayOutputStream.toByteArray();
045            }
046    
047            public abstract void sanitize(
048                            long companyId, long groupId, long userId, String className,
049                            long classPK, String contentType, String[] modes,
050                            InputStream inputStream, OutputStream outputStream,
051                            Map<String, Object> options)
052                    throws SanitizerException;
053    
054            public String sanitize(
055                            long companyId, long groupId, long userId, String className,
056                            long classPK, String contentType, String[] modes, String s,
057                            Map<String, Object> options)
058                    throws SanitizerException {
059    
060                    ByteArrayOutputStream byteArrayOutputStream =
061                            new ByteArrayOutputStream();
062    
063                    sanitize(
064                            companyId, groupId, userId, className, classPK, contentType,
065                            modes, new ByteArrayInputStream(s.getBytes()),
066                            byteArrayOutputStream, options);
067    
068                    return byteArrayOutputStream.toString();
069            }
070    
071    }