<commit_before>/**********************************************************************************
 * $URL$
 * $Id$
 ***********************************************************************************
 *
 * 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.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.portal.api.PortalRenderContext;
import org.sakaiproject.portal.charon.velocity.VelocityPortalRenderEngine;
import org.sakaiproject.portal.util.BrowserDetector;
import org.sakaiproject.util.ResourceLoader;
import org.w3c.tidy.Tidy;

/**
 * <p>
 * This class operates as Mock portal to enable testing of a set of templates.
 * It can be used to drive any render engine, but is setup for the default
 * render engine. It is run as a unit test.
 * </p>
 */
public class MockCharonPortal extends HttpServlet
{


	/** Our log (commons). */
	private static Log log = LogFactory.getLog(MockCharonPortal.class);

	private VelocityPortalRenderEngine rengine;

	private File outputDir;

	private String outputFile;

	private Object resourceLoader;

	public MockCharonPortal(File outputDir) throws Exception
	{
		this.outputDir = outputDir;
		String renderEngineClass = VelocityPortalRenderEngine.class.getName();

		Class c = Class.forName(renderEngineClass);
		rengine = (VelocityPortalRenderEngine) c.newInstance();
		rengine.setPortalConfig("/testportalvelocity.config");
		rengine.setDebug(true);
		rengine.init();

	}


	public void doError(boolean withSession, boolean withToolSession) throws IOException
	{

		// start the response
		PortalRenderContext rcontext = startPageContext();
		
		
		if ( withSession ) {
			rcontext.put("s", new MockSession());
		}
		if ( withToolSession ) {
			rcontext.put("ts", new MockToolSession());
		}
		
		rcontext.put("req", new MockHttpServletRequest());

		showSession(rcontext);

		showSnoop(rcontext);

		sendResponse(rcontext, "error");
	}

	private void showSnoop(PortalRenderContext rcontext)
	{

		rcontext.put("snoopRequest", "snoopRequest");

		Map m = new HashMap();
		m.put("param1", "configparam1");
		m.put("param1", "configparam1");
		rcontext.put("snoopServletConfigParams", m);
		rcontext.put("snoopRequest", "snoopRequest");
		rcontext.put("snoopRequestHeaders", m);
		rcontext.put("snoopRequestParamsSingle", m);
		rcontext.put("snoopRequestParamsMulti", m);
		rcontext.put("snoopRequestAttr", m);
	}

	public void doGallery() throws IOException
	{
		PortalRenderContext rcontext = startPageContext();

		// the 'little' top area
		includeGalleryNav(rcontext);

		includeWorksite(rcontext);

		includeBottom(rcontext);

		sendResponse(rcontext, "gallery");
	}

	public void doNavLogin() throws IOException
	{
		// start the response
		PortalRenderContext rcontext = startPageContext();

		includeLogo(rcontext);

		sendResponse(rcontext, "login");
	}

	public void doPage() throws IOException
	{
		PortalRenderContext rcontext = startPageContext();

		includePage(rcontext);

		includeBottom(rcontext);

		sendResponse(rcontext, "page");
	}

	private PortalRenderContext startPageContext()
	{
		PortalRenderContext rcontext = rengine.newRenderContext(null);
		
		rcontext.put("pageSkinRepo", "skinRepo");
		rcontext.put("pageSkin", "skin");
		rcontext.put("pageTitle", "Web.escapeHtml(title)");
		rcontext.put("pageScriptPath", "getScriptPath()");
		rcontext.put("pageTop", Boolean.valueOf(true));
		rcontext.put("pageSiteType", "class=\"siteType\" ");
		rcontext.put("toolParamResetState", "PARM_STATE_RESET");
		rcontext.put("rloader", resourceLoader);
		

		rcontext.put("sitReset", "sitReset");
		rcontext.put("browser", new BrowserDetector("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2"));

		return rcontext;
	}

	public void doSite() throws IOException
	{
		PortalRenderContext rcontext = startPageContext();

		// the 'full' top area
		includeSiteNav(rcontext);

		includeWorksite(rcontext);

		includeBottom(rcontext);

		// end the response
		sendResponse(rcontext, "site");
	}

	public void doSiteFrameTop() throws IOException<commit_msg>NOJIRA<commit_after>/**********************************************************************************
 * $URL$
 * $Id$
 ***********************************************************************************
 *
 * 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.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.portal.api.PortalRenderContext;
import org.sakaiproject.portal.charon.velocity.VelocityPortalRenderEngine;
import org.sakaiproject.portal.util.BrowserDetector;
import org.sakaiproject.util.ResourceLoader;
import org.w3c.tidy.Tidy;

/**
 * <p>
 * This class operates as Mock portal to enable testing of a set of templates.
 * It can be used to drive any render engine, but is setup for the default
 * render engine. It is run as a unit test.
 * </p>
 */
public class MockCharonPortal extends HttpServlet
{

