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.base;
020
021import java.net.URI;
022
023import org.jgrapes.portal.base.events.PageResourceRequest;
024import org.jgrapes.portal.base.events.PortletResourceRequest;
025
026/**
027 * Provides support for creating URIs in the portal scope that
028 * are forwarded to components listening on the portal channel.  
029 */
030public interface RenderSupport {
031
032    /**
033     * Returns the portal library URI.
034     *
035     * @param uri the uri
036     * @return the uri
037     */
038    URI portalBaseResource(URI uri);
039
040    /**
041     * Convenience method that converts the path to an URI
042     * before calling {@link #portalBaseResource(URI)}.
043     * 
044     * @param path the path 
045     * @return the resulting URI
046     */
047    default URI portalBaseResource(String path) {
048        return portalBaseResource(PortalUtils.uriFromPath(path));
049    }
050
051    /**
052     * Create a reference to a resource provided by the portal.
053     * 
054     * @param uri the URI  
055     * @return the resulting URI
056     */
057    URI portalResource(URI uri);
058
059    /**
060     * Convenience method that converts the path to an URI
061     * before calling {@link #portalResource(URI)}.
062     * 
063     * @param path the path 
064     * @return the resulting URI
065     */
066    default URI portalResource(String path) {
067        return portalResource(PortalUtils.uriFromPath(path));
068    }
069
070    /**
071     * Create a reference to a resource provided by a page resource
072     * provider. Requesting the resulting URI results in a 
073     * {@link PageResourceRequest}.
074     * 
075     * @param uri the URI made available as
076     * {@link PageResourceRequest#resourceUri()}  
077     * @return the resulting URI
078     */
079    URI pageResource(URI uri);
080
081    /**
082     * Convenience method that converts the path to an URI
083     * before calling {@link #pageResource(URI)}.
084     * 
085     * @param path the path 
086     * @return the resulting URI
087     */
088    default URI pageResource(String path) {
089        return pageResource(PortalUtils.uriFromPath(path));
090    }
091
092    /**
093     * Create a reference to a resource provided by a portlet
094     * of the given type. Requesting the resulting URI results
095     * in a {@link PortletResourceRequest}.
096     * 
097     * @param portletType the portlet type
098     * @param uri the URI made available as 
099     * {@link PortletResourceRequest#resourceUri()}
100     * @return the resulting URI
101     */
102    URI portletResource(String portletType, URI uri);
103
104    /**
105     * Convenience method that converts the path to an URI
106     * before calling {@link #portletResource(String, URI)}.
107     * 
108     * @param portletType the portlet type
109     * @param path the path 
110     * @return the resulting URI
111     */
112    default URI portletResource(String portletType, String path) {
113        return portletResource(portletType, PortalUtils.uriFromPath(path));
114    }
115
116    /**
117     * Indicates if minified resources should be used.
118     * 
119     * @return the setting
120     */
121    boolean useMinifiedResources();
122}