abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r477984 - in /incubator/abdera/java/trunk/extensions/src: main/java/org/apache/abdera/ext/bidi/ test/java/org/apache/abdera/test/ext/ test/java/org/apache/abdera/test/ext/bidi/
Date Wed, 22 Nov 2006 00:10:44 GMT
Author: jmsnell
Date: Tue Nov 21 16:10:44 2006
New Revision: 477984

URL: http://svn.apache.org/viewvc?view=rev&rev=477984
Log:
Revised bidi code to sync up with http://www.ietf.org/internet-drafts/draft-snell-atompub-bidi-01.txt

This draft puts the dir into the Atom namespace.  Again, this is experimental and should not
be used
for production code as it is still under discussion by the atom wg.

Added:
    incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/bidi/
    incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/bidi/BidiTest.java
Modified:
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/bidi/BidiHelper.java
    incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/bidi/BidiHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/bidi/BidiHelper.java?view=diff&rev=477984&r1=477983&r2=477984
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/bidi/BidiHelper.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/bidi/BidiHelper.java
Tue Nov 21 16:10:44 2006
@@ -21,7 +21,6 @@
 
 import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
-import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.io.CharUtils;
 
 /**
@@ -30,11 +29,9 @@
  * 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.</p>
  * 
- * <p>The behavior implemented here is very simple.  The code looks for a dir
- * attribute either in the Atom namespace, the XHTML namespace or the 
- * Atom Bidi namespace (http://www.ietf.org/internet-drafts/draft-snell-atompub-bidi-00.txt).</p>
+ * <p>Based on http://www.ietf.org/internet-drafts/draft-snell-atompub-bidi-01.txt</p>
  * 
- * e.g.,
+ * <p>Example:</p>
  * <pre>
  *   &lt;feed xmlns="http://www.w3.org/2005/Atom" dir="rtl">
  *     ...
@@ -70,8 +67,6 @@
  */
 public final class BidiHelper {
 
-  private static final QName XHTML_DIR = new QName(Constants.XHTML_NS,"dir");
-  private static final QName ABIDI_DIR = new QName("http://purl.org/atompub/bidi","dir");
   private static final QName DIR = new QName("dir");
   
   BidiHelper() {}
@@ -83,67 +78,23 @@
    */
   public static <T extends Element>void setDirection(
     Direction direction, 
-    QName attribute, 
     T element) {
       if (direction != Direction.UNSPECIFIED)
         element.setAttributeValue(
-          attribute, 
+          DIR, 
           direction.toString().toLowerCase());
-      else 
-        element.removeAttribute(attribute);
+      else if (direction == Direction.UNSPECIFIED)
+        element.setAttributeValue(DIR,"");
+      else if (direction == null)
+        element.removeAttribute(DIR);
   }
   
   /**
-   * Set the value of dir attribute
-   */
-  public static <T extends Element>void setDirection(
-    Direction direction, 
-    T element) {
-      String dir = element.getAttributeValue("dir");
-      if (dir != null) {
-        setDirection(direction, DIR, element);
-      }
-      dir = element.getAttributeValue(XHTML_DIR);
-      if (dir != null) {
-        setDirection(direction, XHTML_DIR, element);
-      }
-      dir = element.getAttributeValue(ABIDI_DIR);
-      if (dir != null) {
-        setDirection(direction, ABIDI_DIR, element);
-      }
-      setDirection(direction, DIR, element);
-  }
-  
-  /**
-   * Get the in-scope direction for an element.  Currently, this is less
-   * than ideal because there currently isn't any standard way of expressing
-   * the direction in an Atom feed.  So, let's just support multiple approaches
-   * and hope that we get to the same place in the end. 
+   * Get the in-scope direction for an element.
    */
   public static <T extends Element>Direction getDirection(T element) {
-    // Couple of options since this hasn't yet been nailed down by the WG
     Direction direction = Direction.UNSPECIFIED;
-    // First try looking for a non-prefixed dir attribute
     String dir = element.getAttributeValue("dir");
-    // failing that, try looking for the XHTML dir attribute
-    if (dir == null) dir = element.getAttributeValue(XHTML_DIR);
-    // failing that, try looking for the proposed Atom bidi dir attribute
-    if (dir == null) dir = element.getAttributeValue(ABIDI_DIR);
-    // failing that, try looking for any attribute with the name dir in any 
-    // namespace and values that look appropriate
-    if (dir == null) {
-      for (QName qname : element.getAttributes()) {
-        if (qname.getLocalPart().equalsIgnoreCase("dir")) {
-          String value = element.getAttributeValue(qname);
-          if (value != null && value.length() > 0) {
-            try {
-              direction = Direction.valueOf(value.toUpperCase());
-              if (direction != null) return direction;
-            } catch (Exception e) {}
-          }
-        }
-      }
-    }
     if (dir != null && dir.length() > 0)
       direction = Direction.valueOf(dir.toUpperCase());
     else if (dir == null) {

Modified: incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java?view=diff&rev=477984&r1=477983&r2=477984
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java
Tue Nov 21 16:10:44 2006
@@ -20,6 +20,7 @@
 import org.apache.abdera.test.ext.media.MediaTest;
 import org.apache.abdera.test.ext.opensearch.*;
 import org.apache.abdera.test.ext.thread.ThreadTest;
+import org.apache.abdera.test.ext.bidi.BidiTest;
 import org.apache.abdera.test.ext.history.FeedPagingTest;
 
 public class TestSuite extends junit.framework.TestSuite {
@@ -34,5 +35,6 @@
     addTestSuite(FeedPagingTest.class);
     addTestSuite(ThreadTest.class);
     addTestSuite(MediaTest.class);
+    addTestSuite(BidiTest.class);
   }
 }

Added: incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/bidi/BidiTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/bidi/BidiTest.java?view=auto&rev=477984
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/bidi/BidiTest.java
(added)
+++ incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/bidi/BidiTest.java
Tue Nov 21 16:10:44 2006
@@ -0,0 +1,47 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.test.ext.bidi;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.bidi.BidiHelper;
+import org.apache.abdera.ext.bidi.BidiHelper.Direction;
+import org.apache.abdera.model.Feed;
+
+import junit.framework.TestCase;
+
+public class BidiTest extends TestCase {
+
+  public static void testBidi() throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Feed feed = abdera.getFactory().newFeed();
+    feed.setTitle("Testing");
+    feed.setSubtitle("Testing");
+    BidiHelper.setDirection(Direction.RTL, feed);
+    BidiHelper.setDirection(Direction.LTR, feed.getSubtitleElement());
+    
+    assertNotNull(feed.getAttributeValue("dir"));
+    assertEquals(BidiHelper.getDirection(feed), Direction.RTL);
+    assertEquals(BidiHelper.getDirection(feed.getTitleElement()), Direction.RTL);
+    assertEquals(BidiHelper.getDirection(feed.getSubtitleElement()), Direction.LTR);
+    assertEquals(BidiHelper.getBidiElementText(feed.getTitleElement()), BidiHelper.getBidiText(Direction.RTL,
"Testing"));
+    assertEquals(BidiHelper.getBidiElementText(feed.getSubtitleElement()), BidiHelper.getBidiText(Direction.LTR,
"Testing"));
+    
+  }
+  
+}



Mime
View raw message