String newNormalizationForm = "NFC";
if (getArgumentCount() > 1)
{newNormalizationForm = getArgument(1).eval(contextSequence).getStringValue().toUpperCase().trim();}
//TODO : handle the "FULLY-NORMALIZED" string...
if ("".equals(newNormalizationForm))
{result = new StringValue(s1.getStringValue());}
else {
Object returnedObject = null;
try {
if (clazz == null)
{clazz = Class.forName("com.ibm.icu.text.Normalizer");}
if (modeField == null || !normalizationForm.equals(newNormalizationForm)) {
try {
modeField = clazz.getField(newNormalizationForm);
} catch (final NoSuchFieldException e) {
logger.error("err:FOCH0003: unknown normalization form");
throw new XPathException(this, ErrorCodes.FOCH0003, "unknown normalization form");
}
//com.ibm.icu.text.Normalizer.Mode
modeObject = modeField.get(null);
normalizationForm = newNormalizationForm;
}
if (constructor == null)
//Second argument shouldn't be a problem : modeField always has the same type
{constructor = clazz.getConstructor(
new Class[] { String.class, modeField.getType(), Integer.TYPE}
);}
final Object[] args = new Object[] { s1.getStringValue(), modeObject, DUMMY_INTEGER };
if (method == null)
{method = clazz.getMethod( "getText", (Class[])null );}
//Normalizer n = new Normalizer(s1.getStringValue(), Normalizer.NFC, 0);
final Object instance = constructor.newInstance(args);
//result = new StringValue(n.getText());
returnedObject = method.invoke( instance, (Object[])null );
} catch (final Exception e) {
logger.error("Can not find the ICU4J library in the classpath " + e.getMessage());
throw new XPathException(this, "Can not find the ICU4J library in the classpath " + e.getMessage());
}
result = new StringValue((String)returnedObject);
}
}
if (context.getProfiler().isEnabled())
{context.getProfiler().end(this, "", result);}