com.limegroup.gnutella.xml
Class LimeXMLDocument

java.lang.Object
  extended bycom.limegroup.gnutella.xml.LimeXMLDocument
All Implemented Interfaces:
java.io.Serializable

public class LimeXMLDocument
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
static java.lang.String XML_HEADER
           
static java.lang.String XML_ID_ATTRIBUTE_STRING
           
 
Constructor Summary
LimeXMLDocument(java.util.Collection nameValueList, java.lang.String schemaURI)
          Constructs a new LimeXMLDocument
LimeXMLDocument(org.w3c.dom.Node node, org.w3c.dom.Node rootElement)
           
LimeXMLDocument(java.lang.String XMLStr)
           
 
Method Summary
static java.lang.String constructXML(java.util.List namValList, java.lang.String uri)
          finds the structure of the document by looking at the names of the keys in the NameValue List and creates an XML string.
 boolean equals(java.lang.Object o)
          Overrides equals to check for equality of all xml document fields.
 java.lang.String getAction()
           
 java.lang.String getIdentifier()
          Returns the name of the file that the data in this XML document corresponds to.
 java.util.List getKeyWords()
          Returns all the non-numeric fields in this.
 java.util.Set getNameValueSet()
          Returns a Set of Map.Entry, where each key-value corresponds to a Canonicalized field name (placeholder), and its corresponding value in the XML Document.
 int getNumFields()
           
 java.util.List getOrderedNameValueList()
          This method is only guaranteed to work if getSchemaURI() returns a non-null value.
 java.lang.String getSchemaURI()
          Returns the unique identifier which identifies the schema this XML document conforms to
 java.lang.String getValue(java.lang.String fieldName)
           
 java.util.Collection getValueList()
          Returns a collection of the values of this LimeXMLDocument.
 java.lang.String getXMLString()
           
 java.lang.String getXMLStringWithIdentifier()
           
 int hashCode()
          Overrides Object.hashCode to satisfy the contract for hashCode, given that we're overriding equals.
 void setIdentifier(java.lang.String id)
           
 void setSchemaURI(java.lang.String uri)
          This method is used by Lime Peer Server
 java.lang.String toString()
          Returns the XML identifier for the string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_ID_ATTRIBUTE_STRING

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

XML_HEADER

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

LimeXMLDocument

public LimeXMLDocument(java.lang.String XMLStr)
                throws org.xml.sax.SAXException,
                       SchemaNotFoundException,
                       java.io.IOException

LimeXMLDocument

public LimeXMLDocument(org.w3c.dom.Node node,
                       org.w3c.dom.Node rootElement)
                throws SchemaNotFoundException,
                       java.io.IOException

LimeXMLDocument

public LimeXMLDocument(java.util.Collection nameValueList,
                       java.lang.String schemaURI)
Constructs a new LimeXMLDocument

Parameters:
nameValueList - List (of NameValue) of fieldnames (in canonicalized form) and corresponding values that will be used to create the new instance
schemaURI - The schema URI for the LimeXMLDocument to be created
Method Detail

setIdentifier

public void setIdentifier(java.lang.String id)

setSchemaURI

public void setSchemaURI(java.lang.String uri)
This method is used by Lime Peer Server


getNumFields

public int getNumFields()

getKeyWords

public java.util.List getKeyWords()
Returns all the non-numeric fields in this. These are not necessarily QRP keywords. For example, one of the elements of the returned list may be "Some comment-blah". QRP code may want to split this into the QRP keywords "Some", "comment", and "blah".


getSchemaURI

public java.lang.String getSchemaURI()
Returns the unique identifier which identifies the schema this XML document conforms to


getIdentifier

public java.lang.String getIdentifier()
Returns the name of the file that the data in this XML document corresponds to. If the meta-data does not correspond to any file in the file system, this method will rerurn a null.


getAction

public java.lang.String getAction()

getNameValueSet

public java.util.Set getNameValueSet()
Returns a Set of Map.Entry, where each key-value corresponds to a Canonicalized field name (placeholder), and its corresponding value in the XML Document.

Canonicalization:

So as to preserve the structure, Structure.Field will be represented as Structure__Field (Double Underscore is being used as a delimiter to represent the structure).

In case of multiple structured values with same name, as might occur while using + or * in the regular expressions in schema, those should be represented as using the array index using the __ notation (withouth the square brackets) for e.g. myarray[0].name ==> myarray__0__name attribute names for an element in the XML schema should be postfixed with __ (double underscore). So element.attribute ==> element__attribute__

Returns:
a Set of Map.Entry, where each key-value corresponds to a canonicalized field name (placeholder), and its corresponding value in the XML Document.

getValueList

public java.util.Collection getValueList()
Returns a collection of the values of this LimeXMLDocument.


getOrderedNameValueList

public java.util.List getOrderedNameValueList()
                                       throws SchemaNotFoundException
This method is only guaranteed to work if getSchemaURI() returns a non-null value.

Returns:
a List , where each name-value corresponds to a canonicalized field name (placeholder), and its corresponding value in the XML Document. This list is ORDERED according to the schema URI of this document.
Throws:
SchemaNotFoundException - Thrown if you called this without providing a valid XML schema. So please make sure your schema is ok.

getValue

public java.lang.String getValue(java.lang.String fieldName)

getXMLString

public java.lang.String getXMLString()
                              throws SchemaNotFoundException
Returns:
an XML string that will be re-created as this document when it is re-assembled in another machine.
Throws:
SchemaNotFoundException - DO NOT CALL THIS METHOD unless you know that getSchemaURI() returns a valid xml schema. Set it yourself with setSchemaURI().

getXMLStringWithIdentifier

public java.lang.String getXMLStringWithIdentifier()
                                            throws SchemaNotFoundException
Returns:
an XML string that will be re-created as this document when it is re-assembled in another machine. this xml string contains the filename identifier too (as an attribute).
Throws:
SchemaNotFoundException - DO NOT CALL THIS METHOD unless you know that getSchemaURI() returns a valid xml schema. Set it yourself with setSchemaURI().

constructXML

public static java.lang.String constructXML(java.util.List namValList,
                                            java.lang.String uri)
finds the structure of the document by looking at the names of the keys in the NameValue List and creates an XML string.

The name value list must have the correct ordering.

The values are converted into the correect encoding as per the XML specifications. So the caller of this method need not pre-encode the special XML characters into the values.


equals

public boolean equals(java.lang.Object o)
Overrides equals to check for equality of all xml document fields.

Parameters:
o - the object to compare
Returns:
true if the objects are equal, false otherwise

hashCode

public int hashCode()
Overrides Object.hashCode to satisfy the contract for hashCode, given that we're overriding equals.

Returns:
a hashcode for this object for use in hash-based collections

toString

public java.lang.String toString()
Returns the XML identifier for the string.