abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1372163 [2/4] - in /abdera/java/branches/axiom-upgrade: ./ dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/io/ parser/ parser/src/main/java/org/apache/abdera/parser/stax/ parser/src/test/java/org/apache/abdera/test/parser/stax/...
Date Sun, 12 Aug 2012 18:07:54 GMT

Propchange: abdera/java/branches/axiom-upgrade/
------------------------------------------------------------------------------
  Merged /abdera/java/trunk:r1371963-1372162

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:r1371963-1372162

Modified: abdera/java/branches/axiom-upgrade/parser/pom.xml
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/pom.xml?rev=1372163&r1=1372162&r2=1372163&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/pom.xml (original)
+++ abdera/java/branches/axiom-upgrade/parser/pom.xml Sun Aug 12 18:07:30 2012
@@ -72,13 +72,4 @@
       <scope>runtime</scope>
     </dependency>
   </dependencies>
-    <repositories>
-        <repository>
-            <id>apache.snapshots</id>
-            <url>http://repository.apache.org/snapshots</url>
-           <snapshots>
-               <enabled>true</enabled>
-           </snapshots>
-        </repository>
-    </repositories>
 </project>

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=1372163&r1=1372162&r2=1372163&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 12 18:07:30 2012
@@ -20,8 +20,6 @@ package org.apache.abdera.parser.stax;
 import java.util.Map;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.abdera.filter.ParseFilter;
@@ -32,15 +30,12 @@ import org.apache.abdera.model.Text;
 import org.apache.abdera.parser.ParseException;
 import org.apache.abdera.parser.ParserOptions;
 import org.apache.abdera.util.Constants;
-import org.apache.axiom.om.OMConstants;
 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.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
@@ -52,27 +47,15 @@ public class FOMBuilder extends StAXOMBu
     private final FOMFactory fomfactory;
     private final ParserOptions parserOptions;
     private boolean indoc = false;
-    private int depthInSkipElement = 0;
-    private boolean ignoreWhitespace = false;
-    private boolean ignoreComments = false;
-    private boolean ignorePI = false;
 
     public FOMBuilder(FOMFactory factory, XMLStreamReader parser, ParserOptions parserOptions)
{
-        super(factory, parser);
+        super(factory, new FOMStAXFilter(parser, parserOptions));
         this.document = (OMDocument)factory.newDocument();
         this.parserOptions = parserOptions;
         this.fomfactory = factory;
         String enc = parser.getCharacterEncodingScheme();
         document.setCharsetEncoding(enc != null ? enc : "utf-8");
         document.setXMLVersion(parser.getVersion() != null ? parser.getVersion() : "1.0");
-        if (parserOptions != null) {
-            ParseFilter parseFilter = parserOptions.getParseFilter();
-            if (parseFilter != null) {
-                ignoreWhitespace = parseFilter.getIgnoreWhitespace();
-                ignoreComments = parseFilter.getIgnoreComments();
-                ignorePI = parseFilter.getIgnoreProcessingInstructions();
-            }
-        }
     }
 
     public ParserOptions getParserOptions() {
@@ -112,32 +95,6 @@ public class FOMBuilder extends StAXOMBu
             : true;
     }
 
-    private OMNode applyTextFilter(int type) {
-        if (parserOptions != null) {
-            ParseFilter parseFilter = parserOptions.getParseFilter();
-            if (parseFilter != null) {
-                if (parser.isWhiteSpace() && parseFilter.getIgnoreWhitespace())
-                    return createOMText("", type);
-            }
-        }
-        return createOMText(type);
-    }
-
-    private int getNextElementToParse() throws XMLStreamException {
-        int token = parser.next();
-        if (depthInSkipElement == 0 && token != XMLStreamConstants.START_ELEMENT)
{
-            return token;
-        } else if (token == XMLStreamConstants.START_ELEMENT && isAcceptableToParse(parser.getName(),
false)
-            && depthInSkipElement == 0) {
-            return token;
-        } else if (token == XMLStreamConstants.START_ELEMENT) {
-            depthInSkipElement++;
-        } else if (token == XMLStreamConstants.END_ELEMENT) { // otherwise skip like crazy
-            depthInSkipElement--;
-        }
-        return getNextElementToParse();
-    }
-
     /**
      * Method next.
      * 
@@ -146,79 +103,9 @@ public class FOMBuilder extends StAXOMBu
      */
     public int next() throws OMException {
         try {
-            if (done) {
-                throw new OMException();
-            }
-            int token = getNextElementToParse();
-            if (!cache) {
-                return token;
-            }
-            switch (token) {
-                case XMLStreamConstants.START_ELEMENT:
-                    lastNode = createOMElement();
-                    break;
-                case XMLStreamConstants.START_DOCUMENT:
-                    document.setXMLVersion(parser.getVersion() != null ? parser.getVersion()
: "1.0");
-                    document.setCharsetEncoding(parser.getEncoding() != null ? parser.getEncoding()
: "utf-8");
-                    document.setStandalone(parser.isStandalone() ? YES : NO);
-                    break;
-                case XMLStreamConstants.CHARACTERS:
-                    lastNode = applyTextFilter(XMLStreamConstants.CHARACTERS);
-                    break;
-                case XMLStreamConstants.CDATA:
-                    lastNode = applyTextFilter(XMLStreamConstants.CDATA);
-                    break;
-                case XMLStreamConstants.END_ELEMENT:
-                    endElement();
-                    break;
-                case XMLStreamConstants.END_DOCUMENT:
-                    done = true;
-                    ((OMContainerEx)this.document).setComplete(true);
-                    break;
-                case XMLStreamConstants.SPACE:
-                    if (!ignoreWhitespace)
-                        lastNode = createOMText(XMLStreamConstants.SPACE);
-                    break;
-                case XMLStreamConstants.COMMENT:
-                    if (!ignoreComments)
-                        createComment();
-                    break;
-                case XMLStreamConstants.DTD:
-                    // Current StAX cursor model implementations inconsistently handle DTDs.
-                    // Woodstox, for instance, does not provide a means of getting to the
complete
-                    // doctype declaration (which is actually valid according to the spec,
which
-                    // is broken). The StAX reference impl returns the complete doctype declaration
-                    // despite the fact that doing so is apparently against the spec. We
can get
-                    // to the complete declaration in Woodstox if we want to use their proprietary
-                    // extension APIs. It's unclear how other Stax impls handle this. So..
for now,
-                    // we're just going to ignore the DTD. The DTD will still be processed
as far
-                    // as entities are concerned, but we will not be able to reserialize
the parsed
-                    // document with the DTD. Since very few folks actually use DTD's in
feeds
-                    // right now (and we should likely be encouraging folks not to do so),
this
-                    // shouldn't be that big of a problem
-                    // if (!parserOptions.getIgnoreDoctype())
-                    // createDTD();
-                    break;
-                case XMLStreamConstants.PROCESSING_INSTRUCTION:
-                    if (!ignorePI)
-                        createPI();
-                    break;
-                case XMLStreamConstants.ENTITY_REFERENCE:
-                    String val = parserOptions.resolveEntity(super.getName());
-                    if (val == null)
-                        throw new ParseException("Unresolved undeclared entity: " + super.getName());
-                    else
-                        lastNode = createOMText(val, XMLStreamConstants.CHARACTERS);
-                    break;
-                default:
-                    throw new ParseException();
-            }
-            return token;
-        } catch (ParseException e) {
-            throw e;
+            return super.next();
         } catch (OMException e) {
-            throw new ParseException(e);
-        } catch (Exception e) {
+            // TODO: transforming the OMException here is not ideal!
             throw new ParseException(e);
         }
     }
