Yparxoyn pros to paron treis kuries klaseis poy yposthrizontai -- CGI, Email kai HTML. Skeftomai na pros8esw klaseis gia na antimetwpisw ta MIME-diamorfwmena eisagomena (input) kai ejagomena (output) -- MIMEin & MIMEout, antistoixa.
Yparxoyn epishs merikes support kai test klaseis.
CGI_Test,
Email_Test kai
HTML_Test skopeuoyn na xrhsimopoih8oun gia na
elegjoyn thn egkatastash sas.
Mporoun epishs na xrhsimopoih8oun san ena shmeio-ekkinhshs gia ta dika sas programmata Java poy xrhsimopoioun ayth th biblio8hkh klasewn.
H
Text klash einai h yperklash kai gia tis duo klaseis, thn
Email
kai thn HTML
.
public class CGI
H CGI klash krataei tis ``CGI Plhrofories'' -- Metablhtes periballontos
apo ton diakomisth istou kai to onoma/timh poy stelnontai apo mia forma
otan h submit energeia einai epilegmenh.
Oles oi plhrofories apo8hkeuontai se ena Properties
antikeimeno klashs.
Ayth h klash einai sto paketo ``Orbits.net''.
CGI() // Kataskeyasths.
getNames() // Pairnei th lista onomatwn.
getValue() // Pairnei thn timh formas kata prosdiorismeno onoma.
CGI_Test
.
Kataskeyazei ena antikeimeno poy periexei ta dia8esima CGI dedomena.
public CGI()
Otan kataskeyazetai ena antikeimeno CGI, oles oi dia8esimes CGI plhrofories anarrofountai se apo8hkh topika sto neo antikeimeno.
Kanei lista twn onomatwn poy einai orismenes gia na exoyn antistoixes times.
public Enumeration getKeys ()
Parexei thn plhrh lista twn onomatwn gia ta opoia antistoixes times einai orismenes.
Mia Enumeration
olwn twn orismenwn onomatwn.
Epanakta thn value sysxetismenh me to name poy exei oristei.
public String getValue ( String name )
Ayth h me8odos parexei th antistoixia metaju twn
names
kai values
poy stelnontai apo mia HTML forma.
To kleidi kata to opoio oi times epilegontai.
Ena String
poy perilambanei thn timh.
Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn klash CGI
kai ena programma elegxoy poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to paketo Java CGI leitoyrgei swsta.
main() // Programma main().
CGI
.
Parexei mia main()
me8odo.
public static void main( String argv[] )
Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy den kanei tipota allo apo to na anaferei mia lista me ola ta dia8esima onoma/timh zeygaria kai tis trexoyses times toys.
Epixeirhmata perasmena sto programma apo
to java.cgi
script.
Pros to paron axrhsimopoihth.
public class Email extends Text
Mhnumata sxhmatizontai me thn Text
klash add*()
me8odoys
kai tis e-mail-sygkekrimenes me8odoys poy prosti8entai apo aythn thn klash.
Otan oloklhrw8ei, to mhnyma stelnetai ston proorismo toy.
Ayth h klash einai sto paketo ``Orbits.net''.
Email() // Kataskeyasths.
send() // Stelnei to e-mail mhnyma.
sendTo() // Pros8etei enan proorismo gia to mhnyma.
subject() // Ry8mizei to 8ema: gia to mhnyma.
Email_Test, Text
.
Kataskeyazei ena antikeimeno to opoio 8a periexei ena email mhnyma.
public Email()
Ry8mizei ena keno mhnyma gia na oloklhrw8ei apo tis Email me8odoys.
Text
.
Stelnei to e-mail mhnyma.
public void send ()
Ayth diamorfwnei kai stelnei to mhnyma. An kamia dieu8ynsh proorismou den exei ry8mistei, de lambanetai kamia energeia.
Pros8etei enan proorismo gia ayto to mhnyma.
public String sendTo ( String address )
Pros8etei thn address
sth lista proorismwn gia
aythn thn me8odo.
Den yparxei kanena orio ru8mishs ston ari8mo proorismwn poy ena e-mail mhnyma mporei na exei.
Eimai sigoyros pws an sxhmatisete th lista arketa megalh, mporeite na yperbei te
to mege8os ths listas parametrwn poy o Mail Transport
Agent mporei na apodex8ei h na katanalwsete th mnhmh sas.
Enas proorismos gia na steilete ayto to mhnyma.
Stelnei to 8ema gia ayto to mhnyma.
public void subject ( String subject )
Ayth h me8odos ry8mizei to keimeno gia thn grammh Subject:
toy e-mail.
An klh8ei perissoteres apo mia fores, to teleytaio ry8mismeno 8ema einai ayto poy xrhsimopoieitai.
To keimeno ths Subject:
grammhs aytou toy mhnumatos.
Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn Email
klash
kai ena test programma poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to Java CGI
paketo leitoyrgei swsta.
main() // Programma main().
Email
.
Parexei mia main()
me8odo.
public static void main( String argv[] )
Ayto einai to shmeio kataxwrhshs gia ena programma CGI
poy anaferei mia lista me ola ta dia8esima onoma/timh zeygaria kai tis trexoyses times toys.
Epishs, 8a steilei ayth th lista sthn ka8orismenh dieu8ynsh sthn Email
metablhth.
Epixeirhmata perniountai sto programma apo
to java.cgi
senario.
Pros to paron axrhsimopoihta.
public class HTML extends Text
Mhnumata sxhmatizontai me thn Text
klash add*()
me8odoys
kai tis HTML-sygkekrimenes me8odoys poy prosti8entai apo aythn thn klash.
Otan oloklhrw8ei, to mhnyma stelnetai ston proorismo toy.
Pros to paron, den yparxei elegxos sfalmatwn gia na epibebaiwsei oti oi me8odoi dhmioyrgias-listas xrhsimopoiountai se mia swsth seira, opote o programmatisths prepei na pairnei metra gia na mhn parabiasei thn HTML suntajh.
Ayth h klash einai sto paketo ``Orbits.net''.
HTML() // Kataskeyasths.
author() // Ry8mizei to onoma toy syggrafea toy eggrafoy.
definitionList() // 3ekina mia lista orismwn.
definitionListTerm() // Pros8etei enan oro sth lista orismwn.
endList() // Teleiwnei mia lista.
listItem() // Pros8etei mia kataxwrish se mia lista.
send() // Stelnei to HTML mhnyma.
title() // Ry8mizei to keimeno gia ton titlo toy eggrafoy.
HTML_Test, Text
.
Dhmioyrgei ena antikeimeno poy 8a periexei ena HTML mhnyma.
public HTML()
Ry8mizei ena keno mhnyma na symplhrw8ei apo tis HTML me8odoys.
Text
.
Ry8mizei to onoma toy syggrafea toy eggrafoy.
public void author ( String author )
Ry8mizei to onoma toy syggrafea toy eggrafoy se author
.
To keimeno poy prepei na xrhsimopoih8ei san o syggrafeas aytou toy mhnumatos.
title()
.
Arxizei mia lista orismwn.
public void definitionList ()
Arxizei mia lista orismwn.
H definition list einai mia lista eidikeymenh etsi wste ka8e kataxwrish sth
lista einai enas term akoloy8oumenos apo to text orismwn
gia ayton ton oro.
H arxh mias listas orismwn 8a prepei na akoloy8eitai apo
toylaxiston) ena oros/keimeno zeygari kai mia klhsh sthn endList()
me8odo.
Shmeiwste pws, pros to paron, oi listes den mporoun na einai fwliasmenes (nested)
h mia mesa sthn allh.
definitionListTerm()
, endList()
,
listItem()
.
Pros8etei enan oro sth lista orismwn.
public void definitionListTerm ()
Pros8etei enan oro sth lista orismwn.
To keimeno gia to kommati toy oroy ths trexoysas kataxwrhshs listas 8a prepei na episynaptetai
sto mhnyma afou h me8odos aytou kaleitai kai prin mia antistoixh
listItem
me8odos kaleitai.
definitionList()
, listItem()
.
Teleiwnei mia lista.
public void endList ()
Teleiwnei mia lista. Ayth h me8odos kleinei mia lista. Shmeiwste oti, pros to paron, oi listes den mporoun na einai fwliasmenes (nested), h mia mesa sthn allh.
definitionList()
.
Pros8etei mia kataxwrhsh se mia lista.
public void listItem ()
public void listItem ( String item )
public boolean listItem ( String term, String item )
Pros8etei mia kataxwrhsh se mia lista.
An h prwth forma xrhsimopoieitai, to keimeno gia thn trexwn antikeimeno listas 8a prepei na
episynaptetai sto mhnyma afou h me8odos ayth kaleitai kai prin alles
me8odoi listas kalountai.
Sthn deuterh kai trith forma, to item
keimeno prosdiorizetai san mia
parametros sth me8odo anti na (h epipros8etws sto na) episynaptetai sto
mhnyma.
H trith forma einai eidikh stis listes orismwn kai parexei kai ton
oro kai toy orismo ths kataxwrhshs listas.
To keimeno ayths ths kataxwrhshs listas.
To keimeno ayths ths listas orismwn toy kommatiou toy oroy kataxwrhshs.
definitionList()
, definitionListTerm()
,
endList()
.
Stelnei to HTML mhnyma.
public void send ()
Stelnei to HTML mhnyma.
Ry8mizei to keimeno gia ton titlo eggrafoy.
public void title ( String title )
Ry8mizei to keimeno gia ton titlo eggrafoy.
To keimeno aytou toy titloy toy mhnumatos.
author()
.
Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn HTML
klash
kai ena test programma poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to paketo
Java CGI leitoyrgei swsta.
main() // Programma main().
HTML
.
Parexei mia main()
me8odo.
public static void main( String argv[] )
Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy epistrefei mia lista twn dia8esimwn onoma/timh zeygariwn se ena HTML eggrafo, me to ka8e onoma/timh zeygari na apeikonizetai se ena stoixeio listas orismwn.
Epixeirhmata perasmena sto programma apo
to java.cgi
senario.
Pros to paron de xrhsimopoiountai.
public abstract class Text
H klash einai h yperklash twn Email
kai HTML
klasewn.
Mhnumata xtizontai me tis me8odoys se aythn thn klash kai symplhrwnetai kai
diamorfwnetai me tis me8odoys se ypoklaseis.
Ayth h klash einai sto paketo ``Orbits.text''.
Text() // Kataskeyasths.
add() // Pros8etei keimeno se ayto to antikeimeno.
addLineBreak() // Pros8etei mia diakoph grammhs.
addParagraph() // Pros8etei mia diakoph paragrafoy.
Email
, HTML
.
Pros8etei keimeno se ayto to antikeimeno.
public void add ( char addition )
public void add ( String addition )
public void add ( StringBuffer addition )
Pros8etei addition
sta periexomena aytou toy antikeimenoy keimenoy.
Keimeno poy prepei na proste8ei sto antikeimeno keimenoy
addLineBreak()
, addParagraph()
.
Anagkazei mia diakoph grammhs se ayto to shmeio sto keimeno.
public void addLineBreak ()
Pros8etei mia diakoph grammhs sto keimeno sto trexon shmeio.
add()
, addParagraph()
.
Arxizei mia nea paragrafo.
public void add ()
Arxizei mia nea paragrafo se ayto to shmeio sth roh keimenoy.
add()
, addLineBreak()
.