abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1374703 - in /abdera/java/branches/axiom-upgrade: ./ dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/io/ parser/src/main/java/org/apache/abdera/parser/stax/ parser/src/test/java/org/apache/abdera/test/parser/stax/ parser/src/te...
Date Sun, 19 Aug 2012 07:57:55 GMT
Author: veithen
Date: Sun Aug 19 07:57:55 2012
New Revision: 1374703

URL: http://svn.apache.org/viewvc?rev=1374703&view=rev
Log:
Merged latest changes from trunk.

Modified:
    abdera/java/branches/axiom-upgrade/   (props changed)
    abdera/java/branches/axiom-upgrade/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/io/CompressionUtil.java
  (props changed)
    abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
    abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
    abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMStAXFilter.java
    abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
    abdera/java/branches/axiom-upgrade/parser/src/test/resources/parseroptionstest.xml
    abdera/java/branches/axiom-upgrade/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java
  (props changed)

Propchange: abdera/java/branches/axiom-upgrade/
------------------------------------------------------------------------------
  Merged /abdera/java/trunk:r1372274-1374702

Propchange: abdera/java/branches/axiom-upgrade/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/io/CompressionUtil.java
------------------------------------------------------------------------------
  Merged /abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/io/CompressionUtil.java:r1372274-1374702

Modified: abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java?rev=1374703&r1=1374702&r2=1374703&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
(original)
+++ abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
Sun Aug 19 07:57:55 2012
@@ -17,12 +17,9 @@
  */
 package org.apache.abdera.parser.stax;
 
-import java.util.Map;
-
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.abdera.filter.ParseFilter;
 import org.apache.abdera.model.Content;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
@@ -34,12 +31,10 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 
 @SuppressWarnings( {"unchecked", "deprecation"})
 public class FOMBuilder extends StAXOMBuilder implements Constants {
@@ -87,14 +82,6 @@ public class FOMBuilder extends StAXOMBu
         return ctype;
     }
 