	/** Our log (commons). */
	private static Log log = LogFactory.getLog(MockCharonPortal.class);

	private VelocityPortalRenderEngine rengine;

	private File outputDir;

	private String outputFile;

	private Object resourceLoader;

	public MockCharonPortal(File outputDir) throws Exception
	{
		this.outputDir = outputDir;
		String renderEngineClass = VelocityPortalRenderEngine.class.getName();

		Class c = Class.forName(renderEngineClass);
		rengine = (VelocityPortalRenderEngine) c.newInstance();
		rengine.setPortalConfig("/testportalvelocity.config");
		rengine.setDebug(true);
		rengine.init();

	}


	public void doError(boolean withSession, boolean withToolSession) throws IOException
	{

		// start the response
		PortalRenderContext rcontext = startPageContext();
		
		
		if ( withSession ) {
			rcontext.put("s", new MockSession());
		}
		if ( withToolSession ) {
			rcontext.put("ts", new MockToolSession());
		}
		
		rcontext.put("req", new MockHttpServletRequest());

		showSession(rcontext);

		showSnoop(rcontext);

		sendResponse(rcontext, "error");
	}

	private void showSnoop(PortalRenderContext rcontext)
	{

		rcontext.put("snoopRequest", "snoopRequest");

		Map m = new HashMap();
		m.put("param1", "configparam1");
		m.put("param1", "configparam1");
		rcontext.put("snoopServletConfigParams", m);
		rcontext.put("snoopRequest", "snoopRequest");
		rcontext.put("snoopRequestHeaders", m);
		rcontext.put("snoopRequestParamsSingle", m);
		rcontext.put("snoopRequestParamsMulti", m);
		rcontext.put("snoopRequestAttr", m);
	}

	public void doGallery() throws IOException
	{
		PortalRenderContext rcontext = startPageContext();

		// the 'little' top area
		includeGalleryNav(rcontext);

		includeWorksite(rcontext);

		includeBottom(rcontext);

		sendResponse(rcontext, "gallery");
	}

	public void doNavLogin() throws IOException
	{
		// start the response
		PortalRenderContext rcontext = startPageContext();

		includeLogo(rcontext);

		sendResponse(rcontext, "login");
	}

	public void doPage() throws IOException
	{
		PortalRenderContext rcontext = startPageContext();

		includePage(rcontext);

		includeBottom(rcontext);

		sendResponse(rcontext, "page");
	}

	private PortalRenderContext startPageContext()
	{
		PortalRenderContext rcontext = rengine.newRenderContext(null);
		
		rcontext.put("pageSkinRepo", "skinRepo");
		rcontext.put("pageSkin", "skin");
		rcontext.put("pageTitle", "Web.escapeHtml(title)");
		rcontext.put("pageScriptPath", "getScriptPath()");
		rcontext.put("pageTop", Boolean.valueOf(true));
		rcontext.put("pageSiteType", "class=\"siteType\" ");
		rcontext.put("toolParamResetState", "PARM_STATE_RESET");
		rcontext.put("rloader", resourceLoader);
		
                String headCssToolBase = "<link href=\""
                        + "/tool_base.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
                String headCssToolSkin = "<link href=\"" 
                + "/tool.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
                String headCss = headCssToolBase + headCssToolSkin;
                String headJs = "<script type=\"text/javascript\" language=\"JavaScript\" src=\"/library/js/headscripts.js\"></script>\n";
                String head = headCss + headJs;

                rcontext.put("sakai_html_head", head);
                rcontext.put("sakai_html_head_css", headCss);
                rcontext.put("sakai_html_head_css_base", headCssToolBase);
                rcontext.put("sakai_html_head_css_skin", headCssToolSkin);
                rcontext.put("sakai_html_head_js", headJs);

		rcontext.put("sitReset", "sitReset");
		rcontext.put("browser", new BrowserDetector("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2"));

		return rcontext;
	}

	public void doSite() throws IOException
	{
		PortalRenderContext rcontext = startPageContext();

		// the 'full' top area
		includeSiteNav(rcontext);

		includeWorksite(rcontext);

		includeBottom(rcontext);

		// end the response
		sendResponse(rcontext, "site");
	}

	public void doSiteFrameTop() throws IOException
{'fraction_non_alphanumeric': 0.1584397036508078, 'fraction_numerical': 0.007497991609390342, 'mean_word_length': 4.701781170483461, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5533365', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3276, 'n_words': 801}