org.tm4j.topicmap.utils
Class XTMWriter

java.lang.Object
  extended byorg.tm4j.topicmap.utils.XTMWriter
All Implemented Interfaces:
TopicMapWriter, WalkerHandler

public class XTMWriter
extends java.lang.Object
implements TopicMapWriter


Field Summary
static java.lang.String OPTION_EXPORT_IMPLIED_IDS
           
static java.lang.String OPTION_EXPORT_RESOURCE_BASE
           
static java.lang.String OPTION_EXPORT_RESOURCE_IDS
           
static java.lang.String OPTION_IDREF_PREFIX
           
static java.lang.String OPTION_WRITE_AS_FRAGMENT
           
static java.lang.String OPTION_WRITE_STUB_TOPICS
           
static java.lang.String OPTION_XLINK_PREFIX
           
static java.lang.String OPTION_XTM_PREFIX
           
 
Constructor Summary
XTMWriter()
          Creates a new XTMWriter object.
 
Method Summary
 void baseNameString(java.lang.String id, java.lang.String value)
           
protected  void characters(java.lang.String value)
           
protected  void closeParameters()
           
protected  void closeSubjectIdentity()
           
protected  void closeTypes()
           
 void endAssociation()
           
 void endAssociation(Association assoc)
           
 void endBaseName()
           
 void endBaseName(BaseName bn)
           
 void endInstanceOf()
           
 void endMember()
           
 void endMember(Member m)
           
 void endMergeMap()
           
 void endOccurrence()
           
 void endOccurrence(Occurrence occ)
           
 void endParameters()
           
 void endRoleSpec()
           
 void endScope()
           
 void endSubjectIdentity()
           
 void endTopic()
           
 void endTopic(Topic t)
           
 void endTopicMap()
           
 void endTopicMap(TopicMap tm)
           
 void endVariant()
           
 void endVariant(Variant var)
           
 void endVariantName()
           
protected  void endXTMElement(java.lang.String localName)
           
protected  java.lang.String getDocumentPart(java.lang.String addressString)
          Returns that part of a URI locator address which preceeds the fragment separator '#'
 boolean getExportImpliedIDs()
          Deprecated. from 0.9.0
 boolean getExportResourceIDs()
          Deprecated. from 0.9.0
protected  java.lang.String getID(TopicMap tm)
           
protected  java.lang.String getID(TopicMapObject tmo)
          Returns the id attribute value to be exported for the specified TopicMapObject.
 java.lang.String getIDRefPrefix()
          Deprecated. from 0.9.0
protected  java.lang.String getResourceID(TopicMapObject tmo, Locator srcLoc)
          Returns the fragment part of tmo's resourceLocator property if, and only if the document part of the resourceLocator matches the doucment part of the containing TopicMap object's resourceLocator property.
 java.lang.String getXLinkNSPrefix()
          Deprecated. from 0.9.0
 java.lang.String getXTMNSPrefix()
          Deprecated. from 0.9.0
protected  java.lang.String makeRelative(java.lang.String id)
           
 void onParameter(Topic param)
           
 void onPlayer(Topic p)
           
 void onRoleSpec(Topic rs)
           
protected  void onScopedObject(java.lang.String soID)
           
 void onSubject(Locator subject)
           
 void onSubjectIndicator(Locator subjInd)
           
 void onTheme(Topic theme)
           
 void onType(Topic type)
           
 void onVariantName(VariantName varName)
           
protected  void openParameters()
           