-    private boolean isAcceptableToParse(QName qname, boolean attribute) {
-        if (parserOptions == null)
-            return true;
-        ParseFilter filter = parserOptions.getParseFilter();
-        return (filter != null) ? (!attribute) ? filter.acceptable(qname) : filter.acceptable(parser.getName(),
qname)
-            : true;
-    }
-
     /**
      * Method next.
      * 
@@ -110,14 +97,6 @@ public class FOMBuilder extends StAXOMBu
         }
     }
 
-    private QName getAlias(QName qname) {
-        Map<QName, QName> map = parserOptions.getQNameAliasMap();
-        if (map == null)
-            return qname;
-        QName alias = map.get(qname);
-        return alias != null ? alias : qname;
-    }
-
     @Override
     protected OMElement constructNode(OMContainer parent, String name) {
         OMElement element = null;
@@ -126,9 +105,6 @@ public class FOMBuilder extends StAXOMBu
             indoc = true;
         }
         QName qname = parser.getName();
-        if (parserOptions.isQNameAliasMappingEnabled()) {
-            qname = getAlias(qname);
-        }
         element = fomfactory.createElement(qname, parent, this);
         if (element == null) {
             element = new FOMElement(qname, parent, fomfactory, this);
@@ -136,30 +112,6 @@ public class FOMBuilder extends StAXOMBu
         return element;
     }
 
-    @Override
-    protected void processAttributes(OMElement node) {
-        int attribCount = parser.getAttributeCount();
-        for (int i = 0; i < attribCount; i++) {
-            QName attr = parser.getAttributeName(i);
-            if (isAcceptableToParse(attr, true)) {
-                String uri = parser.getAttributeNamespace(i);
-                String prefix = parser.getAttributePrefix(i);
-                OMNamespace namespace = null;
-                if (uri != null && uri.length() > 0) {
-                    namespace = node.findNamespace(uri, prefix);
-                    if (namespace == null) {
-                        if (prefix == null || "".equals(prefix)) {
-                            prefix = OMSerializerUtil.getNextNSPrefix();
-                        }
-                        namespace = node.declareNamespace(uri, prefix);
-                    }
-                }
-                String value = parser.getAttributeValue(i);
-                node.addAttribute(parser.getAttributeLocalName(i), value, namespace);
-            }
-        }
-    }
-
     public <T extends Element> Document<T> getFomDocument() {
         while (!indoc && !done) {
             next();

Modified: abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java?rev=1374703&r1=1374702&r2=1374703&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
(original)
+++ abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
Sun Aug 19 07:57:55 2012
@@ -192,10 +192,12 @@ public class FOMDocument<T extends Eleme
                     OMComment comment = (OMComment)node;
                     factory.createOMComment(omdoc, comment.getValue());
                     break;
-                case OMNode.DTD_NODE:
-                    OMDocType doctype = (OMDocType)node;
-                    factory.createOMDocType(omdoc, doctype.getValue());
-                    break;
+                // TODO: Decide what to do with this code; it will no longer work in Axiom
1.2.14 (because of AXIOM-437).
+                //       On the other hand, since we filter out DTDs, this code is never
triggered.
+//                case OMNode.DTD_NODE:
+//                    OMDocType doctype = (OMDocType)node;
+//                    factory.createOMDocType(omdoc, doctype.getValue());
+//                    break;
                 case OMNode.ELEMENT_NODE:
                     Element el = (Element)node;
                     omdoc.addChild((OMNode)el.clone());

Modified: abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMStAXFilter.java
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMStAXFilter.java?rev=1374703&r1=1374702&r2=1374703&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMStAXFilter.java
(original)
+++ abdera/java/branches/axiom-upgrade/parser/src/main/java/org/apache/abdera/parser/stax/FOMStAXFilter.java
Sun Aug 19 07:57:55 2012
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera.parser.stax;
 
+import java.util.Map;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -47,7 +49,10 @@ class FOMStAXFilter extends XMLStreamRea
     private boolean ignorePI = false;
     private int depthInSkipElement;
     private int altEventType;
+    private QName altQName;
     private String altText;
+    private int[] attributeMap;
+    private int attributeCount;
     
     FOMStAXFilter(XMLStreamReader parent, ParserOptions parserOptions) {
         super(parent);
@@ -58,6 +63,7 @@ class FOMStAXFilter extends XMLStreamRea
                 ignoreWhitespace = parseFilter.getIgnoreWhitespace();
                 ignoreComments = parseFilter.getIgnoreComments();
                 ignorePI = parseFilter.getIgnoreProcessingInstructions();
+                attributeMap = new int[8];
             }
         }
         resetEvent();
@@ -65,17 +71,39 @@ class FOMStAXFilter extends XMLStreamRea
 
     private void resetEvent() {
         altEventType = -1;
+        altQName = null;
         altText = null;
+        attributeCount = -1;
     }
     
-    private boolean isAcceptableToParse(QName qname, boolean attribute) {
-        if (parserOptions == null)
-            return true;
-        ParseFilter filter = parserOptions.getParseFilter();
-        return (filter != null) ? (!attribute) ? filter.acceptable(qname) : filter.acceptable(getName(),
qname)
-            : true;
+    private void translateQName() {
+        if (parserOptions.isQNameAliasMappingEnabled()) {
+            Map<QName,QName> map = parserOptions.getQNameAliasMap();
+            if (map != null) {
+                altQName = map.get(super.getName());
+            }
+        }
     }
-
+    
+    private void mapAttributes() {
+        attributeCount = 0;
+        int orgAttCount = super.getAttributeCount();
+        if (orgAttCount > 0) {
+            QName elementQName = super.getName();
+            ParseFilter filter = parserOptions.getParseFilter();
+            for (int i=0; i<orgAttCount; i++) {
+                if (filter.acceptable(elementQName, super.getAttributeName(i))) {
+                    if (attributeCount == attributeMap.length) {
+                        int[] newAttributeMap = new int[attributeMap.length*2];
+                        System.arraycopy(attributeMap, 0, newAttributeMap, 0, attributeMap.length);
+                        attributeMap = newAttributeMap;
+                    }
+                    attributeMap[attributeCount++] = i;
+                }
+            }
+        }
+    }
+    
     @Override
     public int next() throws XMLStreamException {
         resetEvent();
@@ -107,10 +135,18 @@ class FOMStAXFilter extends XMLStreamRea
                         // shouldn't be that big of a problem
                         continue;
                     case START_ELEMENT:
-                        if (!isAcceptableToParse(getName(), false)) {
+                        ParseFilter filter = parserOptions.getParseFilter();
+                        if (filter != null && !filter.acceptable(super.getName()))
{
                             depthInSkipElement = 1;
                             continue;
                         }
+                        translateQName();
+                        if (attributeMap != null) {
+                            mapAttributes();
+                        }
+                        break;
+                    case END_ELEMENT:
+                        translateQName();
                         break;
                     case SPACE:
                         if (ignoreWhitespace) {
@@ -157,4 +193,54 @@ class FOMStAXFilter extends XMLStreamRea
     public String getText() {
         return altText != null ? altText : super.getText();
     }
+
+    @Override
+    public String getNamespaceURI() {
+        return altQName != null ? altQName.getNamespaceURI() : super.getNamespaceURI();
+    }
+
+    @Override
+    public String getLocalName() {
+        return altQName != null ? altQName.getLocalPart() : super.getLocalName();
+    }
+
+    @Override
+    public QName getName() {
+        return altQName != null ? altQName : super.getName();
+    }
+
+    @Override
+    public int getAttributeCount() {
+        return attributeCount != -1 ? attributeCount : super.getAttributeCount();
+    }
+
+    @Override
+    public String getAttributeNamespace(int index) {
+        return attributeCount != -1 ? super.getAttributeNamespace(attributeMap[index]) :
super.getAttributeNamespace(index);
+    }
+
+    @Override
+    public String getAttributeLocalName(int index) {
+        return attributeCount != -1 ? super.getAttributeLocalName(attributeMap[index]) :
super.getAttributeLocalName(index);
+    }
+
+    @Override
+    public String getAttributePrefix(int index) {
+        return attributeCount != -1 ? super.getAttributePrefix(attributeMap[index]) : super.getAttributePrefix(index);
+    }
+
+    @Override
+    public QName getAttributeName(int index) {
+        return attributeCount != -1 ? super.getAttributeName(attributeMap[index]) : super.getAttributeName(index);
+    }
+
+    @Override
+    public String getAttributeType(int index) {
+        return attributeCount != -1 ? super.getAttributeType(attributeMap[index]) : super.getAttributeType(index);
+    }
+
+    @Override
+    public String getAttributeValue(int index) {
+        return attributeCount != -1 ? super.getAttributeValue(attributeMap[index]) : super.getAttributeValue(index);
+    }
 }

Modified: abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java?rev=1374703&r1=1374702&r2=1374703&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
(original)
+++ abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
Sun Aug 19 07:57:55 2012
@@ -18,14 +18,23 @@
 package org.apache.abdera.test.parser.stax;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
 import org.apache.abdera.Abdera;
 import org.apache.abdera.filter.ParseFilter;
 import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
 import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.util.filter.AbstractParseFilter;
 import org.junit.Test;
 
 public class ParserOptionsTest {
@@ -66,4 +75,37 @@ public class ParserOptionsTest {
                 "/parseroptionstest.xml"), options);
         assertEquals("", doc.getRoot().getEntries().get(0).getSummary());
     }
+    
+    @Test
+    public void testAttributeFiltering() {
+        final QName filteredAttribute = new QName("urn:test", "attr");
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        options.setParseFilter(new AbstractParseFilter() {
+            public boolean acceptable(QName qname) {
+                return true;
+            }
+
+            public boolean acceptable(QName qname, QName attribute) {
+                return !filteredAttribute.equals(attribute);
+            }
+        });
+        Document<Feed> doc = parser.parse(ParserOptionsTest.class.getResourceAsStream(
+                "/parseroptionstest.xml"), options);
+        Entry entry = doc.getRoot().getEntries().get(0);
+        assertNull(entry.getAttributeValue(filteredAttribute));
+    }
+    
+    @Test
+    public void testQNameAliasMapping() {
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        Map<QName,QName> qnameAliases = new HashMap<QName,QName>();
+        qnameAliases.put(new QName("urn:test", "mylink"), new QName("http://www.w3.org/2005/Atom",
"link"));
+        options.setQNameAliasMap(qnameAliases);
+        options.setQNameAliasMappingEnabled(true);
+        Document<Feed> doc = parser.parse(ParserOptionsTest.class.getResourceAsStream(
+                "/parseroptionstest.xml"), options);
+        assertFalse(doc.getRoot().getEntries().get(0).getLinks().isEmpty());
+    }
 }

Modified: abdera/java/branches/axiom-upgrade/parser/src/test/resources/parseroptionstest.xml
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/src/test/resources/parseroptionstest.xml?rev=1374703&r1=1374702&r2=1374703&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/src/test/resources/parseroptionstest.xml (original)
+++ abdera/java/branches/axiom-upgrade/parser/src/test/resources/parseroptionstest.xml Sun
Aug 19 07:57:55 2012
@@ -2,9 +2,9 @@
 <feed xmlns="http://www.w3.org/2005/Atom">
     <!-- comment -->
     <?pi processing instruction?>
-    <entry>
+    <entry x:attr="value" xmlns:x="urn:test">
         <title>Atom-Powered Robots Run Amok</title>
-        <link href="http://example.org/2003/12/13/atom03"/>
+        <ns:mylink href="http://example.org/2003/12/13/atom03" xmlns:ns="urn:test"/>
         <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
         <updated>2003-12-13T18:30:02Z</updated>
         <summary>      </summary>

Propchange: abdera/java/branches/axiom-upgrade/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java
------------------------------------------------------------------------------
  Merged /abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java:r1372274-1374702



Mime
View raw message