nu.xom.samples
Class RDDLToTable

java.lang.Object
  extended by nu.xom.NodeFactory
      extended by nu.xom.samples.RDDLToTable

public class RDDLToTable
extends nu.xom.NodeFactory

Demonstrates a custom NodeFactory that converts rddl:resource elements to XHTML tables. This is inspired by Example 8-11 in Processing XML with Java. In brief, it demonstrates that major modifications may have to take place in endElement but can still be effectively streamed.

rddl:resource elements are replaced by a simple table. The various attributes of the resource are mapped to different parts of the table. In particular, a rddl:resource like this:

<rddl:resource
        id="note-xlink2rdf"
       xlink:title="W3C NOTE XLink2RDF"
       xlink:role="http://www.w3.org/TR/html4/"
       xlink:arcrole="http://www.rddl.org/purposes#reference"
       xlink:href="http://www.w3.org/TR/xlink2rdf/"
       >
     <li>
       <a href="http://www.w3.org/TR/xlink2rdf/">
        W3C Note Harvesting RDF Statements from XLinks
      </a>
    </li>
</rddl:resource>

will turn into an XHTML table that looks like this:

<table id="note-xlink2rdf">
 <caption>W3C NOTE XLink2RDF</caption>
 <tr><td>Role: </td><td>http://www.w3.org/TR/html4/</td></tr>
 <tr><td>Arcrole: </td><td>http://www.rddl.org/purposes#reference</td></tr>
 <tr><td>Href: </td><td><a href="http://www.w3.org/TR/xlink2rdf/">
  http://www.w3.org/TR/xlink2rdf/</a></td></tr>
 <tr>
   <td colspan="2">
     <li>
       <a href="http://www.w3.org/TR/xlink2rdf/">
         W3C Note Harvesting RDF Statements from XLinks
       </a>
     </li>
   </td>
 </tr>
</table>

Version:
1.0
Author:
Elliotte Rusty Harold

Field Summary
static java.lang.String RDDL_NAMESPACE
           
static java.lang.String XHTML_NAMESPACE
           
static java.lang.String XLINK_NAMESPACE
           
 
Constructor Summary
RDDLToTable()
           
 
Method Summary
 nu.xom.Nodes finishMakingElement(nu.xom.Element element)
           Signals the end of an element.
static void main(java.lang.String[] args)
           
 nu.xom.Nodes makeDocType(java.lang.String rootElementName, java.lang.String publicID, java.lang.String systemID)
           Returns a new Nodes object containing a DocType object with the specified root element name, system ID, and public ID.
 
Methods inherited from class nu.xom.NodeFactory
finishMakingDocument, makeAttribute, makeComment, makeProcessingInstruction, makeRootElement, makeText, startMakingDocument, startMakingElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RDDL_NAMESPACE

public static final java.lang.String RDDL_NAMESPACE
See Also:
Constant Field Values

XHTML_NAMESPACE

public static final java.lang.String XHTML_NAMESPACE
See Also:
Constant Field Values

XLINK_NAMESPACE

public static final java.lang.String XLINK_NAMESPACE
See Also:
Constant Field Values
Constructor Detail

RDDLToTable

public RDDLToTable()
Method Detail

main

public static void main(java.lang.String[] args)

finishMakingElement

public nu.xom.Nodes finishMakingElement(nu.xom.Element element)
Description copied from class: nu.xom.NodeFactory

Signals the end of an element. This method should return the Nodes to be added to the tree. They need not contain the Element that was passed to this method, though most often they will. By default the Nodes returned contain only the built element. However, subclasses may return a list containing any number of nodes, all of which will be added to the tree at the current position in the order given by the list (subject to the usual well-formedness constraints, of course. For instance, the list should not contain a DocType object unless the element is the root element, and the document does not already have a DocType). All of the nodes returned must be parentless. If this method returns an empty list, then the element (including all its contents) is not included in the finished document.

To process an element at a time, override this method in a subclass so that it functions as a callback. When you're done processing the Element, return an empty list so that it will be removed from the tree and garbage collected. Be careful not to return an empty list for the root element though. That is, when the element passed to this method is the root element, the list returned must contain exactly one Element object. The simplest way to check this is testing if element.getParent() instanceof Document.

Do not detach element or any of its ancestors while inside this method. Doing so can royally muck up the build.

Overrides:
finishMakingElement in class nu.xom.NodeFactory
Parameters:
element - the finished Element
Returns:
the nodes to be added to the tree

makeDocType

public nu.xom.Nodes makeDocType(java.lang.String rootElementName,
                                java.lang.String publicID,
                                java.lang.String systemID)
Description copied from class: nu.xom.NodeFactory

Returns a new Nodes object containing a DocType object with the specified root element name, system ID, and public ID.

Subclasses may change the root element name, public ID, system ID, or other characteristics of the DocType returned. Subclasses may change the nodes returned from this method. They may return a Nodes object containing any number of comments and processing instructions which are appended to the current parent node. This Nodes object may not contain any Document, Element, Attribute, or Text objects. All of the nodes returned must be parentless. Subclasses may return an empty Nodes to indicate the DocType should not be included in the finished document.

Overrides:
makeDocType in class nu.xom.NodeFactory
Parameters:
rootElementName - the declared, qualified name for the root element
publicID - the public ID of the external DTD subset
systemID - the URL of the external DTD subset
Returns:
the nodes to be added to the document


Copyright 2002-2005 Elliotte Rusty Harold
elharo@metalab.unc.edu