abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [26/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/parser/axiom/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/StaxStreamWriter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/StaxStreamWriter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/StaxStreamWriter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,390 @@
+/*
+ * 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.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.anno.Name;
+import org.apache.abdera2.writer.AbstractStreamWriter;
+import org.apache.abdera2.writer.StreamWriter;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.util.StAXWriterConfiguration;
+import org.apache.axiom.util.stax.dialect.StAXDialect;
+
+@Name("default")
+public class StaxStreamWriter extends AbstractStreamWriter {
+    private static final StAXWriterConfiguration ABDERA_WRITER_CONFIGURATION = new StAXWriterConfiguration() {
+        public XMLOutputFactory configure(XMLOutputFactory factory, StAXDialect dialect) {
+            factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
+            return factory;
+        }
+        
+        // This is used in log statements inside Axiom
+        @Override
+        public String toString() {
+            return "ABDERA";
+        }
+    }; 
+
+    private static final String NAME = "default";
+
+    private XMLStreamWriter writer;
+    private int depth = 0;
+    private int textwritten = 0;
+
+    public StaxStreamWriter(Abdera abdera) {
+        super(abdera, NAME);
+    }
+
+    public StaxStreamWriter(Abdera abdera, Writer writer) {
+        super(abdera, NAME);
+        setWriter(writer);
+    }
+
+    public StaxStreamWriter(Abdera abdera, OutputStream out) {
+        super(abdera, NAME);
+        setOutputStream(out);
+    }
+
+    public StaxStreamWriter(Abdera abdera, OutputStream out, String charset) {
+        super(abdera, NAME);
+        setOutputStream(out, charset);
+    }
+
+    public StreamWriter setWriter(java.io.Writer writer) {
+        try {
+            this.writer = createXMLStreamWriter(writer);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    private static XMLStreamWriter createXMLStreamWriter(Writer out) throws XMLStreamException {
+        XMLOutputFactory outputFactory = StAXUtils.getXMLOutputFactory(ABDERA_WRITER_CONFIGURATION);
+        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out);
+        return writer;
+    }
+
+    public StreamWriter setOutputStream(java.io.OutputStream out) {
+        try {
+            this.writer = createXMLStreamWriter(out, "UTF-8");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    private static XMLStreamWriter createXMLStreamWriter(OutputStream out, String encoding) throws XMLStreamException {
+        XMLOutputFactory outputFactory = StAXUtils.getXMLOutputFactory(ABDERA_WRITER_CONFIGURATION);
+        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, encoding);
+        return writer;
+    }
+
+    public StreamWriter setOutputStream(java.io.OutputStream out, String charset) {
+        try {
+            this.writer = createXMLStreamWriter(out, charset);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter startDocument(String xmlversion, String charset) {
+        try {
+            writer.writeStartDocument(xmlversion, charset);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter startDocument(String xmlversion) {
+        try {
+            writer.writeStartDocument(xmlversion);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter endDocument() {
+        try {
+            writer.writeEndDocument();
+            writer.flush();
+            if (autoclose)
+                writer.close();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter endElement() {
+        try {
+            if (autoindent && textwritten == 0) {
+                pop();
+                indent();
+            } else
+                pop();
+            writer.writeEndElement();
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    private void writeNamespace(String prefix, String namespace, boolean attr) throws XMLStreamException {
+        prefix = prefix != null ? prefix : "";
+        if (!declared(prefix, namespace)) {
+            if (attr && (namespace == null || "".equals(namespace)))
+                return;
+            if (prefix != null)
+                writer.writeNamespace(prefix, namespace);
+            else
+                writer.writeDefaultNamespace(namespace);
+            declare(prefix, namespace);
+            if (autoflush)
+                writer.flush();
+        }
+    }
+
+    private boolean needToWriteNamespace(String prefix, String namespace) {
+        NamespaceContext nc = writer.getNamespaceContext();
+        String uri = nc.getNamespaceURI(prefix != null ? prefix : "");
+        return uri != null ? !uri.equals(namespace) : true;
+    }
+
+    public StreamWriter startElement(String name, String namespace, String prefix) {
+        try {
+            if ((prefix == null || prefix.equals("")) && namespace != null)
+                prefix = writer.getPrefix(namespace);
+            if (autoindent && textwritten == 0)
+                indent();
+            push();
+            if (prefix != null && !prefix.equals("")) {
+                writer.writeStartElement(prefix, name, namespace);
+                if (needToWriteNamespace(prefix, namespace))
+                    writeNamespace(prefix, namespace, false);
+            } else if (namespace != null) {
+                writer.writeStartElement("", name, namespace);
+                if (needToWriteNamespace(prefix, namespace))
+                    writeNamespace(prefix, namespace, false);
+            } else {
+                writer.writeStartElement("", name, "");
+                writer.writeDefaultNamespace("");
+            }
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+          e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writeElementText(String value) {
+        if (value == null) return this;
+        try {
+            textwritten++;
+            writer.writeCharacters(value);
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writeComment(String value) {
+        try {
+            if (autoindent)
+                indent();
+            writer.writeComment(value);
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writePI(String value) {
+        try {
+            if (autoindent)
+                indent();
+            writer.writeProcessingInstruction(value);
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writePI(String value, String target) {
+        try {
+            if (autoindent)
+                indent();
+            writer.writeProcessingInstruction(value, target);
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writeId() {
+        return writeId(FOMElement.generateUuid());
+    }
+
+    public StreamWriter writeDefaultNamespace(String uri) {
+        try {
+            writer.writeDefaultNamespace(uri);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writeNamespace(String prefix, String uri) {
+        try {
+            writer.writeNamespace(prefix, uri);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter writeAttribute(String name, String namespace, String prefix, String value) {
+        if (value == null)
+            return this;
+        try {
+            if (prefix != null) {
+                if (!prefix.equals("xml"))
+                    writeNamespace(prefix, namespace, true);
+                writer.writeAttribute(prefix, namespace, name, value);
+            } else if (namespace != null) {
+                if (!namespace.equals(Constants.XML_NS))
+                    ;
+                writeNamespace(prefix, namespace, true);
+                writer.writeAttribute(namespace, name, value);
+            } else {
+                writer.writeAttribute(name, value);
+            }
+            if (autoflush)
+                writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    private final Stack<Map<String, String>> namespaces = new Stack<Map<String, String>>();
+
+    private void push() {
+        namespaces.push(new HashMap<String, String>());
+        depth++;
+    }
+
+    private void pop() {
+        depth--;
+        if (textwritten > 0)
+            textwritten--;
+        if (!namespaces.isEmpty())
+            namespaces.pop();
+    }
+
+    private void declare(String prefix, String namespace) {
+        if (namespaces.isEmpty())
+            return;
+        Map<String, String> frame = namespaces.peek();
+        frame.put(prefix, namespace);
+    }
+
+    private boolean declared(String prefix, String namespace) {
+        for (int n = namespaces.size() - 1; n >= 0; n--) {
+            Map<String, String> frame = namespaces.get(n);
+            String chk = frame.get(prefix);
+            if (chk == null && namespace == null)
+                return true;
+            if (chk == null && namespace != null)
+                continue;
+            if (chk != null && namespace == null)
+                continue;
+            if (chk.equals(namespace))
+                return true;
+        }
+        return false;
+    }
+
+    public StreamWriter flush() {
+        try {
+            writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public StreamWriter indent() {
+        try {
+            char[] indent = new char[depth * 2];
+            Arrays.fill(indent, ' ');
+            writer.writeCharacters("\n");
+            writer.writeCharacters(indent, 0, indent.length);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    public void close() throws IOException {
+        try {
+            writer.close();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public StreamWriter setPrefix(String prefix, String uri) {
+        try {
+            writer.setPrefix(prefix, uri);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.filter;
+
+
+public abstract class AbstractParseFilter implements ParseFilter {
+
+    private static final long serialVersionUID = -1866308276050148524L;
+
+    private static final byte COMMENTS = 1;
+    private static final byte WHITESPACE = 2;
+    private static final byte PI = 4;
+
+    protected byte flags = 0;
+
+    private void toggle(boolean s, byte flag) {
+        if (s)
+            flags |= flag;
+        else
+            flags &= ~flag;
+    }
+
+    private boolean check(byte flag) {
+        return (flags & flag) == flag;
+    }
+
+    public ParseFilter setIgnoreComments(boolean ignore) {
+        toggle(ignore, COMMENTS);
+        return this;
+    }
+
+    public ParseFilter setIgnoreWhitespace(boolean ignore) {
+        toggle(ignore, (byte)WHITESPACE);
+        return this;
+    }
+
+    public ParseFilter setIgnoreProcessingInstructions(boolean ignore) {
+        toggle(ignore, (byte)PI);
+        return this;
+    }
+
+    public boolean getIgnoreComments() {
+        return check(COMMENTS);
+    }
+
+    public boolean getIgnoreProcessingInstructions() {
+        return check(PI);
+    }
+
+    public boolean getIgnoreWhitespace() {
+        return check(WHITESPACE);
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractSetParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractSetParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractSetParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/AbstractSetParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,137 @@
+/*
+ * 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.filter;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * ParseFilter's determine which elements and attributes are acceptable 
+ * within a parsed document. They are set via the ParserOptions.setParseFilter 
+ * method.
+ * 
+ * New in 2.0, the AbstractSetParseFilter is not synchronized and should not
+ * be used by multiple threads
+ */
+public abstract class AbstractSetParseFilter 
+  extends AbstractParseFilter 
+  implements Cloneable, SetParseFilter {
+
+    private static final long serialVersionUID = -758691949740569208L;
+
+    private transient Set<QName> 
+      qnames = new HashSet<QName>();
+    private transient Map<QName, Set<QName>> 
+      attributes = new HashMap<QName, Set<QName>>();
+
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+
+    public AbstractSetParseFilter add(QName qname) {
+        if (!contains(qname))
+          qnames.add(qname);
+        return this;
+    }
+
+    public boolean contains(QName qname) {
+      return qnames.contains(qname);
+    }
+
+    public AbstractSetParseFilter add(QName parent, QName attribute) {
+        if (attributes.containsKey(parent)) {
+            Set<QName> attrs = attributes.get(parent);
+            if (!attrs.contains(attribute))
+                attrs.add(attribute);
+        } else {
+            Set<QName> attrs = new HashSet<QName>();
+            attrs.add(attribute);
+            attributes.put(parent, attrs);
+        }
+        return this;
+    }
+
+    public boolean contains(QName qname, QName attribute) {
+        if (attributes.containsKey(qname)) {
+            Set<QName> attrs = attributes.get(qname);
+            return attrs.contains(attribute);
+        } else {
+            return false;
+        }
+    }
+
+    public abstract boolean acceptable(QName qname);
+
+    public abstract boolean acceptable(QName qname, QName attribute);
+
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+
+        // qnames field
+        assert qnames != null;
+        out.writeInt(qnames.size());
+        for (QName q : qnames) {
+            out.writeObject(q);
+        }
+
+        // attributes field
+        assert attributes != null;
+        out.writeInt(attributes.size());
+        for (Map.Entry<QName, Set<QName>> e : attributes.entrySet()) {
+            out.writeObject(e.getKey());
+            final Set<QName> v = e.getValue();
+            assert v != null;
+            out.writeInt(v.size());
+            for (QName q : v) {
+                out.writeObject(q);
+            }
+        }
+    }
+
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+
+        // qnames field
+        final int qnamesSize = in.readInt();
+        qnames = new HashSet<QName>(qnamesSize);
+        for (int i = 0; i < qnamesSize; i++) {
+            qnames.add((QName)in.readObject());
+        }
+
+        // attributes field
+        final int attributesSize = in.readInt();
+        attributes = new HashMap<QName, Set<QName>>();
+        for (int i = 0; i < attributesSize; i++) {
+            final QName k = (QName)in.readObject();
+            final int vSize = in.readInt();
+            final Set<QName> v = new HashSet<QName>(vSize);
+            for (int j = 0; j < vSize; j++) {
+                v.add((QName)in.readObject());
+            }
+            attributes.put(k, v);
+        }
+    }
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/BlackListParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/BlackListParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/BlackListParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/BlackListParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.filter;
+
+import javax.xml.namespace.QName;
+
+/**
+ * BlackList Implementation of ParseFilter. The QNames listed will be considered unacceptable. In general, black list
+ * based filtering is problematic, at best, due largely to the fact that it's easier to define safe subsets of elements
+ * than it is to define unsafe subsets.
+ */
+public class BlackListParseFilter extends AbstractSetParseFilter {
+
+    private static final long serialVersionUID = -8428373486568649179L;
+
+    public boolean acceptable(QName qname) {
+        return !contains(qname);
+    }
+
+    public boolean acceptable(QName qname, QName attribute) {
+        return !contains(qname, attribute);
+    }
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/CompoundParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/CompoundParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/CompoundParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/CompoundParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,110 @@
+/*
+ * 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.filter;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * <p>
+ * A simple compound parse filter that allows us to apply multiple parse filters to a single parse operation.
+ * </p>
+ * 
+ * <pre>
+ * CompoundParseFilter filter =
+ *     new CompoundParseFilter(CompoundParseFilter.Condition.ACCEPTABLE_TO_ALL, new SafeContentWhiteListParseFilter(),
+ *                             new MyWhiteListParseFilter(), new MySomeOtherKindOfParseFilter());
+ * options.setParseFilter(filter);
+ * </pre>
+ */
+public class CompoundParseFilter 
+  extends AbstractParseFilter 
+  implements ParseFilter {
+
+    private static final long serialVersionUID = -7871289035422204698L;
+
+    public enum Condition {
+        ACCEPTABLE_TO_ALL, 
+        ACCEPTABLE_TO_ANY, 
+        UNACCEPTABLE_TO_ALL, 
+        UNACCEPTABLE_TO_ANY;
+
+        byte evaluate(boolean b) {
+            if (b) {
+                switch (this) {
+                    case ACCEPTABLE_TO_ANY:
+                        return 1;
+                    case UNACCEPTABLE_TO_ALL:
+                        return -1;
+                }
+            } else {
+                switch (this) {
+                    case ACCEPTABLE_TO_ALL:
+                        return -1;
+                    case UNACCEPTABLE_TO_ANY:
+                        return 1;
+                }
+            }
+            return 0;
+        }
+    };
+
+    protected final Condition condition;
+    protected final ParseFilter[] filters;
+
+    public CompoundParseFilter(Condition condition, ParseFilter... filters) {
+        this.filters = filters;
+        this.condition = condition;
+    }
+
+    public CompoundParseFilter(ParseFilter... filters) {
+        this(Condition.ACCEPTABLE_TO_ANY, filters);
+    }
+
+    private ParseFilter[] getFilters() {
+        return filters;
+    }
+
+    public boolean acceptable(QName qname) {
+        for (ParseFilter filter : getFilters()) {
+            switch (condition.evaluate(filter.acceptable(qname))) {
+                case 1:
+                    return true;
+                case -1:
+                    return false;
+            }
+        }
+        return true;
+    }
+
+    public boolean acceptable(QName qname, QName attribute) {
+        for (ParseFilter filter : getFilters()) {
+            switch (condition.evaluate(filter.acceptable(qname, attribute))) {
+                case 1:
+                    return true;
+                case -1:
+                    return false;
+            }
+        }
+        return true;
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/NonOpParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/NonOpParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/NonOpParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/NonOpParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.filter;
+
+import javax.xml.namespace.QName;
+
+public class NonOpParseFilter extends AbstractParseFilter {
+
+    private static final long serialVersionUID = -1895875728388522456L;
+
+    public boolean acceptable(QName qname) {
+        return true;
+    }
+
+    public boolean acceptable(QName qname, QName attribute) {
+        return true;
+    }
+
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/ParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/ParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/ParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/ParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.filter;
+
+import java.io.Serializable;
+
+import javax.xml.namespace.QName;
+
+/**
+ * ParseFilter's determine which elements and attributes are acceptable within a parsed document. They are set via the
+ * ParserOptions.setParseFilter method.
+ */
+public interface ParseFilter extends Cloneable, Serializable {
+
+    /**
+     * Clone this ParseFilter
+     */
+    Object clone() throws CloneNotSupportedException;
+
+    /**
+     * Returns true if elements with the given QName are acceptable
+     */
+    boolean acceptable(QName qname);
+
+    /**
+     * Returns true if attributes with the given qname appearing on elements with the given qname are acceptable
+     */
+    boolean acceptable(QName qname, QName attribute);
+
+    /**
+     * Return true if the parser should ignore comments
+     */
+    boolean getIgnoreComments();
+
+    /**
+     * Return true if the parser should ignore insignificant whitespace
+     */
+    boolean getIgnoreWhitespace();
+
+    /**
+     * Return true if the parser should ignore processing instructions
+     */
+    boolean getIgnoreProcessingInstructions();
+
+    /**
+     * True if the parser should ignore comments
+     */
+    ParseFilter setIgnoreComments(boolean ignore);
+
+    /**
+     * True if the parser should ignore insignificant whitespace
+     */
+    ParseFilter setIgnoreWhitespace(boolean ignore);
+
+    /**
+     * True if the parser should ignore processing instructions
+     */
+    ParseFilter setIgnoreProcessingInstructions(boolean ignore);
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SafeContentWhiteListParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SafeContentWhiteListParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SafeContentWhiteListParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SafeContentWhiteListParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,91 @@
+/*
+ * 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.filter;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.Constants;
+
+public class SafeContentWhiteListParseFilter 
+    extends AbstractParseFilter 
+    implements ParseFilter {
+
+    private static final long serialVersionUID = -4802312485715572721L;
+
+    private static enum xhtml_elements {
+        a, abbr, acronym, address, area, b, bdo, big, blockquote, br, 
+        button, caption, center, cite, code, col, colgroup, dd, del, dfn, 
+        dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, 
+        h6, hr, i, img, input, ins, kbd, label, legend, li, map, menu, 
+        ol, optgroup, option, p, pre, q, s, samp, select, small, span, 
+        strike, strong, sub, sup, table, tbody, td, textarea, tfoot, 
+        th, thead, tr, tt, u, ul, var
+    };
+
+    private static enum xhtml_attributes {
+        abbr, accept, accept_charset, accesskey, action, align, alt, axis, 
+        border, cellpadding, cellspacing, CHAR, charoff, charset, checked, 
+        cite, CLASS, clear, cols, colspan, color, compact, coords, datetime, 
+        dir, disabled, enctype, FOR, frame, headers, height, href, hreflang, 
+        hspace, id, ismap, label, lang, longdesc, maxlength, media, method, 
+        multiple, name, nohref, noshade, nowrap, prompt, readonly, rel, rev, 
+        rows, rowspan, rules, scope, selected, shape, size, span, src, start, 
+        summary, tabindex, target, title, type, usemap, valign, value, vspace, 
+        width;
+
+        static String fix(String v) {
+            if (v.equalsIgnoreCase("char"))
+                return "CHAR";
+            if (v.equalsIgnoreCase("for"))
+                return "FOR";
+            if (v.equalsIgnoreCase("class"))
+                return "CLASS";
+            return v.toLowerCase();
+        }
+    };
+
+    public boolean acceptable(QName qname) {
+        if (qname.getNamespaceURI().equals(Constants.XHTML_NS)) {
+            try {
+                xhtml_elements.valueOf(qname.getLocalPart().toLowerCase());
+                return true;
+            } catch (Exception e) {
+            }
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public boolean acceptable(QName qname, QName attribute) {
+        if (qname.getNamespaceURI().equals(Constants.XHTML_NS)) {
+            try {
+                xhtml_attributes.valueOf(xhtml_attributes.fix(attribute.getLocalPart().toLowerCase()));
+                return true;
+            } catch (Exception e) {
+            }
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SetParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SetParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SetParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/SetParseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.parser.filter;
+
+import javax.xml.namespace.QName;
+
+/**
+ * A ParseFilter that is based on an internal collection of QName's.
+ */
+public interface SetParseFilter extends ParseFilter {
+
+    /**
+     * Add an element QName to the parse filter
+     */
+    SetParseFilter add(QName qname);
+
+    /**
+     * Returns true if the given qname has been added to the filter
+     */
+    boolean contains(QName qname);
+
+    /**
+     * Adds an attribute to the parse filter
+     */
+    SetParseFilter add(QName parent, QName attribute);
+
+    /**
+     * Returns true if the given attribute has been added to the filter
+     */
+    boolean contains(QName qname, QName attribute);
+
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/WhiteListParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/WhiteListParseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/WhiteListParseFilter.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/WhiteListParseFilter.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.parser.filter;
+
+import javax.xml.namespace.QName;
+
+/**
+ * WhiteList Implementation of ParseFilter. Only the QNames listed will be considered acceptable
+ */
+public class WhiteListParseFilter extends AbstractSetParseFilter {
+
+    private static final long serialVersionUID = -2126524829459798481L;
+    private final boolean listAttributesExplicitly;
+
+    public WhiteListParseFilter() {
+        this(false);
+    }
+
+    /**
+     * If listAttributesExplicity == true, attributes MUST be whitelisted independently of the elements on which they
+     * appear, otherwise, all attributes will automatically be considered acceptable if the containing element is
+     * considered acceptable.
+     */
+    public WhiteListParseFilter(boolean listAttributesExplicitly) {
+        this.listAttributesExplicitly = listAttributesExplicitly;
+    }
+
+    public boolean acceptable(QName qname) {
+        return contains(qname);
+    }
+
+    public boolean acceptable(QName qname, QName attribute) {
+        return (listAttributesExplicitly) ? 
+            contains(qname, attribute) && acceptable(qname) : 
+            acceptable(qname);
+    }
+
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/AbstractEntityProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/AbstractEntityProvider.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/AbstractEntityProvider.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/AbstractEntityProvider.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.protocol;
+
+import java.util.Date;
+
+import org.apache.abdera2.common.http.EntityTag;
+
+public abstract class AbstractEntityProvider implements EntityProvider {
+
+    public String getContentType() {
+        return "application/xml";
+    }
+
+    public EntityTag getEntityTag() {
+        return null;
+    }
+
+    public Date getLastModified() {
+        return null;
+    }
+
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/EntityProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/EntityProvider.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/EntityProvider.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/EntityProvider.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.protocol;
+
+import java.util.Date;
+
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.writer.StreamWriter;
+
+/**
+ * An EntityProvider is used to serialize entities using the StreamWriter interface. The EntityProvider interface can be
+ * implemented by applications to provide an efficient means of serializing non-FOM objects to Atom/XML.
+ */
+public interface EntityProvider {
+
+    /**
+     * Write to the specified StreamWriter
+     */
+    void writeTo(StreamWriter sw);
+
+    /**
+     * True if the serialization is repeatable.
+     */
+    boolean isRepeatable();
+
+    /**
+     * Return the mime content type of the serialized entity
+     */
+    String getContentType();
+
+    /**
+     * Return the EntityTag of the entity,
+     */
+    EntityTag getEntityTag();
+
+    /**
+     * Return the Last-Modified date of the entity
+     */
+    Date getLastModified();
+
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/AbderaProtocolException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/AbderaProtocolException.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/AbderaProtocolException.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/AbderaProtocolException.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.protocol.error;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.protocol.ProtocolException;
+
+public class AbderaProtocolException extends ProtocolException {
+
+    private static final long serialVersionUID = 1017447143200419489L;
+    private final Error error;
+
+    public AbderaProtocolException(Error error) {
+        super(error.getCode(),error.getMessage());
+        this.error = error;
+    }
+
+    public AbderaProtocolException(Abdera abdera, int code, String message) {
+        super(code,message);
+        this.error = Error.create(abdera, code, message);
+    }
+
+    public Error getError() {
+        return error;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        String message = error != null ? error.getMessage() : null;
+        int code = error != null ? error.getCode() : 0;
+        result = prime * result + ((message == null) ? 0 : message.hashCode());
+        result = prime * result + code;
+        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 AbderaProtocolException other = (AbderaProtocolException)obj;
+        String message = error != null ? error.getMessage() : null;
+        int code = error != null ? error.getCode() : 0;
+        String omessage = other.error != null ? other.error.getMessage() : null;
+        int ocode = other.error != null ? other.error.getCode() : 0;
+        if (message == null) {
+            if (omessage != null)
+                return false;
+        } else if (!message.equals(omessage))
+            return false;
+        if (code != ocode)
+            return false;
+        return true;
+    }
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/AbderaProtocolException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/Error.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/Error.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/Error.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/Error.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,127 @@
+/*
+ * 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.protocol.error;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ExtensibleElementWrapper;
+import org.apache.abdera2.writer.StreamWriter;
+
+import static org.apache.abdera2.protocol.error.ErrorExtensionFactory.*;
+
+/**
+ * Abdera protocol error element. The Abdera error document provides a simple structure for reporting errors back to
+ * Abdera clients.
+ */
+@org.apache.abdera2.common.anno.QName(value="error",ns=NS)
+public class Error extends ExtensibleElementWrapper {
+
+    public Error(Element internal) {
+        super(internal);
+    }
+
+    public Error(Factory factory, QName qname) {
+        super(factory, qname);
+    }
+
+    /**
+     * The code should typically match the HTTP status code; however, certain application scenarios may require the use
+     * of a different code
+     */
+    public int getCode() {
+        String code = getSimpleExtension(CODE);
+        return code != null ? Integer.parseInt(code) : -1;
+    }
+
+    /**
+     * The code should typically match the HTTP status code; however, certain application scenarios may require the use
+     * of a different code
+     */
+    public Error setCode(int code) {
+        if (code > -1) {
+            Element element = getExtension(CODE);
+            if (element != null) {
+                element.setText(Integer.toString(code));
+            } else {
+                addSimpleExtension(CODE, Integer.toString(code));
+            }
+        } else {
+            Element element = getExtension(CODE);
+            if (element != null)
+                element.discard();
+        }
+        return this;
+    }
+
+    /**
+     * Human-readable, language-sensitive description of the error
+     */
+    public String getMessage() {
+        return getSimpleExtension(MESSAGE);
+    }
+
+    /**
+     * Human-readable, language-sensitive description of the error
+     */
+    public Error setMessage(String message) {
+        if (message != null) {
+            Element element = getExtension(MESSAGE);
+            if (element != null) {
+                element.setText(message);
+            } else {
+                addSimpleExtension(MESSAGE, message);
+            }
+        } else {
+            Element element = getExtension(MESSAGE);
+            if (element != null)
+                element.discard();
+        }
+        return this;
+    }
+
+    /**
+     * Will throw a ProtocolException that wraps this element. This is useful on the client side to surface error
+     * responses
+     */
+    public void throwException() {
+        throw new AbderaProtocolException(this);
+    }
+
+    /**
+     * Create a new Error object
+     */
+    public static Error create(Abdera abdera, int code, String message) {
+        return create(abdera, code, message, null);
+    }
+
+    public static Error create(Abdera abdera, int code, String message, Throwable t) {
+        Document<Error> doc = abdera.getFactory().newDocument();
+        Error error = abdera.getFactory().newElement(ERROR, doc);
+        error.setCode(code).setMessage(message);
+        return error;
+    }
+
+    public static void create(StreamWriter sw, int code, String message, Throwable t) {
+        sw.startDocument().startElement(ERROR).startElement(CODE).writeElementText(code).endElement()
+            .startElement(MESSAGE).writeElementText(message).endElement().endElement().endDocument();
+    }
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/Error.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/ErrorExtensionFactory.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/ErrorExtensionFactory.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/ErrorExtensionFactory.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/ErrorExtensionFactory.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,36 @@
+/*
+ * 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.protocol.error;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.anno.Namespace;
+import org.apache.abdera2.factory.AbstractExtensionFactory;
+import org.apache.abdera2.factory.AbstractExtensionFactory.Impls;
+import org.apache.abdera2.factory.AbstractExtensionFactory.Impl;
+
+@Namespace("http://abdera.apache.org")
+@Impls({@Impl(org.apache.abdera2.protocol.error.Error.class)})
+public class ErrorExtensionFactory extends AbstractExtensionFactory {
+
+  public static final String NS = "http://abdera.apache.org";
+  public static final QName ERROR = new QName(NS, "error");
+  public static final QName CODE = new QName(NS, "code");
+  public static final QName MESSAGE = new QName(NS, "message");
+
+}

Propchange: abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/ErrorExtensionFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbderaConfiguration.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbderaConfiguration.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbderaConfiguration.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbderaConfiguration.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,109 @@
+/*
+ * 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.util;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.Discover;
+import org.apache.abdera2.common.anno.AnnoUtil;
+import org.apache.abdera2.factory.ExtensionFactory;
+import org.apache.abdera2.factory.StreamBuilder;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.parser.axiom.PrettyWriter;
+import org.apache.abdera2.protocol.error.ErrorExtensionFactory;
+import org.apache.abdera2.writer.StreamWriter;
+import org.apache.abdera2.writer.Writer;
+
+
+/**
+ * Provides the basic configuration for the Abdera default implementation. This class should not be accessed by
+ * applications directly without very good reason.
+ */
+public final class AbderaConfiguration 
+  extends AbstractConfiguration
+  implements Constants, Configuration {
+
+    private static final long serialVersionUID = 7460203853824337559L;
+
+    public AbderaConfiguration(Abdera abdera) {
+        super(null,abdera);
+    }
+
+    protected AbderaConfiguration(ResourceBundle bundle, Abdera abdera) {
+      super(bundle,abdera);
+    }
+
+    protected Set<ExtensionFactory> loadExtensionFactories() {
+        Set<ExtensionFactory> list = new HashSet<ExtensionFactory>();
+        list.add(new ErrorExtensionFactory());
+        Iterable<ExtensionFactory> factories = 
+          Discover.locate(ExtensionFactory.class);
+        for (ExtensionFactory factory : factories)
+            list.add(factory);
+        return list;
+    }
+
+    protected Map<String, Writer> initNamedWriters() {
+        Map<String, Writer> writers = null;
+        Iterable<Writer> _writers = Discover.locate(Writer.class,abdera);
+        writers = Collections.synchronizedMap(new HashMap<String, Writer>());
+        for (Writer writer : _writers) {
+            writers.put(AnnoUtil.getName(writer), writer);
+        }
+        writers.put(AnnoUtil.getName(PrettyWriter.class).toLowerCase(), new PrettyWriter());
+        return writers;
+    }
+
+    protected Map<String, Class<? extends StreamWriter>> initStreamWriters() {
+        Map<String, Class<? extends StreamWriter>> writers = null;
+        Iterable<Class<? extends StreamWriter>> _writers = 
+          Discover.locate("org.apache.abdera2.writer.StreamWriter", true, abdera);
+        writers = Collections.synchronizedMap(new HashMap<String, Class<? extends StreamWriter>>());
+        for (Class<? extends StreamWriter> writer : _writers) {
+            String name = AnnoUtil.getName(writer);
+            if (name != null)
+                writers.put(name.toLowerCase(), writer);
+        }
+        writers.put("fom", StreamBuilder.class);
+        return writers;
+    }
+
+    protected Map<String, Parser> initNamedParsers() {
+        Map<String, Parser> parsers = null;
+        Iterable<Parser> _parsers = Discover.locate(Parser.class, abdera);
+        parsers = Collections.synchronizedMap(new HashMap<String, Parser>());
+        for (Parser parser : _parsers)
+            parsers.put(AnnoUtil.getName(parser), parser);
+        return parsers;
+    }
+
+    public <T>T newInstance(Abdera abdera, Class<T> _class, String defaultImpl) {
+      return Discover.locate(
+          _class, 
+          abdera.getConfiguration().getConfigurationOption(
+              _class.getName(), defaultImpl), abdera);      
+    }
+    
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbstractConfiguration.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbstractConfiguration.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/util/AbstractConfiguration.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,215 @@
+/*
+ * 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.util;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.Localizer;
+import org.apache.abdera2.common.anno.AnnoUtil;
+import org.apache.abdera2.factory.ExtensionFactory;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.writer.StreamWriter;
+import org.apache.abdera2.writer.Writer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class AbstractConfiguration implements Constants, Configuration {
+
+    private static final long serialVersionUID = 7460203853824337559L;
+    private final static Log log = LogFactory.getLog(AbstractConfiguration.class);
+
+    private static ResourceBundle getBundle(Locale locale) {
+        ResourceBundle bundle = null;
+        try {
+            bundle = ResourceBundle.getBundle(
+              "abdera", locale, 
+              Thread.currentThread().getContextClassLoader());
+        } catch (Exception e) {
+            // Do nothing
+        }
+        return bundle;
+    }
+
+    protected final Abdera abdera;
+    protected final ResourceBundle bundle;
+    protected final Set<ExtensionFactory> factories;
+    protected final Map<String, Writer> writers;
+    protected final Map<String, Class<? extends StreamWriter>> streamwriters;
+    protected final Map<String, Parser> parsers;
+
+    public AbstractConfiguration(Abdera abdera) {
+        this(null,abdera);
+    }
+
+    protected AbstractConfiguration(ResourceBundle bundle, Abdera abdera) {
+        this.abdera = abdera;
+        this.bundle = (bundle != null) ? bundle : 
+          AbstractConfiguration.getBundle(Locale.getDefault());
+        factories = loadExtensionFactories();
+        writers = initNamedWriters();
+        parsers = initNamedParsers();
+        streamwriters = initStreamWriters();
+    }
+
+    protected abstract Set<ExtensionFactory> loadExtensionFactories();
+
+    protected ResourceBundle getBundle() {
+        return bundle;
+    }
+
+    /**
+     * Retrieve the value of the specified configuration option
+     * 
+     * @return The configuration option value or null
+     */
+    public String getConfigurationOption(String id) {
+        String option = System.getProperty(id);
+        if (option == null) {
+            try {
+                ResourceBundle bundle = getBundle();
+                if (bundle != null)
+                    option = bundle.getString(id);
+            } catch (Exception e) {
+                // Do Nothing
+            }
+        }
+        return option;
+    }
+
+    /**
+     * Retrieve the value of the specified configuration option or _default if the value is null
+     * 
+     * @return The configuration option value of _default
+     */
+    public String getConfigurationOption(String id, String _default) {
+        String value = getConfigurationOption(id);
+        return (value != null) ? value : _default;
+    }
+
+    /**
+     * Registers an ExtensionFactory implementation.
+     */
+    public AbstractConfiguration addExtensionFactory(ExtensionFactory factory) {
+        this.factories.add(factory);
+        return this;
+    }
+
+    /**
+     * Returns the listing of registered ExtensionFactory implementations
+     */
+    public Iterable<ExtensionFactory> getExtensionFactories() {
+        return factories;
+    }
+
+    /**
+     * Registers a NamedWriter implementation
+     */
+    public AbstractConfiguration addWriter(Writer writer) {
+        Map<String, Writer> writers = getWriters();
+        String name = AnnoUtil.getName(writer);
+        if (!writers.containsKey(name)) {
+            writers.put(name, writer);
+        } else {
+            log.warn("The NamedWriter is already registered: " + name);
+        }
+        return this;
+    }
+
+    /**
+     * Registers NamedWriter implementations using the /META-INF/services/org.apache.abdera.writer.NamedWriter file
+     */
+    protected abstract Map<String, Writer> initNamedWriters();
+
+    /**
+     * Registers StreamWriter implementations using the /META-INF/services/org.apache.abdera.writer.StreamWriter file
+     */
+    protected abstract Map<String, Class<? extends StreamWriter>> initStreamWriters();
+
+    /**
+     * Returns the collection of NamedWriters
+     */
+    public Map<String, Writer> getWriters() {
+        return writers;
+    }
+
+    /**
+     * Returns the collection of NamedWriters
+     */
+    public Map<String, Class<? extends StreamWriter>> getStreamWriters() {
+        return streamwriters;
+    }
+
+    /**
+     * Registers a NamedParser implementation
+     */
+    public AbstractConfiguration addParser(Parser parser) {
+        Map<String, Parser> parsers = getParsers();
+        String name = AnnoUtil.getName(parser);
+        if (!parsers.containsKey(name)) {
+            parsers.put(name, parser);
+        } else {
+            log.warn("The NamedParser is already registered: " + name);
+        }
+        return this;
+    }
+
+    /**
+     * Registers a StreamWriter implementation
+     */
+    public AbstractConfiguration addStreamWriter(Class<? extends StreamWriter> sw) {
+        Map<String, Class<? extends StreamWriter>> streamWriters = getStreamWriters();
+        String swName = AnnoUtil.getName(sw);
+        if (!streamWriters.containsKey(swName)) {
+            streamWriters.put(swName, sw);
+        } else {
+            log.warn("The StreamWriter is already registered: " + swName);
+        }
+        return this;
+    }
+
+    /**
+     * Registers NamedParser implementations using the /META-INF/services/org.apache.abdera.writer.NamedParser file
+     */
+    protected abstract Map<String, Parser> initNamedParsers();
+
+    /**
+     * Returns the collection of Named Parsers
+     */
+    public Map<String, Parser> getParsers() {
+        return parsers;
+    }
+
+    public <T>T newInstance(Abdera abdera, Class<T> _class) {
+      try {
+        return newInstance(abdera,_class,AnnoUtil.getDefaultImplementation(_class));
+      } catch (Throwable t) {
+        throw throwex("IMPLEMENTATION.NOT.AVAILABLE",_class.getSimpleName(), t);
+      }
+    }    
+    
+    public abstract <T>T newInstance(Abdera abdera, Class<T> _class, String defaultImpl);
+    
+    protected RuntimeException throwex(String id, String arg, Throwable t) {
+        return new RuntimeException(Localizer.sprintf(id, arg), t);
+    }
+}

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

Added: abdera/abdera2/core/src/main/java/org/apache/abdera2/util/Configuration.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/util/Configuration.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/core/src/main/java/org/apache/abdera2/util/Configuration.java (added)
+++ abdera/abdera2/core/src/main/java/org/apache/abdera2/util/Configuration.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,100 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.anno.DefaultImplementation;
+import org.apache.abdera2.factory.ExtensionFactory;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.writer.StreamWriter;
+import org.apache.abdera2.writer.Writer;
+
+@DefaultImplementation("org.apache.abdera2.util.AbderaConfiguration")
+public interface Configuration extends Serializable {
+
+    /**
+     * Retrieve the value of the specified configuration option
+     * 
+     * @return The configuration option value or null
+     */
+    public abstract String getConfigurationOption(String id);
+
+    /**
+     * Retrieve the value of the specified configuration option or _default if the value is null
+     * 
+     * @return The configuration option value of _default
+     */
+    public abstract String getConfigurationOption(String id, String _default);
+
+    public <T>T newInstance(Abdera abdera, Class<T> _class);
+        
+    /**
+     * Get the collection of Parsers;
+     */
+    public Map<String, Parser> getParsers();
+
+    /**
+     * Get the collection of Writers
+     */
+    public Map<String, Writer> getWriters();
+
+    /**
+     * Get the collection of StreamWriters
+     */
+    public Map<String, Class<? extends StreamWriter>> getStreamWriters();
+
+    /**
+     * Get the collection of ExtensionFactory impls
+     */
+    public Iterable<ExtensionFactory> getExtensionFactories();
+
+    /**
+     * Registers a new Parser, this method doesn't override a parser if already exists.
+     * 
+     * @param parser is the new Parser to add
+     * @return the instance of the configuration class
+     */
+    public Configuration addParser(Parser parser);
+
+    /**
+     * Registers a new Writer, this method doesn't override a writer if already exists.
+     * 
+     * @param writer is the new Writer to add
+     * @return the instance of the configuration class
+     */
+    public Configuration addWriter(Writer writer);
+
+    /**
+     * Registers a new ExtensionFactory, this method doesn't override an extensionFactory if already exists.
+     * 
+     * @param factory is the new ExtensionFactory to add
+     * @return the instance of the configuration class
+     */
+    public Configuration addExtensionFactory(ExtensionFactory factory);
+
+    /**
+     * Registers a new StreamWriter, this method doesn't override a streamWriter if already exists.
+     * 
+     * @param sw is the new StreamWriter to add
+     * @return the instance of the configuration class
+     */
+    public Configuration addStreamWriter(Class<? extends StreamWriter> sw);
+}

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



Mime
View raw message