WebReference.com - Part 2 of Extending the JXTA Shell, from Early Adopter JXTA (Wrox Press). (1/4) | WebReference

WebReference.com - Part 2 of Extending the JXTA Shell, from Early Adopter JXTA (Wrox Press). (1/4)

current pageTo page 2To page 3To page 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:

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:

SwitchDescription
-eCreate an element. The element name should immediately follow, and then any content of the element
-cCombine 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
-dCreate 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.


current pageTo page 2To page 3To page 4
[next]

Created: January 28, 2002
Revised: January 28, 2002


URL: http://webreference.com/programming/jxta/chap3/2/