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.
-
father
- A reference to the Applet used for displaying messages and getting parameters from the HTML containing the Applet
-
local
- If this is true the Applet will search information on the local harddisk this is used for debuging
-
makeAltCgi
-
-
makeCrossCgi
-
-
makeWrittenCgi
-
-
pages
- Hashtable with the pages as PageData objects.
-
shouldInitPages
- This is true if the DataLoader should get the Pages from the server
Set in the constructor
-
shouldInitStudents
- This is true if teh DataLoader should get the Students and there answers from the server.
-
students
- Hastable with key = studentCedula and value = AnswerData
-
subject
- The name of the course/subject
-
DataLoader(Applet)
- Constructor, creates the hashtables and sets the local variable from the HTML containing the Applet
-
DataLoader(Applet, boolean, boolean)
- Does the same as the other contsructor, but sets wether the DataLoader should retrive both Pages and StudentAnswers
-
DataLoader(Applet, int)
- Used by the CreateCourseApplet
-
addPageData(PageData)
- Adds a PageData object to the pages hashtable
-
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.
-
BRToNewLine(String)
- Does the reverse the newLineToBR
-
changePageDataTitle(String, String)
- Call this to change the PageTitle of a PageData object.
-
checkPassword(String, String, String)
- Calls the checkPassword.perl that checks the teatchers password on the server
-
createPageOnServer(String, String, String)
- Stores a page on the server.
-
getAllPageDataFromServer()
- Calls the script getAllDataFiles.perl from the server the HTML page returned.
-
getAllStudentAnswers()
- Calls the script getAllAnswers.perl on the server, and parses the returned HTML page.
-
getAnswerData(String)
- Gets the AnswerData object for a student.
-
getPageData(String)
-
-
getPageTitles()
-
-
getSendAltString(PageData, StringBuffer)
- Get the String that is sent to the server for a QuestionPage of type alt.
-
getSendCrossString(PageData, StringBuffer)
- Get the String that is sent to the server for a Cross type QuestionPage
-
getSendWrittenString(PageData, StringBuffer)
- Get the String that is sent to the server for a QuestionPage of type written.
-
getStream(String)
- Contacts a CGI script on the server using a normal GET call.
-
getStudentCedulas()
-
-
getStudentNames()
-
-
getStudents()
- Calls the getStudents.perl script on the server for retriving the students for the selected subject.
-
getSubject()
-
-
newLineToBR(String)
- Used to replace new lines char
strings
This is used for the written questions
-
removePageFromServer(String)
- Removes a page from the server by calling the rmPage.perl on the server.
-
run()
- Depending on the settings of shouldInitPages and shouldInitStudents this method calls
getAllPageDataFromServer, getStudents and getAllStudentsAnswers for the selected subject.
-
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.
-
setSubject(String)
- Sets the subject for the information that the DataLoader should load when run is called
-
underScoreToWhite(String)
- Used to replace "_" in the pageTitles with spaces so they can be displayed without
underscore to the user.
-
whiteToUnderScore(String)
- Used to replace spaces in the pageTitles with "_" so they can be used as filenames on the server
makeCrossCgi
static final String makeCrossCgi
makeAltCgi
static final String makeAltCgi
makeWrittenCgi
static final String makeWrittenCgi
shouldInitPages
boolean shouldInitPages
- This is true if the DataLoader should get the Pages from the server
Set in the constructor
shouldInitStudents
boolean shouldInitStudents
- This is true if teh DataLoader should get the Students and there answers from the server.
Set in the constructor
pages
Hashtable pages
- Hashtable with the pages as PageData objects.
Key = pageTitle value = PageData
students
Hashtable students
- Hastable with key = studentCedula and value = AnswerData
father
Applet father
- A reference to the Applet used for displaying messages and getting parameters from the HTML containing the Applet
local
boolean local
- If this is true the Applet will search information on the local harddisk this is used for debuging
subject
String subject
- The name of the course/subject
DataLoader
public DataLoader(Applet father,
int dum)
- Used by the CreateCourseApplet
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
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
getSubject
public String getSubject()
- Returns:
- the subject that the DataLoader has loaded information for.
setSubject
public void setSubject(String sub)
- Sets the subject for the information that the DataLoader should load when run is called
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.
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.
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
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
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
BRToNewLine
public static String BRToNewLine(String str)
- Does the reverse the newLineToBR
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.
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
getPageData
public PageData getPageData(String title)
- Parameters:
- title - the title of the PageData object.
- Returns:
- the PageData object for the pageTitle
addPageData
public void addPageData(PageData pd)
- Adds a PageData object to the pages hashtable
- Parameters:
- pd - the PageData to be added
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.
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.
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.
getPageTitles
public Enumeration getPageTitles()
- Returns:
- an Enumeration with all the PageTitles
getStudentCedulas
public Enumeration getStudentCedulas()
- Returns:
- an Enumeration with all the students cedulas
getStudentNames
public Enumeration getStudentNames()
- Returns:
- s an Enumeration with all the students names
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
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
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
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
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
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
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
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