001    /**
002     * Copyright (c) 2000-2010 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 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    }