org.apache.abdera.ext.bidi
Class BidiHelper

java.lang.Object
  extended by org.apache.abdera.ext.bidi.BidiHelper

public final class BidiHelper
extends Object

This is (hopefully) temporary. Ideally, this would be wrapped into the core model API so that the bidi stuff is handled seamlessly. There are still details being worked out on the Atom WG list and it's likely that at least one other impl (mozilla) will do something slightly different.

Based on http://www.ietf.org/internet-drafts/draft-snell-atompub-bidi-04.txt

Example:

   <feed xmlns="http://www.w3.org/2005/Atom" dir="rtl">
     ...
   </feed>
 

The getBidi___ elements use the in-scope direction to wrap the text with the appropriate Unicode control characters. e.g. if dir="rtl", the text is wrapped with the RLE and PDF controls. If the text already contains the control chars, the dir attribute is ignored.

 org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
 org.apache.abdera.model.Feed feed = abdera.getFactory().newFeed();
 feed.setAttributeValue("dir", "rtl");
 feed.setTitle("Testing");
 feed.addCategory("foo");
 
 System.out.println(BidiHelper.getBidiElementText(feed.getTitleElement()));
 System.out.println(BidiHelper.getBidiAttributeValue(feed.getCategories().get(0), "term"));
 


Field Summary
static QName DIR
           
 
Method Summary
static
<T extends Element>
String
getBidiAttributeValue(T element, QName name)
          Return the text content of the specified attribute using the in-scope directionality
static
<T extends Element>
String
getBidiAttributeValue(T element, String name)
          Return the text content of the specified attribute using the in-scope directionality
static
<T extends Element>
String
getBidiChildText(T element, QName child)
          Return the textual content of a child element using the in-scope directionality
static
<T extends Element>
String
getBidiElementText(T element)
          Return the textual content of the specified element
static String getBidiText(Bidi.Direction direction, String text)
          Return the specified text with appropriate Unicode Control Characters given the specified Direction.
static
<T extends Element>
Bidi.Direction
getDirection(T element)
          Get the in-scope direction for an element.
static
<T extends Element>
Bidi.Direction
guessDirectionFromEncoding(T element)
          Attempt to guess the base direction using the charset encoding.
static
<T extends Element>
Bidi.Direction
guessDirectionFromEncoding(T element, boolean ignoredir)
          Attempt to guess the base direction using the charset encoding.
static
<T extends Element>
Bidi.Direction
guessDirectionFromJavaBidi(T element)
          Use Java's built in support for bidi text to determine the base directionality of the element's text.
static
<T extends Element>
Bidi.Direction
guessDirectionFromJavaBidi(T element, boolean ignoredir)
          Use Java's built in support for bidi text to determine the base directionality of the element's text.
static
<T extends Element>
Bidi.Direction
guessDirectionFromLanguage(T element)
          Attempt to guess the base direction using the in-scope language.
static
<T extends Element>
Bidi.Direction
guessDirectionFromLanguage(T element, boolean ignoredir)
          Attempt to guess the base direction using the in-scope language.
static
<T extends Element>
Bidi.Direction
guessDirectionFromTextProperties(T element)
          Attempt to guess the base direction of an element using an analysis of the directional properties of the characters used.
static
<T extends Element>
Bidi.Direction
guessDirectionFromTextProperties(T element, boolean ignoredir)
          Attempt to guess the base direction of an element using an analysis of the directional properties of the characters used.
static
<T extends Element>
void
setDirection(Bidi.Direction direction, T element)
          Set the value of dir attribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR

public static final QName DIR
Method Detail

setDirection

public static <T extends Element> void setDirection(Bidi.Direction direction,
                                                    T element)
Set the value of dir attribute


getDirection

public static <T extends Element> Bidi.Direction getDirection(T element)
Get the in-scope direction for an element.


getBidiText

public static String getBidiText(Bidi.Direction direction,
                                 String text)
