001    /**
002     * Copyright (c) 2000-2013 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.InputStream;
018    import java.io.OutputStream;
019    
020    import java.util.Map;
021    
022    /**
023     * @author Zsolt Balogh
024     * @author Brian Wing Shun Chan
025     */
026    public class SanitizerWrapper implements Sanitizer {
027    
028            public SanitizerWrapper(Sanitizer sanitizer) {
029                    _originalSanitizer = sanitizer;
030                    _sanitizer = sanitizer;
031            }
032    
033            @Override
034            public byte[] sanitize(
035                            long companyId, long groupId, long userId, String className,
036                            long classPK, String contentType, String[] modes, byte[] bytes,
037                            Map<String, Object> options)
038                    throws SanitizerException {
039    
040                    return _sanitizer.sanitize(
041                            companyId, groupId, userId, className, classPK, contentType, modes,
042                            bytes, options);
043            }
044    
045            @Override
046            public 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                    _sanitizer.sanitize(
054                            companyId, groupId, userId, className, classPK, contentType, modes,
055                            inputStream, outputStream, options);
056            }
057    
058            @Override
059            public String sanitize(
060                            long companyId, long groupId, long userId, String className,
061                            long classPK, String contentType, String[] modes, String s,
062                            Map<String, Object> options)
063                    throws SanitizerException {
064    
065                    return _sanitizer.sanitize(
066                            companyId, groupId, userId, className, classPK, contentType, modes,
067                            s, options);
068            }
069    
070            public void setSanitizer(Sanitizer sanitizer) {
071                    if (sanitizer == null) {
072                            _sanitizer = _originalSanitizer;
073                    }
074                    else {
075                            _sanitizer = sanitizer;
076                    }
077            }
078    
079            private Sanitizer _originalSanitizer;
080            private Sanitizer _sanitizer;
081    
082    }