WebReference.com - Part 2 of Extending the JXTA Shell, from Early Adopter JXTA (Wrox Press). (1/4)
[next] |
Early Adopter JXTA
Creating A Complex Shell Extension
[The following is the conclusion of our series of excerpts from the Wrox Press title, Early Adopter JXTA.]
One of the most frustrating things with the basic set of commands included with the
JXTA shell is that we cannot just create a structured document from the command line in any simple way.
In an earlier example, we needed to create a structured document using a text editor, save it into
a file, and then use the importfile
command to import it. This is, needless to say,
very tedious.
We will now create a custom command that will enable us to:
- Create elements in a structured document and store them into environment variables
- Compile elements stored in environment variables and form new elements
- Create a structured document of any type consisting of one or more elements
We will call this command mkdoc
.
The mkdoc
command will enable us to build a complex structured document,
completely using the command line. The switches available will be:
Switch | Description |
-e | Create an element. The element name should immediately follow, and then any content of the element |
-c | Combine elements in environment variables to form a new element. The new element name should immediately follow, and then any environment variables that contain elements to become children of the new element |
-d | Create a structured document, of specified document type, consisting of a set of elements stored in environment variables |
For example, we can create a name element simply:
JXTA> name=mkdoc Âe name Joe Manzini
JXTA> cat name
<name>Joe Manzini</name>
Or combine multiple elements into larger one:
JXTA> phone=mkdoc Âe phone 333-3333
JXTA> cust=mkdoc Âc customer name phone
JXTA> cat cust
<customer><name>Joe Manzini</name><phone>333-3333</phone></customer>
We can then create a structured document using:
JXTA> custdata=mkdoc Âd CustData cust
JXTA> env
name = String (class java.lang.String)
...
custdata = StructuredDocument (class net.jxta.impl.document.LiteXMLDocument)
...
cust = String (class java.lang.String)
phone = String (class java.lang.String)
...
Note that custdata is a structured document, and it contains:
JXTA> cat custdata
<?xml version="1.0"?>
<!DOCTYPE CustData>
<CustData>
<customer>
<name>
Joe Manzini
</name>
<phone>
333-3333
</phone>
</customer>
</CustData>
We can see now we will be able to create potentially large and complex structured
documents using this mkdoc
command.
[next] |
Created: January 28, 2002
Revised: January 28, 2002
URL: https://webreference.com/programming/jxta/chap3/2/