protected  void openSubjectIdentity()
           
 void ref(java.lang.String id, int refType, Locator refValue)
           
 void ref(java.lang.String id, int refType, java.lang.String refValue)
           
 void resourceData(java.lang.String id, java.lang.String data)
           
 void setContentHandler(org.xml.sax.ContentHandler h)
          Sets the SAX ContentHandler to which export events will be notified.
 void setErrorHandler(org.xml.sax.ErrorHandler h)
          Sets the SAX ErrorHandler to which export errors will be notified.
 void setExportImpliedIDs(boolean b)
          Deprecated. from 0.9.0 use setProperty(OPTION_EXPORT_IMPLIED_IDS, String);
 void setExportResourceIDs(boolean b)
          Deprecated. from 0.9.0 use setProperty(OPTION_EXPORT_RESOURCE_IDS, String);
 void setIDRefPrefix(java.lang.String idRefPrefix)
          Deprecated. from 0.9.0 use setProperty(OPTION_IDREF_PREFIX, String);
 void setProperty(java.lang.String propertyName, java.lang.String propertyValue)
           
 void setWriteAsFragment(boolean asFragment)
          Deprecated. from 0.9.0 use setProperty(OPTION_WRITE_AS_FRAGMENT, String);
 void setXLinkNSPrefix(java.lang.String nsPrefix)
          Deprecated. from 0.9.0 use setProperty(OPTION_XLINK_PREFIX, String);
 void setXTMNSPrefix(java.lang.String nsPrefix)
          Deprecated. from 0.9.0 use setProperty(OPTION_XTM_PREFIX, String);
 boolean startAssociation(Association assoc)
           
 void startAssociation(java.lang.String id)
           
 boolean startBaseName(BaseName bn)
           
 void startBaseName(java.lang.String id)
           
 void startInstanceOf(java.lang.String id)
           
 boolean startMember(Member m)
           
 void startMember(java.lang.String id)
           
 void startMergeMap(java.lang.String id, java.lang.String mergeMapURI)
           
 boolean startOccurrence(Occurrence occ)
           
 void startOccurrence(java.lang.String id)
           
 void startParameters(java.lang.String id)
           
 void startRoleSpec(java.lang.String id)
           
 boolean startScope()
           
 void startScope(java.lang.String id)
           
 void startSubjectIdentity(java.lang.String id)
           
 void startTopic(java.lang.String id)
           
 boolean startTopic(Topic t)
           
 void startTopicMap(java.lang.String id, java.lang.String base)
           
 boolean startTopicMap(TopicMap tm)
           
 void startVariant(java.lang.String id)
           
 boolean startVariant(Variant var)
           
 void startVariantName(java.lang.String id)
           
protected  void startXTMElement(java.lang.String localName, org.xml.sax.Attributes atts)
           
protected  void startXTMElement(java.lang.String localName, java.lang.String id)
           
protected  void startXTMElement(java.lang.String localName, java.lang.String id, java.lang.String href)
           
protected  void topicRef(Topic t)
           
protected  void writeBaseNameString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_WRITE_AS_FRAGMENT

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

OPTION_XTM_PREFIX

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

OPTION_XLINK_PREFIX

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

OPTION_IDREF_PREFIX

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

OPTION_EXPORT_RESOURCE_IDS

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

OPTION_EXPORT_RESOURCE_BASE

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

OPTION_EXPORT_IMPLIED_IDS

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

OPTION_WRITE_STUB_TOPICS

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

XTMWriter

public XTMWriter()
Creates a new XTMWriter object.

Method Detail

setWriteAsFragment

public void setWriteAsFragment(boolean asFragment)
Deprecated. from 0.9.0 use setProperty(OPTION_WRITE_AS_FRAGMENT, String);

Sets whether or not the topic map should be written as an XML fragment. If true then no startDocument() or endDocument() events will be generated.

Parameters:
asFragment - true to write the topic map as an XML fragment, false to write the topic map as a separate document.

setXTMNSPrefix

public void setXTMNSPrefix(java.lang.String nsPrefix)
Deprecated. from 0.9.0 use setProperty(OPTION_XTM_PREFIX, String);

Sets the namespace prefix to be applied to elements in the XTM namespace.

Parameters:
nsPrefix - the XTM namespace prefix for this XTM file.

getXTMNSPrefix

public java.lang.String getXTMNSPrefix()
Deprecated. from 0.9.0

Returns the namespace prefix to be applied to elements in the XTM namespace

Returns:
the XTM namespace prefix string.

setXLinkNSPrefix

public void setXLinkNSPrefix(java.lang.String nsPrefix)
Deprecated. from 0.9.0 use setProperty(OPTION_XLINK_PREFIX, String);

Sets the namespace prefix to be applied to attributes in the XLink namespace.

Parameters:
nsPrefix - the XLink namespace prefix to be assigned.

getXLinkNSPrefix

public java.lang.String getXLinkNSPrefix()
Deprecated. from 0.9.0

Returns the namespace prefix to be applied to attributes in the XLink namespace

Returns:
the XLink namespace prefix string.

setIDRefPrefix

public void setIDRefPrefix(java.lang.String idRefPrefix)
Deprecated. from 0.9.0 use setProperty(OPTION_IDREF_PREFIX, String);

Sets the string prefix to be applied to a topic ID when specifying the string in a topicRef element. Typically, this should only be set to the default value ('#') for use in XLink based reference syntax (such as XTM). A Hytime-based or other addressing scheme may require different prefixes.


getIDRefPrefix

public java.lang.String getIDRefPrefix()
Deprecated. from 0.9.0

Returns the prefix to be applied to a topic ID when using it for the href attribute value of a topicRef element.

See Also:
setIDRefPrefix(String)

getExportResourceIDs

public boolean getExportResourceIDs()
Deprecated. from 0.9.0

Returns the value of the exportResourceIDs option of the writer.

Returns:
the option value as a boolean
See Also:
setExportResourceIDs(boolean)

setExportResourceIDs

public void setExportResourceIDs(boolean b)
Deprecated. from 0.9.0 use setProperty(OPTION_EXPORT_RESOURCE_IDS, String);

Sets the exportResourceIDs option for the writer.

If this option is set to true then for each object exported, if that object has a value for its sourceLocators property and if the document part of one of the sourceLocators values matches the document part of the resourceBase property of the XTMWriter instance, then the fragment part of the sourceLocator value will be exported as the id attribute value of the XTM element.

If the object being exported is a Topic and its sourceLocators property does not contain a value where the document part of the sourceLocator does not match the document part of the resourceBase value, then all of the Topic object's subjectIndicators will be checked and if one of those has a document part which matches the document part of the resourceBase value, then the fragment part of that subjectIndicator will be exported as the <topic> element's id attribute.

Note This setting overrides the exportImpliedIDs property - in other words, if exportImpliedIDs is false and exportResourceIDs is true, then id attributes will still be generated for any object with a non-empty sourceLocators value. If both settings are true, then the ID generated from the sourceLocators of the object takes precedence over the ID generated from the id property of the object.

Parameters:
b - the new value of the exportResourceIDs option

setExportImpliedIDs

public void setExportImpliedIDs(boolean b)
Deprecated. from 0.9.0 use setProperty(OPTION_EXPORT_IMPLIED_IDS, String);

Sets the exportImpliedIDs option for the writer.

If this option is set to false, then IDs will only be generated for <topic> elements. Otherwise, IDs will be generated for all elements in the exported XTM file which are created to represent an object in the TopicMap being exported.

Parameters:
b - the new value for the exportImpliedIDs option
See Also:
setExportResourceIDs(boolean)

getExportImpliedIDs

public boolean getExportImpliedIDs()
Deprecated. from 0.9.0

Returns the value of the exportImpliedIDs option of the writer.

Returns:
the value of the option as a boolean
See Also:
setExportImpliedIDs(boolean)

setContentHandler

public void setContentHandler(org.xml.sax.ContentHandler h)
Sets the SAX ContentHandler to which export events will be notified.

Specified by:
setContentHandler in interface TopicMapWriter
Parameters:
h - the ContentHandler to receive the SAX events generated by the export process

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler h)
Sets the SAX ErrorHandler to which export errors will be notified.

Specified by:
setErrorHandler in interface TopicMapWriter
Parameters:
h - the ErrorHandler to receive any errors generated by the export process.

setProperty

public void setProperty(java.lang.String propertyName,
                        java.lang.String propertyValue)
                 throws WriterPropertyNotRecognizedException
Throws:
WriterPropertyNotRecognizedException

startXTMElement

protected void startXTMElement(java.lang.String localName,
                               org.xml.sax.Attributes atts)

startXTMElement

protected void startXTMElement(java.lang.String localName,
                               java.lang.String id)

makeRelative

protected java.lang.String makeRelative(java.lang.String id)

startXTMElement

protected void startXTMElement(java.lang.String localName,
                               java.lang.String id,
                               java.lang.String href)

endXTMElement

protected void endXTMElement(java.lang.String localName)

characters

protected void characters(java.lang.String value)

startTopicMap

public void startTopicMap(java.lang.String id,
                          java.lang.String base)
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endTopicMap

public void endTopicMap()
                 throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startTopic

public void startTopic(java.lang.String id)
                throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endTopic

public void endTopic()
              throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startInstanceOf

public void startInstanceOf(java.lang.String id)
                     throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endInstanceOf

public void endInstanceOf()
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startSubjectIdentity

public void startSubjectIdentity(java.lang.String id)
                          throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endSubjectIdentity

public void endSubjectIdentity()
                        throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startBaseName

