abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [21/49] - in /abdera/abdera2: ./ .settings/ activities/ activities/src/ activities/src/main/ activities/src/main/java/ activities/src/main/java/org/ activities/src/main/java/org/apache/ activities/src/main/java/org/apache/abdera2/ ...
Date Tue, 20 Sep 2011 15:57:20 GMT
Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CategorySchemeSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CategorySchemeSelector.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CategorySchemeSelector.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CategorySchemeSelector.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.abdera2.model.selector;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Category;
+
+/**
+ * Selector implementation that selects Category elements using the 
+ * specified scheme(s).
+ * @see org.apache.abdera2.common.selector.Selector
+ */
+public class CategorySchemeSelector 
+  implements Selector {
+
+  private static final long serialVersionUID = 7008363856043465676L;
+  private final Set<IRI> schemes = new HashSet<IRI>();
+  
+  public CategorySchemeSelector(String... schemes) {
+    for (String scheme : schemes)
+      this.schemes.add(new IRI(scheme));
+  }
+  
+  public CategorySchemeSelector(IRI... schemes) {
+    for (IRI scheme : schemes) 
+      this.schemes.add(scheme);
+  }
+  
+  public boolean select(Object item) {
+    if (!(item instanceof Category)) return false;
+    return schemes.isEmpty() || schemes.contains(((Category)item).getScheme());
+  }
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CategorySchemeSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CollectionAcceptSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CollectionAcceptSelector.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CollectionAcceptSelector.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CollectionAcceptSelector.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.abdera2.model.selector;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Collection;
+
+/**
+ * Selector implementation that selects Collections elements that contain
+ * specific mimetypes, or compatible equivalent mimetimes within child
+ * accept elements
+ */
+public class CollectionAcceptSelector 
+  implements Selector {
+
+  private static final long serialVersionUID = 1821941024155067263L;
+  private final Set<MimeType> types = 
+    new HashSet<MimeType>();
+  
+  public CollectionAcceptSelector(String... types) {
+    try {
+      for (String type:types)
+        this.types.add(new MimeType(type));
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
+    }
+  }
+  
+  public CollectionAcceptSelector(MimeType... types) {
+    for (MimeType type : types)
+      this.types.add(type);
+  }
+  
+  public boolean select(Object item) {
+    if (!(item instanceof Collection)) return false;
+    Collection citem = (Collection) item;
+    for (MimeType type : types) 
+      if (!citem.accepts(type))
+        return false;
+    return true;
+  }
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CollectionAcceptSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkHrefLangSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkHrefLangSelector.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkHrefLangSelector.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkHrefLangSelector.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.abdera2.model.selector;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.common.lang.Range;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Link;
+
+/**
+ * Selector implementation that selects Link elements specifying
+ * a matching hreflang attribute.
+ * @see org.apache.abdera2.common.selector.Selector
+ */
+public class LinkHrefLangSelector implements Selector {
+
+  private static final long serialVersionUID = 7008363856043465676L;
+  private final Set<Lang> langs = new HashSet<Lang>();
+  private final Range range;
+  
+  public LinkHrefLangSelector(Range range) {
+    this.range = range;
+  }
+  
+  public LinkHrefLangSelector(String... langs) {
+    this.range = null;
+    for (String lang : langs)
+      this.langs.add(new Lang(lang));
+  }
+  
+  public LinkHrefLangSelector(Lang... langs) {
+    this.range = null;
+    for (Lang lang : langs)
+      this.langs.add(lang);
+  }
+
+  public boolean select(Object item) {
+    if (!(item instanceof Link)) return false;
+    Link link = (Link)item;
+    Lang lang = new Lang(link.getHrefLang());
+    return range != null ? 
+      range.matches(lang) : 
+        langs.isEmpty() || 
+        langs.contains(lang);
+  }
+
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkHrefLangSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkRelSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkRelSelector.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkRelSelector.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkRelSelector.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.abdera2.model.selector;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Link;
+
+/**
+ * Selector implementation that selects Link elements 
+ * that match a given set of rel attribute values
+ * @see org.apache.abdera2.common.selector.Selector
+ */
+public class LinkRelSelector implements Selector {
+
+  private static final long serialVersionUID = 7008363856043465676L;
+  private final Set<String> rels = new HashSet<String>();
+  
+  public LinkRelSelector(String... rels) {
+    for (String rel : rels)
+      this.rels.add(rel);
+  }
+
+  public boolean select(Object item) {
+    if (!(item instanceof Link)) return false;
+    Link link = (Link)item;
+    String rel = link.getRel();
+    rel = rel == null || 
+          rel.length() == 0 ? 
+              Link.REL_ALTERNATE : rel;
+    rel = rel.toLowerCase();
+    return rels.isEmpty() || 
+           rels.contains(rel) || 
+           rels.contains(Link.Helper.getRelEquiv(rel));
+  }
+
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/LinkRelSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/XPathSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/XPathSelector.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/XPathSelector.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/XPathSelector.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.abdera2.model.selector;
+
+import java.util.Map;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.xpath.XPath;
+
+/**
+ * Selects a collection based on a boolean XPath expression
+ * @see org.apache.abdera2.common.selector.Selector
+ */
+public class XPathSelector implements Selector {
+
+    private static final long serialVersionUID = 7751803876821166591L;
+
+    private final XPath xpath;
+    private final Map<String, String> namespaces;
+    private final String path;
+
+    public XPathSelector(String path) {
+        this(path, (Abdera.getInstance()).getXPath());
+    }
+
+    public XPathSelector(String path, XPath xpath) {
+        this(path, xpath, xpath.getDefaultNamespaces());
+    }
+
+    public XPathSelector(String path, XPath xpath, Map<String, String> namespaces) {
+        this.path = path;
+        this.xpath = xpath;
+        this.namespaces = namespaces;
+    }
+
+    public boolean select(Object element) {
+      if (!(element instanceof Element)) return false;
+        if (xpath.booleanValueOf(path, (Element)element, namespaces)) {
+            return true;
+        }
+        return false;
+    }
+
+    public void addNamespace(String prefix, String uri) {
+        namespaces.put(prefix, uri);
+    }
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/XPathSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParser.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParser.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParser.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParser.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,170 @@
+/*
+ * 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.abdera2.parser;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+
+/**
+ * Abstract base implementation of Abdera Parser.
+ */
+public abstract class AbstractParser implements Parser {
+
+    protected Abdera abdera;
+    protected ParserOptions options; 
+    protected final Set<String> formats = new HashSet<String>();
+
+    protected AbstractParser() {
+        this(Abdera.getInstance());
+    }
+    
+    protected AbstractParser(String... formats) {
+      this(Abdera.getInstance(),formats);
+    }
+
+    protected AbstractParser(Abdera abdera) {
+        this.abdera = abdera;
+    }
+    
+    protected AbstractParser(Abdera abdera, String... formats) {
+      this.abdera = abdera;
+      for (String format : formats)
+        this.formats.add(format);
+    }
+
+    public Abdera getAbdera() {
+        return abdera;
+    }
+
+    public void setAbdera(Abdera abdera) {
+        this.abdera = abdera;
+    }
+
+    public Factory getFactory() {
+        return getAbdera().getFactory();
+    }
+
+    public <T extends Element> Document<T> parse(InputStream in) throws ParseException {
+        return parse(in, null, getDefaultParserOptions());
+    }
+
+    public <T extends Element> Document<T> parse(XMLStreamReader reader) throws ParseException {
+        return parse(reader, null, getDefaultParserOptions());
+    }
+
+    public <T extends Element> Document<T> parse(InputStream in, String base) throws ParseException {
+        return parse(in, base, getDefaultParserOptions());
+    }
+
+    public <T extends Element> Document<T> parse(InputStream in, ParserOptions options) throws ParseException {
+        return parse(in, null, options);
+    }
+
+    public <T extends Element> Document<T> parse(InputStream in, String base, ParserOptions options)
+        throws ParseException {
+        return parse(new InputStreamReader(in), base, options);
+    }
+
+    public <T extends Element> Document<T> parse(Reader in) throws ParseException {
+        return parse(in, null, getDefaultParserOptions());
+    }
+
+    public <T extends Element> Document<T> parse(Reader in, String base) throws ParseException {
+        return parse(in, base, getDefaultParserOptions());
+    }
+
+    public <T extends Element> Document<T> parse(Reader in, ParserOptions options) throws ParseException {
+        return parse(in, null, options);
+    }
+
+    public <T extends Element> Document<T> parse(ReadableByteChannel buf, ParserOptions options) throws ParseException {
+        return parse(buf, null, options);
+    }
+
+    public <T extends Element> Document<T> parse(ReadableByteChannel buf, String base, ParserOptions options)
+        throws ParseException {
+        String charset = options.getCharset();
+        return parse(Channels.newReader(buf, charset != null ? charset : "utf-8"), base, options);
+    }
+
+    public <T extends Element> Document<T> parse(ReadableByteChannel buf, String base) throws ParseException {
+        return parse(buf, base, getDefaultParserOptions());
+    }
+
+    public <T extends Element> Document<T> parse(ReadableByteChannel buf) throws ParseException {
+        return parse(buf, null, getDefaultParserOptions());
+    }
+
+    public synchronized ParserOptions getDefaultParserOptions() {
+        if (options == null)
+            options = initDefaultParserOptions();
+
+        // Make a copy of the options, so that changes to it don't result in
+        // changes to the Parser's defaults. Also, this allows us to remain
+        // thread safe without having to make ParseOptions implementations
+        // synchronized.
+
+        try {
+            return (ParserOptions)options.clone();
+        } catch (CloneNotSupportedException cnse) {
+            // This shouldn't actually happen
+            throw new RuntimeException(cnse);
+        }
+    }
+
+    protected abstract ParserOptions initDefaultParserOptions();
+
+    public synchronized Parser setDefaultParserOptions(ParserOptions options) {
+        // Ok, we need to make a defensive copy of the options, since otherwise
+        // the caller still has access to the object, which means our access to
+        // it isn't certain to be thread safe.
+
+        try {
+            this.options = (options != null) ? (ParserOptions)options.clone() : initDefaultParserOptions();
+            return this;
+        } catch (CloneNotSupportedException cnse) {
+            // This shouldn't actually happen
+            throw new RuntimeException(cnse);
+        }
+    }
+
+    public Iterable<String> getInputFormats() {
+      return formats;
+  }
+
+  public boolean parsesFormat(String mediatype) {
+      for (String format : formats) {
+          if (MimeTypeHelper.isMatch(format, mediatype))
+              return true;
+      }
+      return false;
+  }
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParserOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParserOptions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParserOptions.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParserOptions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,434 @@
+/*
+ * 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.abdera2.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.io.Compression;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.parser.filter.ParseFilter;
+
+/**
+ * Non thread-safe abstract implementation of ParserOptions
+ */
+public abstract class AbstractParserOptions implements ParserOptions, Cloneable {
+
+    protected Factory factory = null;
+    protected String charset = null;
+    protected ParseFilter parseFilter = null;
+    protected boolean detect = false;
+    protected boolean preserve = true;
+    protected boolean filterreserved = false;
+    protected char replacement = 0;
+    protected Compression.CompressionCodec[] codecs = null;
+    protected boolean resolveentities = true;
+    protected Map<String, String> entities = new HashMap<String, String>();
+
+    protected boolean qnamealiasing = false;
+    protected Map<QName, QName> aliases = null;
+
+    protected abstract void initFactory();
+
+    protected abstract void checkFactory(Factory factory);
+
+    protected AbstractParserOptions() {
+        initDefaultEntities();
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        AbstractParserOptions copy = (AbstractParserOptions)super.clone();
+
+        // Object's clone implementation takes care of the rest, we just need
+        // deep copies of the two filters, in case they're carrying around some
+        // state with them.
+
+        if (parseFilter != null)
+            copy.parseFilter = (ParseFilter)parseFilter.clone();
+
+        return copy;
+    }
+
+    public Factory getFactory() {
+        if (factory == null)
+            initFactory();
+        return factory;
+    }
+
+    public ParserOptions setFactory(Factory factory) {
+        checkFactory(factory);
+        this.factory = factory;
+        return this;
+    }
+
+    public String getCharset() {
+        return charset;
+    }
+
+    public ParserOptions setCharset(String charset) {
+        this.charset = charset;
+        return this;
+    }
+
+    public ParseFilter getParseFilter() {
+        return parseFilter;
+    }
+
+    public ParserOptions setParseFilter(ParseFilter parseFilter) {
+        this.parseFilter = parseFilter;
+        return this;
+    }
+
+    public boolean getAutodetectCharset() {
+        return this.detect;
+    }
+
+    public ParserOptions setAutodetectCharset(boolean detect) {
+        this.detect = detect;
+        return this;
+    }
+
+    public boolean getMustPreserveWhitespace() {
+        return preserve;
+    }
+
+    public ParserOptions setMustPreserveWhitespace(boolean preserve) {
+        this.preserve = preserve;
+        return this;
+    }
+
+    public boolean getFilterRestrictedCharacters() {
+        return filterreserved;
+    }
+
+    public ParserOptions setFilterRestrictedCharacters(boolean filter) {
+        this.filterreserved = filter;
+        return this;
+    }
+
+    public char getFilterRestrictedCharacterReplacement() {
+        return replacement;
+    }
+
+    public ParserOptions setFilterRestrictedCharacterReplacement(char replacement) {
+        this.replacement = replacement;
+        return this;
+    }
+
+    public Compression.CompressionCodec[] getCompressionCodecs() {
+        return codecs;
+    }
+
+    public ParserOptions setCompressionCodecs(Compression.CompressionCodec... codecs) {
+        this.codecs = codecs;
+        return this;
+    }
+
+    public ParserOptions registerEntity(String name, String value) {
+        entities.put(name, value);
+        return this;
+    }
+
+    private void initDefaultEntities() {
+        registerEntity("quot", "\"");
+        registerEntity("amp", "\u0026");
+        registerEntity("lt", "\u003C");
+        registerEntity("gt", "\u003E");
+        registerEntity("nbsp", " ");
+        registerEntity("iexcl", "\u00A1");
+        registerEntity("cent", "\u00A2");
+        registerEntity("pound", "\u00A3");
+        registerEntity("curren", "\u00A4");
+        registerEntity("yen", "\u00A5");
+        registerEntity("brvbar", "\u00A6");
+        registerEntity("sect", "\u00A7");
+        registerEntity("uml", "\u00A8");
+        registerEntity("copy", "\u00A9");
+        registerEntity("ordf", "\u00AA");
+        registerEntity("laquo", "\u00AB");
+        registerEntity("not", "\u00AC");
+        registerEntity("shy", "\u00AD");
+        registerEntity("reg", "\u00AE");
+        registerEntity("macr", "\u00AF");
+        registerEntity("deg", "\u00B0");
+        registerEntity("plusmn", "\u00B1");
+        registerEntity("sup2", "\u00B2");
+        registerEntity("sup3", "\u00B3");
+        registerEntity("acute", "\u00B4");
+        registerEntity("micro", "\u00B5");
+        registerEntity("para", "\u00B6");
+        registerEntity("middot", "\u00B7");
+        registerEntity("cedil", "\u00B8");
+        registerEntity("sup1", "\u00B9");
+        registerEntity("ordm", "\u00BA");
+        registerEntity("raquo", "\u00BB");
+        registerEntity("frac14", "\u00BC");
+        registerEntity("frac12", "\u00BD");
+        registerEntity("frac34", "\u00BE");
+        registerEntity("iquest", "\u00BF");
+        registerEntity("Agrave", "\u00C0");
+        registerEntity("Aacute", "\u00C1");
+        registerEntity("Acirc", "\u00C2");
+        registerEntity("Atilde", "\u00C3");
+        registerEntity("Auml", "\u00C4");
+        registerEntity("Aring", "\u00C5");
+        registerEntity("AElig", "\u00C6");
+        registerEntity("Ccedil", "\u00C7");
+        registerEntity("Egrave", "\u00C8");
+        registerEntity("Eacute", "\u00C9");
+        registerEntity("Ecirc", "\u00CA");
+        registerEntity("Euml", "\u00CB");
+        registerEntity("Igrave", "\u00CC");
+        registerEntity("Iacute", "\u00CD");
+        registerEntity("Icirc", "\u00CE");
+        registerEntity("Iuml", "\u00CF");
+        registerEntity("ETH", "\u00D0");
+        registerEntity("Ntilde", "\u00D1");
+        registerEntity("Ograve", "\u00D2");
+        registerEntity("Oacute", "\u00D3");
+        registerEntity("Ocirc", "\u00D4");
+        registerEntity("Otilde", "\u00D5");
+        registerEntity("Ouml", "\u00D6");
+        registerEntity("times", "\u00D7");
+        registerEntity("Oslash", "\u00D8");
+        registerEntity("Ugrave", "\u00D9");
+        registerEntity("Uacute", "\u00DA");
+        registerEntity("Ucirc", "\u00DB");
+        registerEntity("Uuml", "\u00DC");
+        registerEntity("Yacute", "\u00DD");
+        registerEntity("THORN", "\u00DE");
+        registerEntity("szlig", "\u00DF");
+        registerEntity("agrave", "\u00E0");
+        registerEntity("aacute", "\u00E1");
+        registerEntity("acirc", "\u00E2");
+        registerEntity("atilde", "\u00E3");
+        registerEntity("auml", "\u00E4");
+        registerEntity("aring", "\u00E5");
+        registerEntity("aelig", "\u00E6");
+        registerEntity("ccedil", "\u00E7");
+        registerEntity("egrave", "\u00E8");
+        registerEntity("eacute", "\u00E9");
+        registerEntity("ecirc", "\u00EA");
+        registerEntity("euml", "\u00EB");
+        registerEntity("igrave", "\u00EC");
+        registerEntity("iacute", "\u00ED");
+        registerEntity("icirc", "\u00EE");
+        registerEntity("iuml", "\u00EF");
+        registerEntity("eth", "\u00F0");
+        registerEntity("ntilde", "\u00F1");
+        registerEntity("ograve", "\u00F2");
+        registerEntity("oacute", "\u00F3");
+        registerEntity("ocirc", "\u00F4");
+        registerEntity("otilde", "\u00F5");
+        registerEntity("ouml", "\u00F6");
+        registerEntity("divide", "\u00F7");
+        registerEntity("oslash", "\u00F8");
+        registerEntity("ugrave", "\u00F9");
+        registerEntity("uacute", "\u00FA");
+        registerEntity("ucirc", "\u00FB");
+        registerEntity("uuml", "\u00FC");
+        registerEntity("yacute", "\u00FD");
+        registerEntity("thorn", "\u00FE");
+        registerEntity("yuml", "\u00FF");
+        registerEntity("OElig", "\u0152");
+        registerEntity("oelig", "\u0153");
+        registerEntity("Scaron", "\u0160");
+        registerEntity("scaron", "\u0161");
+        registerEntity("Yuml", "\u0178");
+        registerEntity("fnof", "\u0192");
+        registerEntity("circ", "\u02C6");
+        registerEntity("tilde", "\u02DC");
+        registerEntity("Alpha", "\u0391");
+        registerEntity("Beta", "\u0392");
+        registerEntity("Gamma", "\u0393");
+        registerEntity("Delta", "\u0394");
+        registerEntity("Epsilon", "\u0395");
+        registerEntity("Zeta", "\u0396");
+        registerEntity("Eta", "\u0397");
+        registerEntity("Theta", "\u0398");
+        registerEntity("Iota", "\u0399");
+        registerEntity("Kappa", "\u039A");
+        registerEntity("Lambda", "\u039B");
+        registerEntity("Mu", "\u039C");
+        registerEntity("Nu", "\u039D");
+        registerEntity("Xi", "\u039E");
+        registerEntity("Omicron", "\u039F");
+        registerEntity("Pi", "\u03A0");
+        registerEntity("Rho", "\u03A1");
+        registerEntity("Sigma", "\u03A3");
+        registerEntity("Tau", "\u03A4");
+        registerEntity("Upsilon", "\u03A5");
+        registerEntity("Phi", "\u03A6");
+        registerEntity("Chi", "\u03A7");
+        registerEntity("Psi", "\u03A8");
+        registerEntity("Omega", "\u03A9");
+        registerEntity("alpha", "\u03B1");
+        registerEntity("beta", "\u03B2");
+        registerEntity("gamma", "\u03B3");
+        registerEntity("delta", "\u03B4");
+        registerEntity("epsilon", "\u03B5");
+        registerEntity("zeta", "\u03B6");
+        registerEntity("eta", "\u03B7");
+        registerEntity("theta", "\u03B8");
+        registerEntity("iota", "\u03B9");
+        registerEntity("kappa", "\u03BA");
+        registerEntity("lambda", "\u03BB");
+        registerEntity("mu", "\u03BC");
+        registerEntity("nu", "\u03BD");
+        registerEntity("xi", "\u03BE");
+        registerEntity("omicron", "\u03BF");
+        registerEntity("pi", "\u03C0");
+        registerEntity("rho", "\u03C1");
+        registerEntity("sigmaf", "\u03C2");
+        registerEntity("sigma", "\u03C3");
+        registerEntity("tau", "\u03C4");
+        registerEntity("upsilon", "\u03C5");
+        registerEntity("phi", "\u03C6");
+        registerEntity("chi", "\u03C7");
+        registerEntity("psi", "\u03C8");
+        registerEntity("omega", "\u03C9");
+        registerEntity("thetasym", "\u03D1");
+        registerEntity("upsih", "\u03D2");
+        registerEntity("piv", "\u03D6");
+        registerEntity("ensp", "\u2002");
+        registerEntity("emsp", "\u2003");
+        registerEntity("thinsp", "\u2009");
+        registerEntity("zwnj", "\u200C");
+        registerEntity("zwj", "\u200D");
+        registerEntity("lrm", "\u200E");
+        registerEntity("rlm", "\u200F");
+        registerEntity("ndash", "\u2013");
+        registerEntity("mdash", "\u2014");
+        registerEntity("lsquo", "\u2018");
+        registerEntity("rsquo", "\u2019");
+        registerEntity("sbquo", "\u201A");
+        registerEntity("ldquo", "\u201C");
+        registerEntity("rdquo", "\u201D");
+        registerEntity("bdquo", "\u201E");
+        registerEntity("dagger", "\u2020");
+        registerEntity("Dagger", "\u2021");
+        registerEntity("bull", "\u2022");
+        registerEntity("hellip", "\u2026");
+        registerEntity("permil", "\u2030");
+        registerEntity("prime", "\u2032");
+        registerEntity("Prime", "\u2033");
+        registerEntity("lsaquo", "\u2039");
+        registerEntity("rsaquo", "\u203A");
+        registerEntity("oline", "\u203E");
+        registerEntity("frasl", "\u2044");
+        registerEntity("euro", "\u20AC");
+        registerEntity("image", "\u2111");
+        registerEntity("weierp", "\u2118");
+        registerEntity("real", "\u211C");
+        registerEntity("trade", "\u2122");
+        registerEntity("alefsym", "\u2135");
+        registerEntity("larr", "\u2190");
+        registerEntity("uarr", "\u2191");
+        registerEntity("rarr", "\u2192");
+        registerEntity("darr", "\u2193");
+        registerEntity("harr", "\u2194");
+        registerEntity("crarr", "\u21B5");
+        registerEntity("lArr", "\u21D0");
+        registerEntity("uArr", "\u21D1");
+        registerEntity("rArr", "\u21D2");
+        registerEntity("dArr", "\u21D3");
+        registerEntity("hArr", "\u21D4");
+        registerEntity("forall", "\u2200");
+        registerEntity("part", "\u2202");
+        registerEntity("exist", "\u2203");
+        registerEntity("empty", "\u2205");
+        registerEntity("nabla", "\u2207");
+        registerEntity("isin", "\u2208");
+        registerEntity("notin", "\u2209");
+        registerEntity("ni", "\u220B");
+        registerEntity("prod", "\u220F");
+        registerEntity("sum", "\u2211");
+        registerEntity("minus", "\u2212");
+        registerEntity("lowast", "\u2217");
+        registerEntity("radic", "\u221A");
+        registerEntity("prop", "\u221D");
+        registerEntity("infin", "\u221E");
+        registerEntity("ang", "\u2220");
+        registerEntity("and", "\u2227");
+        registerEntity("or", "\u2228");
+        registerEntity("cap", "\u2229");
+        registerEntity("cup", "\u222A");
+        registerEntity("int", "\u222B");
+        registerEntity("there4", "\u2234");
+        registerEntity("sim", "\u223C");
+        registerEntity("cong", "\u2245");
+        registerEntity("asymp", "\u2248");
+        registerEntity("ne", "\u2260");
+        registerEntity("equiv", "\u2261");
+        registerEntity("le", "\u2264");
+        registerEntity("ge", "\u2265");
+        registerEntity("sub", "\u2282");
+        registerEntity("sup", "\u2283");
+        registerEntity("nsub", "\u2284");
+        registerEntity("sube", "\u2286");
+        registerEntity("supe", "\u2287");
+        registerEntity("oplus", "\u2295");
+        registerEntity("otimes", "\u2297");
+        registerEntity("perp", "\u22A5");
+        registerEntity("sdot", "\u22C5");
+        registerEntity("lceil", "\u2308");
+        registerEntity("rceil", "\u2309");
+        registerEntity("lfloor", "\u230A");
+        registerEntity("rfloor", "\u230B");
+        registerEntity("lang", "\u2329");
+        registerEntity("rang", "\u232A");
+        registerEntity("loz", "\u25CA");
+        registerEntity("spades", "\u2660");
+        registerEntity("clubs", "\u2663");
+        registerEntity("hearts", "\u2665");
+        registerEntity("diams", "\u2666");
+    }
+
+    public String resolveEntity(String name) {
+        return resolveentities ? entities.get(name) : null;
+    }
+
+    public ParserOptions setResolveEntities(boolean resolve) {
+        this.resolveentities = resolve;
+        return this;
+    }
+
+    public boolean getResolveEntities() {
+        return this.resolveentities;
+    }
+
+    public Map<QName, QName> getQNameAliasMap() {
+        return aliases;
+    }
+
+    public ParserOptions setQNameAliasMap(Map<QName, QName> map) {
+        this.aliases = map;
+        return this;
+    }
+
+    public boolean isQNameAliasMappingEnabled() {
+        return qnamealiasing;
+    }
+
+    public ParserOptions setQNameAliasMappingEnabled(boolean enabled) {
+        this.qnamealiasing = enabled;
+        return this;
+    }
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/AbstractParserOptions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParseException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParseException.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParseException.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParseException.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.abdera2.parser;
+
+public class ParseException extends RuntimeException {
+
+    private static final long serialVersionUID = -2586758177341912116L;
+
+    public ParseException() {
+        super();
+    }
+
+    public ParseException(String message) {
+        super(message);
+    }
+
+    public ParseException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ParseException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParseException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/Parser.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/Parser.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/Parser.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/Parser.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,220 @@
+/*
+ * 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.abdera2.parser;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.nio.channels.ReadableByteChannel;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.abdera2.common.anno.DefaultImplementation;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+
+@DefaultImplementation("org.apache.abdera2.parser.axiom.FOMParser")
+public interface Parser {
+
+    /**
+     * Parse the input stream using the default character set encoding (UTF-8)
+     * 
+     * @param in The input stream to parse
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(InputStream in) throws ParseException;
+
+    /**
+     * Parse the input stream using the default character set encoding (UTF-8)
+     * 
+     * @param reader The XMLStreamReader to use to parse
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(XMLStreamReader reader) throws ParseException;
+
+    /**
+     * Parse the input stream using the default character set encoding (UTF-8). The specified Base URI is used to
+     * resolve relative references contained in the document
+     * 
+     * @param in The input stream to parse
+     * @param base The Base URI of the document
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(InputStream in, String base) throws ParseException;
+
+    /**
+     * Parse the input stream using the default character set encoding (UTF-8). The specified Base URI is used to
+     * resolve relative references contained in the document
+     * 
+     * @param in The input stream to parse
+     * @param options The Parse options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(InputStream in, ParserOptions options) throws ParseException;
+
+    /**
+     * Parse the input stream using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param in The input stream to parse
+     * @param base The Base URI of the document
+     * @param options The Parse Options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(InputStream in, String base, ParserOptions options) throws ParseException;
+
+    /**
+     * Parse the reader using the default Base URI and options
+     * 
+     * @param in The Reader to parse
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(Reader in) throws ParseException;
+
+    /**
+     * Parse the reader using the specified Base URI
+     * 
+     * @param in The Reader to parse
+     * @param base The Base URI
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(Reader in, String base) throws ParseException;
+
+    /**
+     * Parse the reader using the specified Base URI
+     * 
+     * @param in The Reader to parse
+     * @param options The Parse Options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(Reader in, ParserOptions options) throws ParseException;
+
+    /**
+     * Parse the reader using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param in The reader to parse
+     * @param base The Base URI of the document
+     * @param options The Parse Options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(Reader in, String base, ParserOptions options) throws ParseException;
+
+    /**
+     * Parse the channel using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param in The ReadableByteChannel to parse
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(ReadableByteChannel buf) throws ParseException;
+
+    /**
+     * Parse the channel using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param in The ReadableByteChannel to parse
+     * @param base The Base URI of the document
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(ReadableByteChannel buf, String base) throws ParseException;
+
+    /**
+     * Parse the channel using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param in The ReadableByteChannel to parse
+     * @param base The Base URI of the document
+     * @param options The Parse Options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(ReadableByteChannel buf, String base, ParserOptions options)
+        throws ParseException;
+
+    /**
+     * Parse the channel using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param reader the XMLStreamReader parser to use to parse
+     * @param base The Base URI of the document
+     * @param options The Parse Options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(XMLStreamReader reader, String base, ParserOptions options)
+        throws ParseException;
+
+    /**
+     * Parse the channel using using the specified Parse options. The parse options can be used to control various
+     * aspects of the parsing process such as the character set encoding to use and whether certain elements should be
+     * ignored. The specified Base URI is used to resolve relative references contained in the document.
+     * 
+     * @param in The ReadableByteChannel to parse
+     * @param options The Parse Options
+     * @return The parsed Abdera Document
+     * @throws ParseException if the parse failed
+     */
+    <T extends Element> Document<T> parse(ReadableByteChannel buf, ParserOptions options) throws ParseException;
+
+    /**
+     * Return the default parser options for this Parser. This method returns a copy of the default options. Changes to
+     * this instance will not affect the defaults returned by subsequent requests.
+     * 
+     * @return The default ParserOptions
+     */
+    ParserOptions getDefaultParserOptions();
+
+    /**
+     * Set the default parser options for this Parser. This method copies the specified options.
+     * 
+     * @param options The Parser Options to use as the default
+     */
+    Parser setDefaultParserOptions(ParserOptions options);
+
+    /**
+     * Returns a listing of media type of the format consumed by this parser
+     * 
+     * @return An array of MIME Media Types
+     */
+    Iterable<String> getInputFormats();
+
+    /**
+     * Returns true if this parser is capable of consuming the specified media type
+     * 
+     * @param mediatype The MIME media type to check
+     * @return True if the media type is supported
+     */
+    boolean parsesFormat(String mediatype);
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/Parser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserFactory.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserFactory.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserFactory.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserFactory.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.abdera2.parser;
+
+import org.apache.abdera2.common.anno.DefaultImplementation;
+
+/**
+ * The ParserFactory is used a acquire instances of alternative parsers registered with Abdera.
+ * 
+ * @see org.apache.abdera2.parser.abdera.parser.NamedParser
+ */
+@DefaultImplementation("org.apache.abdera2.parser.axiom.FOMParserFactory")
+public interface ParserFactory {
+
+    /**
+     * Get the default parser. This is equivalent to calling Abdera.getParser()
+     * 
+     * @return The default parser implementation
+     */
+    <T extends Parser> T getParser();
+
+    /**
+     * Get the named parser
+     * 
+     * @param name The name of the parser instance to retrieve
+     * @return The Named parser instance
+     */
+    <T extends Parser> T getParser(String name);
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserOptions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserOptions.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserOptions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,166 @@
+/*
+ * 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.abdera2.parser;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.io.Compression;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.parser.filter.ParseFilter;
+
+/**
+ * Parser options are used to modify the behavior of the parser.
+ */
+public interface ParserOptions extends Cloneable {
+
+    Object clone() throws CloneNotSupportedException;
+
+    /**
+     * Returns the factory the parser should use
+     */
+    Factory getFactory();
+
+    /**
+     * Sets the factory the parser should use
+     */
+    ParserOptions setFactory(Factory factory);
+
+    /**
+     * Returns the default character set to use for the parsed document
+     */
+    String getCharset();
+
+    /**
+     * Sets the character set to use for the parsed document
+     */
+    ParserOptions setCharset(String charset);
+
+    /**
+     * Returns the Parse Filter. The parse filter is a set of XML QNames that the parse should watch out for. If the
+     * filter is null, the parser will parse all elements in the document. I the filter is not null, the parser will
+     * only pay attention to elements whose QName's appear in the filter list.
+     */
+    ParseFilter getParseFilter();
+
+    /**
+     * Sets the Parse Filter. The parse filter is a set of XML QNames that the parse should watch out for. If the filter
+     * is null, the parser will parse all elements in the document. I the filter is not null, the parser will only pay
+     * attention to elements whose QName's appear in the filter list.
+     */
+    ParserOptions setParseFilter(ParseFilter parseFilter);
+
+    /**
+     * Returns true if the parser should attempt to automatically detect the character encoding from the stream
+     */
+    boolean getAutodetectCharset();
+
+    /**
+     * If true, the parser will attempt to automatically detect the character encoding from the stream by checking for
+     * the byte order mark or checking the XML prolog.
+     */
+    ParserOptions setAutodetectCharset(boolean detect);
+
+    /**
+     * If false, the parser will trim leading and trailing whitespace in element and attribute values unless there is an
+     * in-scope xml:space="preserve".
+     */
+    boolean getMustPreserveWhitespace();
+
+    /**
+     * If false, the parser will trim leading and trailing whitespace in element and attribute values unless there is an
+     * in-scope xml:space="preserve".
+     */
+    ParserOptions setMustPreserveWhitespace(boolean preserve);
+
+    /**
+     * If true, the parser will attempt to silently filter out invalid XML characters appearing within the XML document.
+     */
+    boolean getFilterRestrictedCharacters();
+
+    /**
+     * If true, the parser will attempt to silently filter out invalid XML characters appearing within the XML document
+     */
+    ParserOptions setFilterRestrictedCharacters(boolean filter);
+
+    /**
+     * If getFilterRestrictedCharacters is true, restricted characters will be replaced with the specified character
+     */
+    char getFilterRestrictedCharacterReplacement();
+
+    /**
+     * If getFilterRestrictedCharacters is true, restricted characters will be replaced with the specified character
+     */
+    ParserOptions setFilterRestrictedCharacterReplacement(char replacement);
+
+    /**
+     * When parsing an InputStream that contains compressed data, use these codecs to decompress the stream. Only used
+     * when parsing an InputStream. Ignored when parsing a Reader
+     */
+    Compression.CompressionCodec[] getCompressionCodecs();
+
+    /**
+     * When parsing an InputStream that contains compressed data, use these codecs to decompress the stream. Only used
+     * when parsing an InputStream. Ignored when parsing a Reader
+     */
+    ParserOptions setCompressionCodecs(Compression.CompressionCodec... codecs);
+
+    /**
+     * Register a named entity. This provides an escape clause for when feeds use entities that are not supported in XML
+     * without a DTD decl. By default, all of the (X)HTML entities are preregistered
+     */
+    ParserOptions registerEntity(String name, String value);
+
+    /**
+     * Resolves a value for a named entity. This provides an escape clause for when feeds use entities that are not
+     * supported in XML without a DTD decl. By default, all of the (X)HTML entities are preregistered
+     */
+    String resolveEntity(String name);
+
+    /**
+     * True if undeclared named entities should be resolved.
+     */
+    ParserOptions setResolveEntities(boolean resolve);
+
+    /**
+     * True if undeclared named entities should be resolved.
+     */
+    boolean getResolveEntities();
+
+    /**
+     * True if QName-Alias mapping is enabled
+     */
+    ParserOptions setQNameAliasMappingEnabled(boolean enabled);
+
+    /**
+     * True if QName-Alias mapping is enabled (default is false)
+     */
+    boolean isQNameAliasMappingEnabled();
+
+    /**
+     * Get the QName-Alias Mapping (default null)
+     */
+    Map<QName, QName> getQNameAliasMap();
+
+    /**
+     * Set the QName-Alias Mapping
+     */
+    ParserOptions setQNameAliasMap(Map<QName, QName> map);
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/ParserOptions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMAttribute.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMAttribute.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMAttribute.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMAttribute.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,76 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Attribute;
+import org.apache.axiom.om.OMAttribute;
+
+public class FOMAttribute implements Attribute {
+
+    private final OMAttribute attr;
+
+    protected FOMAttribute(OMAttribute attr) {
+        this.attr = attr;
+    }
+
+    public QName getQName() {
+        return attr.getQName();
+    }
+
+    public String getText() {
+        return attr.getAttributeValue();
+    }
+
+    public Attribute setText(String text) {
+        attr.setAttributeValue(text);
+        return this;
+    }
+
+    public Factory getFactory() {
+        return (Factory)attr.getOMFactory();
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((attr == null) ? 0 : attr.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final FOMAttribute other = (FOMAttribute)obj;
+        if (attr == null) {
+            if (other.attr != null)
+                return false;
+        } else if (!attr.equals(other.attr))
+            return false;
+        return true;
+    }
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMAttribute.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMBuilder.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMBuilder.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMBuilder.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMBuilder.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,376 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+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.abdera2.common.Constants;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Text;
+import org.apache.abdera2.parser.ParseException;
+import org.apache.abdera2.parser.ParserOptions;
+import org.apache.abdera2.parser.filter.ParseFilter;
+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;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
+
+@SuppressWarnings( {"unchecked", "deprecation"})
+public class FOMBuilder extends StAXOMBuilder implements Constants {
+
+    private final FOMFactory fomfactory;
+    private final ParserOptions parserOptions;
+    private boolean indoc = false;
+    private int depth = 0;
+    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);
+        this.document = (OMDocument)factory.newDocument();
+        this.parserOptions = parserOptions;
+        this.fomfactory = factory;
+        String version = parser.getVersion();
+        String enc = parser.getCharacterEncodingScheme();
+        document.setCharsetEncoding(enc != null ? enc : "utf-8");
+        document.setXMLVersion(version != null ? version : "1.0");
+        if (parserOptions != null) {
+            ParseFilter parseFilter = parserOptions.getParseFilter();
+            if (parseFilter != null) {
+                ignoreWhitespace = parseFilter.getIgnoreWhitespace();
+                ignoreComments = parseFilter.getIgnoreComments();
+                ignorePI = parseFilter.getIgnoreProcessingInstructions();
+            }
+        }
+    }
+
+    public ParserOptions getParserOptions() {
+        return parserOptions;
+    }
+
+    @Override
+    protected OMNode createOMElement() throws OMException {
+        depth++;
+        OMElement node;
+        String elementName = parser.getLocalName();
+        if (lastNode == null) {
+            node = constructNode(null, elementName);
+        } else if (lastNode.isComplete()) {
+            node = constructNode((OMContainer)lastNode.getParent(), elementName);
+            if (node != null) {
+                ((OMNodeEx)lastNode).setNextOMSibling(node);
+                ((OMNodeEx)node).setPreviousOMSibling(lastNode);
+            }
+        } else {
+            OMElement e = (OMElement)lastNode;
+            node = constructNode((OMElement)lastNode, elementName);
+            e.addChild(node);
+        }
+        return node;
+    }
+
+    protected Text.Type getTextType() {
+        Text.Type ttype = Text.Type.TEXT;
+        String type = parser.getAttributeValue(null, LN_TYPE);
+        if (type != null) {
+            ttype = Text.Type.typeFromString(type);
+            if (ttype == null)
+                throw new FOMUnsupportedTextTypeException(type);
+        }
+        return ttype;
+    }
+
+    protected Content.Type getContentType() {
+        Content.Type ctype = Content.Type.TEXT;
+        String type = parser.getAttributeValue(null, LN_TYPE);
+        String src = parser.getAttributeValue(null, LN_SRC);
+        if (type != null) {
+            ctype = Content.Type.typeFromString(type);
+            if (ctype == null)
+                throw new FOMUnsupportedContentTypeException(type);
+        } else if (type == null && src != null) {
+            ctype = Content.Type.MEDIA;
+        }
+        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;
+    }
+
+    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.
+     * 
+     * @return Returns int.
+     * @throws OMException
+     */
+    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;
+        } catch (OMException e) {
+            throw new ParseException(e);
+        } catch (Exception e) {
+            throw new ParseException(e);
+        }
+    }
+
+    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;
+    }
+
+    protected OMElement constructNode(OMContainer parent, String name) {
+        OMElement element = null;
+        if (!indoc) {
+            parent = document;
+            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);
+        }
+        if (element != null) {
+            this.processNamespaceData(element);
+            processAttributes(element);
+        }
+        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);
+            }
+        }
+    }
+
+    @Override
+    protected void endElement() {
+        if (lastNode != null && lastNode.isComplete()) {
+            OMElement parent = (OMElement)lastNode.getParent();
+            ((OMNodeEx)parent).setComplete(true);
+            lastNode = parent;
+        } else {
+            OMNode e = lastNode;
+            if (e != null)
+                ((OMNodeEx)e).setComplete(true);
+        }
+        depth--;
+    }
+
+    public <T extends Element> Document<T> getFomDocument() {
+        while (!indoc && !done) {
+            next();
+        }
+        return (Document<T>)document;
+    }
+
+    public OMDocument getDocument() {
+        return (OMDocument)getFomDocument();
+    }
+
+    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);
+        }
+    }
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategories.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategories.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategories.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategories.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,193 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Categories;
+import org.apache.abdera2.model.Category;
+import org.apache.axiom.om.OMContainer;
+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.OMXMLParserWrapper;
+
+public class FOMCategories extends FOMExtensibleElement implements Categories {
+
+    private static final long serialVersionUID = 5480273546375102411L;
+
+    public FOMCategories() {
+        super(CATEGORIES, new FOMDocument<Categories>(), new FOMFactory());
+        init();
+    }
+
+    public FOMCategories(String name, OMNamespace namespace, OMContainer parent, OMFactory factory)
+        throws OMException {
+        super(name, namespace, parent, factory);
+        init();
+    }
+
+    public FOMCategories(QName qname, OMContainer parent, OMFactory factory) {
+        super(qname, parent, factory);
+        init();
+    }
+
+    public FOMCategories(QName qname, OMContainer parent, OMFactory factory, OMXMLParserWrapper builder) {
+        super(qname, parent, factory, builder);
+    }
+
+    public FOMCategories(OMContainer parent, OMFactory factory) throws OMException {
+        super(CATEGORIES, parent, factory);
+        init();
+    }
+
+    public FOMCategories(OMContainer parent, OMFactory factory, OMXMLParserWrapper builder) throws OMException {
+        super(CATEGORIES, parent, factory, builder);
+    }
+
+    private void init() {
+        this.declareNamespace(ATOM_NS, "atom");
+    }
+
+    public Categories addCategory(Category category) {
+        complete();
+        addChild((OMElement)category);
+        return this;
+    }
+
+    public Category addCategory(String term) {
+        complete();
+        FOMFactory factory = (FOMFactory)this.factory;
+        Category category = factory.newCategory(this);
+        category.setTerm(term);
+        return category;
+    }
+
+    public Category addCategory(String scheme, String term, String label) {
+        complete();
+        FOMFactory factory = (FOMFactory)this.factory;
+        Category category = factory.newCategory(this);
+        category.setTerm(term);
+        category.setScheme(scheme);
+        category.setLabel(label);
+        return category;
+
+    }
+
+    public List<Category> getCategories() {
+        return _getChildrenAsSet(CATEGORY);
+    }
+
+    public List<Category> getCategories(String scheme) {
+        return FOMElement.getCategories(this, scheme);
+    }
+
+    private List<Category> copyCategoriesWithScheme(List<Category> cats) {
+        List<Category> newcats = new ArrayList<Category>();
+        IRI scheme = getScheme();
+        for (Category cat : cats) {
+            Category newcat = (Category)cat.clone();
+            if (newcat.getScheme() == null && scheme != null)
+                newcat.setScheme(scheme.toString());
+            newcats.add(newcat);
+        }
+        return newcats;
+    }
+
+    public List<Category> getCategoriesWithScheme() {
+        return copyCategoriesWithScheme(getCategories());
+    }
+
+    public List<Category> getCategoriesWithScheme(String scheme) {
+        return copyCategoriesWithScheme(getCategories(scheme));
+    }
+
+    public List<Category> getCategories(Selector selector) {
+      return _getChildrenAsSet(CATEGORY, selector);
+    }
+    
+    public IRI getScheme() {
+        String value = getAttributeValue(SCHEME);
+        return (value != null) ? new IRI(value) : null;
+    }
+
+    public boolean isFixed() {
+        String value = getAttributeValue(FIXED);
+        return (value != null && value.equals(YES));
+    }
+
+    public Categories setFixed(boolean fixed) {
+        complete();
+        if (fixed && !isFixed())
+            setAttributeValue(FIXED, YES);
+        else if (!fixed && isFixed())
+            removeAttribute(FIXED);
+        return this;
+    }
+
+    public Categories setScheme(String scheme) {
+      complete();
+        return setAttributeValue(SCHEME, scheme==null?null:new IRI(scheme).toString());
+    }
+
+    public IRI getHref() {
+        return _getUriValue(getAttributeValue(HREF));
+    }
+
+    public IRI getResolvedHref() {
+        return _resolve(getResolvedBaseUri(), getHref());
+    }
+
+    public Categories setHref(String href) {
+      complete();
+      return setAttributeValue(HREF,href==null?null:(new IRI(href)).toString());
+    }
+
+    public boolean contains(String term) {
+        return contains(term, null);
+    }
+
+    public boolean contains(String term, String scheme) {
+        List<Category> categories = getCategories();
+        IRI catscheme = getScheme();
+        IRI uri = (scheme != null) ? new IRI(scheme) : catscheme;
+        for (Category category : categories) {
+            String t = category.getTerm();
+            IRI s = (category.getScheme() != null) ? category.getScheme() : catscheme;
+            if (t.equals(term) && ((uri != null) ? uri.equals(s) : s == null))
+                return true;
+        }
+        return false;
+    }
+
+    public boolean isOutOfLine() {
+        boolean answer = false;
+        try {
+            answer = getHref() != null;
+        } catch (Exception e) {
+        }
+        return answer;
+    }
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategories.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message