@@ -287,50 +174,4 @@ public class FOMBuilder extends StAXOMBu
     public FOMFactory getFactory() {
         return fomfactory;
     }
-
-    /**
-     * Method createOMText.
-     * 
-     * @return Returns OMNode.
-     * @throws OMException
-     */
-    protected OMNode createOMText(String value, int textType) throws OMException {
-        OMNode node = null;
-        if (lastNode == null) {
-            return null;
-        } else if (!lastNode.isComplete()) {
-            node = createOMText(value, (OMElement)lastNode, textType);
-        } else {
-            OMContainer parent = lastNode.getParent();
-            if (!(parent instanceof OMDocument)) {
-                node = createOMText(value, (OMElement)parent, textType);
-            }
-        }
-        return node;
-    }
-
-    /**
-     * This method will check whether the text can be optimizable using IS_BINARY flag. If
that is set then we try to
-     * get the data handler.
-     * 
-     * @param omElement
-     * @param textType
-     * @return omNode
-     */
-    private OMNode createOMText(String value, OMElement omElement, int textType) {
-        try {
-            // TODO:Check on this. I'm not sure it's actually used
-            // if (isDataHandlerAware && Boolean.TRUE == parser.getProperty(OMConstants.IS_BINARY))
{
-            if (Boolean.TRUE == parser.getProperty(OMConstants.IS_BINARY)) {
-                Object dataHandler = parser.getProperty(OMConstants.DATA_HANDLER);
-                OMText text = new FOMTextValue(dataHandler, true, (OMFactory)this);
-                omElement.addChild(text);
-                return text;
-            } else {
-                return new FOMTextValue(omElement, value, textType, (OMFactory)this.fomfactory);
-            }
-        } catch (IllegalArgumentException e) {
-            return new FOMTextValue(omElement, value, textType, (OMFactory)this.fomfactory);
-        }
-    }
 }

Modified: abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java
URL: http://svn.apache.org/viewvc/abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java?rev=1372163&r1=1372162&r2=1372163&view=diff
==============================================================================
--- abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java
(original)
+++ abdera/java/branches/axiom-upgrade/parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java
Sun Aug 12 18:07:30 2012
@@ -33,20 +33,11 @@ public abstract class BaseParserTestCase
         return abdera.getParser();
     }
 
-    protected static <T extends Element> Document<T> parse(IRI uri) {
-        try {
-            String uriStr = uri.toString();
-            String path = uriStr.substring(uriStr.indexOf("//") + 1);
-            InputStream stream = BaseParserTestCase.class.getResourceAsStream(path);
-            return getParser().parse(stream, uri.toString());
-        } catch (Exception e) {
-            // when getting it local fails, fall back to getting it from the server
-            try {
-                return getParser().parse(uri.toURL().openStream(), uri.toString());
-            } catch (Exception ex) {
-            }
-        }
-        return null;
+    protected static <T extends Element> Document<T> parse(IRI uri) throws Exception
{
+        String uriStr = uri.toString();
+        String path = uriStr.substring(uriStr.indexOf("//") + 1);
+        InputStream stream = BaseParserTestCase.class.getResourceAsStream(path);
+        return getParser().parse(stream, uri.toString());
     }
 
 }



Mime
View raw message