001    /**
002     * Copyright (c) 2000-2012 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[] bytes,
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, modes,
041                            new ByteArrayInputStream(bytes), byteArrayOutputStream, options);
042    
043                    return byteArrayOutputStream.toByteArray();
044            }
045    
046            public abstract void sanitize(
047                            long companyId, long groupId, long userId, String className,
048                            long classPK, String contentType, String[] modes,
049                            InputStream inputStream, OutputStream outputStream,
050                            Map<String, Object> options)
051                    throws SanitizerException;
052    
053            public String sanitize(
054                            long companyId, long groupId, long userId, String className,
055                            long classPK, String contentType, String[] modes, String s,
056                            Map<String, Object> options)
057                    throws SanitizerException {
058    
059                    ByteArrayOutputStream byteArrayOutputStream =
060                            new ByteArrayOutputStream();
061    
062                    sanitize(
063                            companyId, groupId, userId, className, classPK, contentType, modes,
064                            new ByteArrayInputStream(s.getBytes()), byteArrayOutputStream,
065                            options);
066    
067                    return byteArrayOutputStream.toString();
068            }
069    
070    }