JudoScript.COM Design principles of Judo the sport and the language
HomeJudo LanguageJuSP PlatformJamaica Language 
Judo ReferenceJuSP ReferenceWiki/WeblogTutorials/PresentationsDownloadsGoodiesFeedback  
Book: The Judo Language 0.9
 








In this chapter:

Chapter 17. Internet Scripting

By James Jianbo Huang

printer-friendly version

Not done yet. For now, please read this article.

 
HTTP Client Features   to be done


 
HTTP Server Features   to be done


 
Create A HTTP Proxy Server   to be done


 
UDP and Broadcasting   to be done


 
Send Mail   to be finished

You can send e-mails directly from Judo. To use the e-mail feature, you need to have the javax.mail packages in the class path. It can be obtained from various places, such as the "j2ee.jar" file in the J2EE installation. Before sending any messages, you must first connect to a mail server by calling the system function:

mail::connect( server [ , username [ , password ] ] );
mail::disconnect;

The server may include a port number, separated by a colon. Once connected, you can easily send one, two, fitfy or a million e-mails from a simple Judo script; spamming is never easier. Well, if one does want to spam, there are zillions of ways anyway.

The syntax for sending mail is:

SendMail ::= mail::send [ charset ] ( ( from | to | cc | bcc | attach | subject | body | htmlBody ) :Expr )+

As you see, text and/or HTML messages can be sent at the same time. You can specify character sets for addresses, subject and bodies. If charset is set to mail::send, both the text and HTML bodies will use it. A charset can have "charest=". The following two examples are equivalent:

  mail::send 'iso-2022-jp' ...
  mail::send 'charset=iso-2022-jp' ...

Alternatively, you can call the system function setCharset() to set the language character set for the whole language environment. The mail::send command uses that if no charset is explicitly specified in itself. This global character set may affect text encoding used in other places.

Files can be attached; messages can be sent to a list of "to", "cc" and/or "bcc" recipients; within each list, recipients are separated by commas. Each clause can appear at most once. For the message bodies, the here-doc is a big convenience. Here is an example:

mail::send
   from: 'syang@exotic.nat'
     to: 'foodback@judoscript.com, syang56@yahoo.cum'
subject: 'bug report'
   body: [[*
         Hi there,

         Judo is cool. I'm doing a lot and will do a lot more
         with it.

         I think I've found a bug. I have a program, 'tvcontrol.judo';
         there is a function like this:

           function switchTV $on {
             if $on { turnOnTV(); } else { turnOffTV(); }
           }

         however, when it is called with $on=3, it turns off my VCR!
         I believe this is a bug in Judo that, when the value
         is not 0 or 1, it emits erroneous radio shock waves that
         affect other appliances than the intended one. Please take
         a look. Thank you!

         Best regards,
         -- Steve Young
         *]];

The following example sends out trial software to newly registered users, whose information is stored in a database. For each user with status "NEW", a zip file and a "readme.txt" file are sent, and his/her status is changed to "TRIAL VERSION" in the database. This program is likely executed by a scheduled job that runs at midnight or later.

db::connect to 'jdbc:oracle:thin:@localhost:1521:userdb', 'onlyme', 'uggess';

db::query u:
  select email, lastname, solute from usertbl where status='NEW';

db::prepare: update userdb set status='TRIAL VERSION' where email=?;
while u.next() {
  sendSoftware(u.email, u.lastname, u.solute);
  db::update with @1 = u.email;
}

function sendSoftware email, lname, solute
{
  mail::send
     from: 'info@judoscript.com'
       to: email
  subject: 'The software. Thank you!'
   attach: 'readme.txt, software.zip'
     body: [[*
           Dear (* solute *) (* lname *),

           Thank you very much for your interest in this software.
           Attached is a zip file for the software and a readme
           text file. Follow the instructions therein for
           installation and using. Enjoy!

           Please visit www.judoscript.com for the latest news
           and information. Thank you!

           Sincerely,
           Judo
           *]]
 htmlBody: [[*
           <html><body>
           <p>Dear (* solute *) (* lname *),

           <p>Thank you very much for your interest in <i>this software</i>.
           Attached is a <u>zip file</u> for the software and a <u>readme
           text</u> file. Follow the instructions therein for installation
           and using. Enjoy!

           <p>Please visit <a href=http://www.judoscript.com>judoscript.com</a>
           for the latest news and information. Thank you!

           <p>Sincerely,
           <p>Judo
           </body></html>
           *]]
  ;
}

 
SSH and SCP   to be done

The SSH and SCP features uses ISNetworks' distribution of MindTerm package, a GPL'ed open-source pure Java SSH/SCP bundle. It is a GUI program that you can use daily; its SCP screen looks like a FTP GUI client. Very handy! Download it from ISNetworks. Make sure the version is "version 1.2.1 SCP release 3" or up. Unpack and put the class jar file into your classpath, and run

%java mindbright.application.MindTerm

If it is the first time use, it prompts you for host, user and password, and generates necessary keys automatically. You should run it to establish such environment before using Judo's SSH/SCP features. By the way, the nice SCP screen is available on its "File" menu, not so obvious to the first-time users.

Once the jar file is in the classpath and you have set up the environment, please refer to the language spec for how to use. It is rather straightforward.


 
FTP   to be done


 
back to top
 



Copyright © 2001-2005 JudoScript.COM. All Rights Reserved.