⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 api.java

📁 用于Scorm课件对API的操作
💻 JAVA
字号:
/* Simple prototype for a SCORM API applet */
/* Programming by: Robert Pohl - robert@learnways.com */

import java.applet.Applet;    
import java.awt.Graphics; 
import java.net.*;
import java.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.*;

              
public class API extends Applet {
	String WebService;/*提交服务地址*/
	String StudentId;/*学员ID*/
	String CoursewareId;/*课件ID*/
	String Identifier;/*章节点标识*/
	public void init() {
		WebService = getParameter("url");
		StudentId = getParameter("StudentId");
		CoursewareId = getParameter("CoursewareId");	
	}
	
	public void LMSSetIdentifier(String parameter)
	{
		Identifier = parameter;
	}
	
	public void paint(Graphics g)
	{
		//g.drawString("API Started...", 0,15);
	}

	public String LMSInitialize(String parameter)
	{
		if (parameter == "")
		{
			return "true";
		}
		else
		{			
			return GetXml("",parameter,"LMSInitialize");
		}
	}
	
	public String LMSGetValue(String element)
	{
		/* returns a string, information from the LMS */
		return GetXml("",element,"LMSGetValue");
	}
	
	public String LMSSetValue(String element, String value)
	{
		/* Set a value to LMS from SCO */
		/* returns true or false */	
		if (element == "")
		{
			return "true";
		}
		else
		{
			return GetXml(value,element,"LMSSetValue");
		}
	}
	
	public String LMSCommit(String parameter)
	{
		/* returns true or false */
		if (parameter == "")
		{
			return "true";
		}
		else
		{
			return GetXml("",parameter,"LMSCommit");
		}
		
	}
	
	public String LMSFinish(String parameter)
	{
		/* returns true or false */
		if (parameter == "")
		{
			return "true";
		}
		else
		{
			return GetXml("",parameter,"LMSFinish");
		}
	}
	
	public String LMSGetLastError()
	{
		/* returns latest error code. 0 = no error */
		return GetXml("","","LMSGetLastError");
		
	}
		
	public String LMSGetErrorString(String errorCode)
	{
		/* returns textual error message */
		return GetXml("",errorCode,"LMSGetErrorString");		
	}
	
	public String LMSGetDiagnostic(String errorCode)
	{
		/* returns textual error message */
		return GetXml("",errorCode,"LMSGetDiagnostic");
	}

	 public String GetXml(String myData,String myParameter, String myAction)
	 {
		String s = WebService+myAction+"?StudentId="+StudentId+"&CoursewareId="+CoursewareId+"&Identifier="+Identifier+"&parameter="+myParameter+"&myvalue="+myData;
		String outPut="";		
		try
		{
			URL Url = new URL(s);
			InputStream in = Url.openStream();
			BufferedReader indata = new BufferedReader(new InputStreamReader(in));
			String rad;
	
			indata.readLine();
			indata.readLine();
			outPut = indata.readLine();
			int i = outPut.indexOf("</");
			String tagName = "value"; // this is the tagname of the value
			outPut = outPut.substring((int)(tagName.length()+4), (int)(outPut.length()-((tagName.length()+2)*2)+6));
		}
		catch(IOException e)
		{
			outPut="fel: "+e.getMessage();
		}
		return outPut;
	  }	
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -