Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
$URL: https://source.sakaiproject.org/svn/portal/tags/portal-base-2.9.0-b06/portal-render-engine-impl/impl/src/java/org/sakaiproject/portal/charon/velocity/VelocityPortalRenderEngine.java $ $Id: VelocityPortalRenderEngine.java 92546 2011-05-03 18:48:27Z csev@umich.edu $ Copyright (c) 2005, 2006, 2007, 2008 The Sakai Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.osedu.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.sakaiproject.portal.charon.velocity;
 
 import java.io.Writer;
 import java.util.List;
 import java.util.Map;
 
 
A velocity render engine adapter

Author(s):
ieb
Version:
$Rev: 92546 $
Since:
Sakai 2.4
 
 
 public class VelocityPortalRenderEngine implements PortalRenderEngine
 {
 	private static final Log log = LogFactory.getLog(VelocityPortalRenderEngine.class);
 
 
 	private boolean debug = false;
 
 
 
 	private String defaultSkin = "defaultskin";
 
 	private boolean styleAble = false;
 
 	private boolean styleAbleContentSummary = false;
 
 
 
 
 	private String portalConfig = "portalvelocity.config";
 
 	public void init() throws Exception
 	{
 		try
 		{
 			 = .getBoolean("portal.styleable"false);
 					"portal.styleable.contentSummary"false);
 			 = .getString("portal.templates""neoskin");
 		}
 		catch (Exception ex)
 		{
 					.warn("No Server configuration service available, assuming default settings ");
 		}
 		if (  == null ) {
			.warn("No session Manager, assuming test mode ");
		}
				"org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
		.setProperty("runtime.log.logsystem.log4j.category""ve.portal");
		Properties p = new Properties();
		InputStream in = null;
		try {
		if ( in == null ) {
			throw new RuntimeException("Unable to load configuration "+);
else {
			.info("Loaded "+);
		}
		p.load(in);
		Map<StringStringm = new HashMap<StringString>();
		m.put("name");
		m.put("display""Default");
		/*
		 * m = new HashMap(); m.put("name", "skintwo"); m.put("display", "Skin
		 * Two"); availablePortalSkins.add(m);
		 */
		.getTemplate("/vm/"++"/macros.vm");
		}
		catch (IOException e) {
			throw new RuntimeException("Exception encounterd:  " + ee);
		}
		finally {
			if (in != null) {
				try {
					in.close();
catch (IOException e) {
					//not much to do
				}
			}
		}
	}
	{
		// this is just for testing, it should be in the path or portal to
		// ensure that the skin remains.
		rc.put("pageSkins");
		rc.put("styleableStyleSheet"generateStyleAbleStyleSheet());
		rc.put("styleableJS"generateStyleAbleJavaScript());
		rc.put("styleable");
		String portalSkin = ;
		if (request != null)
		{
			HttpSession session = request.getSession();
			portalSkin = (Stringsession.getAttribute("portalskin");
			String newPortalSkin = request.getParameter("portalskin");
			if (newPortalSkin != null && newPortalSkin.length() > 0)
			{
				session.setAttribute("portalskin"newPortalSkin);
				portalSkin = newPortalSkin;
				.debug("Set Skin To " + portalSkin);
			}
			else
			{
				if (portalSkin == null || portalSkin.length() == 0)
				{
					portalSkin = ;
					session.setAttribute("portalskin"portalSkin);
				}
			}
			rc.put("pageCurrentSkin"portalSkin);
			.debug("Current Skin is " + portalSkin);
		}
		else
		{
			.debug("No Request Object Skin is default");
			rc.put("pageCurrentSkin");
		}
		InputStream stream = null;
		try
		{
			Properties p = new Properties();
			stream = this.getClass().getResourceAsStream(
					"/" + portalSkin + "/options.config");
			p.load(stream);
		}
		catch (Exception ex)
		{
			.info("No options loaded "ex);
		finally {
			if (stream != null) {
				try {
					stream.close();
catch (IOException e) {
					//not much to do in this case
				}
			}
		}
		return rc;
	}
	public void render(String templatePortalRenderContext rcontextWriter out)
			throws Exception
	{
		String skin = (Stringvc.get("pageCurrentSkin");
		if (skin == null || skin.length() == 0)
		{
			skin = ;
		}
		if (!.equals(skin))
		{
			.getTemplate("/vm/" + skin + "/macros.vm");
		}
		.mergeTemplate("/vm/" + skin + "/" + template + ".vm",
	}
	{
		{
			if (sp != null)
			{
				String userId = getCurrentUserId();
				try
				{
					return sp.generateStyleSheet(userId);
					// ca.utoronto.atrc.transformable.common.prefs.Preferences
					// prefsForUser = TransformAblePrefsService
					// .getTransformAblePreferences(userId);
					// return StyleAbleService.generateStyleSheet(prefsForUser);
				}
				catch (Exception e)
				{
					return null;
				}
			}
		}
		return null;
	}

Returns:
null if no JavaScript is needed
	{
		// Enable / disable StyleAble javascript based on property flag.
		{
			if (sp != null)
			{
				String userId = getCurrentUserId();
				try
				{
					return sp.generateJavaScript(userId);
					// ca.utoronto.atrc.transformable.common.prefs.Preferences
					// prefsForUser = TransformAblePrefsService
					// .getTransformAblePreferences(userId);
					// return StyleAbleService.generateJavaScript(prefsForUser);
				}
				catch (Exception e)
				{
					return null;
				}
			}
		}
		return null;
	}
	{
		if (  == null ) {
			return "test-mode-user";
else {
		}
	}
	public boolean isDebug()
	{
		return ;
	}
	public void setDebug(boolean debug)
	{
		this. = debug;
	}

Returns:
the context
	{
		return ;
	}

Parameters:
context the context to set
	public void setContext(ServletContext context)
	{
		this. = context;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.sakaiproject.portal.api.PortalRenderEngine#setupForward(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse,
	 *      org.sakaiproject.tool.api.Placement, java.lang.String)
	 */
			Placement pString skin)
	{
		String headJs = (Stringreq.getAttribute("sakai.html.head.js");
		String headCssToolBase = (Stringreq.getAttribute("sakai.html.head.css.base");
		String headCssToolSkin = (Stringreq.getAttribute("sakai.html.head.css.skin");
		String bodyonload = (Stringreq.getAttribute("sakai.html.body.onload");
		String customUserCss = generateStyleAbleStyleSheet();
		if (customUserCss != null)
		{
			customUserCss = "<style type=\"text/css\" title=\"StyleAble\">\n"
customUserCss + "</style>\n";
		}
		else
		{
			customUserCss = "";
		}
		if (styleAbleJs != null)
		{
			styleAbleJs = "<script "
"type=\"text/javascript\" language=\"JavaScript\">\n" + styleAbleJs
"\n</script>\n";
			headJs = headJs + styleAbleJs;
			bodyonload = bodyonload + "styleableonload();";
		}
		headCssToolSkin = headCssToolSkin + customUserCss;
		String headCss = headCssToolBase + headCssToolSkin + customUserCss;
		String head = headCss + headJs;
		req.setAttribute("sakai.html.head"head);
		req.setAttribute("sakai.html.head.css"headCss);
		req.setAttribute("sakai.html.head.js"headJs);
		req.setAttribute("sakai.html.head.css.base"headCssToolBase);
		req.setAttribute("sakai.html.head.css.skin"headCssToolSkin);
		req.setAttribute("sakai.html.body.onload"bodyonload);
	}

Returns:
the stylable
	public boolean isStyleAble()
	{
		return ;
	}

Parameters:
stylable the stylable to set
	public void setStyleAble(boolean styleAble)
	{
		this. = styleAble;
	}

Parameters:
instance
	public void setPortalService(PortalService instance)
	{
		this. = instance;
	}

Returns:
the serverConfigurationService
	{
	}

Parameters:
serverConfigurationService the serverConfigurationService to set
			ServerConfigurationService serverConfigurationService)
	{
		this. = serverConfigurationService;
	}

Returns:
the sessionManager
	{
	}

Parameters:
sessionManager the sessionManager to set
	public void setSessionManager(SessionManager sessionManager)
	{
		this. = sessionManager;
	}

Returns:
the portalConfig
	{
		return ;
	}

Parameters:
portalConfig the portalConfig to set
	public void setPortalConfig(String portalConfig)
	{
		this. = portalConfig;
	}
New to GrepCode? Check out our FAQ X