chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1061233 [7/15] - in /incubator/chemistry/dotcmis: branches/ tags/ trunk/ trunk/DotCMIS/ trunk/DotCMIS/Properties/ trunk/DotCMIS/Service References/ trunk/DotCMIS/Service References/CMISWebServicesReference/ trunk/DotCMIS/binding/ trunk/Dot...
Date Thu, 20 Jan 2011 11:38:50 GMT
Added: incubator/chemistry/dotcmis/trunk/DotCMIS/app.config
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/app.config?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/app.config (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/app.config Thu Jan 20 11:38:48 2011
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <system.serviceModel>
+        <bindings>
+            <basicHttpBinding>
+                <binding name="DiscoveryServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="MultiFilingServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="NavigationServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="ObjectServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="PolicyServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="RelationshipServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="RepositoryServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="VersioningServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+                <binding name="ACLServicePortBinding" closeTimeout="00:01:00"
+                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
+                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
+                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
+                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
+                    useDefaultWebProxy="true">
+                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
+                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
+                    <security mode="None">
+                        <transport clientCredentialType="None" proxyCredentialType="None"
+                            realm="" />
+                        <message clientCredentialType="UserName" algorithmSuite="Default" />
+                    </security>
+                </binding>
+            </basicHttpBinding>
+        </bindings>
+        <client>
+            <endpoint address="http://cmis/services/DiscoveryService.DiscoveryServicePort"
+                binding="basicHttpBinding" bindingConfiguration="DiscoveryServicePortBinding"
+                contract="CMISWebServicesReference.DiscoveryServicePort" name="DiscoveryServicePort" />
+            <endpoint address="http://cmis/services/MultiFilingService.MultiFilingServicePort"
+                binding="basicHttpBinding" bindingConfiguration="MultiFilingServicePortBinding"
+                contract="CMISWebServicesReference.MultiFilingServicePort"
+                name="MultiFilingServicePort" />
+            <endpoint address="http://cmis/services/NavigationService.NavigationServicePort"
+                binding="basicHttpBinding" bindingConfiguration="NavigationServicePortBinding"
+                contract="CMISWebServicesReference.NavigationServicePort"
+                name="NavigationServicePort" />
+            <endpoint address="http://cmis/services/ObjectService.ObjectServicePort"
+                binding="basicHttpBinding" bindingConfiguration="ObjectServicePortBinding"
+                contract="CMISWebServicesReference.ObjectServicePort" name="ObjectServicePort" />
+            <endpoint address="http://cmis/services/PolicyService.PolicyServicePort"
+                binding="basicHttpBinding" bindingConfiguration="PolicyServicePortBinding"
+                contract="CMISWebServicesReference.PolicyServicePort" name="PolicyServicePort" />
+            <endpoint address="http://cmis/services/RelationshipService.RelationshipServicePort"
+                binding="basicHttpBinding" bindingConfiguration="RelationshipServicePortBinding"
+                contract="CMISWebServicesReference.RelationshipServicePort"
+                name="RelationshipServicePort" />
+            <endpoint address="http://cmis/services/RepositoryService.RepositoryServicePort"
+                binding="basicHttpBinding" bindingConfiguration="RepositoryServicePortBinding"
+                contract="CMISWebServicesReference.RepositoryServicePort"
+                name="RepositoryServicePort" />
+            <endpoint address="http://cmis/services/VersioningService.VersioningServicePort"
+                binding="basicHttpBinding" bindingConfiguration="VersioningServicePortBinding"
+                contract="CMISWebServicesReference.VersioningServicePort"
+                name="VersioningServicePort" />
+            <endpoint address="http://cmis/services/ACLService.ACLServicePort"
+                binding="basicHttpBinding" bindingConfiguration="ACLServicePortBinding"
+                contract="CMISWebServicesReference.ACLServicePort" name="ACLServicePort" />
+        </client>
+    </system.serviceModel>
+</configuration>
\ No newline at end of file

Added: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs Thu Jan 20 11:38:48 2011
@@ -0,0 +1,377 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using DotCMIS.Binding.Impl;
+using System.Web;
+
+namespace DotCMIS.Binding.AtomPub
+{
+    internal class LinkCache
+    {
+        private const int CacheSizeRepositories = 10;
+        private const int CacheSizeTypes = 100;
+        private const int CacheSizeLinks = 400;
+
+        private ICache linkCache;
+        private ICache typeLinkCache;
+        private ICache collectionLinkCache;
+        private ICache templateCache;
+        private ICache repositoryLinkCache;
+
+        public LinkCache(BindingSession session)
+        {
+            int repCount = session.GetValue(SessionParameter.CacheSizeRepositories, CacheSizeRepositories);
+            if (repCount < 1)
+            {
+                repCount = CacheSizeRepositories;
+            }
+
+            int typeCount = session.GetValue(SessionParameter.CacheSizeTypes, CacheSizeTypes);
+            if (typeCount < 1)
+            {
+                typeCount = CacheSizeTypes;
+            }
+
+            int objCount = session.GetValue(SessionParameter.CacheSizeLinks, CacheSizeLinks);
+            if (objCount < 1)
+            {
+                objCount = CacheSizeLinks;
+            }
+
+            linkCache = new Cache("Link Cache");
+            linkCache.Initialize(new string[] {
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository
+                typeof(LruCacheLevel).FullName + " " + LruCacheLevel.MaxEntries + "=" + objCount, // id
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=16", // rel
+                typeof(ContentTypeCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=3,"
+                        + DictionaryCacheLevel.SingleValue + "=true" // type
+        });
+
+            typeLinkCache = new Cache("Type Link Cache");
+            typeLinkCache.Initialize(new string[] {
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository
+                typeof(LruCacheLevel).FullName + " " + LruCacheLevel.MaxEntries + "=" + typeCount, // id
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=16", // rel
+                typeof(ContentTypeCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=3,"
+                        + DictionaryCacheLevel.SingleValue + "=true"// type
+        });
+
+            collectionLinkCache = new Cache("Collection Link Cache");
+            collectionLinkCache.Initialize(new string[] {
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=8" // collection
+        });
+
+            templateCache = new Cache("URI Template Cache");
+            templateCache.Initialize(new string[] {
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=6" // type
+        });
+
+            repositoryLinkCache = new Cache("Repository Link Cache");
+            repositoryLinkCache.Initialize(new string[] {
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository
+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=6" // rel
+        });
+        }
+
+        // ---- links ---
+
+        public void AddLink(string repositoryId, string id, string rel, string type, string link)
+        {
+            linkCache.Put(new string[] { repositoryId, id, rel, type }, link);
+        }
+
+        public void RemoveLinks(string repositoryId, string id)
+        {
+            linkCache.Remove(new string[] { repositoryId, id });
+        }
+
+        public string GetLink(string repositoryId, string id, string rel, string type)
+        {
+            return (string)linkCache.Get(new string[] { repositoryId, id, rel, type });
+        }
+
+        public string GetLink(string repositoryId, string id, string rel)
+        {
+            return GetLink(repositoryId, id, rel, null);
+        }
+
+        public int CheckLink(string repositoryId, string id, string rel, string type)
+        {
+            return linkCache.Check(new string[] { repositoryId, id, rel, type });
+        }
+
+        public void LockLinks()
+        {
+            linkCache.Lock();
+        }
+
+        public void UnlockLinks()
+        {
+            linkCache.Unlock();
+        }
+
+        // ---- type links ---
+
+        public void AddTypeLink(string repositoryId, string id, string rel, string type, string link)
+        {
+            typeLinkCache.Put(new string[] { repositoryId, id, rel, type }, link);
+        }
+
+        public void RemoveTypeLinks(string repositoryId, string id)
+        {
+            typeLinkCache.Remove(new string[] { repositoryId, id });
+        }
+
+        public string GetTypeLink(string repositoryId, string id, string rel, string type)
+        {
+            return (string)typeLinkCache.Get(new string[] { repositoryId, id, rel, type });
+        }
+
+        public void LockTypeLinks()
+        {
+            typeLinkCache.Lock();
+        }
+
+        public void UnlockTypeLinks()
+        {
+            typeLinkCache.Unlock();
+        }
+
+        // ---- collections ----
+
+        public void AddCollection(string repositoryId, string collection, string link)
+        {
+            collectionLinkCache.Put(new string[] { repositoryId, collection }, link);
+        }
+
+        public string GetCollection(string repositoryId, string collection)
+        {
+            return (string)collectionLinkCache.Get(new string[] { repositoryId, collection });
+        }
+
+        // ---- templates ----
+
+        public void AddTemplate(string repositoryId, string type, string link)
+        {
+            templateCache.Put(new string[] { repositoryId, type }, link);
+        }
+
+        public string GetTemplateLink(string repositoryId, string type, IDictionary<string, object> parameters)
+        {
+            string template = (string)templateCache.Get(new string[] { repositoryId, type });
+            if (template == null)
+            {
+                return null;
+            }
+
+            StringBuilder result = new StringBuilder();
+            StringBuilder param = new StringBuilder();
+
+            bool paramMode = false;
+            for (int i = 0; i < template.Length; i++)
+            {
+                char c = template[i];
+
+                if (paramMode)
+                {
+                    if (c == '}')
+                    {
+                        paramMode = false;
+
+                        object paramValue;
+                        if (parameters.TryGetValue(param.ToString(), out paramValue))
+                        {
+                            result.Append(HttpUtility.UrlEncode(UrlBuilder.NormalizeParameter(paramValue)));
+                        }
+
+                        param = new StringBuilder();
+                    }
+                    else
+                    {
+                        param.Append(c);
+                    }
+                }
+                else
+                {
+                    if (c == '{')
+                    {
+                        paramMode = true;
+                    }
+                    else
+                    {
+                        result.Append(c);
+                    }
+                }
+            }
+
+            return result.ToString();
+        }
+
+        // ---- repository links ----
+
+        public void AddRepositoryLink(string repositoryId, string rel, string link)
+        {
+            repositoryLinkCache.Put(new string[] { repositoryId, rel }, link);
+        }
+
+        public string GetRepositoryLink(string repositoryId, string rel)
+        {
+            return (string)repositoryLinkCache.Get(new string[] { repositoryId, rel });
+        }
+
+        // ---- clear ----
+
+        public void ClearRepository(string repositoryId)
+        {
+            linkCache.Remove(new string[] { repositoryId });
+            typeLinkCache.Remove(new string[] { repositoryId });
+            collectionLinkCache.Remove(new string[] { repositoryId });
+            templateCache.Remove(new string[] { repositoryId });
+            repositoryLinkCache.Remove(new string[] { repositoryId });
+        }
+    }
+
+    internal class ContentTypeCacheLevel : DictionaryCacheLevel
+    {
+        public ContentTypeCacheLevel()
+        {
+            EnableKeyFallback(null);
+        }
+
+        public override object this[string key]
+        {
+            get
+            {
+                return base[Normalize(key)];
+            }
+            set
+            {
+                base[Normalize(key)] = value;
+            }
+        }
+
+        public override void Remove(string key)
+        {
+            base.Remove(Normalize(key));
+        }
+
+        private string Normalize(string key)
+        {
+            if (key == null)
+            {
+                return null;
+            }
+
+            StringBuilder sb = new StringBuilder();
+            int parameterStart = 0;
+
+            // first, get the MIME type
+            for (int i = 0; i < key.Length; i++)
+            {
+                char c = key[i];
+
+                if (Char.IsWhiteSpace(c))
+                {
+                    continue;
+                }
+                else if (c == ';')
+                {
+                    parameterStart = i;
+                    break;
+                }
+
+                sb.Append(Char.ToLower(c));
+            }
+
+            // if parameters have been found, gather them
+            if (parameterStart > 0)
+            {
+                SortedList<string, string> parameter = new SortedList<string, string>();
+                StringBuilder ksb = new StringBuilder();
+                StringBuilder vsb = new StringBuilder();
+                bool isKey = true;
+
+                for (int i = parameterStart + 1; i < key.Length; i++)
+                {
+                    char c = key[i];
+                    if (Char.IsWhiteSpace(c))
+                    {
+                        continue;
+                    }
+
+                    if (isKey)
+                    {
+                        if (c == '=')
+                        {
+                            // value start
+                            isKey = false;
+                            continue;
+                        }
+
+                        ksb.Append(Char.ToLower(c));
+                    }
+                    else
+                    {
+                        if (c == ';')
+                        {
+                            // next key
+                            isKey = true;
+
+                            parameter.Add(ksb.ToString(), vsb.ToString());
+
+                            ksb = new StringBuilder();
+                            vsb = new StringBuilder();
+
+                            continue;
+                        }
+                        else if (c == '"')
+                        {
+                            // filter quotes
+                            continue;
+                        }
+
+                        vsb.Append(Char.ToLower(c));
+                    }
+                }
+
+                // add last parameter
+                if (ksb.Length > 0)
+                {
+                    parameter.Add(ksb.ToString(), vsb.ToString());
+                }
+
+                // write parameters sorted by key
+                for (int i = 0; i < parameter.Count; i++)
+                {
+                    sb.Append(";");
+                    sb.Append(parameter.Keys[i]);
+                    sb.Append("=");
+                    sb.Append(parameter.Values[i]);
+                }
+            }
+
+            return sb.ToString();
+        }
+    }
+}

Added: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-parser.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-parser.cs?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-parser.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-parser.cs Thu Jan 20 11:38:48 2011
@@ -0,0 +1,808 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+using DotCMIS.CMISWebServicesReference;
+using DotCMIS.Exceptions;
+using System.Globalization;
+
+namespace DotCMIS.Binding.AtomPub
+{
+    internal class AtomPubParser
+    {
+        private static XmlSerializer RepositoryInfoSerializer;
+        private static XmlSerializer TypeDefintionSerializer;
+        private static XmlSerializer ObjectSerializer;
+        private static XmlSerializer AllowableActionsSerializer;
+        private static XmlSerializer AclSerializer;
+
+        static AtomPubParser()
+        {
+            XmlRootAttribute repositoryInfoXmlRoot = new XmlRootAttribute("repositoryInfo");
+            repositoryInfoXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            RepositoryInfoSerializer = new XmlSerializer(typeof(cmisRepositoryInfoType), repositoryInfoXmlRoot);
+
+            XmlRootAttribute typeDefinitionXmlRoot = new XmlRootAttribute("type");
+            typeDefinitionXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            TypeDefintionSerializer = new XmlSerializer(typeof(cmisTypeDefinitionType), typeDefinitionXmlRoot);
+
+            XmlRootAttribute objectXmlRoot = new XmlRootAttribute("object");
+            objectXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            ObjectSerializer = new XmlSerializer(typeof(cmisObjectType), objectXmlRoot);
+
+            XmlRootAttribute allowableActionsXmlRoot = new XmlRootAttribute("allowableActions");
+            allowableActionsXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            AllowableActionsSerializer = new XmlSerializer(typeof(cmisAllowableActionsType), objectXmlRoot);
+
+            XmlRootAttribute aclXmlRoot = new XmlRootAttribute("accessControlList");
+            aclXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            AclSerializer = new XmlSerializer(typeof(cmisAccessControlListType), objectXmlRoot);
+        }
+
+        private Stream stream;
+        private AtomBase parseResult;
+
+        public AtomPubParser(Stream stream)
+        {
+            if (stream == null)
+            {
+                throw new ArgumentNullException("stream");
+            }
+
+            this.stream = stream;
+        }
+
+        public AtomBase GetParseResults()
+        {
+            return parseResult;
+        }
+
+        public void Parse()
+        {
+            XmlReaderSettings settings = new XmlReaderSettings();
+            settings.IgnoreWhitespace = true;
+            settings.IgnoreComments = true;
+
+            XmlReader reader = XmlReader.Create(stream, settings);
+            try
+            {
+                while (true)
+                {
+                    if (reader.IsStartElement())
+                    {
+                        if (AtomPubConstants.NamespaceAtom == reader.NamespaceURI)
+                        {
+                            if (AtomPubConstants.TagFeed == reader.LocalName)
+                            {
+                                parseResult = ParseFeed(reader);
+                                break;
+                            }
+                            else if (AtomPubConstants.TagEntry == reader.LocalName)
+                            {
+                                parseResult = ParseEntry(reader);
+                                break;
+                            }
+                        }
+                        else if (AtomPubConstants.NamespaceCMIS == reader.NamespaceURI)
+                        {
+                            if (AtomPubConstants.TagAllowableActions == reader.LocalName)
+                            {
+                                parseResult = ParseAllowableActions(reader);
+                                break;
+                            }
+                            else if (AtomPubConstants.TagACL == reader.LocalName)
+                            {
+                                parseResult = ParseACL(reader);
+                                break;
+                            }
+                        }
+                        else if (AtomPubConstants.NamespaceAPP == reader.NamespaceURI)
+                        {
+                            if (AtomPubConstants.TagService == reader.LocalName)
+                            {
+                                parseResult = ParseServiceDoc(reader);
+                                break;
+                            }
+                        }
+                    }
+
+                    if (!reader.Read()) { break; }
+                }
+            }
+            finally
+            {
+                try { reader.Close(); }
+                catch (Exception) { }
+                try { stream.Close(); }
+                catch (Exception) { }
+            }
+        }
+
+        private ServiceDoc ParseServiceDoc(XmlReader reader)
+        {
+            ServiceDoc result = new ServiceDoc();
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    if (AtomPubConstants.NamespaceAPP == reader.NamespaceURI)
+                    {
+                        if (AtomPubConstants.TagWorkspace == reader.LocalName)
+                        {
+                            result.AddWorkspace(ParseWorkspace(reader));
+                        }
+                        else
+                        {
+                            skip(reader);
+                        }
+                    }
+                    else
+                    {
+                        skip(reader);
+                    }
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            return result;
+        }
+
+        private RepositoryWorkspace ParseWorkspace(XmlReader reader)
+        {
+            RepositoryWorkspace workspace = new RepositoryWorkspace();
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    AtomElement element = ParseWorkspaceElement(reader);
+
+                    if (element != null && element.Object is cmisRepositoryInfoType)
+                    {
+                        workspace.Id = ((cmisRepositoryInfoType)element.Object).repositoryId;
+                    }
+
+                    workspace.AddElement(element);
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            reader.Read();
+
+            return workspace;
+        }
+
+        private AtomElement ParseWorkspaceElement(XmlReader reader)
+        {
+            if (AtomPubConstants.NamespaceRestAtom == reader.NamespaceURI)
+            {
+                if (AtomPubConstants.TagRepositoryInfo == reader.LocalName)
+                {
+                    return DeserializeRepositoryInfo(reader);
+                }
+                else if (AtomPubConstants.TagUriTemplate == reader.LocalName)
+                {
+                    return ParseTemplate(reader);
+                }
+            }
+            else if (AtomPubConstants.NamespaceAtom == reader.NamespaceURI)
+            {
+                if (AtomPubConstants.TagLink == reader.LocalName)
+                {
+                    return ParseLink(reader);
+                }
+            }
+            else if (AtomPubConstants.NamespaceAPP == reader.NamespaceURI)
+            {
+                if (AtomPubConstants.TagCollection == reader.LocalName)
+                {
+                    return ParseCollection(reader);
+                }
+            }
+
+            skip(reader);
+
+            return null;
+        }
+
+        private AtomElement ParseTemplate(XmlReader reader)
+        {
+            Dictionary<string, string> result = new Dictionary<string, string>();
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    if (AtomPubConstants.NamespaceRestAtom == reader.NamespaceURI)
+                    {
+                        if (AtomPubConstants.TagTemplateTemplate == reader.LocalName)
+                        {
+                            result["template"] = ReadText(reader);
+                        }
+                        else if (AtomPubConstants.TagTemplateType == reader.LocalName)
+                        {
+                            result["type"] = ReadText(reader);
+                        }
+                        else
+                        {
+                            skip(reader);
+                        }
+                    }
+                    else
+                    {
+                        skip(reader);
+                    }
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            reader.Read();
+
+            return new AtomElement(ns, ln, result);
+        }
+
+        private AtomElement ParseCollection(XmlReader reader)
+        {
+            Dictionary<string, string> result = new Dictionary<string, string>();
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+
+            if (reader.MoveToAttribute("href"))
+            {
+                result["href"] = reader.Value;
+                reader.MoveToElement();
+            }
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    if (AtomPubConstants.NamespaceRestAtom == reader.NamespaceURI && AtomPubConstants.TagCollectionType == reader.LocalName)
+                    {
+                        result["collectionType"] = ReadText(reader);
+                    }
+                    else
+                    {
+                        skip(reader);
+                    }
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            reader.Read();
+
+            return new AtomElement(ns, ln, result);
+        }
+
+        private AtomElement ParseLink(XmlReader reader)
+        {
+            AtomLink result = new AtomLink();
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+
+            if (reader.HasAttributes)
+            {
+                while (reader.MoveToNextAttribute())
+                {
+                    if (AtomPubConstants.LinkRel == reader.Name)
+                    {
+                        result.Rel = reader.Value;
+                    }
+                    else if (AtomPubConstants.LinkHref == reader.Name)
+                    {
+                        result.Href = reader.Value;
+                    }
+                    else if (AtomPubConstants.LinkType == reader.Name)
+                    {
+                        result.Type = reader.Value;
+                    }
+                }
+                reader.MoveToElement();
+            }
+
+            skip(reader);
+
+            return new AtomElement(ns, ln, result);
+        }
+
+        private AtomFeed ParseFeed(XmlReader reader)
+        {
+            AtomFeed feed = new AtomFeed();
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    if (AtomPubConstants.NamespaceAtom == reader.NamespaceURI)
+                    {
+                        if (AtomPubConstants.TagLink == reader.LocalName)
+                        {
+                            feed.AddElement(ParseLink(reader));
+                        }
+                        else if (AtomPubConstants.TagEntry == reader.LocalName)
+                        {
+                            feed.AddEntry(ParseEntry(reader));
+                        }
+                        else
+                        {
+                            skip(reader);
+                        }
+                    }
+                    else if (AtomPubConstants.NamespaceRestAtom == reader.NamespaceURI)
+                    {
+                        if (AtomPubConstants.TagNumItems == reader.LocalName)
+                        {
+                            feed.AddElement(ParseLong(reader));
+                        }
+                        else
+                        {
+                            skip(reader);
+                        }
+                    }
+                    else
+                    {
+                        skip(reader);
+                    }
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            reader.Read();
+
+            return feed;
+        }
+
+        private AtomEntry ParseEntry(XmlReader reader)
+        {
+            AtomEntry entry = new AtomEntry();
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    AtomElement element = ParseElement(reader);
+
+                    if (element != null)
+                    {
+                        entry.AddElement(element);
+
+                        if (element.Object is cmisObjectType && ((cmisObjectType)element.Object).properties != null)
+                        {
+                            foreach (cmisProperty prop in ((cmisObjectType)element.Object).properties.Items)
+                            {
+                                if (PropertyIds.ObjectId == prop.propertyDefinitionId)
+                                {
+                                    entry.Id = ((cmisPropertyId)prop).value[0];
+                                }
+                            }
+                        }
+                        else if (element.Object is cmisTypeDefinitionType)
+                        {
+                            entry.Id = ((cmisTypeDefinitionType)element.Object).id;
+                        }
+                    }
+
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            reader.Read();
+
+            return entry;
+        }
+
+        private AtomAcl ParseACL(XmlReader reader)
+        {
+            AtomAcl result = new AtomAcl();
+            result.ACL = DeserializeACL(reader);
+            return result;
+        }
+
+        private AtomAllowableActions ParseAllowableActions(XmlReader reader)
+        {
+            AtomAllowableActions result = new AtomAllowableActions();
+            result.AllowableActions = DeserializeAllowableActions(reader);
+            return result;
+        }
+
+        private AtomElement ParseElement(XmlReader reader)
+        {
+            if (AtomPubConstants.NamespaceRestAtom == reader.NamespaceURI)
+            {
+                if (AtomPubConstants.TagObject == reader.LocalName)
+                {
+                    return DeserializeObject(reader);
+                }
+                else if (AtomPubConstants.TagPathSegment == reader.LocalName
+                      || AtomPubConstants.TagRelativePathSegment == reader.LocalName)
+                {
+                    return ParseText(reader);
+                }
+                else if (AtomPubConstants.TagType == reader.LocalName)
+                {
+                    return DeserializeTypeDefinition(reader);
+                }
+                else if (AtomPubConstants.TagChildren == reader.LocalName)
+                {
+                    return ParseChildren(reader);
+                }
+            }
+            else if (AtomPubConstants.NamespaceAtom == reader.NamespaceURI)
+            {
+                if (AtomPubConstants.TagLink == reader.LocalName)
+                {
+                    return ParseLink(reader);
+                }
+                else if (AtomPubConstants.TagContent == reader.LocalName)
+                {
+                    return ParseAtomContentSrc(reader);
+                }
+            }
+
+            skip(reader);
+
+            return null;
+        }
+
+        private AtomElement ParseChildren(XmlReader reader)
+        {
+            AtomElement result = null;
+            string childName = reader.LocalName;
+            string childNamespace = reader.NamespaceURI;
+
+            reader.Read();
+            while (true)
+            {
+                if (reader.NodeType == XmlNodeType.Element)
+                {
+                    if (AtomPubConstants.NamespaceAtom == reader.NamespaceURI && AtomPubConstants.TagFeed == reader.LocalName)
+                    {
+                        result = new AtomElement(childNamespace, childName, ParseFeed(reader));
+                    }
+                    else
+                    {
+                        skip(reader);
+                    }
+                }
+                else if (reader.NodeType == XmlNodeType.EndElement)
+                {
+                    break;
+                }
+                else
+                {
+                    if (!reader.Read()) { break; }
+                }
+            }
+
+            reader.Read();
+
+            return result;
+        }
+
+        private AtomElement ParseAtomContentSrc(XmlReader reader)
+        {
+            AtomLink result = new AtomLink();
+            result.Rel = AtomPubConstants.LinkRelContent;
+
+            if (reader.MoveToAttribute(AtomPubConstants.ContentSrc))
+            {
+                result.Href = reader.Value;
+                reader.MoveToElement();
+            }
+
+            skip(reader);
+
+            return new AtomElement(reader.NamespaceURI, reader.LocalName, result);
+        }
+
+        private AtomElement ParseText(XmlReader reader)
+        {
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+            return new AtomElement(ns, ln, ReadText(reader));
+        }
+
+        private AtomElement ParseLong(XmlReader reader)
+        {
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+            return new AtomElement(ns, ln, Int64.Parse(ReadText(reader)));
+        }
+
+        private AtomElement DeserializeRepositoryInfo(XmlReader reader)
+        {
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+            return new AtomElement(ns, ln, RepositoryInfoSerializer.Deserialize(reader));
+        }
+
+        private AtomElement DeserializeTypeDefinition(XmlReader reader)
+        {
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+            return new AtomElement(ns, ln, TypeDefintionSerializer.Deserialize(reader));
+        }
+
+        private AtomElement DeserializeObject(XmlReader reader)
+        {
+            string ns = reader.NamespaceURI;
+            string ln = reader.LocalName;
+            return new AtomElement(ns, ln, ObjectSerializer.Deserialize(reader));
+        }
+
+        private cmisAccessControlListType DeserializeACL(XmlReader reader)
+        {
+            return (cmisAccessControlListType)AclSerializer.Deserialize(reader);
+        }
+
+
+        private cmisAllowableActionsType DeserializeAllowableActions(XmlReader reader)
+        {
+            return (cmisAllowableActionsType)AllowableActionsSerializer.Deserialize(reader);
+        }
+
+        private string ReadText(XmlReader reader)
+        {
+            string text = null;
+            if (reader.Read())
+            {
+                text = reader.ReadContentAsString();
+                reader.Read();
+            }
+
+            return text;
+        }
+
+        private void skip(XmlReader reader)
+        {
+            if (!reader.IsEmptyElement)
+            {
+                int level = 1;
+                while (reader.Read())
+                {
+                    if (reader.NodeType == XmlNodeType.Element)
+                    {
+                        level++;
+                    }
+                    else if (reader.NodeType == XmlNodeType.EndElement)
+                    {
+                        level--;
+                        if (level == 0)
+                        {
+                            break;
+                        }
+                    }
+                }
+            }
+
+            reader.Read();
+        }
+    }
+
+    internal class AtomElement
+    {
+        public string Namespace { get; private set; }
+        public string LocalName { get; private set; }
+        public object Object { get; private set; }
+
+        public AtomElement(string elementNamespace, string elementLocalName, object elementObject)
+        {
+            Namespace = elementNamespace;
+            LocalName = elementLocalName;
+            Object = elementObject;
+        }
+
+        public override string ToString()
+        {
+            return "{" + Namespace + "}" + LocalName + ": " + Object;
+        }
+    }
+
+    internal abstract class AtomBase
+    {
+        public IList<AtomElement> elements = new List<AtomElement>();
+
+        public abstract string GetAtomType();
+
+        public IList<AtomElement> GetElements()
+        {
+            return elements;
+        }
+
+        public void AddElement(AtomElement element)
+        {
+            if (element != null)
+            {
+                elements.Add(element);
+            }
+        }
+    }
+
+    internal class ServiceDoc : AtomBase
+    {
+        private IList<RepositoryWorkspace> workspaces = new List<RepositoryWorkspace>();
+
+        public override string GetAtomType()
+        {
+            return "Service Document";
+        }
+
+        public IList<RepositoryWorkspace> GetWorkspaces()
+        {
+            return workspaces;
+        }
+
+        public void AddWorkspace(RepositoryWorkspace ws)
+        {
+            if (ws != null)
+            {
+                workspaces.Add(ws);
+            }
+        }
+
+        public override string ToString()
+        {
+            return "Service Doc: " + workspaces;
+        }
+    }
+
+    internal class RepositoryWorkspace : AtomBase
+    {
+        public string Id { get; set; }
+
+        public override string GetAtomType()
+        {
+            return "Repository Workspace";
+        }
+
+        public override string ToString()
+        {
+            return "Workspace \"" + Id + "\": " + GetElements();
+        }
+    }
+
+    internal class AtomEntry : AtomBase
+    {
+        public string Id { get; set; }
+
+        public override string GetAtomType()
+        {
+            return "Atom Entry";
+        }
+
+        public override string ToString()
+        {
+            return "Entry \"" + Id + "\": " + GetElements();
+        }
+    }
+
+    internal class AtomFeed : AtomBase
+    {
+        private IList<AtomEntry> entries = new List<AtomEntry>();
+
+        public override string GetAtomType()
+        {
+            return "Atom Feed";
+        }
+
+        public IList<AtomEntry> GetEntries()
+        {
+            return entries;
+        }
+
+        public void AddEntry(AtomEntry entry)
+        {
+            if (entry != null)
+            {
+                entries.Add(entry);
+            }
+        }
+
+        public override string ToString()
+        {
+            return "Feed : " + GetElements() + " " + entries;
+        }
+    }
+
+    internal class AtomAcl : AtomBase
+    {
+        public cmisAccessControlListType ACL { get; set; }
+
+        public override string GetAtomType()
+        {
+            return "ACL";
+        }
+    }
+
+    internal class AtomAllowableActions : AtomBase
+    {
+        public cmisAllowableActionsType AllowableActions { get; set; }
+
+        public override string GetAtomType()
+        {
+            return "Allowable Actions";
+        }
+    }
+
+    internal class AtomLink
+    {
+        public string Rel { get; set; }
+        public string Type { get; set; }
+        public string Href { get; set; }
+
+        public override string ToString()
+        {
+            return "Link: rel=\"" + Rel + "\" type=\"" + Type + "\" href=\"" + Href + "\"";
+        }
+    }
+}

Added: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs Thu Jan 20 11:38:48 2011
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using DotCMIS.CMISWebServicesReference;
+using System.IO;
+using DotCMIS.Exceptions;
+using System.Xml;
+using System.Globalization;
+using System.Xml.Serialization;
+using DotCMIS.Enums;
+
+namespace DotCMIS.Binding.AtomPub
+{
+    internal class AtomWriter
+    {
+        public static XmlSerializer ObjectSerializer;
+        public static XmlSerializer AclSerializer;
+
+        static AtomWriter()
+        {
+            XmlRootAttribute objectXmlRoot = new XmlRootAttribute("object");
+            objectXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            ObjectSerializer = new XmlSerializer(typeof(cmisObjectType), objectXmlRoot);
+
+            XmlRootAttribute aclXmlRoot = new XmlRootAttribute("acl");
+            aclXmlRoot.Namespace = AtomPubConstants.NamespaceRestAtom;
+            AclSerializer = new XmlSerializer(typeof(cmisAccessControlListType), objectXmlRoot);
+        }
+
+        public const string PrefixAtom = "atom";
+        public const string PrefixCMIS = "cmis";
+        public const string PrefixRestAtom = "cmisra";
+    }
+
+    internal class AtomEntryWriter
+    {
+        private const int BufferSize = 64 * 1024;
+
+        private cmisObjectType cmisObject;
+        private Stream stream;
+        private string mediaType;
+
+        public AtomEntryWriter(cmisObjectType cmisObject)
+            : this(cmisObject, null, null)
+        {
+        }
+
+        public AtomEntryWriter(cmisObjectType cmisObject, string mediaType, Stream stream)
+        {
+            if (cmisObject == null || cmisObject.properties == null)
+            {
+                throw new CmisInvalidArgumentException("Object and properties must not be null!");
+            }
+
+            if (stream != null && mediaType == null)
+            {
+                throw new CmisInvalidArgumentException("Media type must be set if a stream is present!");
+            }
+
+            this.cmisObject = cmisObject;
+            this.mediaType = mediaType;
+            this.stream = stream;
+        }
+
+        public void Write(Stream outStream)
+        {
+            using (XmlWriter writer = XmlWriter.Create(outStream))
+            {
+                // start doc
+                writer.WriteStartDocument();
+
+                // start entry
+                writer.WriteStartElement(AtomWriter.PrefixAtom, AtomPubConstants.TagEntry, AtomPubConstants.NamespaceAtom);
+                writer.WriteAttributeString("xmlns", AtomWriter.PrefixAtom, null, AtomPubConstants.NamespaceAtom);
+                writer.WriteAttributeString("xmlns", AtomWriter.PrefixCMIS, null, AtomPubConstants.NamespaceCMIS);
+                writer.WriteAttributeString("xmlns", AtomWriter.PrefixRestAtom, null, AtomPubConstants.NamespaceRestAtom);
+
+                // atom:id
+                writer.WriteStartElement(AtomWriter.PrefixAtom, AtomPubConstants.TagAtomId, AtomPubConstants.NamespaceAtom);
+                writer.WriteString("urn:uuid:00000000-0000-0000-0000-00000000000");
+                writer.WriteEndElement();
+
+                // atom:title
+                writer.WriteStartElement(AtomWriter.PrefixAtom, AtomPubConstants.TagAtomTitle, AtomPubConstants.NamespaceAtom);
+                writer.WriteString(GetTitle());
+                writer.WriteEndElement();
+
+                // atom:updated
+                writer.WriteStartElement(AtomWriter.PrefixAtom, AtomPubConstants.TagAtomUpdated, AtomPubConstants.NamespaceAtom);
+                writer.WriteString(GetUpdated());
+                writer.WriteEndElement();
+
+                // content
+                if (stream != null)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixRestAtom, AtomPubConstants.TagContent, AtomPubConstants.NamespaceRestAtom);
+
+                    writer.WriteStartElement(AtomWriter.PrefixRestAtom, AtomPubConstants.TagContentMediatype, AtomPubConstants.NamespaceRestAtom);
+                    writer.WriteString(mediaType);
+                    writer.WriteEndElement();
+
+                    writer.WriteStartElement(AtomWriter.PrefixRestAtom, AtomPubConstants.TagContentBase64, AtomPubConstants.NamespaceRestAtom);
+                    WriteContent(writer);
+                    writer.WriteEndElement();
+
+                    writer.WriteEndElement();
+                }
+
+                // object
+                AtomWriter.ObjectSerializer.Serialize(writer, cmisObject);
+
+                // end entry
+                writer.WriteEndElement();
+
+                // end document
+                writer.WriteEndDocument();
+
+                writer.Flush();
+            }
+        }
+
+        // ---- internal ----
+
+        private string GetTitle()
+        {
+            string result = "";
+
+            foreach (cmisProperty property in cmisObject.properties.Items)
+            {
+                if (PropertyIds.Name == property.propertyDefinitionId && property is cmisPropertyString)
+                {
+                    string[] values = ((cmisPropertyString)property).value;
+                    if (values != null && values.Length > 0)
+                    {
+                        return values[0];
+                    }
+                }
+            }
+
+            return result;
+        }
+
+        private string GetUpdated()
+        {
+            return DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture);
+        }
+
+        private void WriteContent(XmlWriter writer)
+        {
+            byte[] byteArray = null;
+
+            if (stream is MemoryStream)
+            {
+                byteArray = ((MemoryStream)stream).ToArray();
+            }
+            else
+            {
+                MemoryStream memStream = new MemoryStream();
+                byte[] buffer = new byte[BufferSize];
+                int bytes;
+                while ((bytes = stream.Read(buffer, 0, buffer.Length)) > 0)
+                {
+                    memStream.Write(buffer, 0, bytes);
+                }
+                byteArray = memStream.ToArray();
+            }
+
+            writer.WriteBase64(byteArray, 0, byteArray.Length);
+        }
+    }
+
+    internal class AtomQueryWriter
+    {
+        private string statement;
+        private bool? searchAllVersions;
+        private bool? includeAllowableActions;
+        private IncludeRelationships? includeRelationships;
+        private string renditionFilter;
+        private long? maxItems;
+        private long? skipCount;
+
+        public AtomQueryWriter(string statement, bool? searchAllVersions,
+            bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+            long? maxItems, long? skipCount)
+        {
+            this.statement = statement;
+            this.searchAllVersions = searchAllVersions;
+            this.includeAllowableActions = includeAllowableActions;
+            this.includeRelationships = includeRelationships;
+            this.renditionFilter = renditionFilter;
+            this.maxItems = maxItems;
+            this.skipCount = skipCount;
+        }
+
+        public void Write(Stream outStream)
+        {
+            using (XmlWriter writer = XmlWriter.Create(outStream))
+            {
+                // start doc
+                writer.WriteStartDocument();
+
+                // start query
+                writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagQuery, AtomPubConstants.NamespaceCMIS);
+                writer.WriteAttributeString("xmlns", AtomWriter.PrefixAtom, null, AtomPubConstants.NamespaceAtom);
+                writer.WriteAttributeString("xmlns", AtomWriter.PrefixCMIS, null, AtomPubConstants.NamespaceCMIS);
+                writer.WriteAttributeString("xmlns", AtomWriter.PrefixRestAtom, null, AtomPubConstants.NamespaceRestAtom);
+
+                // cmis:statement
+                writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagStatement, AtomPubConstants.NamespaceCMIS);
+                writer.WriteString(statement);
+                writer.WriteEndElement();
+
+                // cmis:searchAllVersions
+                if (searchAllVersions.HasValue)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagSearchAllVersions, AtomPubConstants.NamespaceCMIS);
+                    writer.WriteString(searchAllVersions.Value ? "true" : "false");
+                    writer.WriteEndElement();
+                }
+
+                // cmis:includeAllowableActions
+                if (includeAllowableActions.HasValue)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagIncludeAllowableActions, AtomPubConstants.NamespaceCMIS);
+                    writer.WriteString(includeAllowableActions.Value ? "true" : "false");
+                    writer.WriteEndElement();
+                }
+
+                // cmis:includeRelationships
+                if (includeRelationships.HasValue)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagIncludeRelationships, AtomPubConstants.NamespaceCMIS);
+                    writer.WriteString(includeRelationships.GetCmisValue());
+                    writer.WriteEndElement();
+                }
+
+                // cmis:renditionFilter
+                if (renditionFilter != null)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagRenditionFilter, AtomPubConstants.NamespaceCMIS);
+                    writer.WriteString(renditionFilter);
+                    writer.WriteEndElement();
+                }
+
+                // cmis:maxItems
+                if (maxItems.HasValue)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagMaxItems, AtomPubConstants.NamespaceCMIS);
+                    writer.WriteString(maxItems.ToString());
+                    writer.WriteEndElement();
+                }
+
+                // cmis:skipCount
+                if (skipCount.HasValue)
+                {
+                    writer.WriteStartElement(AtomWriter.PrefixCMIS, AtomPubConstants.TagSkipCount, AtomPubConstants.NamespaceCMIS);
+                    writer.WriteString(skipCount.ToString());
+                    writer.WriteEndElement();
+                }
+
+                // end query
+                writer.WriteEndElement();
+
+                // end document
+                writer.WriteEndDocument();
+
+                writer.Flush();
+            }
+        }
+    }
+}



Mime
View raw message