All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class distans.DataLoader

java.lang.Object
   |
   +----distans.DataLoader

public class DataLoader
extends Object
The DataLoader makes out the layer between the MakePageApplet and ReadAnswerApplet and the Cgi scripts on the Server. It also contains two hashtables with references to the PageData and AnswerData data structures. All Pages and Answers are retrived from the server when run() is called.


Variable Index

 o father
A reference to the Applet used for displaying messages and getting parameters from the HTML containing the Applet
 o local
If this is true the Applet will search information on the local harddisk this is used for debuging
 o makeAltCgi
 o makeCrossCgi
 o makeWrittenCgi
 o pages
Hashtable with the pages as PageData objects.
 o shouldInitPages
This is true if the DataLoader should get the Pages from the server Set in the constructor
 o shouldInitStudents
This is true if teh DataLoader should get the Students and there answers from the server.
 o students
Hastable with key = studentCedula and value = AnswerData
 o subject
The name of the course/subject

Constructor Index

 o DataLoader(Applet)
Constructor, creates the hashtables and sets the local variable from the HTML containing the Applet
 o DataLoader(Applet, boolean, boolean)
Does the same as the other contsructor, but sets wether the DataLoader should retrive both Pages and StudentAnswers
 o DataLoader(Applet, int)
Used by the CreateCourseApplet

Method Index

 o addPageData(PageData)
Adds a PageData object to the pages hashtable
 o appendVariable(String, String, StringBuffer)
This is used to append a variable name and data on a String that is going to be sent to the CGI script This is the syntax of cgi strings &variableName=variableData&variableName=variableData etc.
 o BRToNewLine(String)
Does the reverse the newLineToBR
 o changePageDataTitle(String, String)
Call this to change the PageTitle of a PageData object.
 o checkPassword(String, String, String)
Calls the checkPassword.perl that checks the teatchers password on the server
 o createPageOnServer(String, String, String)
Stores a page on the server.
 o getAllPageDataFromServer()
Calls the script getAllDataFiles.perl from the server the HTML page returned.
 o getAllStudentAnswers()
Calls the script getAllAnswers.perl on the server, and parses the returned HTML page.
 o getAnswerData(String)
Gets the AnswerData object for a student.
 o getPageData(String)
 o getPageTitles()
 o getSendAltString(PageData, StringBuffer)
Get the String that is sent to the server for a QuestionPage of type alt.
 o getSendCrossString(PageData, StringBuffer)
Get the String that is sent to the server for a Cross type QuestionPage
 o getSendWrittenString(PageData, StringBuffer)
Get the String that is sent to the server for a QuestionPage of type written.
 o getStream(String)
Contacts a CGI script on the server using a normal GET call.
 o getStudentCedulas()
 o getStudentNames()
 o getStudents()
Calls the getStudents.perl script on the server for retriving the students for the selected subject.
 o getSubject()
 o newLineToBR(String)
Used to replace new lines char
strings This is used for the written questions
 o removePageFromServer(String)
Removes a page from the server by calling the rmPage.perl on the server.
 o run()
Depending on the settings of shouldInitPages and shouldInitStudents this method calls getAllPageDataFromServer, getStudents and getAllStudentsAnswers for the selected subject.
 o sendPage(String)
Stores a page on the server by calling the createPageOnServer method Besides that this method creates the common part of the String sent.
 o setSubject(String)
Sets the subject for the information that the DataLoader should load when run is called
 o underScoreToWhite(String)
Used to replace "_" in the pageTitles with spaces so they can be displayed without underscore to the user.
 o whiteToUnderScore(String)
Used to replace spaces in the pageTitles with "_" so they can be used as filenames on the server

Variables

 o makeCrossCgi
 static final String makeCrossCgi
 o makeAltCgi
 static final String makeAltCgi
 o makeWrittenCgi
 static final String makeWrittenCgi
 o shouldInitPages
 boolean shouldInitPages
This is true if the DataLoader should get the Pages from the server Set in the constructor

 o shouldInitStudents
 boolean shouldInitStudents
This is true if teh DataLoader should get the Students and there answers from the server. Set in the constructor

 o pages
 Hashtable pages
Hashtable with the pages as PageData objects. Key = pageTitle value = PageData

 o students
 Hashtable students
Hastable with key = studentCedula and value = AnswerData

 o father
 Applet father
A reference to the Applet used for displaying messages and getting parameters from the HTML containing the Applet

 o local
 boolean local
If this is true the Applet will search information on the local harddisk this is used for debuging

 o subject
 String subject
The name of the course/subject

Constructors

 o DataLoader
 public DataLoader(Applet father,
                   int dum)
Used by the CreateCourseApplet

 o DataLoader
 private DataLoader(Applet father)
Constructor, creates the hashtables and sets the local variable from the HTML containing the Applet

Parameters:
father - the Applet that uses the DataLoader
 o DataLoader
 public DataLoader(Applet father,
                   boolean initPages,
                   boolean initStudents)
Does the same as the other contsructor, but sets wether the DataLoader should retrive both Pages and StudentAnswers

Parameters:
father, - the Applet

Methods

 o getSubject
 public String getSubject()
Returns:
the subject that the DataLoader has loaded information for.
 o setSubject
 public void setSubject(String sub)
Sets the subject for the information that the DataLoader should load when run is called

 o run
 public void run()
Depending on the settings of shouldInitPages and shouldInitStudents this method calls getAllPageDataFromServer, getStudents and getAllStudentsAnswers for the selected subject. The DataLoader is currently not threaded but could easily be so.

 o getAllStudentAnswers
 private void getAllStudentAnswers()
