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