Return the specified text with appropriate Unicode Control Characters given the specified Direction.

Parameters:
direction - The Directionality of the text
text - The text to wrap within Unicode Control Characters
Returns:
The directionally-wrapped text

getBidiChildText

public static <T extends Element> String getBidiChildText(T element,
                                                          QName child)
Return the textual content of a child element using the in-scope directionality

Parameters:
element - The parent element
child - The XML QName of the child element
Returns:
The directionally-wrapped text of the child element

getBidiElementText

public static <T extends Element> String getBidiElementText(T element)
Return the textual content of the specified element

Parameters:
element - An element containing directionally-sensitive text
Returns:
The directionally-wrapped text of the element

getBidiAttributeValue

public static <T extends Element> String getBidiAttributeValue(T element,
                                                               String name)
Return the text content of the specified attribute using the in-scope directionality

Parameters:
element - The parent element
name - the name of the attribute
Returns:
The directionally-wrapped text of the attribute

getBidiAttributeValue

public static <T extends Element> String getBidiAttributeValue(T element,
                                                               QName name)
Return the text content of the specified attribute using the in-scope directionality

Parameters:
element - The parent element
name - the name of the attribute
Returns:
The directionally-wrapped text of the attribute

guessDirectionFromLanguage

public static <T extends Element> Bidi.Direction guessDirectionFromLanguage(T element)
Attempt to guess the base direction using the in-scope language. Implements the method used by Internet Explorer 7's feed view documented here: http://blogs.msdn.com/rssteam/archive/2007/05/17/reading-feeds-in-right-to-left-order.aspx. This algorithm differs slightly from the method documented in that the primary language tag is case insensitive. If the language tag is not specified, then the default Locale is used to determine the direction. If the dir attribute is specified, the direction will be determine using it's value instead of the language


guessDirectionFromLanguage

public static <T extends Element> Bidi.Direction guessDirectionFromLanguage(T element,
                                                                            boolean ignoredir)
Attempt to guess the base direction using the in-scope language. Implements the method used by Internet Explorer 7's feed view documented here: http://blogs.msdn.com/rssteam/archive/2007/05/17/reading-feeds-in-right-to-left-order.aspx. This algorithm differs slightly from the method documented in that the primary language tag is case insensitive. If the language tag is not specified, then the default Locale is used to determine the direction. 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.


guessDirectionFromEncoding

public static <T extends Element> Bidi.Direction guessDirectionFromEncoding(T element)
Attempt to guess the base direction using the charset encoding. This is a bit of a last resort approach


guessDirectionFromEncoding

public static <T extends Element> Bidi.Direction guessDirectionFromEncoding(T element,
                                                                            boolean ignoredir)
Attempt to guess the base direction using the charset encoding. This is a bit of a last resort approach


guessDirectionFromTextProperties

public static <T extends Element> Bidi.Direction guessDirectionFromTextProperties(T element)
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 If the dir attribute is specified, the direction will be determine using it's value instead of the characteristics of the text


guessDirectionFromTextProperties

public static <T extends Element> Bidi.Direction guessDirectionFromTextProperties(T element,
                                                                                  boolean ignoredir)
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.


guessDirectionFromJavaBidi

public static <T extends Element> Bidi.Direction guessDirectionFromJavaBidi(T element)
Use Java's built in support for bidi text to determine the base directionality of the element's text. The response to this only indicates the *base* directionality, it does not indicate whether or not there are any RTL characters in the text. If the dir attribute is specified, the direction will be determine using it's value instead of the characteristics of the text


guessDirectionFromJavaBidi

public static <T extends Element> Bidi.Direction guessDirectionFromJavaBidi(T element,
                                                                            boolean ignoredir)
Use Java's built in support for bidi text to determine the base directionality of the element's text. The response to this only indicates the *base* directionality, it does not indicate whether or not there are any RTL characters in the text. 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.



Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.