001    /**
002     * Copyright (c) 2000-present 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.url;
016    
017    import com.liferay.portal.kernel.util.ReflectionUtil;
018    
019    import java.net.MalformedURLException;
020    import java.net.URL;
021    
022    import java.util.Set;
023    
024    import javax.servlet.ServletContext;
025    
026    /**
027     * @author Raymond Aug??
028     */
029    public class ServletContextURLContainer implements URLContainer {
030    
031            public ServletContextURLContainer(ServletContext servletContext) {
032                    _servletContext = servletContext;
033            }
034    
035            @Override
036            public URL getResource(String name) {
037                    try {
038                            return _servletContext.getResource(name);
039                    }
040                    catch (MalformedURLException mue) {
041                            return ReflectionUtil.throwException(mue);
042                    }
043            }
044    
045            @Override
046            public Set<String> getResources(String path) {
047                    return _servletContext.getResourcePaths(path);
048            }
049    
050            private final ServletContext _servletContext;
051    
052    }