------------------------------------------ The Tools and the TslShell ------------------------------------------- ------------------------------------------- 1. Overview ------------------------------------------- The TslShell is part of the JArtifex framework (http://de.geocities.com/jartifex/index.html). The TslShell class should be used as superclass for any console applications, using the commandline input. One reference example is already implemented inside the class 'tsl.tools.shell.jshell' The TslShell provides you the following: - configurable command shell instantiating through an xml file - all commands are configurable through an xml file - a lot of useful file methods ------------------------------------------- 1.1 Introduction ------------------------------------------- Mostly everything in this class is configurable through the xml file. Therefore everytime, a keyword will be used inside this documentation, the default value of this keyword will be taken. ------------------------------------------- 2. Using it without own implementations ------------------------------------------- ------------------------------------------- 2.1 Configuring keywords and any variables ------------------------------------------- Inside the jshell.xml script you can define some keywords and any variables. This will be done inside the jshell tag. For the complete list of defineable keywords look at the table 4.3 . If you want to use some predefined variables in your shell scripts, you do it in this part, too (e.g.: myVar="myValue"). ------------------------------------------- 2.2 Defining ShellCommands ------------------------------------------- Have a look at this example: There are 2 steps. First the properties of the shellcommand, then the properties of the method to start. option: ------- The options may some single characters like 'rl'. This option lets the TslShell look for the 'recursive' and the 'long' parameter, to give it to the method. Be careful: If you define this options, the user has to use them with this command. If you want to use Boolean parameters with values like 'true' and 'false', you must not define option characters! keywords: --------- Keywords are some words, devided by ','. If you try to start this command inside the TslShell, the inputanalyser expects a value after the keyword (belonging to it). This is the same as defining a key-value-pair. array: ------ Array=true means, that the last method parameter is an array to put the last arguments into. If the last method parameter is of type String, the TslShell puts the last given arguments of your input into this string. For example, if you type: 'sql select * from test' All words after 'sql' will be given as only one parameter for the command 'sql'. reflectionarray: ---------------- Reflectionarray is an intern property. For more information, have a look at the javadoc. default: -------- You can give static arguments as method parameters. If you want, that the method 'cmd' has everytime as first argument 'hepp', set default="hepp". If you start then 'cmd hepp2', the TslShell will start the command: 'cmd hepp hepp2' variables: ---------- The given method will store some results into this variables. Each method should store by default its main content to the variable 'item'! The basic class stores the return value to a variable named equal to the command name! output: ------- If output="standard" all output of this method will be given to the standardoutput (monitor). ------------------------------------------- 2.3 Starting the shell ------------------------------------------- Before you start it the first time, you have to start the setup batch file. This sets the jartifex_home variable to find the tsl classes. Then you can start the batch file 'tools/shell.bat'. If you need any help, type 'help' (and use the enter key). To see detailed information about a command, type help + commandname (e.g.: 'help jsed'). If you want to see , what you typed or started before, type stack. This lists you the history commands. To exit the shell, type 'exit'. ------------------------------------------- 2.3.1 Starting any command ------------------------------------------- You can start any command through keyboard, file, commandline or clipboard. The next chapter lists the commandtypes. ------------------------------------------- 2.3.2 Command types and there arguments ------------------------------------------- a.)There are 3 intern static commands: - help : shows a short help - stack : shows all historical commands - exit : exits the shell and the jvm b.)defining variables: $x=anything c.)Java expressions System.out.println(test) @x.toString() d.)Shellcommands (loaded through jshell.xml) dir -r -l e.)Pure java code starts and ends with 'purejava'. write any java code and execute it! There are six types of arguments: - options : starting with '-', ee.g.: -f) - key value pairs : starting '-' aand containing the '=' - input output def. : starting witth '<', '>', '>>' piping in and output streams - variables : starting with '$'.. - references : starting with '@' - booleans : 'true' or 'false' - alphanumeric text : any other paarameter ------------------------------------------- 2.3.2.1 ShellCommand (defined through the xml file) ------------------------------------------- Have a look at the jshell.xml file , to see all shellcommands, where the property 'name' of defines the command itself. The result of any shellcommand will be stored inside the variable $result and a variable with the same name as the command name. So, if you start the command 'ftp www.myhost.de myuser mypasswd' you can use the ftp variable like this: '@ftp.getCurrentDirectory()' ------------------------------------------- 2.3.2.2 Internal Command (static defined inside the code) ------------------------------------------- There are three static commands: help : shows a short list of all shellcommands stack : lists all commands from history exit : exits the shell application and the jvm ------------------------------------------- 2.3.2.3 Java Command (full classpath + method + parameter) ------------------------------------------- The most important is to input the full classpath like: java.lang.System.out.println("test"); you can input any oneline java expression that uses objects of members or methodresults. But you cannot use casts or any java language keywords. If you want to execute a block of pure java code, you have to look here <>. ------------------------------------------- 2.3.2.4 Pure java code ------------------------------------------- If you enter: purejava you go into the pure java block code. Now you can write any java code. At the end, you have to enter 'purejava' again and the java code will be compiled and executed! The compiled class has the following standard content: The following imports are set: tsl.* tsl.tools.* java.util.* javax.swing.* The following methods can be used directly: getParent() get(String control) show(String text) show(TableVector tv) Important: THE CLASSPATH HAS TO CONTAIN THE JAVA-VM-LIBRARY 'lib/tools.jar' Example: show(((JArtifex)parent).getJArtifexInfo()); ------------------------------------------- 2.3.2.5 Commands starting with a variable sign ------------------------------------------- ------------------------------------------- 2.3.3 Variables and Object-References ------------------------------------------- You can set variables (starting with '$') and use them anywhere. For example: $jartifex_home=c:/jartifex dir $jartifex_home You can use this variables inside java expressions: @jartifex_home.toString() ------------------------------------------- 2.3.4 Using the commandstack ------------------------------------------- To show the commandstack enter 'stack' (+Return) This lists you all commands from the history. If you enter '$' together with the number of the desired stack command this command will be started. For example: $1 (+Return) 2.3.5 Using the reference implementation jshell This shell provides you a big number of tools to start inside this shell. Here is a list of all defined and configured commands: command comment ------------------------------------------- ask ask {text} beanvisualizer beanvisualizer {instance} browse browse {file} calc calc {numerical operations without spaces} call call {script} capital capital {capital, interest, years} cd cd {path[*]} connect connect {driver} {url} {user} {passwd} copy copy {source} {destination} debug debug {true|false} delete delete {files} dir dir {files} [-r] [-l] [-n] [-t] [-a] edit edit {file} eval eval {expression} [calculate] ff ff {file} [-c] [-r] [-a] ffor ffor {files} [step {delimiter}] {shell-command} find find {expression} {files} [-r] for for {iteratorobject} {shell-command} ftp ftp {host} [user] [passwd] ftp0 ftp0 {host} get get {url} if if ({expression}) {shell-command} info info [object [-g:gui]]|[-l:locals]|[-o:globals]|[-e:lasterror] j j {classpath} {method} {parameter} jar jar {files} jartifex jartifex {jartifex xml file} javac javac {class} javap javap {classpath} jsed jsed {search regexp} {replace regexp} {file filter} [-r] [flags] [outdir] jstart jstart [java-expression] loadclass loadclass {urlpath, classname} logging logging (false: prints all output to the standardoutput) mail mail {smtpServer} {to} {from} {subject} {body} man shows a graphical editor listing the helpfile mkdir mkdir {path} modem modem {initstring} monitor monitor {name} {keylogger|key|action|focus|mouse} more more {files} [-r: recursive] [-a: ask for each file] move move {source} {destination} newinstance newinstance {urlpath, classname} objectbrowser objectbrowser {instance} observe observe {object, milliseconds} option option [key] [value] print print {expression} printer printer {text} [printerdevice] [-q:crossformat] printfile printfile {textfile} [printerdevice] [-q:crossformat] pwd pwd (shows the current directory) select select {list} [selectColumn] [gui] [readfromfile] set set {variable name} ={value} show show {data} socket socket {host} {port} sql sql {expression} ssh ssh {host} start start {os command} telnet telnet {host} [user] [passwd] view view {gif/jpg file} wgrab wgrab {Url} {level} {otherHosts} The command line (OS depending!) -------------------------------- start:jshell[shell ] [globaloption] {{ [file | string]} | [option]} [>outputfile] shell: : you can define the location from where the configurationfile will be loaded : default is './jshell.xml' modes: -c : start command from clipboard -f : start command from file -s : open input shell with initial string globaloptions: -debug : debug mode -trace : tracemode options: -r : recursive -y : ask before doing an action -format : formats the output (html, rtf, notproportional) static commands: help: prints this help exit: exits the input stack: shows command-stack Some commandline hints: ----------------------- variables start with '$' (e.g.: $home=c:/home ) you can use object references starting with '@' (e.g.:@home.toString() ) you can start javamethods (e.g.: tsl.StringUtil.calculate(1+2) ) you can start pure javacode inside blocks starting with '{', ending with '}' be careful with '='. The shell in Windows eliminates this sign! ------------------------------------------- 3. Implementing your own shell ------------------------------------------- Extend the class 'tsl.tools.shell.TslShell', looking at the reference implementation 'tsl.tools.shell.jshell'. Implement a main method, starting the method 'createShellFromXml(...)'. Implement your new class with your wanted methods and create your configuration file, simular to the existing file 'jshell.xml', but defining commands, starting your new methods. Have a look at 2.3.2 and 4.2 for informations about the static commands and the argument types , you can use. ------------------------------------------- 3.1 Implementing the XmlObject interface ------------------------------------------- ------------------------------------------- 3.2 Embedding it into the TslShell ------------------------------------------- ------------------------------------------- 3.3 Using existing methods ------------------------------------------- ------------------------------------------- 4.1 Table: command line ------------------------------------------- ------------------------------------------- 4.2 Table: static commands and keywords ------------------------------------------- help prints a short help overview exit exits the inputloop stack prints all commands from history -f behind this option, you specifyy a script to start the commands from -s starts the shell loop -c starts commands from system cliipboard -shell defines the path to the connfiguration xmlfile (default: ./jshell.xml) -r recursive -l long (e.g. descriptions) -y don't ask -format formats the output. The ouutput will be embedded to some of the following formats: html, rtf, notproportional. For example: -format=html ------------------------------------------- 4.3 Table: Defineable Keywords ------------------------------------------- keyname default ------------------------------------------- name JArtifex TslShell Version 0.9 prompt [tsl] option - valuepair = variable $ start start parameter parameter inputstream < outputstream > or >> comment # blockstart purejava blockend purejava javaexpression (\\w+\\.)+\\w+\\s*\\(.*\\) -------------------------------------------- ------------------------------------------- 4.4 Table: used classes, interfaces and other files ------------------------------------------- -------------------------------------------- tsl.StringUtil tsl.Console tsl.MethodThread tsl.tools.shell.TslShell tsl.tools.shell.ShellCommand tsl.tools.xml.XmlObject --------------------------------------------