public void startBaseName(java.lang.String id)
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endBaseName

public void endBaseName()
                 throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startOccurrence

public void startOccurrence(java.lang.String id)
                     throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endOccurrence

public void endOccurrence()
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startAssociation

public void startAssociation(java.lang.String id)
                      throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endAssociation

public void endAssociation()
                    throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startMember

public void startMember(java.lang.String id)
                 throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endMember

public void endMember()
               throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startRoleSpec

public void startRoleSpec(java.lang.String id)
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endRoleSpec

public void endRoleSpec()
                 throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startMergeMap

public void startMergeMap(java.lang.String id,
                          java.lang.String mergeMapURI)
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endMergeMap

public void endMergeMap()
                 throws TopicMapProcessingException
Throws:
TopicMapProcessingException

ref

public void ref(java.lang.String id,
                int refType,
                Locator refValue)
         throws TopicMapProcessingException
Throws:
TopicMapProcessingException

ref

public void ref(java.lang.String id,
                int refType,
                java.lang.String refValue)
         throws TopicMapProcessingException
Throws:
TopicMapProcessingException

resourceData

public void resourceData(java.lang.String id,
                         java.lang.String data)
                  throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startScope

public void startScope(java.lang.String id)
                throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endScope

public void endScope()
              throws TopicMapProcessingException
Specified by:
endScope in interface WalkerHandler
Throws:
TopicMapProcessingException

baseNameString

public void baseNameString(java.lang.String id,
                           java.lang.String value)
                    throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startVariant

public void startVariant(java.lang.String id)
                  throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endVariant

public void endVariant()
                throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startParameters

public void startParameters(java.lang.String id)
                     throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endParameters

public void endParameters()
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startVariantName

public void startVariantName(java.lang.String id)
                      throws TopicMapProcessingException
Throws:
TopicMapProcessingException

endVariantName

public void endVariantName()
                    throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startTopicMap

public boolean startTopicMap(TopicMap tm)
                      throws TopicMapProcessingException
Specified by:
startTopicMap in interface WalkerHandler
Throws:
TopicMapProcessingException

endTopicMap

public void endTopicMap(TopicMap tm)
                 throws TopicMapProcessingException
Specified by:
endTopicMap in interface WalkerHandler
Throws:
TopicMapProcessingException

startTopic

public boolean startTopic(Topic t)
                   throws TopicMapProcessingException
Specified by:
startTopic in interface WalkerHandler
Throws:
TopicMapProcessingException

endTopic

public void endTopic(Topic t)
              throws TopicMapProcessingException
Specified by:
endTopic in interface WalkerHandler
Throws:
TopicMapProcessingException

onType

public void onType(Topic type)
            throws TopicMapProcessingException
Specified by:
onType in interface WalkerHandler
Throws:
TopicMapProcessingException

closeTypes

protected void closeTypes()
                   throws TopicMapProcessingException
Throws:
TopicMapProcessingException

openSubjectIdentity

protected void openSubjectIdentity()
                            throws TopicMapProcessingException
Throws:
TopicMapProcessingException

closeSubjectIdentity

protected void closeSubjectIdentity()
                             throws TopicMapProcessingException
Throws:
TopicMapProcessingException

onSubject

public void onSubject(Locator subject)
               throws TopicMapProcessingException
Specified by:
onSubject in interface WalkerHandler
Throws:
TopicMapProcessingException

onSubjectIndicator

public void onSubjectIndicator(Locator subjInd)
                        throws TopicMapProcessingException
Specified by:
onSubjectIndicator in interface WalkerHandler
Throws:
TopicMapProcessingException

startBaseName

public boolean startBaseName(BaseName bn)
                      throws TopicMapProcessingException
Specified by:
startBaseName in interface WalkerHandler
Throws:
TopicMapProcessingException

endBaseName

public void endBaseName(BaseName bn)
                 throws TopicMapProcessingException
Specified by:
endBaseName in interface WalkerHandler
Throws:
TopicMapProcessingException

writeBaseNameString

protected void writeBaseNameString()
                            throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startScope

public boolean startScope()
                   throws TopicMapProcessingException
Specified by:
startScope in interface WalkerHandler
Throws:
TopicMapProcessingException

onTheme

public void onTheme(Topic theme)
             throws TopicMapProcessingException
Specified by:
onTheme in interface WalkerHandler
Throws:
TopicMapProcessingException

