org.tm4j.topicmap.utils.extractors
Class TopicNameExtractor

java.lang.Object
  extended byorg.tm4j.topicmap.utils.extractors.ExtractorBase
      extended byorg.tm4j.topicmap.utils.extractors.TopicNameExtractor
All Implemented Interfaces:
uk.co.jezuk.mango.BinaryFunction, uk.co.jezuk.mango.UnaryFunction

public class TopicNameExtractor
extends ExtractorBase
implements uk.co.jezuk.mango.BinaryFunction

An extractor function which takes a Topic as input and returns a String as output. The string returned will be one of the base name strings for the input Topic. This function provides a number of configuration options for controlling the selection and transformation of the returned string.

The base name returned is selected as follows:

  1. First the BaseName which has the most preferred themes in its scope is selected. If there is a tie, then an arbitrary selection is made.
  2. If the BaseName has some variants and the list of preferred variant parameters is not empty, then the variant name that has the most preferred parameters and has a resourceData (string) value rather than a resourceRef (Locator) value is selected. In the case of a tie, an arbitrary selection is made.
  3. If no item is selected by the above two steps, the string "[no name]" is returned.
  4. If step (2) above selected a Variant, then the data value of the Variant's VariantName is returned.
  5. If step(2) does not select a Variant but step (1) selected a BaseName, then the BaseName's baseNameString value is returned.

Prior to being returned, the string value may be folded to lower case and/or have special XML characters escaped.


Constructor Summary
TopicNameExtractor()
           
 
Method Summary
 java.lang.Object _extract(java.lang.Object in)
           
 void addPreferredTheme(Topic theme)
          Adds a Topic to the list of scope themes that are preferred for the returned name string.
 void addPreferredVariant(Topic v)
          Adds a Topic to the list of variant parameters that are preferred for the returned name string.
 void clearPreferredThemes()
          Clears the set of scope themes that are preferred for the returned name string.
 void clearPreferredVariants()
          Clears the set of variant parameters that are preferred for the returned name string.
 java.lang.Object fn(java.lang.Object in, java.lang.Object arg)
           
 void removePreferredVariant(Topic v)
          Removes a Topic from the list of variant parameters that are preferred for the returned name string.
 void setCaseFolding(boolean foldCase)
          Sets the case-folding flag.
 void setXmlEscaping(boolean xmlEscape)
          Sets the XML escaping flag.
 
Methods inherited from class org.tm4j.topicmap.utils.extractors.ExtractorBase
fn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TopicNameExtractor

public TopicNameExtractor()
Method Detail

addPreferredVariant

public void addPreferredVariant(Topic v)
Adds a Topic to the list of variant parameters that are preferred for the returned name string.

Parameters:
v - the variant parameter to add

removePreferredVariant

public void removePreferredVariant(Topic v)
Removes a Topic from the list of variant parameters that are preferred for the returned name string.

Parameters:
v - the variant parameter to remove

addPreferredTheme

public void addPreferredTheme(Topic theme)
Adds a Topic to the list of scope themes that are preferred for the returned name string.

Parameters:
theme - the scope theme to add

clearPreferredThemes

public void clearPreferredThemes()
Clears the set of scope themes that are preferred for the returned name string.


clearPreferredVariants

public void clearPreferredVariants()
Clears the set of variant parameters that are preferred for the returned name string.


_extract

public java.lang.Object _extract(java.lang.Object in)
Specified by:
_extract in class ExtractorBase

fn

public java.lang.Object fn(java.lang.Object in,
                           java.lang.Object arg)
Specified by:
fn in interface uk.co.jezuk.mango.BinaryFunction

setCaseFolding

public void setCaseFolding(boolean foldCase)
Sets the case-folding flag. If this flag is set to true then the returned string will be transformed by folding it to lower case.

Parameters:
foldCase - the new value for the case-folding flag.

setXmlEscaping

public void setXmlEscaping(boolean xmlEscape)
Sets the XML escaping flag. If this flag is set to true then the XML special characters &, < and > will be escaped to &amp; &lt; and &gt; respectively.

Parameters:
xmlEscape - the new value for the XML escaping flag.