groovity.portal.lib.layout.grvt Maven / Gradle / Ivy
/*******************************************************************************
* © 2018 Disney | ABC Television Group
*
* Licensed under the Apache License, Version 2.0 (the "Apache License")
* with the following modification; you may not use this file except in
* compliance with the Apache License and the following modification to it:
* Section 6. Trademarks. is deleted and replaced with:
*
* 6. Trademarks. This License does not grant permission to use the trade
* names, trademarks, service marks, or product names of the Licensor
* and its affiliates, except as required to comply with Section 4(c) of
* the License and to reproduce the content of the NOTICE file.
*
* You may obtain a copy of the Apache License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Apache License with the above modification is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the Apache License for the specific
* language governing permissions and limitations under the Apache License.
*******************************************************************************/
import java.net.URLEncoder;
import javax.servlet.RequestDispatcher;
import groovy.lang.Closure;
static conf=[
PORTAL_LOGIN_LINK : "/portal/session/login?redirect=",
PORTAL_LOGOUT_LINK : "/portal/session/logout?redirect=",
PORTAL_BASE_URL : "",
PORTAL_HEAD_SECTION : "",
PORTAL_TITLE : "Portal",
PORTAL_FOOTER : "Copyright 2018 - All Rights Reserved"
]
@Tag(
info="present a page in the portal layout"
)
class Portal{
def tag(Map atts, Closure body){
def portal = load('/groovity/portal/lib/portal');
def layoutLib = load('/groovity/portal/lib/layout');
def pageRoles = null;
def sourcePath = null;
if(body.binding.hasVariable('portalPageConfig')){
sourcePath = portalPageConfig.path;
pageRoles = portalPageConfig.roles;
}
if(!sourcePath) {
sourcePath = (body.getClass().getClassLoader().getSourcePath() - ".grvt")
}
sitemap = portal.getSitemap();
def crumbs = []; // will hold breadcrumb
int spos = 0;
StringBuilder sb = new StringBuilder();
def tools = null; // will hold tab list if called for
def ancestors = null;
int slashCount = 0;
//walk source path to build breadcrumb list and tab list
while(spos>=0){
slashCount++;
def sbts = sb.toString();
def page = sitemap.find{ it.path==sbts+"/index" || it.path==sbts+"/" };
if(page?.tabs){
tools = [page]
tools.addAll(portal.getPages(sbts))
ancestors = sitemap.findAll{ it.tabs && it.path!='/' && sbts.startsWith(it.path - '/index') && sbts != (it.path - '/index') }.sort{ it.path.length() };
}
int nextPos = sourcePath.indexOf("/",spos+1);
if(nextPos>0){
sb.append(sourcePath.substring(spos,nextPos));
if(slashCount>1){
crumbs << sb.toString();
}
}
else{
String p = sourcePath.substring(spos);
if(p!="/index"){
sb.append(p);
crumbs << sb.toString();
}
}
spos=nextPos;
}
//lookup page details from sitemap for breadcrumb links
crumbs = crumbs.collect{ cr ->
crIndex = cr+"/index";
sitemap.find{ cr==it.path || crIndex==it.path };
}.findAll{ it!=null }
//build redirect URL for login/logout links
def rpath = request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);
def rquery = rpath ? request.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING) : request.queryString;
rpath = rpath ?: request.pathInfo ?: request.servletPath;
redirectUrl = new StringBuilder(layoutLib.conf.PORTAL_BASE_URL);
if(binding.hasVariable('error')){
def eu = error.uri
if(eu){
if(eu.startsWith(layoutLib.conf.PORTAL_LOGIN_LINK)){
rpath = eu.substring(layoutLib.conf.PORTAL_LOGIN_LINK.length())
}
else{
rpath = eu
}
rpath = URLDecoder.decode(rpath,"UTF-8")
rquery = null
}
else{
rpath = '/'
}
}
redirectUrl << rpath;
if(rquery){
redirectUrl << "?"
redirectUrl << rquery
}
redirectUrl = URLEncoder.encode(redirectUrl.toString());
def factory = load('/data/factory')
def user = body.request.userPrincipal;
def session = body.request.session
def userRoles = user?.roles;
def inbox = user?.inbox;
currentDepth = 0;
treeRecursion = <~
class="current"
>${currentPage.title}
${treeRecursion}
~>
stream <~
${get(body,'portal')?.title ?: layoutLib.conf.PORTAL_TITLE}
${layoutLib.conf.PORTAL_HEAD_SECTION}
Loading ...
Error processing form: ${formError.message}
${formMessage}
${body}
~>;
}
}
@Tag(
info="present a portlet with tool links in the portal layout",
attrs=[
@Attr(info="Path to portal folder to generate links for",name="path",required=true)
]
)
class PortalLinks{
def tag(Map atts, Closure body){
def portal = load('/groovity/portal/lib/portal');
def path = resolve(atts,'path',String.class)
def org = portal.sitemap.find{it.path == path};
def user = body.request.userPrincipal
if(!org.roles ||
(!user && org.roles.contains('anon')) ||
user?.hasRole(body.request.session, path, org.roles)
){
stream <~
~>
}
}
}
@Tag(
info="create a portlet in the portal layout",
attrs=[
@Attr(info="Portlet title",name="title"),
@Attr(info="Optional href link for portlet title",name="link"),
@Attr(info="set true to create a double-width portlet", name="wide"),
@Attr(info="Set roles allowed to view this portlet",name="roles")
]
)
class Portlet{
def tag(Map atts, Closure body){
def title = resolve(atts,'title',String.class)
def link = resolve(atts,'link',String.class)
def wide = resolve(atts,'wide',Boolean.class)
def portletRoles = resolve(atts,'roles',String[].class)
portletRoles = portletRoles ? Arrays.asList(portletRoles) :[];
if(portletRoles.isEmpty() || body.roles.find{ portletRoles.contains(it) }){
stream <~
wide">
${title}
${title}
${body}
~>
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy