Skip to content

Commit

Permalink
Merge pull request sakaiproject#1852 from jonespm/SAK-30440
Browse files Browse the repository at this point in the history
SAK-30440 Refactor CSS code in portal into util
  • Loading branch information
juanjmerono committed Mar 4, 2016
2 parents f32f768 + 3b8e6c2 commit b9eac64
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public static void addGlobalData(Site site, Properties props, Properties custom,
// Send along the CSS URL list
String tool_css_all = ServerConfigurationService.getString("basiclti.consumer.ext_sakai_launch_presentation_css_url_all",null);
if ( site != null && tool_css_all == null ) {
tool_css_all = getOurServerUrl() + CSSUtils.getCssToolBase() + ',' + getOurServerUrl() + CSSUtils.getCssToolSkin(site);
tool_css_all = getOurServerUrl() + CSSUtils.getCssToolBase() + ',' + getOurServerUrl() + CSSUtils.getCssToolSkinCDN(CSSUtils.getSkinFromSite(site));
}
setProperty(props,"ext_sakai_" + BasicLTIConstants.LAUNCH_PRESENTATION_CSS_URL + "_list", tool_css_all);

Expand Down
2 changes: 1 addition & 1 deletion basiclti/basiclti-portlet/src/webapp/contentitem.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%@ page import="org.sakaiproject.portal.util.PortalUtils" %>
<%@ page import="org.sakaiproject.portal.util.CSSUtils" %>
<title>IMS ContentItem Experimental Support</title>
<link href="<%= CSSUtils.getCssToolSkinCDN((String) null) %>" rel="stylesheet">
<%= CSSUtils.getCssToolSkinLink((String) null) %>
<script src="<%= PortalUtils.getScriptPath() %>headscripts.js<%= PortalUtils.getCDNQuery() %>"></script>
<style>
.card {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,32 +1257,7 @@ public Properties toolHeaderProperties(HttpServletRequest req, String skin, Plac
{
Properties retval = new Properties();

// setup html information that the tool might need (skin, body on load,
// js includes, etc).

String headCssPortalSkin = "<link href=\""
+ PortalUtils.getCDNPath()
+ CSSUtils.getCssPortalSkin(skin)
+ PortalUtils.getCDNQuery()
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";

String headCssToolBase = "<link href=\""
+ PortalUtils.getCDNPath()
+ CSSUtils.getCssToolBase()
+ PortalUtils.getCDNQuery()
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";

if ( ! ToolUtils.isInlineRequest(req) ) {
headCssToolBase = headCssPortalSkin + headCssToolBase;
}

String headCssToolSkin = "<link href=\""
+ PortalUtils.getCDNPath()
+ CSSUtils.getCssToolSkin(skin)
+ PortalUtils.getCDNQuery()
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";

String headCss = headCssToolBase + headCssToolSkin;
String headCss = CSSUtils.getCssHead(skin,ToolUtils.isInlineRequest(req));

Editor editor = portalService.getActiveEditor(placement);
String preloadScript = editor.getPreloadScript() == null ? ""
Expand Down Expand Up @@ -1375,8 +1350,8 @@ public Properties toolHeaderProperties(HttpServletRequest req, String skin, Plac
retval.setProperty("sakai.html.head", head);
retval.setProperty("sakai.html.head.css", headCss);
retval.setProperty("sakai.html.head.lang", rloader.getLocale().getLanguage());
retval.setProperty("sakai.html.head.css.base", headCssToolBase);
retval.setProperty("sakai.html.head.css.skin", headCssToolSkin);
req.setAttribute("sakai.html.head.css.base", CSSUtils.getCssToolBaseLink(skin,ToolUtils.isInlineRequest(req)));
req.setAttribute("sakai.html.head.css.skin", CSSUtils.getCssToolSkinLink(skin));
retval.setProperty("sakai.html.head.js", headJs.toString());

return retval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.portal.util.CSSUtils;
import org.sakaiproject.portal.util.ErrorReporter;
import org.sakaiproject.portal.util.ToolURLManagerImpl;
import org.sakaiproject.portal.util.ToolUtils;
import org.sakaiproject.portal.util.URLUtils;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.ToolConfiguration;
Expand Down Expand Up @@ -282,24 +284,16 @@ protected void setupForward(HttpServletRequest req, HttpServletResponse res,
{
// setup html information that the tool might need (skin, body on load,
// js includes, etc).
if (skin == null || skin.length() == 0)
skin = ServerConfigurationService.getString("skin.default");
String skinRepo = ServerConfigurationService.getString("skin.repo");
String headCssToolBase = "<link href=\""
+ skinRepo
+ "/tool_base.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
String headCssToolSkin = "<link href=\"" + skinRepo + "/" + skin
+ "/tool.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
String headCss = headCssToolBase + headCssToolSkin;
String headCss = CSSUtils.getCssHead(skin, ToolUtils.isInlineRequest(req));
String headJs = "<script type=\"text/javascript\" src=\"/library/js/headscripts.js\"></script>\n";

Site site=null;
// SAK-22384
if (p != null && MATHJAX_ENABLED_AT_SYSTEM_LEVEL)
{
ToolConfiguration toolConfig = SiteService.findTool(p.getId());
if (toolConfig != null) {
String siteId = toolConfig.getSiteId();
Site site;
try {
site = SiteService.getSiteVisit(siteId);
}
Expand Down Expand Up @@ -343,8 +337,8 @@ protected void setupForward(HttpServletRequest req, HttpServletResponse res,

req.setAttribute("sakai.html.head", head);
req.setAttribute("sakai.html.head.css", headCss);
req.setAttribute("sakai.html.head.css.base", headCssToolBase);
req.setAttribute("sakai.html.head.css.skin", headCssToolSkin);
req.setAttribute("sakai.html.head.css.base", CSSUtils.getCssToolBaseLink(CSSUtils.getSkinFromSite(site),ToolUtils.isInlineRequest(req)));
req.setAttribute("sakai.html.head.css.skin", CSSUtils.getCssToolSkinLink(CSSUtils.getSkinFromSite(site)));
req.setAttribute("sakai.html.head.js", headJs);
req.setAttribute("sakai.html.body.onload", bodyonload.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public static String getCssToolBase()
return cssToolBase;
}

/**
* Returns a URL for the tool_base.css suitable for putting in an href= fieldresolved for CDN
*
* @return <code>cssToolBase</code> URL for the tool_base.css
*/
public static String getCssToolBaseCDN()
{
String cssToolBaseCDN = PortalUtils.getCDNPath()
+ getCssToolBase()
+ PortalUtils.getCDNQuery();
return cssToolBaseCDN;
}


/**
* Captures the (yes) overly complex rules for the skin folder naming convention
*
Expand Down Expand Up @@ -72,6 +86,21 @@ public static String getCssToolSkin(String skinFolder)
return cssToolSkin;
}

/**
* Returns a URL for the print.css suitable for putting in an href= field for media="print".
*
* @param <code>skinFolder</code>
* where the print.css skin lives for this site.
* @return <code>cssPrintSkin</code> URL for the print.css
*/
public static String getCssPrintSkin(String skinFolder)
{
skinFolder = adjustCssSkinFolder(skinFolder);
String skinRepo = ServerConfigurationService.getString("skin.repo");
String cssPrintSkin = skinRepo + "/" + skinFolder + "/print.css";
return cssPrintSkin;
}

/**
* Returns a URL for the portal.css suitable for putting in an href= field.
*
Expand All @@ -87,6 +116,21 @@ public static String getCssPortalSkin(String skinFolder)
return cssPortalSkin;
}

/**
* Returns a URL for the portal.css suitable for putting in an href= field resolved for CDN
*
* @param <code>skinFolder</code>
* where the portal.css skin lives for this site.
* @return <code>cssPortalSkin</code> URL for the portal.css
*/
public static String getCssPortalSkinCDN(String skinFolder)
{
String cssPortalSkin = PortalUtils.getCDNPath()
+ getCssPortalSkin(skinFolder)
+ PortalUtils.getCDNQuery();

return cssPortalSkin;
}

/**
* Returns a URL for the tool.css suitable for putting in an href= field.
Expand All @@ -105,31 +149,86 @@ public static String getCssToolSkinCDN(String skinFolder)
}

/**
* Returns a URL for the tool.css suitable for putting in an href= field.
* Returns a URL for the print.css suitable for putting in an href= field for media="print"
*
* @param <code>site</code>
* The site for this tool.
* @return <code>cssToolSkin</code> URL for the tool.css
* @param <code>skinFolder</code>
* where the print.css skin lives for this site.
* @return <code>cssPrintSkin</code> URL for the print.css
*/
public static String getCssToolSkin(Site site)
public static String getCssPrintSkinCDN(String skinFolder)
{
String skinFolder = site.getSkin();
return getCssToolSkin(skinFolder);
String cssPrintSkin = getCssPrintSkin(skinFolder);
if ( cssPrintSkin.startsWith("/") ) {
cssPrintSkin = PortalUtils.getCDNPath() + cssPrintSkin + PortalUtils.getCDNQuery();
}
return cssPrintSkin;
}

/**
* Returns a URL for the tool.css suitable for putting in an href= field.
*
* @param <code>site</code>
* The site for this tool.
* @return <code>cssToolSkin</code> URL for the tool.css
/**
* Convenience method to retrieve the skin folder from a site
* @param site
* @return skinFolder
*/
public static String getCssToolSkinCDN(Site site)
{
String skinFolder = site.getSkin();
return getCssToolSkinCDN(skinFolder);
public static String getSkinFromSite(Site site) {
String skinFolder=null;
if (site!=null) {
skinFolder = site.getSkin();
}
return skinFolder;
}

/**
* Gets the full CSS link for the portal skin
* @param skin
* @return headCssPortalSkin
*/
public static String getPortalSkinLink(String skin) {
String headCssPortalSkin = "<link href=\""
+ getCssPortalSkinCDN(skin)
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"screen, tty, tv, handheld, projection\" />\n";
return headCssPortalSkin;
}

/**
* Gets the full CSS link for the tool skin (including print version)
* @param skin
* @param isInlineRequest
* @return headCssToolBse
*/
public static String getCssToolBaseLink(String skin,boolean isInlineRequest) {
String headCssPortalSkin = "<link href=\""
+ getCssPortalSkinCDN(skin)
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"screen, tty, tv, handheld, projection\" />\n";

}
String headCssToolBase = "<link href=\""
+ getCssToolBaseCDN()
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"screen, tty, tv, handheld, projection\" />\n";

if ( ! isInlineRequest ) {
headCssToolBase = headCssPortalSkin + headCssToolBase;
}
return headCssToolBase;

}

public static String getCssToolSkinLink(String skin) {
String headCssToolSkin = "<link href=\""
+ getCssToolSkinCDN(skin)
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"screen, tty, tv, handheld, projection\" />\n";

String headCssPrintSkin = "<link href=\""
+ getCssPrintSkinCDN(skin)
+ "\" type=\"text/css\" rel=\"stylesheet\" media=\"print\" />\n";

return headCssToolSkin + headCssPrintSkin;
}

public static String getCssHead(String skin, boolean isInlineRequest) {
// setup html information that the tool might need (skin, body on load,
// js includes, etc).
String headCssToolBase = getCssToolBaseLink(skin,isInlineRequest);
String headCssToolSkin = getCssToolSkinLink(skin);
return headCssToolBase + headCssToolSkin;
}

}

0 comments on commit b9eac64

Please sign in to comment.