String reversed;
String value;
boolean inverse;
String nodeName;
ArabicShaping arabicshaper = new ArabicShaping(
ArabicShaping.LETTERS_SHAPE|
ArabicShaping.TEXT_DIRECTION_LOGICAL|
ArabicShaping.LENGTH_GROW_SHRINK);
String elementNames[] = {"fo:block", "fo:inline",
"fo:basic-link"};
//nameCount = elementNames.length();
nameCount = 3;
for(l = 0; l < nameCount; l++) {
elements = document.getElementsByTagName(elementNames[l]);
if (elements != null) {
elementCount = elements.getLength();
for (k = 0; k < elementCount; k++) {
element = (Element)elements.item(k);
element.setAttribute("direction", "rtl");
if(element.hasChildNodes()) {
childs = element.getChildNodes();
childCount = childs.getLength();
// check whether node only contains inline and link elements
inverse = true;
for (j = 0; j < childCount; j++) {
child = childs.item(j);
if(child.getNodeType() == Node.TEXT_NODE) {
if((child.getNodeValue().replaceAll(" ", "").length() > 1)) {
value = childs.item(j).getNodeValue();
value = arabicshaper.shape(value);
value = invertArabic(value);
/*reversed = "";
for(m = value.length()-1; m >= 0; m--) {
reversed += value.charAt(m);
}*/