chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r781949 [4/5] - in /incubator/chemistry/trunk/chemistry: ./ chemistry-atompub-client/ chemistry-atompub-client/src/ chemistry-atompub-client/src/main/ chemistry-atompub-client/src/main/java/ chemistry-atompub-client/src/main/java/org/ chemi...
Date Fri, 05 Jun 2009 09:05:22 GMT
Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/AbstractXmlObjectWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/AbstractXmlObjectWriter.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/AbstractXmlObjectWriter.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/AbstractXmlObjectWriter.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.chemistry.atompub.client.common.xml.XMLWriter;
+
+/**
+ *
+ */
+public abstract class AbstractXmlObjectWriter<T> implements XmlObjectWriter<T> {
+
+    public abstract String getContentType();
+
+    public void write(T object, File file) throws IOException {
+        FileWriter w = new FileWriter(file);
+        try {
+            write(object, w);
+        } finally {
+            w.close();
+        }
+    }
+
+    public void write(T object, OutputStream out) throws IOException {
+        write(object, new XMLWriter(new OutputStreamWriter(out)));
+    }
+
+    public void write(T object, Writer writer) throws IOException {
+        write(object, new XMLWriter(writer));
+    }
+
+    public abstract void write(T object, XMLWriter writer) throws IOException;
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/AbstractXmlObjectWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/AbstractXmlObjectWriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/DefaultEntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/DefaultEntryReader.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/DefaultEntryReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/DefaultEntryReader.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,37 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ *
+ */
+public class DefaultEntryReader extends AbstractObjectReader<XmlObject> {
+
+    @Override
+    protected XmlObject createObject(ReadContext ctx) {
+        return new XmlObject(ctx.getConnection());
+    }
+
+    @Override
+    protected void readProperty(ReadContext ctx, StaxReader reader,
+            XmlObject object, XmlProperty p) {
+        object.properties.put(p.getName(), p.getValue());
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/DefaultEntryReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/DefaultEntryReader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/EntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/EntryReader.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/EntryReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/EntryReader.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ *
+ */
+public interface EntryReader<T> {
+
+    T read(ReadContext ctx, URL url) throws XMLStreamException, IOException;
+
+    T read(ReadContext ctx, File file) throws XMLStreamException, IOException;
+
+    T read(ReadContext ctx, InputStream in) throws XMLStreamException;
+
+    T read(ReadContext ctx, XMLStreamReader xr) throws XMLStreamException;
+
+    T read(ReadContext ctx, StaxReader sr) throws XMLStreamException;
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/EntryReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/EntryReader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/FeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/FeedReader.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/FeedReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/FeedReader.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,45 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ *
+ */
+public interface FeedReader<T> extends XMLStreamConstants, ATOM {
+
+    T read(ReadContext ctx, URL url) throws XMLStreamException, IOException;
+
+    T read(ReadContext ctx, File file) throws XMLStreamException, IOException;
+
+    T read(ReadContext ctx, InputStream in) throws XMLStreamException;
+
+    T read(ReadContext ctx, Reader reader) throws XMLStreamException;
+
+    T read(ReadContext ctx, StaxReader reader) throws XMLStreamException;
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/FeedReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/FeedReader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ListFeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ListFeedReader.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ListFeedReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ListFeedReader.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ *
+ */
+public class ListFeedReader<T> extends AbstractFeedReader<List<T>, T> {
+
+    public ListFeedReader(EntryReader<T> entryReader) {
+        super(entryReader);
+    }
+
+    @Override
+    protected List<T> createFeed(StaxReader reader) {
+        return new ArrayList<T>();
+    }
+
+    @Override
+    protected void addEntry(List<T> feed, T entry) {
+        feed.add(entry);
+    }
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ListFeedReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ListFeedReader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ObjectEntryWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ObjectEntryWriter.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ObjectEntryWriter.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ObjectEntryWriter.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,64 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.IOException;
+import java.util.Date;
+
+import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.atompub.client.common.xml.XMLWriter;
+
+/**
+ *
+ */
+public abstract class ObjectEntryWriter extends
+        AbstractXmlObjectWriter<ObjectEntry> {
+
+    @Override
+    public String getContentType() {
+        return "application/atom+xml;type=entry";
+    }
+
+    @Override
+    public void write(ObjectEntry object, XMLWriter xw) throws IOException {
+        try {
+            xw.start();
+            xw.element("entry").xmlns(ATOM.ATOM_NS).xmlns(CMIS.CMIS_PREFIX,
+                    CMIS.CMIS_NS);
+            xw.start();
+            // atom requires an ID to be set even on new created entries ..
+            xw.element("id").content("urn:uuid:" + object.getId());
+            xw.element("title").content((String) object.getValue(Property.NAME));
+            xw.element("updated").content(new Date());
+            xw.element("content").content(""); // TODO fake content for now
+            writeCmisObject(object, xw);
+            xw.end();
+            xw.end();
+        } catch (Exception e) {
+            e.printStackTrace(); // TODO
+            throw new RuntimeException(e);
+        } finally {
+            xw.close();
+        }
+    }
+
+    protected abstract void writeCmisObject(ObjectEntry object, XMLWriter xw)
+            throws IOException;
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ObjectEntryWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ObjectEntryWriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/PropertyIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/PropertyIterator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/PropertyIterator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/PropertyIterator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,81 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.util.ArrayList;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.atompub.client.common.xml.ChildrenIterator;
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ * Iterate over property elements in the current CMIS object on the stream. Each
+ * iteration produces a {@link XmlProperty} object. The returned object is not
+ * yet ready to use since it have a null property definition. The property
+ * definition cannot be known before the object type is detected. This means the
+ * caller is responsible to fill in the property definition as soon as it
+ * detects the object type. To be able to choose the right property definition
+ * the caller must know the name of the property. This name will be passed
+ * through the value member. The caller must reset this member to
+ * {@link XmlProperty#NULL} after the property definition will be set on the
+ * property.
+ */
+public class PropertyIterator extends ChildrenIterator<XmlProperty> {
+
+    public PropertyIterator(StaxReader sr) throws XMLStreamException {
+        super(sr);
+    }
+
+    @Override
+    protected boolean accept() {
+        return reader.getNamespaceURI().equals(CMIS.CMIS_NS)
+                && reader.getLocalName().startsWith("property");
+    }
+
+    @Override
+    protected XmlProperty createValue() throws XMLStreamException {
+        String key = reader.getAttributeValue(CMIS.NAME);
+        if (key == null) {
+            throw new XMLStreamException(
+                    "Parse error. Invalid CMIS property at line: "
+                            + reader.getLocation().getLineNumber()
+                            + ". No name specified");
+        }
+        ValueIterator vi = new ValueIterator(reader);
+        XmlProperty xp = new XmlProperty();
+        xp.value = key; // use value to temporary store the key
+        if (!vi.hasNext()) {
+            return xp;
+        }
+        String val = vi.next();
+        if (!vi.hasNext()) {
+            xp.xmlValue = val;
+            return xp;
+        }
+        ArrayList<String> vals = new ArrayList<String>();
+        vals.add(val);
+        do {
+            val = vi.next();
+            vals.add(val);
+        } while (vi.hasNext());
+        xp.xmlValue = vals;
+        return xp;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/PropertyIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/PropertyIterator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ReadContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ReadContext.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ReadContext.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ReadContext.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,81 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.util.HashMap;
+
+import org.apache.chemistry.Connection;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.Type;
+
+/**
+ *
+ */
+public class ReadContext extends HashMap<Object, Object> {
+
+    private static final long serialVersionUID = 1L;
+
+    protected Type type;
+
+    protected Repository repository;
+
+    protected Connection connection;
+
+    public ReadContext() {
+
+    }
+
+    public ReadContext(Connection connection) {
+        this(connection, null);
+    }
+
+    public ReadContext(Repository repository) {
+        this(repository, null);
+    }
+
+    public ReadContext(Repository repository, Type type) {
+        this.type = type;
+        this.repository = repository;
+        if (repository == null) {
+            throw new IllegalArgumentException(
+                    "A BuildContext must be bound to a repository");
+        }
+    }
+
+    public ReadContext(Connection connection, Type type) {
+        this.connection = connection;
+        this.type = type;
+        this.repository = connection.getRepository();
+        if (repository == null) {
+            throw new IllegalArgumentException(
+                    "A BuildContext must be bound to a repository");
+        }
+    }
+
+    public Repository getRepository() {
+        return repository;
+    }
+
+    public Connection getConnection() {
+        return connection;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ReadContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ReadContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ServiceDocumentReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ServiceDocumentReader.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ServiceDocumentReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ServiceDocumentReader.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,166 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Workspace;
+import org.apache.chemistry.JoinCapability;
+import org.apache.chemistry.QueryCapability;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryInfo;
+import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.atompub.client.app.model.APPRepository;
+import org.apache.chemistry.atompub.client.app.model.APPRepositoryCapabilities;
+import org.apache.chemistry.atompub.client.app.model.APPRepositoryInfo;
+import org.apache.chemistry.atompub.client.common.xml.ChildrenNavigator;
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ * Base class for service document reader implementations.
+ */
+public abstract class ServiceDocumentReader<T extends Repository> {
+
+    protected abstract T createRepository(ReadContext ctx);
+
+    protected abstract void addCollection(T repo, String href, String type);
+
+    protected abstract void setInfo(T repo, RepositoryInfo info);
+
+    public T[] read(ReadContext context, InputStream in) throws IOException {
+        try {
+            StaxReader reader = StaxReader.newReader(in);
+            if (!reader.fwdTag("service")) {
+                throw new IOException("Invalid APP service document");
+            }
+            ArrayList<Repository> repos = new ArrayList<Repository>();
+            ChildrenNavigator workspaces = reader.getChildren("workspace");
+            while (workspaces.next()) {
+                T repo = createRepository(context);
+                ChildrenNavigator children = reader.getChildren();
+                while (children.next()) {
+                    QName name = reader.getName();
+                    if (name.equals(ATOM.COLLECTION)) {
+                        String href = reader.getAttributeValue("href");
+                        String type = reader.getAttributeValue("collectionType");
+                        addCollection(repo, href, type);
+                    } else if (name.equals(CMIS.REPOSITORY_INFO)) {
+                        RepositoryInfo info = readRepositoryInfo(context,
+                                reader);
+                        setInfo(repo, info);
+                    }
+                }
+                repos.add(repo);
+            }
+            return (T[]) repos.toArray(new APPRepository[repos.size()]);
+        } catch (XMLStreamException e) {
+            IOException ioe = new IOException();
+            ioe.initCause(e);
+            throw ioe;
+        }
+    }
+
+    protected RepositoryInfo readRepositoryInfo(ReadContext context,
+            StaxReader reader) throws XMLStreamException {
+        APPRepositoryCapabilities caps = null;
+        Map<String, Object> map = new HashMap<String, Object>();
+        ChildrenNavigator nav = reader.getChildren();
+        while (nav.next()) {
+            String localName = reader.getLocalName();
+            if (localName.equals(CMIS.CAPABILITIES.getLocalPart())) {
+                caps = new APPRepositoryCapabilities();
+                ChildrenNavigator capElems = reader.getChildren();
+                while (capElems.next()) {
+                    localName = reader.getLocalName();
+                    if (localName.equals(CMIS.CAPABILITY_ALL_VERSIONS_SEARCHABLE.getLocalPart())) {
+                        caps.setAllVersionsSearchable(Boolean.parseBoolean(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_MULTIFILING.getLocalPart())) {
+                        caps.setHasMultifiling(Boolean.parseBoolean(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_PWC_SEARCHABLE.getLocalPart())) {
+                        caps.setPWCSearchable(Boolean.parseBoolean(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_PWC_UPDATEABLE.getLocalPart())) {
+                        caps.setPWCUpdatable(Boolean.parseBoolean(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_UNFILING.getLocalPart())) {
+                        caps.setHasUnfiling(Boolean.parseBoolean(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_VERSION_SPECIFIC_FILING.getLocalPart())) {
+                        caps.setHasVersionSpecificFiling(Boolean.parseBoolean(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_QUERY.getLocalPart())) {
+                        caps.setQueryCapability(QueryCapability.valueOf(reader.getElementText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_JOIN.getLocalPart())) {
+                        caps.setJoinCapability(JoinCapability.valueOf(reader.getElementText()));
+                    }
+                }
+            } else if (localName.equals("repositorySpecificInformation")) {
+                readRepositorySpecificInformation(context, reader);
+            } else {
+                map.put(localName, reader.getElementText());
+            }
+        }
+        return new APPRepositoryInfo(caps, map);
+    }
+
+    protected RepositoryInfo getRepositoryInfo(Workspace ws) {
+        Element repoInfo = ws.getFirstChild(CMIS.REPOSITORY_INFO);
+        APPRepositoryCapabilities caps = null;
+        Map<String, Object> map = new HashMap<String, Object>();
+        for (Element el : repoInfo.getElements()) {
+            String localName = el.getQName().getLocalPart();
+            if (localName.equals(CMIS.CAPABILITIES.getLocalPart())) {
+                caps = new APPRepositoryCapabilities();
+                for (Element el2 : el.getElements()) {
+                    localName = el2.getQName().getLocalPart();
+                    if (localName.equals(CMIS.CAPABILITY_ALL_VERSIONS_SEARCHABLE.getLocalPart())) {
+                        caps.setAllVersionsSearchable(Boolean.parseBoolean(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_MULTIFILING.getLocalPart())) {
+                        caps.setHasMultifiling(Boolean.parseBoolean(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_PWC_SEARCHABLE.getLocalPart())) {
+                        caps.setPWCSearchable(Boolean.parseBoolean(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_PWC_UPDATEABLE.getLocalPart())) {
+                        caps.setPWCUpdatable(Boolean.parseBoolean(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_UNFILING.getLocalPart())) {
+                        caps.setHasUnfiling(Boolean.parseBoolean(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_VERSION_SPECIFIC_FILING.getLocalPart())) {
+                        caps.setHasVersionSpecificFiling(Boolean.parseBoolean(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_QUERY.getLocalPart())) {
+                        caps.setQueryCapability(QueryCapability.valueOf(el2.getText()));
+                    } else if (localName.equals(CMIS.CAPABILITY_JOIN.getLocalPart())) {
+                        caps.setJoinCapability(JoinCapability.valueOf(el2.getText()));
+                    }
+                }
+            } else if (localName.equals("repositorySpecificInformation")) {
+                // TODO
+            } else {
+                map.put(localName, el.getText());
+            }
+        }
+        return new APPRepositoryInfo(caps, map);
+    }
+
+    protected void readRepositorySpecificInformation(ReadContext context,
+            StaxReader reader) {
+        // do nothing
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ServiceDocumentReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ServiceDocumentReader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueAdapter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueAdapter.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueAdapter.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueAdapter.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,306 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.model.AtomDate;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.atompub.CMIS;
+
+/**
+ *
+ */
+public abstract class ValueAdapter {
+
+    public abstract Serializable readValue(String xml);
+
+    public abstract String writeValue(Serializable val);
+
+    public abstract Serializable[] createArray(int size);
+
+    public abstract QName getPropertyName();
+
+    public static final ValueAdapter STRING = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return xml;
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new String[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_STRING;
+        }
+    };
+
+    public static final ValueAdapter XML = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return xml;
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new String[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_XML;
+        }
+    };
+
+    public static final ValueAdapter HTML = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return xml;
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new String[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_HTML;
+        }
+    };
+
+    public static final ValueAdapter BOOLEAN = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return Boolean.valueOf(xml);
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new Boolean[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_BOOLEAN;
+        }
+    };
+
+    public static final ValueAdapter INTEGER = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return Integer.valueOf(xml);
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new Integer[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_INTEGER;
+        }
+    };
+
+    public static final ValueAdapter DECIMAL = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return new BigDecimal(xml);
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new BigDecimal[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_DECIMAL;
+        }
+    };
+
+    public static final ValueAdapter DATE = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return AtomDate.valueOf(xml).getCalendar();
+        }
+
+        // accepts both Calendar and Date
+        @Override
+        public String writeValue(Serializable val) {
+            return val.getClass() == Calendar.class ? AtomDate.format(((Calendar) val).getTime())
+                    : AtomDate.format((Date) val);
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new Calendar[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_DATETIME;
+        }
+    };
+
+    public static final ValueAdapter ID = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            return xml;
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new String[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_ID;
+        }
+    };
+
+    public static final ValueAdapter URI = new ValueAdapter() {
+        @Override
+        public Serializable readValue(String xml) {
+            try {
+                return new URI(xml);
+            } catch (Exception e) {
+                throw new IllegalArgumentException("Invalid URI: " + xml);
+            }
+        }
+
+        @Override
+        public String writeValue(Serializable val) {
+            return val.toString();
+        }
+
+        @Override
+        public Serializable[] createArray(int size) {
+            return new String[size];
+        }
+
+        @Override
+        public QName getPropertyName() {
+            return CMIS.PROPERTY_URI;
+        }
+    };
+
+    private final static Map<String, ValueAdapter> adapters = new HashMap<String, ValueAdapter>();
+    static {
+        adapters.put("String", STRING);
+        adapters.put("Boolean", BOOLEAN);
+        adapters.put("Integer", INTEGER);
+        adapters.put("Decimal", DECIMAL);
+        adapters.put("DateTime", DATE);
+        adapters.put("Id", ID);
+        adapters.put("Uri", URI);
+        adapters.put("Xml", XML);
+        adapters.put("Html", HTML);
+
+        adapters.put("string", STRING);
+        adapters.put("boolean", BOOLEAN);
+        adapters.put("integer", INTEGER);
+        adapters.put("decimal", DECIMAL);
+        adapters.put("datetime", DATE);
+        adapters.put("id", ID);
+        adapters.put("uri", URI);
+        adapters.put("xml", XML);
+        adapters.put("html", HTML);
+
+    }
+
+    public static void registerAdapter(String type, ValueAdapter va) {
+        adapters.put(type, va);
+    }
+
+    public static ValueAdapter getAdapter(String type) {
+        return adapters.get(type);
+    }
+
+    public static ValueAdapter getAdapter(PropertyType type) {
+        switch (type.ordinal()) {
+        case PropertyType.STRING_ORD:
+            return ValueAdapter.STRING;
+        case PropertyType.BOOLEAN_ORD:
+            return ValueAdapter.BOOLEAN;
+        case PropertyType.DATETIME_ORD:
+            return ValueAdapter.DATE;
+        case PropertyType.ID_ORD:
+            return ValueAdapter.ID;
+        case PropertyType.INTEGER_ORD:
+            return ValueAdapter.INTEGER;
+        case PropertyType.URI_ORD:
+            return ValueAdapter.URI;
+        case PropertyType.DECIMAL_ORD:
+            return ValueAdapter.DECIMAL;
+        case PropertyType.XML_ORD:
+            return ValueAdapter.XML;
+        case PropertyType.HTML_ORD:
+            return ValueAdapter.HTML;
+        }
+        return null;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueIterator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueIterator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueIterator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,45 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.atompub.client.common.xml.ChildrenIterator;
+import org.apache.chemistry.atompub.client.common.xml.StaxReader;
+
+/**
+ *
+ */
+public class ValueIterator extends ChildrenIterator<String> {
+
+    public ValueIterator(StaxReader sr) throws XMLStreamException {
+        super(sr);
+    }
+
+    @Override
+    protected boolean accept() {
+        return (reader.getLocalName().equals(CMIS.VALUE.getLocalPart()) && reader.getNamespaceURI().equals(
+                CMIS.VALUE.getNamespaceURI()));
+    }
+
+    @Override
+    protected String createValue() throws XMLStreamException {
+        return reader.getElementText();
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/ValueIterator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObject.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObject.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObject.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.chemistry.Connection;
+import org.apache.chemistry.Type;
+
+/**
+ *
+ */
+public class XmlObject {
+
+    protected Type type;
+
+    protected Connection connection;
+
+    protected Map<String, Serializable> properties;
+
+    protected Set<String> allowableActions;
+
+    public XmlObject(Connection connection, Type type) {
+        this.type = type;
+        this.connection = connection;
+        properties = new HashMap<String, Serializable>();
+    }
+
+    public XmlObject(Connection connection) {
+        this(connection, null);
+    }
+
+    public void setType(Type type) {
+        this.type = type;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public Connection getConnection() {
+        return connection;
+    }
+
+    public Map<String, Serializable> getProperties() {
+        return properties;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObject.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObjectWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObjectWriter.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObjectWriter.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObjectWriter.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,41 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import org.apache.chemistry.atompub.client.common.xml.XMLWriter;
+
+/**
+ *
+ */
+public interface XmlObjectWriter<T> {
+
+    String getContentType();
+
+    void write(T object, File file) throws IOException;
+
+    void write(T object, OutputStream out) throws IOException;
+
+    void write(T object, Writer writer) throws IOException;
+
+    void write(T object, XMLWriter writer) throws IOException;
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObjectWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlObjectWriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlProperty.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlProperty.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlProperty.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlProperty.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,179 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.atom;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+
+/**
+ * Implementation of a CMIS property to be used when reading data from XML. This
+ * implementation is creating value objects from the XML strings only when first
+ * accessed, this ensure faster loading of big feeds.
+ */
+public class XmlProperty implements Property {
+
+    protected static final String NULL = new String();
+
+    protected PropertyDefinition def;
+
+    protected Serializable value = NULL;
+
+    protected Object xmlValue;
+
+    public XmlProperty() {
+
+    }
+
+    public XmlProperty(PropertyDefinition def) {
+        this.def = def;
+    }
+
+    public XmlProperty(PropertyDefinition def, String value) {
+        this.def = def;
+        this.xmlValue = value;
+    }
+
+    public XmlProperty(PropertyDefinition def, List<String> value) {
+        this.def = def;
+        this.xmlValue = value;
+    }
+
+    /**
+     * Get the property name
+     *
+     * @return the property name
+     */
+    public String getName() {
+        return def.getName();
+    }
+
+    /**
+     * Get the property adapter which know how to convert the raw value into a
+     * suitable Java object
+     *
+     * @return
+     */
+    public ValueAdapter getAdapter() {
+        return ValueAdapter.getAdapter(def.getType());
+    }
+
+    /**
+     * Get the property value. The returned object is either null either one of
+     * the following types: <li> <code>String</code> or <code>String[]</code> if
+     * an array <li> <code>Calendar</code> or <code>Calendar[]</code> if an array
+     * <li> <code>Boolean</code> or <code>Boolean[]</code> if an array <li>
+     * <code>Integer</code> or <code>Integer[]</code> if an array <li>
+     * <code>URI</code> or <code>URI[]</code> if an array <li>
+     * <code>BugDecimail</code> or <code>BigDecimal[]</code> if an array
+     */
+    @SuppressWarnings("unchecked")
+    public Serializable getValue() {
+        if (value == NULL) { // real value not yet computed
+            if (xmlValue == null) {
+                value = def.getDefaultValue(); // or null?
+            } else {
+                ValueAdapter va = getAdapter();
+                if (va == null) {
+                    throw new IllegalArgumentException("Unknow property type: "
+                            + def.getType());
+                }
+                if (xmlValue.getClass() == String.class) {
+                    if (def.isMultiValued()) {
+                        Serializable[] ar = va.createArray(1);
+                        ar[0] = va.readValue((String) xmlValue);
+                        value = ar;
+                    } else {
+                        value = va.readValue((String) xmlValue);
+                    }
+                } else { // a list
+                    List<String> list = (List<String>) xmlValue;
+                    if (def.isMultiValued()) {
+                        if (def.getType() == PropertyType.STRING) { // optimization
+                            // for
+                            // string
+                            // lists
+                            value = list.toArray(va.createArray(list.size()));
+                        } else {
+                            Serializable[] ar = va.createArray(list.size());
+                            for (int i = 0; i < ar.length; i++) {
+                                ar[i] = va.readValue((String) xmlValue);
+                            }
+                            value = ar;
+                        }
+                    } else {
+                        // TODO throw an exception ?
+                        throw new IllegalArgumentException(
+                                "Multiple value set on a scalar property: "
+                                        + getName());
+                    }
+                }
+            }
+            xmlValue = null; // TODO nullify - or reuse it to keep dirty state?
+        }
+        return value;
+    }
+
+    public void setValue(Serializable value) {
+        if (!def.validates(value)) {
+            throw new IllegalArgumentException("Not a valid value: " + value); // TODO
+            // use
+            // custom
+            // exceptions
+        }
+        this.value = value;
+    }
+
+    public void setValueUnsafe(Serializable value) {
+        this.value = value;
+    }
+
+    public Object getXmlValue() {
+        return xmlValue;
+    }
+
+    public void setXmlValue(String value) {
+        this.xmlValue = value;
+        this.value = NULL;
+    }
+
+    public void setXmlValue(List<String> value) {
+        this.xmlValue = value;
+        this.value = NULL;
+    }
+
+    public void setDefinition(PropertyDefinition def) {
+        this.def = def;
+    }
+
+    public PropertyDefinition getDefinition() {
+        return def;
+    }
+
+    public boolean isValueLoaded() {
+        return value != NULL;
+    }
+
+    @Override
+    public String toString() {
+        return getName() + "=" + (xmlValue == null ? value : xmlValue);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/atom/XmlProperty.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenIterator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenIterator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenIterator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,30 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ *
+ */
+public abstract class ChildrenIterator<T> extends SiblingsIterator<T> {
+
+    public ChildrenIterator(StaxReader sr) throws XMLStreamException {
+        super(sr, sr.getChildrenDepth());
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenIterator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenNavigator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenNavigator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenNavigator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenNavigator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,52 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ *
+ */
+public class ChildrenNavigator {
+
+    protected StaxReader sr;
+
+    protected int depth;
+
+    public ChildrenNavigator(StaxReader sr) throws XMLStreamException {
+        this.sr = sr;
+        int tok = sr.getEventType();
+        if (tok == StaxReader.END_ELEMENT) {
+            depth = sr.depth + 1;
+        } else if (tok == StaxReader.START_ELEMENT) {
+            depth = sr.depth;
+        } else {
+            throw new XMLStreamException(
+                    "Ilegal state: current event must be START_ELEMENT or END_ELEMENT");
+        }
+    }
+
+    public ChildrenNavigator(StaxReader sr, int depth) {
+        this.sr = sr;
+        this.depth = depth;
+    }
+
+    public boolean next() throws XMLStreamException {
+        return sr.fwdSibling(depth);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenNavigator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ChildrenNavigator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ElementIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ElementIterator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ElementIterator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ElementIterator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,86 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * An iterator over the XML elements in the stream that create element objects
+ * each time next method is called.
+ */
+public abstract class ElementIterator<T> implements Iterator<T> {
+
+    protected StaxReader reader;
+
+    protected Boolean hasNext;
+
+    public ElementIterator(StaxReader sr) {
+        this.reader = sr;
+    }
+
+    protected abstract T createValue() throws XMLStreamException;
+
+    protected boolean forward() throws XMLStreamException {
+        return reader.fwd();
+    }
+
+    protected boolean accept() {
+        return true;
+    }
+
+    public boolean hasNext() {
+        if (hasNext == null) {
+            try {
+                while (forward()) {
+                    if (accept()) {
+                        hasNext = Boolean.TRUE;
+                        return true;
+                    }
+                }
+            } catch (Exception e) {
+                throw new ParseException(e);
+            }
+            hasNext = Boolean.FALSE;
+            return false;
+        }
+
+        return hasNext.booleanValue();
+    }
+
+    public T next() {
+        if (hasNext == null) {
+            hasNext();
+        }
+        if (!hasNext) {
+            throw new NoSuchElementException("No more elements in stream");
+        }
+        hasNext = null;
+        try {
+            return createValue();
+        } catch (Exception e) {
+            throw new ParseException(e);
+        }
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException("remove not supported");
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ElementIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ElementIterator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/FilteredChildrenNavigator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/FilteredChildrenNavigator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/FilteredChildrenNavigator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/FilteredChildrenNavigator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,46 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ *
+ */
+public class FilteredChildrenNavigator extends ChildrenNavigator {
+
+    public FilteredChildrenNavigator(StaxReader sr) throws XMLStreamException {
+        super(sr);
+    }
+
+    public FilteredChildrenNavigator(StaxReader sr, int depth) {
+        super(sr, depth);
+    }
+
+    protected boolean accept() {
+        return true;
+    }
+
+    @Override
+    public boolean next() throws XMLStreamException {
+        while (super.next()) {
+            if (accept())
+                return true;
+        }
+        return false;
+    }
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/FilteredChildrenNavigator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/FilteredChildrenNavigator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ParseException.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ParseException.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ParseException.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ParseException.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ *
+ */
+public class ParseException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public ParseException(XMLStreamReader reader, String message) {
+        this("Parse Error at " + reader.getLocation().getLineNumber() + ":"
+                + reader.getLocation().getColumnNumber() + ". " + message);
+    }
+
+    public ParseException(XMLStreamReader reader, Throwable cause) {
+        this("Parse Error at " + reader.getLocation().getLineNumber() + ":"
+                + reader.getLocation().getColumnNumber(), cause);
+    }
+
+    public ParseException(XMLStreamReader reader) {
+        this(reader, "");
+    }
+
+    public ParseException(String message) {
+        super(message);
+    }
+
+    public ParseException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ParseException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ParseException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/ParseException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/SiblingsIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/SiblingsIterator.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/SiblingsIterator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/SiblingsIterator.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * An element iterator that iterates only over the sibling elements.
+ */
+public abstract class SiblingsIterator<T> extends ElementIterator<T> {
+
+    protected int depth;
+
+    public SiblingsIterator(StaxReader sr) throws XMLStreamException {
+        this(sr, sr.getElementDepth());
+    }
+
+    public SiblingsIterator(StaxReader sr, int depth) {
+        super(sr);
+        this.depth = depth;
+    }
+
+    @Override
+    protected boolean forward() throws XMLStreamException {
+        return reader.fwdSibling(depth);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/SiblingsIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/SiblingsIterator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/StaxReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/StaxReader.java?rev=781949&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/StaxReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/StaxReader.java Fri Jun  5 09:05:20 2009
@@ -0,0 +1,325 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.common.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLResolver;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+/**
+ *
+ */
+public class StaxReader extends StreamReaderDelegate {
+
+    protected final static XMLInputFactory factory = XMLInputFactory.newInstance();
+    static {
+        factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
+                Boolean.FALSE);
+        factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
+        factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
+        factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
+        // network detached mode
+        // copied form apache axiom
+        factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
+                Boolean.FALSE);
+        // Some StAX parser such as Woodstox still try to load the external DTD
+        // subset,
+        // even if IS_SUPPORTING_EXTERNAL_ENTITIES is set to false. To work
+        // around this,
+        // we add a custom XMLResolver that returns empty documents. See
+        // WSTX-117 for
+        // an interesting discussion about this.
+        factory.setXMLResolver(new XMLResolver() {
+            public Object resolveEntity(String publicID, String systemID,
+                    String baseURI, String namespace) throws XMLStreamException {
+                return new ByteArrayInputStream(new byte[0]);
+            }
+        });
+    }
+
+    public static final XMLInputFactory getFactory() {
+        return factory;
+    }
+
+    public static StaxReader newReader(InputStream in)
+            throws XMLStreamException {
+        return new StaxReader(factory.createXMLStreamReader(in));
+    }
+
+    public static StaxReader newReader(Reader reader) throws XMLStreamException {
+        return new StaxReader(factory.createXMLStreamReader(reader));
+    }
+
+    public static StaxReader newReader(XMLStreamReader reader)
+            throws XMLStreamException {
+        return new StaxReader(reader);
+    }
+
+    public StaxReader(XMLStreamReader reader) {
+        super(reader);
+    }
+
+    protected int depth;
+
+    protected String defNsUri;
+
+    public int getDepth() {
+        return depth;
+    }
+
+    @Override
+    public String getElementText() throws XMLStreamException {
+        depth--;
+        return super.getElementText();
+    }
+
+    public final int getElementDepth() throws XMLStreamException {
+        return getEventType() == END_ELEMENT ? depth + 1 : depth;
+    }
+
+    public final int getChildrenDepth() throws XMLStreamException {
+        return getElementDepth() + 1;
+    }
+
+    public boolean fwd() throws XMLStreamException {
+        if (!hasNext()) {
+            return false;
+        }
+        int tok = next();
+        if (tok == START_ELEMENT) {
+            depth++;
+        } else if (tok == END_ELEMENT) {
+            depth--;
+        }
+        return true;
+    }
+
+    public boolean fwdTag() throws XMLStreamException {
+        // we need to test first hasNext to be sure we fwd in the stream
+        // this way we are sure we didn't end in the same element (without
+        // forwarding the stream)
+        while (hasNext() && fwd()) {
+            if (getEventType() == START_ELEMENT) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean fwdTag(String localName) throws XMLStreamException {
+        // we need to test first hasNext to be sure we fwd in the stream
+        // this way we are sure we didn't end in the same element (without
+        // forwarding the stream)
+        while (hasNext() && fwd()) {
+            if (getEventType() == START_ELEMENT
+                    && localName.equals(getLocalName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean fwdTag(String nsUri, String localName)
+            throws XMLStreamException {
+        // we need to test first hasNext to be sure we fwd in the stream
+        // this way we are sure we didn't end in the same element (without
+        // forwarding the stream)
+        while (hasNext() && fwd()) {
+            if (getEventType() == START_ELEMENT
+                    && localName.equals(getLocalName())
+                    && nsUri.equals(getNamespaceURI())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean getFirstTag(QName name) throws XMLStreamException {
+        if (getEventType() == START_ELEMENT && getName().equals(name)) {
+            return true;
+        }
+        return fwdTag(name);
+    }
+
+    public boolean getFirstTag(String localName) throws XMLStreamException {
+        if (getEventType() == START_ELEMENT && getLocalName().equals(localName)) {
+            return true;
+        }
+        return fwdTag(localName);
+    }
+
+    public boolean getFirstTag(String nsUri, String localName)
+            throws XMLStreamException {
+        if (getEventType() == START_ELEMENT && getLocalName().equals(localName)
+                && getNamespaceURI().equals(nsUri)) {
+            return true;
+        }
+        return fwdTag(nsUri, localName);
+    }
+
+    public boolean fwdTag(QName name) throws XMLStreamException {
+        // we need to test first hasNext to be sure we fwd in the stream
+        // this way we are sure we didn't end in the same element (without
+        // forwarding the stream)
+        while (hasNext() && fwd()) {
+            if (getEventType() == START_ELEMENT && name.equals(getName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean fwdSibling() throws XMLStreamException {
+        int tok = getEventType();
+        if (tok == END_ELEMENT) {
+            return fwdSibling(depth + 1);
+        } else if (tok == START_ELEMENT) {
+            return fwdSibling(depth);
+        } else {
+            throw new XMLStreamException(
+                    "Ilegal state: current event must be START_ELEMENT or END_ELEMENT");
+        }
+    }
+
+    public boolean fwdSibling(int cdepth) throws XMLStreamException {
+        // we need to test first hasNext to be sure we fwd in the stream
+        // this way we are sure we didn't end in the same element (without
+        // forwarding the stream)
+        while (hasNext() && fwd()) {
+            if (depth < cdepth - 1) {
+                return false;
+            } else if (depth > cdepth) {
+                continue;
+            } else if (getEventType() == START_ELEMENT) { // on same level
+                if (depth == cdepth) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public boolean fwdSibling(String localName) throws XMLStreamException {
+        while (fwdSibling()) {
+            if (localName.equals(getLocalName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean fwdSibling(QName name) throws XMLStreamException {
+        while (fwdSibling()) {
+            if (name.equals(getName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean fwdSibling(String nsUri, String localName)
+            throws XMLStreamException {
+        while (fwdSibling()) {
+            if (localName.equals(getLocalName())
+                    && nsUri.equals(getNamespaceURI())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public ChildrenNavigator getChildren() throws XMLStreamException {
+        return new ChildrenNavigator(this, depth + 1);
+    }
+
+    public ChildrenNavigator getChildren(final String localName)
+            throws XMLStreamException {
+        return new FilteredChildrenNavigator(this, depth + 1) {
+            @Override
+            protected boolean accept() {
+                return localName.equals(getLocalName());
+            }
+        };
+    }
+
+    public ChildrenNavigator getChildren(final String nsUri,
+            final String localName) throws XMLStreamException {
+        return new FilteredChildrenNavigator(this, depth + 1) {
+            @Override
+            protected boolean accept() {
+                return localName.equals(getLocalName())
+                        && nsUri.equals(getNamespaceURI());
+            }
+        };
+    }
+
+    public ChildrenNavigator getChildren(final QName name)
+            throws XMLStreamException {
+        return new FilteredChildrenNavigator(this, depth + 1) {
+            @Override
+            protected boolean accept() {
+                return name.equals(getName());
+            }
+        };
+    }
+
+    public String getAttributeValue(String localName) {
+        int cnt = getAttributeCount();
+        for (int i = 0; i < cnt; i++) {
+            if (localName.equals(getAttributeName(i).getLocalPart())) {
+                return getAttributeValue(i);
+            }
+        }
+        return null;
+    }
+
+    public String getDefaultNamespaceURI() {
+        if (defNsUri == null) {
+            defNsUri = getNamespaceURI("");
+            if (defNsUri == null) {
+                defNsUri = "";
+            }
+        }
+        return defNsUri;
+    }
+
+    @Override
+    public String getAttributeValue(String namespaceURI, String localName) {
+        if (namespaceURI == null) {
+            namespaceURI = "";
+        }
+        String val = super.getAttributeValue(namespaceURI, localName);
+        if (val == null
+                && (namespaceURI.length() == 0 || namespaceURI.equals(getDefaultNamespaceURI()))) {
+            val = getAttributeValue("", localName);
+        }
+        return val;
+    }
+
+    public String getAttributeValue(QName name) {
+        return getAttributeValue(name.getNamespaceURI(), name.getLocalPart());
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/StaxReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/common/xml/StaxReader.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message