com.sun.portal.search.soif
Class SOIF

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--com.sun.portal.search.soif.SOIF
All Implemented Interfaces:
Cloneable, Map, Serializable

public class SOIF
extends HashMap

SOIF (Summary Object Interchange Format) is a general purpose syntax and data structure for representing meta data. It is commonly used to create summaries, or Resource Descriptions, for storage, indexing, and transmission purposes.

A SOIF object has a standard serialized form, for example:

 @DOCUMENT { http://www.siroe.com
 content-type{29}:	text/html; charset=iso-8859-1
 title{16}:	Siroe Consulting
 author-1{14}:	William Lawson
 author-2{16}:	Gregory Blaxland
 author-3{17}:	William Wentworth
 description{245}:	
 Siroe Consulting
 - Business & Industry Solutions 
 - Downloads 
 - Documentation 
 - Developers 
 - Partners 
 - Executives 
 - Press 
 Company Info
 - Investor Relations
 - News & Events
 - Feature Stories
 - Employment
 - Siroe Labs
 Copyright 1994-2002 Siroe Consulting
 }
 

Each SOIF object has a schema (eg, DOCUMENT) and URL.
SOIF attribute values can be plain text or binary.
Multivalued attributes are supported.
The standard SOIF serialized form uses UTF-8 encoding for all character based data.
SOIF attribute names are case-insensitive.

More information on SOIF and the RDM search protocol can be found at http://www.w3.org/TR/NOTE-rdm.html

See Also:
AVPair, Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Field Summary
static String defaultEncoding
          Default char encoding.
static String INVALIDSOIF
          Error message for invalid SOIF.
 
Constructor Summary
SOIF()
          Constructor.
SOIF(byte[] data)
          Constructor.
SOIF(byte[] data, Set allowed)
          Constructor.
SOIF(byte[] data, String encoding)
          Constructor.
SOIF(byte[] data, String encoding, Set allowed)
          Constructor.
SOIF(String schemaName, String URL)
          Constructor.
 
Method Summary
 void absorb(SOIF s)
          Copies all data from another SOIF without replacement.
 void absorb(SOIF s, String[] filter)
          Copies selected data from another SOIF without replacement Ignores case of all attribute names.
 boolean contains(String a)
          Tests for attribute existence.
 boolean containsKey(Object key)
          Case insensistive collection function.
 int contentSize()
           
 Object get(Object key)
          Case insensistive collection function.
 int getAttributeCount()
           
 Set getAttributes()
           
 String[] getAttributesArray()
           
 AVPair getAVPair(String a)
          Gets an AVPair by attribute.
 byte[] getBytes(String a)
          Gets a byte array value by attribute.
 byte[] getBytes(String a, int n)
          Gets a byte array value by multivalue attribute and index.
 String getSchemaName()
           
 String getURL()
           
 String getValue(String a)
          Gets a String value by attribute.
 String getValue(String a, int n)
          Gets a String value by multivalue attribute and index.
 boolean insert(AVPair a)
          Inserts an AVPair, which may be either single or multivalued.
 boolean insert(String a, byte[] b)
          Inserts a byte array valued attribute.
 boolean insert(String a, byte[] b, int n)
          Inserts a String valued attribute with index.
 boolean insert(String a, String v)
          Inserts a String valued attribute.
 boolean insert(String a, String v, int n)
          Inserts a String valued attribute with index.
 void merge(SOIF s)
          Copies all data from another SOIF with replacement.
 void merge(SOIF s, String[] filter)
          Copies selected data from another SOIF with replacement.
 Object put(Object key, Object value)
          Case insensistive collection function.
 Object remove(Object key)
          Case insensistive collection function.
 boolean remove(String a)
          Removes an attribute.
 boolean remove(String a, int n)
          Removes an attribute by index.
 boolean rename(String a, String b)
          Renames attribute a to b.
 void replace(AVPair avp)
          Replaces an attribute-value pair by name.
 void replace(String a, String v)
          Replaces a single-valued attribute.
 void replace(String a, String v, int n)
          Replaces a multivalued attribute by index.
 void setSchemaName(String s)
          Sets the SOIF schema name.
 void setURL(String u)
          Sets the SOIF URL.
 void squeezeMV()
          Squeezes multivalued attributes.
 byte[] toByteArray()
          Creates a byte array representation of this SOIF.
 byte[] toByteArray(Set allowed)
          Creates a byte array representation of this SOIF.
 byte[] toByteArray(String enc)
          Creates a byte array representation of this SOIF.
 byte[] toByteArray(String enc, Set allowed)
          Creates a byte array representation of this SOIF.
 String toString()
          *WARNING*: This should be used for debugging only.
 
