001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2017-2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.portal.jqueryui;
020
021import java.net.URL;
022
023import org.jgrapes.portal.base.ResourceNotFoundException;
024
025/**
026 * Represents a theme provider.
027 */
028public abstract class ThemeProvider {
029
030    /**
031     * Return the id of the theme.
032     * 
033     * @return the result
034     */
035    public abstract String themeId();
036
037    /**
038     * Return the name of the theme. The default implementation 
039     * uses the theme id, replaces underscores with spaces and
040     * capitalizes the first character.
041     * 
042     * @return the result
043     */
044    @SuppressWarnings("PMD.UselessParentheses")
045    public String themeName() {
046        return (Character.toUpperCase(themeId().charAt(0))
047            + themeId().substring(1)).replace('_', ' ');
048    }
049
050    /**
051     * Find the requested resource.
052     * 
053     * @param name the resource name
054     * @return the data as input stream
055     */
056    public URL getResource(String name)
057            throws ResourceNotFoundException {
058        URL resource = getClass().getResource(name);
059        if (resource == null) {
060            throw new ResourceNotFoundException();
061        }
062        return resource;
063    }
064}