Calls the script getAllAnswers.perl on the server, and parses the returned HTML page. The page returned contains information about the students answers on each page. Each student has an AnswerData object which stores the answers for each page.

 o whiteToUnderScore
 public static String whiteToUnderScore(String str)
Used to replace spaces in the pageTitles with "_" so they can be used as filenames on the server

Returns:
a new String without spaces
 o underScoreToWhite
 public static String underScoreToWhite(String str)
Used to replace "_" in the pageTitles with spaces so they can be displayed without underscore to the user.

Returns:
a new String with underscores replaced to spaces
 o newLineToBR
 public static String newLineToBR(String str)
Used to replace new lines char
strings This is used for the written questions

Parameters:
str - the string to be examine
Returns:
a String without newlines
 o BRToNewLine
 public static String BRToNewLine(String str)
Does the reverse the newLineToBR

 o checkPassword
 public String checkPassword(String userName,
                             String password,
                             String subject)
Calls the checkPassword.perl that checks the teatchers password on the server

Parameters:
userName - the user name to be checked
password - the pass word to be checked
subject - the subject that the user wants access to.
Returns:
a code describing if the user had acces or no, see the CGI script documentation for details.
 o changePageDataTitle
 public void changePageDataTitle(String oldTitle,
                                 String newTitle)
Call this to change the PageTitle of a PageData object. As the title is used as key its a bit more complex than just setting a variable

 o getPageData
 public PageData getPageData(String title)
Parameters:
title - the title of the PageData object.
Returns:
the PageData object for the pageTitle
 o addPageData
 public void addPageData(PageData pd)
Adds a PageData object to the pages hashtable

Parameters:
pd - the PageData to be added
 o getAnswerData
 public AnswerData getAnswerData(String cedulaOrName)
Gets the AnswerData object for a student.

Parameters:
cedulaOrName - a String with either the name of the student or his cedula no.
Returns:
the AnswerData object in hashtable students that is associated with the student.
 o getAllPageDataFromServer
 private void getAllPageDataFromServer()
Calls the script getAllDataFiles.perl from the server the HTML page returned. The information is parsed and a new PageData object with the questions and answers is created for each Page. The PageData object is put in the pages hashtable.

 o removePageFromServer
 public boolean removePageFromServer(String pageTitle)
Removes a page from the server by calling the rmPage.perl on the server. If the page haven't yet been stored on the server the script is never called, instead the PageData object is removed from the Hashtable pages.

Parameters:
pageTitle - the page to remove
Returns:
true if the remove operation went alright, false if there occured an error on the server or while connecting to it.
 o getPageTitles
 public Enumeration getPageTitles()
Returns:
an Enumeration with all the PageTitles
 o getStudentCedulas
 public Enumeration getStudentCedulas()
Returns:
an Enumeration with all the students cedulas
 o getStudentNames
 public Enumeration getStudentNames()
Returns:
s an Enumeration with all the students names
 o getStudents
 public void getStudents()
Calls the getStudents.perl script on the server for retriving the students for the selected subject. The page returned is parsed and a AnswerData object is created for each student

 o getSendCrossString
 private String getSendCrossString(PageData pd,
                                   StringBuffer sendThis)
Get the String that is sent to the server for a Cross type QuestionPage

Parameters:
the - PageData object containing the Cross Page Data
sendThis - a StringBuffer with the String that should be sent, the StringBuffer is filled with information that is common for all QuestionPages
Returns:
the String with the cross data
 o getSendWrittenString
 private String getSendWrittenString(PageData pd,
                                     StringBuffer sendThis)
Get the String that is sent to the server for a QuestionPage of type written.

Parameters:
the - PageData object containing the Written Page Data
sendThis - a StringBuffer with the String that should be sent, the StringBuffer is filled with information that is common for all QuestionPages
Returns:
the String with the written data
 o getSendAltString
 private String getSendAltString(PageData pd,
                                 StringBuffer sendThis)
Get the String that is sent to the server for a QuestionPage of type alt.

Parameters:
the - PageData object containing the Alternative Page Data
sendThis - a StringBuffer with the String that should be sent, the StringBuffer is filled with information that is common for all QuestionPages
Returns:
the String with the alt data
 o sendPage
 public boolean sendPage(String pageTitle)
Stores a page on the server by calling the createPageOnServer method Besides that this method creates the common part of the String sent. The other part depends on the QuestionPage type and is filled in by this method calling getSendAltString, getSendCrossString, getSendWrittenString

 o appendVariable
 private void appendVariable(String variableName,
                             String variableData,
                             StringBuffer appendToThis)
This is used to append a variable name and data on a String that is going to be sent to the CGI script This is the syntax of cgi strings &variableName=variableData&variableName=variableData etc. etc.

Parameters:
variableName - the name of the variable e.g. subject
variableData - the data for the variable e.g. TEST
appendToThis - a StringBuffer with the send string so far
 o getStream
 BufferedReader getStream(String cgiString) throws IOException
Contacts a CGI script on the server using a normal GET call.

Parameters:
cgiString - the name of the script e.g. getAllStudents
Returns:
a BufferedReader which could be read from to get the cgi scripts reply
 o createPageOnServer
 public boolean createPageOnServer(String s,
                                   String scriptName,
                                   String pageTitle)
Stores a page on the server. As a page contains of a lot of data the POST method is used. To make a data file with the page on the server the script makeData.perl is called. To make the server create the HTML QuestionPage from the data file, depending on the type one of makeCrossPage.perl, makeAltPage.perl or makeWrittenPage.perl is called. This method does not work on some systems using proxy, the reason is unknown. The code making the POST call is takne from JavaWorld magazine.


All Packages  Class Hierarchy  This Package  Previous  Next  Index