abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r545840 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/model/Element.java core/src/main/java/org/apache/abdera/model/ElementWrapper.java parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
Date Sun, 10 Jun 2007 04:38:59 GMT
Author: jmsnell
Date: Sat Jun  9 21:38:56 2007
New Revision: 545840

URL: http://svn.apache.org/viewvc?view=rev&rev=545840
Log:
Utility methods for retrieving a map of namespaces declared and a listing of all child elements

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Element.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ElementWrapper.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Element.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Element.java?view=diff&rev=545840&r1=545839&r2=545840
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Element.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Element.java Sat
Jun  9 21:38:56 2007
@@ -19,6 +19,7 @@
 
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 
@@ -214,5 +215,9 @@
    * Declare a namespace
    */
   void declareNS(String uri, String prefix);
+  
+  Map<String,String> getNamespaces();
+  
+  <T extends Element>List<T> getElements();
   
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ElementWrapper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ElementWrapper.java?view=diff&rev=545840&r1=545839&r2=545840
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ElementWrapper.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ElementWrapper.java
Sat Jun  9 21:38:56 2007
@@ -22,6 +22,7 @@
 import java.io.Writer;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 
@@ -205,4 +206,13 @@
   public Element getInternal() {
     return internal;
   }
+
+  public <T extends Element> List<T> getElements() {
+    return internal.getElements();
+  }
+
+  public Map<String, String> getNamespaces() {
+    return internal.getNamespaces();
+  }
+  
 }

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java?view=diff&rev=545840&r1=545839&r2=545840
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
Sat Jun  9 21:38:56 2007
@@ -24,9 +24,11 @@
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.activation.MimeType;
 import javax.activation.MimeTypeParseException;
@@ -690,5 +692,30 @@
     if (prefix != null && !prefix.equals("") && !isDeclared(ns, prefix))
{
       declareNS(ns,prefix);
     }
+  }
+
+  public Map<String, String> getNamespaces() {
+    Map<String,String> namespaces = new HashMap<String,String>();
+    OMElement current = this;
+    while(current != null) {
+      Iterator i = current.getAllDeclaredNamespaces();
+      while (i.hasNext()) {
+        OMNamespace ns = (OMNamespace) i.next();
+        String prefix = ns.getPrefix();
+        String uri = ns.getNamespaceURI();
+        if (!namespaces.containsKey(prefix))
+          namespaces.put(prefix, uri);
+      }
+      OMContainer parent = current.getParent();
+      current = (OMElement) ((parent != null && parent instanceof OMElement) ? parent
: null);
+    }
+    return namespaces;
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T extends Element>List<T> getElements() {
+    return new FOMList<T>(
+        new FOMElementIteratorWrapper(
+          (FOMFactory)factory,getChildElements()));
   }
 }



Mime
View raw message