Methods inherited from class java.util.HashMap
clear, clone, containsValue, entrySet, isEmpty, keySet, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

defaultEncoding

public static String defaultEncoding
Default char encoding.

INVALIDSOIF

public static String INVALIDSOIF
Error message for invalid SOIF.
Constructor Detail

SOIF

public SOIF()
Constructor. Creates an empty SOIF object with schema = "-" and URL = "-"

SOIF

public SOIF(String schemaName,
            String URL)
Constructor. Creates an empty SOIF object with the given schema and URL.
Parameters:
schemaName - the SOIF schema name
URL - the SOIF URL

SOIF

public SOIF(byte[] data,
            String encoding,
            Set allowed)
     throws IOException
Constructor. Creates a SOIF by parsing the given byte array using the given character encoding.
Parameters:
data - a byte array SOIF representation
encoding - character encoding for byte/String conversion
allowed - a restricted attribute set for the conversion (use lower case)
Throws:
SOIFException - on parsing error
IOException - if byte array is empty

SOIF

public SOIF(byte[] data,
            String encoding)
     throws IOException
Constructor. Creates a SOIF by parsing the given byte array using the given character encoding.
Parameters:
data - a byte array SOIF representation
encoding - character encoding for byte/String conversion
Throws:
SOIFException - on parsing error
IOException - if byte array is empty

SOIF

public SOIF(byte[] data,
            Set allowed)
     throws IOException
Constructor. Creates a SOIF by parsing the given byte array using the default character encoding (UTF-8).
Parameters:
data - a byte array SOIF representation
allowed - a restricted attribute set for the conversion (use lower case)
Throws:
SOIFException - if parsing error
IOException - if byte array is empty

SOIF

public SOIF(byte[] data)
     throws IOException
Constructor. Creates a SOIF by parsing the given byte array using the default character encoding (UTF-8).
Parameters:
data - a byte array SOIF representation
Throws:
SOIFException - if parsing error
IOException - if byte array is empty
Method Detail

getSchemaName

public String getSchemaName()
Returns:
the SOIF schema name.

setSchemaName

public void setSchemaName(String s)
Sets the SOIF schema name.

getURL

public String getURL()
Returns:
the SOIF URL.

setURL

public void setURL(String u)
Sets the SOIF URL.

getValue

public String getValue(String a)
Gets a String value by attribute. Ignores case of attribute name.
Parameters:
a - the attribute name

getBytes

public byte[] getBytes(String a)
Gets a byte array value by attribute. Ignores case of attribute name.
Parameters:
a - the attribute name

getValue

public String getValue(String a,
                       int n)
Gets a String value by multivalue attribute and index. Ignores case of attribute name.
Parameters:
a - the attribute name
n - the index

getBytes

public byte[] getBytes(String a,
                       int n)
Gets a byte array value by multivalue attribute and index. Ignores case of attribute name.
Parameters:
a - the attribute name
n - the index

getAVPair

public AVPair getAVPair(String a)
Gets an AVPair by attribute. Ignores case of attribute name.
Parameters:
a - the attribute name

contains

public boolean contains(String a)
Tests for attribute existence. Ignores case of attribute name.
Parameters:
a - the attribute name
Returns:
true if the attribute exists in this SOIF

insert

public boolean insert(String a,
                      String v)
Inserts a String valued attribute. Ignores case of attribute name.
Parameters:
a - the attribute name
v - the String value to insert
Returns:
true if added, false if ignored (duplicate)

insert

public boolean insert(String a,
                      byte[] b)
Inserts a byte array valued attribute. Ignores case of attribute name.
Parameters:
a - the attribute name
b - the byte array value to insert
Returns:
true if added, false if ignored (duplicate)

insert

public boolean insert(String a,
                      String v,
                      int n)
Inserts a String valued attribute with index. Ignores case of attribute name.
Parameters:
a - the attribute name
v - the String value to insert
n - the multivalue index position for this value
Returns:
true if added, false if ignored (duplicate or MV index already taken)

insert

public boolean insert(String a,
                      byte[] b,
                      int n)
Inserts a String valued attribute with index. Ignores case of attribute name.
Parameters:
a - the attribute name
b - the byte array value to insert
n - the multivalue index position for this value
Returns:
true if added, false if ignored (duplicate or MV index already taken)

insert

public boolean insert(AVPair a)
Inserts an AVPair, which may be either single or multivalued. Ignores case of attribute name.
Parameters:
a - the AVPair to insert
Returns:
true if added, false if ignored (duplicate attribute name).

