<commit_before>package au.edu.labshare.schedserver.scormpackager.sahara;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

import biz.source_code.miniTemplator.MiniTemplator;

import au.edu.uts.eng.remotelabs.schedserver.dataaccess.entities.RigType;
import au.edu.uts.eng.remotelabs.schedserver.dataaccess.entities.RigTypeMedia;
import au.edu.labshare.schedserver.scormpackager.sahara.RigMedia;

import au.edu.labshare.schedserver.scormpackager.sahara.BlurbDecorator;
import au.edu.labshare.schedserver.scormpackager.sahara.PictureDecorator;
import au.edu.labshare.schedserver.scormpackager.sahara.LaunchButtonDecorator;
import au.edu.labshare.schedserver.scormpackager.sahara.TitleDecorator;


public class RigLaunchPageCreator 
{
	private MiniTemplator templator;
	
	ILaunchPage decoratedPage;
	
	public static final String TEMPLATE_DOCUMENT_TYPE = "scormpackager_template_1";
	
	private LaunchPage launchPage;
	private TitleDecorator titleDecorator;
	private PictureDecorator picDecorator;
	private BlurbDecorator blurbDecorator;
	private LaunchButtonDecorator launchButtonDecorator;
	
	/*
	 * This is the output path we are going to use using the templating engine
	 */
	private String path = null;
	
	public RigLaunchPageCreator()
	{
		try
		{
			Properties defaultProps = new Properties();
		    FileInputStream in;

		    //in = new FileInputStream("resources/scormpackager.properties"); //TODO: Should place this as a static string
		    String cwd = new java.io.File( "." ).getCanonicalPath();
		    if(!cwd.contains("ScormPackager"))
				in = new FileInputStream(cwd + "/ScormPackager/" + "resources/scormpackager.properties"); //TODO: Should place this as a static string
			else
				in = new FileInputStream("resources/scormpackager.properties"); //TODO: Should place this as a static string
		    
	        defaultProps.load(in);
	        in.close();
			templator = new MiniTemplator(defaultProps.getProperty(TEMPLATE_DOCUMENT_TYPE));
		}
		catch(IOException e)
		{
			e.printStackTrace(); //TODO: Need to replace with Sahara Logger
		}
	}
	
	public void setOutputPath(String path)
	{
		this.path = path;
	}
	
	public String getOutputPath()
	{
		return this.path;
	}
	
	// We want to create the LaunchPage by tapping into DataAccess Layer
	public String createLaunchPage(String experimentName, org.hibernate.Session session)
	{		
		launchPage = new LaunchPage();
		RigMedia rigMedia = new RigMedia(session);
		RigType rigType = rigMedia.getRigType(experimentName);
		
		Set<RigTypeMedia> rigTypeMediaSet;
		rigTypeMediaSet = rigType.getMedia();
		
		for(RigTypeMedia itemRigTypeMedia : rigTypeMediaSet)
		{
			// Should decorate based on the type of the media to update
			if(itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_JPEG) || 
			   itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_PNG)  ||
			   itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_GIF))
			{
				picDecorator = new PictureDecorator(launchPage);
				picDecorator.setPicLocation(itemRigTypeMedia.getFileName());
				decoratePage(picDecorator);
			}
			else if(itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_TXT)) //If it is just plain txt we are assuming blurb
			{
				blurbDecorator = new BlurbDecorator(launchPage);<commit_msg>Fixed up the jpeg so now in an LMS it properly displays the 'attached' picture.<commit_after>package au.edu.labshare.schedserver.scormpackager.sahara;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

import biz.source_code.miniTemplator.MiniTemplator;

import au.edu.uts.eng.remotelabs.schedserver.dataaccess.entities.RigType;
import au.edu.uts.eng.remotelabs.schedserver.dataaccess.entities.RigTypeMedia;
import au.edu.labshare.schedserver.scormpackager.sahara.RigMedia;

import au.edu.labshare.schedserver.scormpackager.sahara.BlurbDecorator;
import au.edu.labshare.schedserver.scormpackager.sahara.PictureDecorator;
import au.edu.labshare.schedserver.scormpackager.sahara.LaunchButtonDecorator;
import au.edu.labshare.schedserver.scormpackager.sahara.TitleDecorator;
import au.edu.labshare.schedserver.scormpackager.utilities.ScormUtilities;


public class RigLaunchPageCreator 
{
	private MiniTemplator templator;
	
	ILaunchPage decoratedPage;
	
	public static final String TEMPLATE_DOCUMENT_TYPE = "scormpackager_template_1";
	
	private LaunchPage launchPage;
	private TitleDecorator titleDecorator;
	private PictureDecorator picDecorator;
	private BlurbDecorator blurbDecorator;
	private LaunchButtonDecorator launchButtonDecorator;
	
	/*
	 * This is the output path we are going to use using the templating engine
	 */
	private String path = null;
	
	public RigLaunchPageCreator()
	{
		try
		{
			Properties defaultProps = new Properties();
		    FileInputStream in;

		    //in = new FileInputStream("resources/scormpackager.properties"); //TODO: Should place this as a static string
		    String cwd = new java.io.File( "." ).getCanonicalPath();
		    if(!cwd.contains("ScormPackager"))
				in = new FileInputStream(cwd + "/ScormPackager/" + "resources/scormpackager.properties"); //TODO: Should place this as a static string
			else
				in = new FileInputStream("resources/scormpackager.properties"); //TODO: Should place this as a static string
		    
	        defaultProps.load(in);
	        in.close();
			templator = new MiniTemplator(defaultProps.getProperty(TEMPLATE_DOCUMENT_TYPE));
		}
		catch(IOException e)
		{
			e.printStackTrace(); //TODO: Need to replace with Sahara Logger
		}
	}
	
	public void setOutputPath(String path)
	{
		this.path = path;
	}
	
	public String getOutputPath()
	{
		return this.path;
	}
	
	// We want to create the LaunchPage by tapping into DataAccess Layer
	public String createLaunchPage(String experimentName, org.hibernate.Session session)
	{		
		launchPage = new LaunchPage();
		RigMedia rigMedia = new RigMedia(session);
		RigType rigType = rigMedia.getRigType(experimentName);
		
		Set<RigTypeMedia> rigTypeMediaSet;
		rigTypeMediaSet = rigType.getMedia();
		
		for(RigTypeMedia itemRigTypeMedia : rigTypeMediaSet)
		{
			// Should decorate based on the type of the media to update
			if(itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_JPEG) || 
			   itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_PNG)  ||
			   itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_GIF))
			{
				picDecorator = new PictureDecorator(launchPage);
				picDecorator.setPicLocation(ScormUtilities.getFilenameFromPath(itemRigTypeMedia.getFileName(), "/")); //TODO: Not sure if this only works on UNIX systems
				decoratePage(picDecorator);
			}
			else if(itemRigTypeMedia.getMime().toString().equals(RigMedia.MIME_TXT)) //If it is just plain txt we are assuming blurb
			{
				blurbDecorator = new BlurbDecorator(launchPage);
{'fraction_non_alphanumeric': 0.09456797072896145, 'fraction_numerical': 0.00028145229383619476, 'mean_word_length': 4.726833199033038, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '987780', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2260, 'n_words': 477}