org.apache.abdera.ext.bidi
Class BidiHelper

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

public final class BidiHelper
extends java.lang.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-02.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"));
 


Nested Class Summary
static class BidiHelper.Direction
           
 
Method Summary
static
<T extends Element>
java.lang.String
getBidiAttributeValue(T element, javax.xml.namespace.QName name)
          Return the text content of the specified attribute using the in-scope directionality
static
<T extends Element>
java.lang.String
getBidiAttributeValue(T element, java.lang.String name)
          Return the text content of the specified attribute using the in-scope directionality
static
<T extends Element>
java.lang.String
getBidiChildText(T element, javax.xml.namespace.QName child)
          Return the textual content of a child element using the in-scope directionality
static
<T extends Element>
java.lang.String
getBidiElementText(T element)
          Return the textual content of the specified element
static java.lang.String getBidiText(BidiHelper.Direction direction, java.lang.String text)
          Return the specified text with appropriate Unicode Control Characters given the specified Direction.
static
<T extends Element>
BidiHelper.Direction
getDirection(T element)
          Get the in-scope direction for an element.
static
<T extends Element>
void
setDirection(BidiHelper.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
 

Method Detail

setDirection

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


getDirection

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


getBidiText

public static java.lang.String getBidiText(BidiHelper.Direction direction,
                                           java.lang.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> java.lang.String getBidiChildText(T element,
                                                                    javax.xml.namespace.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> java.lang.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> java.lang.String getBidiAttributeValue(T element,
                                                                         java.lang.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> java.lang.String getBidiAttributeValue(T element,
                                                                         javax.xml.namespace.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