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