replace

public void replace(String a,
                    String v)
Replaces a single-valued attribute. Inserts the attribute if not already present. Ignores case of attribute name.
Parameters:
a - the attibute name
v - the attribute value
s - the attribute

replace

public void replace(String a,
                    String v,
                    int n)
Replaces a multivalued attribute by index. Inserts the attribute if not already present. Ignores case of attribute name.
Parameters:
a - the attibute name
v - the attribute value
n - the multivalued index position to replace

replace

public void replace(AVPair avp)
Replaces an attribute-value pair by name. Ignores case of attribute name.
Parameters:
avp - the attibute-value pair

remove

public boolean remove(String a)
Removes an attribute. Ignores case of attribute name.
Parameters:
a - the attibute name
Returns:
true if present and removed, false otherwise

remove

public boolean remove(String a,
                      int n)
Removes an attribute by index. Ignores case of attribute name.
Returns:
true if present and removed, false if not

rename

public boolean rename(String a,
                      String b)
Renames attribute a to b. Ignores case of attribute name.
Returns:
true if successful

merge

public void merge(SOIF s)
Copies all data from another SOIF with replacement. Ignores case of all attribute names.

merge

public void merge(SOIF s,
                  String[] filter)
Copies selected data from another SOIF with replacement. Ignores case of all attribute names.

absorb

public void absorb(SOIF s)
Copies all data from another SOIF without replacement. Ignores case of all attribute names.

absorb

public void absorb(SOIF s,
                   String[] filter)
Copies selected data from another SOIF without replacement Ignores case of all attribute names.

squeezeMV

public void squeezeMV()
Squeezes multivalued attributes. Packs the AVPair arrays by closing any holes in them towards index zero.

getAttributes

public Set getAttributes()
Returns:
the set of all attribute names in this SOIF. e.g. for Bob-1, Bob-2, Jim-1, return { Bob, Jim }

getAttributesArray

public String[] getAttributesArray()
Returns:
the set of all attribute names in this SOIF as an array. e.g. for Bob-1, Bob-2, Jim-1, return { Bob, Jim }

getAttributeCount

public int getAttributeCount()
Returns:
the number of attributes in this SOIF.

contentSize

public int contentSize()
Returns:
the entire contents size of all AVPairs in this SOIF

put

public Object put(Object key,
                  Object value)
Case insensistive collection function.
Overrides:
put in class HashMap

get

public Object get(Object key)
Case insensistive collection function.
Overrides:
get in class HashMap

remove

public Object remove(Object key)
Case insensistive collection function.
Overrides:
remove in class HashMap

containsKey

public boolean containsKey(Object key)
Case insensistive collection function.
Overrides:
containsKey in class HashMap

toByteArray

public byte[] toByteArray()
                   throws IOException
Creates a byte array representation of this SOIF. Convert this SOIF to a byte array.
Returns:
this SOIF as a byte array using the current encoding
Throws:
UnsupportedEncodingException -  
IOException -  

toByteArray

public byte[] toByteArray(Set allowed)
                   throws IOException
Creates a byte array representation of this SOIF. Convert this SOIF to a byte array.
Parameters:
allowed - a restricted attribute set for the conversion (use lower case)
Returns:
this SOIF as a byte array using the current encoding
Throws:
UnsupportedEncodingException -  
IOException -  

toByteArray

public byte[] toByteArray(String enc)
                   throws IOException
Creates a byte array representation of this SOIF.
Parameters:
enc - character encoding for String/byte conversion
Returns:
this SOIF as a byte array using the given encoding
Throws:
UnsupportedEncodingException -  
IOException -  
See Also:
SOIFInputStream.readSOIF(), SOIFOutputStream.write(SOIF s)

toByteArray

public byte[] toByteArray(String enc,
                          Set allowed)
                   throws IOException
Creates a byte array representation of this SOIF.
Parameters:
enc - character encoding for String/byte conversion
allowed - a restricted attribute set for the conversion (use lower case)
Returns:
this SOIF as a byte array using the given encoding
Throws:
IOException -  
See Also:
SOIFInputStream.readSOIF(), SOIFOutputStream.write(SOIF s)

toString

public String toString()
*WARNING*: This should be used for debugging only.
Overrides:
toString in class AbstractMap
Returns:
a String representation of this SOIF *Warning*: this is not a valid SOIF representation
See Also:
toByteArray(), SOIFInputStream.readSOIF(), SOIFOutputStream.write(SOIF s)