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