/**********************************************************************************
 * $URL$
 * $Id$
 **********************************************************************************
 *
 * Copyright (c) 2003, 2004 The Regents of the University of Michigan, Trustees of Indiana University,
 *                  Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
 * 
 * Licensed under the Educational Community License Version 1.0 (the "License");
 * By obtaining, using and/or copying this Original Work, you agree that you have read,
 * understand, and will comply with the terms and conditions of the Educational Community License.
 * You may obtain a copy of the License at:
 * 
 *      http://cvs.sakaiproject.org/licenses/license_1_0.html
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **********************************************************************************/

// package
package org.sakaiproject.component.legacy.coursemanagement;

// imports
import java.util.List;
import java.util.Vector;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.service.legacy.coursemanagement.Course;
import org.sakaiproject.service.legacy.coursemanagement.CourseManagementProvider;

/**
 * <p>
 * Sample of course management provider.
 * </p>
 * <p>
 * Todo: %%% to be implemented; read course info from some config file.
 * </p>
 * 
 * @author University of Michigan, CHEF Software Development Team
 * @version $Revision$
 */
public class SampleCourseManagementProvider implements CourseManagementProvider
{
	/** Our log (commons). */
	private static Log M_log = LogFactory.getLog(SampleCourseManagementProvider.class);

	/** Sample coursed. */
	protected Course[] m_courses = null;

	/**********************************************************************************************************************************************************************************************************************************************************
	 * Dependencies and their setter methods
	 *********************************************************************************************************************************************************************************************************************************************************/

	/**********************************************************************************************************************************************************************************************************************************************************
	 * Init and Destroy
	 *********************************************************************************************************************************************************************************************************************************************************/

	/**
	 * Final initialization, once all dependencies are set.
	 */
	public void init()
	{
		try
		{
			M_log.info("init()");
		}
		catch (Throwable t)
		{
			M_log.warn("init(): ", t);
		}

		// make sample courses
		Course c = new Course();
		c.setId("2005,FALL,,SMPL,001,001");
		c.setTermId("FALL 2005");
		c.setTitle("Sample Course");
		m_courses = new Course[1];
		m_courses[0] = c;

	} // init

	/**
	 * Returns to uninitialized state. You can use this method to release resources thet your Service allocated when Turbine shuts down.
	 */
	public void destroy()
	{
		M_log.info("destroy()");

	} // destroy

	/**********************************************************************************************************************************************************************************************************************************************************
	 * CourseManagementProvider implementation
	 *********************************************************************************************************************************************************************************************************************************************************/

	/**
	 * @inheritDoc
	 */
	public String getCourseName(String courseId)
	{
		for (int i = 0; i < m_courses.length; i++)
		{
			if (m_courses[i].getId().equals(courseId))
			{
				return m_courses[i].getTitle();
			}
		}
		return null;
	}

	/**
	 * @inheritDoc
	 */
	public Course getCourse(String courseId)
	{
		for (int i = 0; i < m_courses.length; i++)
		{
			if (m_courses[i].getId().equals(courseId))
			{
				return m_courses[i];
			}
		}
		return null;
	}

	/**
	 * @inheritDoc
	 */
	public List getCourseMembers(String courseId)
	{
		for (int i = 0; i < m_courses.length; i++)
		{
			if (m_courses[i].getId().equals(courseId))
			{
				return m_courses[i].getMembers();
			}
		}
		return new Vector();
	}

	/**
	 * @inheritDoc
	 */
	public List getInstructorCourses(String instructorId, String termYear, String termTerm)
	{
		List rv = new Vector();
		for (int i = 0; i < m_courses.length; i++)
		{
			rv.add(m_courses[i]);
		}
		return rv;
	}
}




@@ -4528,44 +4528,190 @@
 %7B%0A%09%09
-for (int i = 0; i %3C m_course
+StringBuffer tab = new StringBuffer();%0A%09%09String%5B%5D fields;%0A%09%09%0A%09%09// A single course with a single section; tab is course and section%0A%09%09fields = courseId.split(%22,%22);%0A%09%09if (field
 s.length
 ; i+
@@ -4698,37 +4698,37 @@
 f (fields.length
-; i++
+ == 6
 )%0A%09%09%7B%0A%09%09%09if (m_c
@@ -4724,100 +4724,166 @@
 %0A%09%09%09
-if (m_courses%5Bi%5D.getId().equals(courseId))%0A%09%09%09%7B%0A%09%09%09%09return m_courses%5Bi%5D.getTitle();%0A%09
+tab.append(fields%5B3%5D); //Subject%0A%09%09%09tab.append(%22 %22);%0A%09%09%09tab.append(fields%5B4%5D); //Catalog number%0A%09%09%09tab.append(%22 %22);%0A%09%09%09tab.append(fields%5B5%5D); //Section%0A
 %09%09%7D%0A%09%09
-%7D
 %0A%09%09r
@@ -4880,37 +4880,50 @@
 %09%09%7D%0A%09%09%0A%09%09return 
-null;
+tab.toString();%0A%09%09
 %0A%09%7D%0A%0A%09/**%0A%09 * @i

Fix to SAK-2222: SiteAction has brittle code which depends on CourseProvider ID Format