topicRef

protected void topicRef(Topic t)
                 throws TopicMapProcessingException
Throws:
TopicMapProcessingException

startVariant

public boolean startVariant(Variant var)
                     throws TopicMapProcessingException
Specified by:
startVariant in interface WalkerHandler
Throws:
TopicMapProcessingException

endVariant

public void endVariant(Variant var)
                throws TopicMapProcessingException
Specified by:
endVariant in interface WalkerHandler
Throws:
TopicMapProcessingException

openParameters

protected void openParameters()
                       throws TopicMapProcessingException
Throws:
TopicMapProcessingException

closeParameters

protected void closeParameters()
                        throws TopicMapProcessingException
Throws:
TopicMapProcessingException

onParameter

public void onParameter(Topic param)
                 throws TopicMapProcessingException
Specified by:
onParameter in interface WalkerHandler
Throws:
TopicMapProcessingException

onVariantName

public void onVariantName(VariantName varName)
                   throws TopicMapProcessingException
Specified by:
onVariantName in interface WalkerHandler
Throws:
TopicMapProcessingException

startOccurrence

public boolean startOccurrence(Occurrence occ)
                        throws TopicMapProcessingException
Specified by:
startOccurrence in interface WalkerHandler
Throws:
TopicMapProcessingException

endOccurrence

public void endOccurrence(Occurrence occ)
                   throws TopicMapProcessingException
Specified by:
endOccurrence in interface WalkerHandler
Throws:
TopicMapProcessingException

startAssociation

public boolean startAssociation(Association assoc)
                         throws TopicMapProcessingException
Specified by:
startAssociation in interface WalkerHandler
Throws:
TopicMapProcessingException

endAssociation

public void endAssociation(Association assoc)
                    throws TopicMapProcessingException
Specified by:
endAssociation in interface WalkerHandler
Throws:
TopicMapProcessingException

startMember

public boolean startMember(Member m)
                    throws TopicMapProcessingException
Specified by:
startMember in interface WalkerHandler
Throws:
TopicMapProcessingException

endMember

public void endMember(Member m)
               throws TopicMapProcessingException
Specified by:
endMember in interface WalkerHandler
Throws:
TopicMapProcessingException

onRoleSpec

public void onRoleSpec(Topic rs)
                throws TopicMapProcessingException
Specified by:
onRoleSpec in interface WalkerHandler
Throws:
TopicMapProcessingException

onPlayer

public void onPlayer(Topic p)
              throws TopicMapProcessingException
Specified by:
onPlayer in interface WalkerHandler
Throws:
TopicMapProcessingException

getID

protected java.lang.String getID(TopicMap tm)

getResourceID

protected java.lang.String getResourceID(TopicMapObject tmo,
                                         Locator srcLoc)
Returns the fragment part of tmo's resourceLocator property if, and only if the document part of the resourceLocator matches the doucment part of the containing TopicMap object's resourceLocator property. This method is used to roundtrip id attribute values which were read in from an XTM file. If a Topic object is passed to this method and it has a resourceLocator property with a document part which does not match the document part of the containing TopicMap's resourceLocator property, then this method will check all of the subjectIndicators of the topic to see if there is one which does - in this case the fragment identifier of that subjectIndicator is returned.

Parameters:
tmo - the TopicMapObject to extract a resource ID from
Returns:
the value which can be assigned to the id attribute of the element exported for tmo or null if either the object or its container TopicMap does not have a resourceLocator specified or if the resourceLocator of the object or the containing TopicMap is not a URILocator instance.

getDocumentPart

protected java.lang.String getDocumentPart(java.lang.String addressString)
Returns that part of a URI locator address which preceeds the fragment separator '#'

Parameters:
addressString - the complete address string
Returns:
all of the address string which preceeds the fragment separator

getID

protected java.lang.String getID(TopicMapObject tmo)
Returns the id attribute value to be exported for the specified TopicMapObject. If the exportResourceIDs option is true and the specified object has an associated resource id as determined by getResourceID(TopicMapObject), then this value is always returned. Otherwise, if the object is a Topic object or if the exportImpliedIDs option is true, then the value of the ID property of the object is returned.

Parameters:
tmo - the object to return the exported id attribute value for
Returns:
the value which should be specified for the id attribute of the XTM element exported for the specified object.

onScopedObject

protected void onScopedObject(java.lang.String soID)