Class Catalog

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--Catalog
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class Catalog
extends org.xml.sax.helpers.DefaultHandler

Parses a corpus catalog file and supplies name resolution service.

Version:
$2007-04-30 04:10:27 mdh$
Author:
Malcolm D. Hyman

Inner Class Summary
protected  class Catalog.SlaveMatch
          Associates a slave text and matching data.
 
Field Summary
static java.lang.String HOST
           
static java.lang.String MAGIC
           
static java.lang.String MAGIC_2
           
static java.lang.String PREFIX
           
 
Constructor Summary
Catalog()
           
 
Method Summary
 boolean add(java.lang.String locator, java.lang.String location, java.lang.String type, java.lang.String author, java.lang.String title, ArborAgent agent)
          Adds an entry to the mapping table.
 void characters(char[] ch, int start, int length)
          This is part of the ContentHandler interface.
 boolean checkForSaves(ArborAgent agent)
          Queries the user on application close if unsaved changes have been made to the generated catalog.
 void clear()
          Clears the name resolution mapping table.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          This is part of the ContentHandler interface.
 java.net.URL getRealDocBase(ContentOwner owner)
          Returns the real (devirtualized) docBase for a ContentOwner.
 Catalog.SlaveMatch getSlaveMatch(java.lang.String locator, int index)
          Returns the SlaveMatch corresponding to a given index for a specified text.
 java.lang.String[] getSlaveTitlesFor(java.lang.String locator)
          Returns an array of slave text titles for a given text.
 boolean isDirty()
          Returns a boolean value indicating whether the catalog is dirty.
 int parse(java.lang.String location)
          Parses the catalog file.
 int parse(java.lang.String location, boolean ignoreErrors)
          Parses the catalog file.
 boolean seen(java.lang.String location)
          Returns true if the specified catalog file has been seen.
 void serialize(java.io.File file, ArborAgent agent)
          Serializes the generated catalog entries as XML.
 int size()
          Returns the number of entries in the catalog.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          This is part of the ContentHandler interface.
 java.lang.String translate(java.lang.String canonical)
          Translates a canonical into an actual URI (string representations).
 java.net.URL translate(java.net.URL canonical)
          Translates a canonical into an actual URI object.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOST

public static final java.lang.String HOST

PREFIX

public static final java.lang.String PREFIX

MAGIC

public static final java.lang.String MAGIC

MAGIC_2

public static final java.lang.String MAGIC_2
Constructor Detail

Catalog

public Catalog()
Method Detail

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
This is part of the ContentHandler interface.
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
This is part of the ContentHandler interface.
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
This is part of the ContentHandler interface.
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

parse

public int parse(java.lang.String location,
                 boolean ignoreErrors)
Parses the catalog file.
Parameters:
location - catalog file URL
ignoreErrors - be silent about errors
Returns:
number of map items parsed

parse

public int parse(java.lang.String location)
Parses the catalog file.
Parameters:
location - catalog file URL
Returns:
number of map items parsed

seen

public boolean seen(java.lang.String location)
Returns true if the specified catalog file has been seen.
Parameters:
location - location URL
Returns:
true if already seen

clear

public void clear()
Clears the name resolution mapping table.

translate

public java.lang.String translate(java.lang.String canonical)
Translates a canonical into an actual URI (string representations).
Parameters:
canonical - canonical URI
Returns:
actual URI

translate

public java.net.URL translate(java.net.URL canonical)
                       throws java.net.MalformedURLException
Translates a canonical into an actual URI object.
Parameters:
canonical - canonical URI
Returns:
actual URI

getRealDocBase

public java.net.URL getRealDocBase(ContentOwner owner)
Returns the real (devirtualized) docBase for a ContentOwner.
Parameters:
owner - ContentOwner

add

public boolean add(java.lang.String locator,
                   java.lang.String location,
                   java.lang.String type,
                   java.lang.String author,
                   java.lang.String title,
                   ArborAgent agent)
Adds an entry to the mapping table. Additionally, the entry is added to a catalog file DOM (generated), which can be serialized.
Parameters:
locator - the locator (virtual URI)
location - the location (actual URL)
type - type descriptor
author - author metadata (may be null)
title - title metadata (may be null)
agent - ArborAgent
Returns:
true if successful

serialize

public void serialize(java.io.File file,
                      ArborAgent agent)
Serializes the generated catalog entries as XML.
Parameters:
file - file where XML is written
agent - ArborAgent

checkForSaves

public boolean checkForSaves(ArborAgent agent)
Queries the user on application close if unsaved changes have been made to the generated catalog. This method should be called prior to application exit. If it returns false, the application should not exit!
Parameters:
agent - ArborAgent
Returns:
false if user selects "Cancel" in confirm dialog

isDirty

public boolean isDirty()
Returns a boolean value indicating whether the catalog is dirty.
Returns:
catalog is dirty?

size

public int size()
Returns the number of entries in the catalog.
Returns:
number of entries in the catalog

getSlaveTitlesFor

public java.lang.String[] getSlaveTitlesFor(java.lang.String locator)
Returns an array of slave text titles for a given text.
Parameters:
locator - locator/URI for master text
Returns:
array of slave text titles

getSlaveMatch

public Catalog.SlaveMatch getSlaveMatch(java.lang.String locator,
                                        int index)
                                 throws java.lang.Exception
Returns the SlaveMatch corresponding to a given index for a specified text.
Parameters:
locator - locator/URI for master text
index - index of slave
Returns:
SlaveMatch