/** * Attempt to guess the base direction of an element using an analysis of the directional properties of the * characters used. This is a brute-force style approach that can achieve fairly reasonable results when the element * text consists primarily of characters with the same bidi properties. This approach is implemented by the Snarfer * feed reader as is documented at http://www.xn--8ws00zhy3a.com/blog/2006/12/right-to-left-rss According to the * Atom Bidi spec, if the dir attribute is set explicitly, we should not do language guessing. This restriction can * be bypassed by setting ignoredir to true. */ public static <T extends Element> Direction guessDirectionFromTextProperties(T element, boolean ignoredir) { if (!ignoredir && hasDirection(element)) return getDirection(element); return Bidi.guessDirectionFromTextProperties(element.getText()); }