org.cdlib.xtf.xslt
Class CharUtils

Object
  extended by CharUtils

public class CharUtils
extends Object

Provides Unicode character-related utilities to be called by XSLT stylesheets through Saxon's extension function mechanism.

Author:
Martin Haye

Field Summary
private static HashMap<String,CharMap> accentMapCache
          Used to avoid recreating AccentMap objects all the time
 
Constructor Summary
CharUtils()
           
 
Method Summary
static String applyAccentMap(XPathContext context, String filePath, String str)
          Applies an accent map to a string, normalizing spaces in the process.
private static CharMap getAccentMap(XPathContext context, String filePath)
          Get the accent map corresponding to a file.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

accentMapCache

private static HashMap<String,CharMap> accentMapCache
Used to avoid recreating AccentMap objects all the time

Constructor Detail

CharUtils

public CharUtils()
Method Detail

getAccentMap

private static CharMap getAccentMap(XPathContext context,
                                    String filePath)
                             throws IOException
Get the accent map corresponding to a file.

Throws:
IOException - if we can't read the file.

applyAccentMap

public static String applyAccentMap(XPathContext context,
                                    String filePath,
                                    String str)
                             throws IOException
Applies an accent map to a string, normalizing spaces in the process. This function is typically used to remove diacritic marks from alphabetic characters. The accent map is read from the file with the given path. If the path is relative, it is resolved relative to the stylesheet calling this function. Note that the accent map is cached in memory so it doesn't need to be repeatedly read.

Parameters:
context - Context used to figure out which stylesheet is calling the function.
filePath - Path to the accent map file in question (typically leading to conf/accentFolding/accentMap.txt)
str - The string whose characters should be mapped.
Returns:
A new string with its characters mapped.
Throws:
IOException