xref: /AOO41X/main/ucb/source/ucp/webdav/webdavresponseparser.cxx (revision c1c10f689322f7a0aeea444d576726e9e9c4db8f)
18590a0fdSAndre Fischer /**************************************************************
28590a0fdSAndre Fischer  *
38590a0fdSAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
48590a0fdSAndre Fischer  * or more contributor license agreements.  See the NOTICE file
58590a0fdSAndre Fischer  * distributed with this work for additional information
68590a0fdSAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
78590a0fdSAndre Fischer  * to you under the Apache License, Version 2.0 (the
88590a0fdSAndre Fischer  * "License"); you may not use this file except in compliance
98590a0fdSAndre Fischer  * with the License.  You may obtain a copy of the License at
108590a0fdSAndre Fischer  *
118590a0fdSAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
128590a0fdSAndre Fischer  *
138590a0fdSAndre Fischer  * Unless required by applicable law or agreed to in writing,
148590a0fdSAndre Fischer  * software distributed under the License is distributed on an
158590a0fdSAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
168590a0fdSAndre Fischer  * KIND, either express or implied.  See the License for the
178590a0fdSAndre Fischer  * specific language governing permissions and limitations
188590a0fdSAndre Fischer  * under the License.
198590a0fdSAndre Fischer  *
208590a0fdSAndre Fischer  *************************************************************/
218590a0fdSAndre Fischer 
228590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove
238590a0fdSAndre Fischer #include "precompiled_ucb.hxx"
248590a0fdSAndre Fischer 
25*c1c10f68SAriel Constenla-Haile #include "webdavresponseparser.hxx"
268590a0fdSAndre Fischer #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
278590a0fdSAndre Fischer #include <cppuhelper/implbase2.hxx>
288590a0fdSAndre Fischer #include <com/sun/star/xml/sax/XParser.hpp>
298590a0fdSAndre Fischer #include <com/sun/star/xml/sax/InputSource.hpp>
308590a0fdSAndre Fischer #include <comphelper/processfactory.hxx>
318590a0fdSAndre Fischer #include <comphelper/seqstream.hxx>
328590a0fdSAndre Fischer #include <com/sun/star/ucb/LockEntry.hpp>
338590a0fdSAndre Fischer #include <com/sun/star/ucb/LockScope.hpp>
348590a0fdSAndre Fischer #include <com/sun/star/ucb/LockType.hpp>
358590a0fdSAndre Fischer #include <map>
368590a0fdSAndre Fischer #include <hash_map>
378590a0fdSAndre Fischer 
388590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
398590a0fdSAndre Fischer 
408590a0fdSAndre Fischer using namespace com::sun::star;
418590a0fdSAndre Fischer 
428590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
438590a0fdSAndre Fischer // WebDAVNamespace enum and StringToEnum converter
448590a0fdSAndre Fischer 
458590a0fdSAndre Fischer namespace
468590a0fdSAndre Fischer {
478590a0fdSAndre Fischer     enum WebDAVNamespace
488590a0fdSAndre Fischer     {
498590a0fdSAndre Fischer         WebDAVNamespace_unknown = 0,
508590a0fdSAndre Fischer         WebDAVNamespace_DAV,
518590a0fdSAndre Fischer         WebDAVNamespace_ucb_openoffice_org_dav_props,
528590a0fdSAndre Fischer 
538590a0fdSAndre Fischer         WebDAVNamespace_last
548590a0fdSAndre Fischer     };
558590a0fdSAndre Fischer 
568590a0fdSAndre Fischer     WebDAVNamespace StrToWebDAVNamespace(const rtl::OUString& rStr)
578590a0fdSAndre Fischer     {
588590a0fdSAndre Fischer         static ::rtl::OUString aStrDAV(::rtl::OUString::createFromAscii("DAV:"));
598590a0fdSAndre Fischer         static ::rtl::OUString aStrUcbOpenofficeOrgDAVProps(::rtl::OUString::createFromAscii("http://ucb.openoffice.org/dav/props/"));
608590a0fdSAndre Fischer 
618590a0fdSAndre Fischer         if(rStr.equals(aStrDAV))
628590a0fdSAndre Fischer         {
638590a0fdSAndre Fischer             return WebDAVNamespace_DAV;
648590a0fdSAndre Fischer         }
658590a0fdSAndre Fischer         else if(rStr.equals(aStrUcbOpenofficeOrgDAVProps))
668590a0fdSAndre Fischer         {
678590a0fdSAndre Fischer             return WebDAVNamespace_ucb_openoffice_org_dav_props;
688590a0fdSAndre Fischer         }
698590a0fdSAndre Fischer 
708590a0fdSAndre Fischer         return WebDAVNamespace_unknown;
718590a0fdSAndre Fischer     }
728590a0fdSAndre Fischer } // end of anonymous namespace
738590a0fdSAndre Fischer 
748590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
758590a0fdSAndre Fischer // WebDAVName enum and StringToEnum converter using hash_map
768590a0fdSAndre Fischer 
778590a0fdSAndre Fischer namespace
788590a0fdSAndre Fischer {
798590a0fdSAndre Fischer     enum WebDAVName
808590a0fdSAndre Fischer     {
818590a0fdSAndre Fischer         WebDAVName_unknown = 0,
828590a0fdSAndre Fischer         WebDAVName_multistatus,
838590a0fdSAndre Fischer         WebDAVName_response,
848590a0fdSAndre Fischer         WebDAVName_href,
858590a0fdSAndre Fischer         WebDAVName_propstat,
868590a0fdSAndre Fischer         WebDAVName_prop,
878590a0fdSAndre Fischer         WebDAVName_resourcetype,
888590a0fdSAndre Fischer         WebDAVName_collection,
898590a0fdSAndre Fischer         WebDAVName_getcontenttype,
908590a0fdSAndre Fischer         WebDAVName_supportedlock,
918590a0fdSAndre Fischer         WebDAVName_lockentry,
928590a0fdSAndre Fischer         WebDAVName_lockscope,
938590a0fdSAndre Fischer         WebDAVName_exclusive,
948590a0fdSAndre Fischer         WebDAVName_locktype,
958590a0fdSAndre Fischer         WebDAVName_write,
968590a0fdSAndre Fischer         WebDAVName_shared,
978590a0fdSAndre Fischer         WebDAVName_status,
988590a0fdSAndre Fischer         WebDAVName_getlastmodified,
998590a0fdSAndre Fischer         WebDAVName_creationdate,
1008590a0fdSAndre Fischer         WebDAVName_getcontentlength,
1018590a0fdSAndre Fischer 
1028590a0fdSAndre Fischer         WebDAVName_last
1038590a0fdSAndre Fischer     };
1048590a0fdSAndre Fischer 
1058590a0fdSAndre Fischer     WebDAVName StrToWebDAVName(const rtl::OUString& rStr)
1068590a0fdSAndre Fischer     {
1078590a0fdSAndre Fischer         typedef std::hash_map< rtl::OUString, WebDAVName, rtl::OUStringHash > WebDAVNameMapper;
1088590a0fdSAndre Fischer         typedef std::pair< rtl::OUString, WebDAVName > WebDAVNameValueType;
1098590a0fdSAndre Fischer         static WebDAVNameMapper aWebDAVNameMapperList;
1108590a0fdSAndre Fischer 
1118590a0fdSAndre Fischer         if(aWebDAVNameMapperList.empty())
1128590a0fdSAndre Fischer         {
1138590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("multistatus"), WebDAVName_multistatus));
1148590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("response"), WebDAVName_response));
1158590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("href"), WebDAVName_href));
1168590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("propstat"), WebDAVName_propstat));
1178590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("prop"), WebDAVName_prop));
1188590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("resourcetype"), WebDAVName_resourcetype));
1198590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("collection"), WebDAVName_collection));
1208590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("getcontenttype"), WebDAVName_getcontenttype));
1218590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("supportedlock"), WebDAVName_supportedlock));
1228590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("lockentry"), WebDAVName_lockentry));
1238590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("lockscope"), WebDAVName_lockscope));
1248590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("exclusive"), WebDAVName_exclusive));
1258590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("locktype"), WebDAVName_locktype));
1268590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("write"), WebDAVName_write));
1278590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("shared"), WebDAVName_shared));
1288590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("status"), WebDAVName_status));
1298590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("getlastmodified"), WebDAVName_getlastmodified));
1308590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("creationdate"), WebDAVName_creationdate));
1318590a0fdSAndre Fischer             aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("getcontentlength"), WebDAVName_getcontentlength));
1328590a0fdSAndre Fischer         }
1338590a0fdSAndre Fischer 
1348590a0fdSAndre Fischer         const WebDAVNameMapper::const_iterator aResult(aWebDAVNameMapperList.find(rStr));
1358590a0fdSAndre Fischer 
1368590a0fdSAndre Fischer         if(aResult == aWebDAVNameMapperList.end())
1378590a0fdSAndre Fischer         {
1388590a0fdSAndre Fischer             return WebDAVName_unknown;
1398590a0fdSAndre Fischer         }
1408590a0fdSAndre Fischer         else
1418590a0fdSAndre Fischer         {
1428590a0fdSAndre Fischer             return aResult->second;
1438590a0fdSAndre Fischer         }
1448590a0fdSAndre Fischer     }
1458590a0fdSAndre Fischer } // end of anonymous namespace
1468590a0fdSAndre Fischer 
1478590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
1488590a0fdSAndre Fischer // WebDAVContext, holding information for each start/endElement pair
1498590a0fdSAndre Fischer 
1508590a0fdSAndre Fischer namespace
1518590a0fdSAndre Fischer {
1528590a0fdSAndre Fischer     typedef std::map< ::rtl::OUString, ::rtl::OUString > NamespaceMap;
1538590a0fdSAndre Fischer     typedef std::pair< const ::rtl::OUString, ::rtl::OUString > NamespaceValueType;
1548590a0fdSAndre Fischer 
1558590a0fdSAndre Fischer     class WebDAVContext
1568590a0fdSAndre Fischer     {
1578590a0fdSAndre Fischer     private:
1588590a0fdSAndre Fischer         WebDAVContext*              mpParent;
1598590a0fdSAndre Fischer         NamespaceMap                maNamespaceMap;
1608590a0fdSAndre Fischer         ::rtl::OUString             maWhiteSpace;
1618590a0fdSAndre Fischer 
1628590a0fdSAndre Fischer         ::rtl::OUString             maNamespace;
1638590a0fdSAndre Fischer         ::rtl::OUString             maName;
1648590a0fdSAndre Fischer 
1658590a0fdSAndre Fischer         WebDAVNamespace             maWebDAVNamespace;
1668590a0fdSAndre Fischer         WebDAVName                  maWebDAVName;
1678590a0fdSAndre Fischer 
1688590a0fdSAndre Fischer         // local helpers
1698590a0fdSAndre Fischer         void parseForNamespaceTokens(const uno::Reference< xml::sax::XAttributeList >& xAttribs);
1708590a0fdSAndre Fischer         ::rtl::OUString mapNamespaceToken(const ::rtl::OUString& rToken) const;
1718590a0fdSAndre Fischer         void splitName(const ::rtl::OUString& rSource);
1728590a0fdSAndre Fischer 
1738590a0fdSAndre Fischer     public:
1748590a0fdSAndre Fischer         WebDAVContext(WebDAVContext* pParent, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs);
1758590a0fdSAndre Fischer         ~WebDAVContext();
1768590a0fdSAndre Fischer 
1778590a0fdSAndre Fischer         WebDAVContext* getParent() const { return mpParent; }
1788590a0fdSAndre Fischer         ::rtl::OUString& getWhiteSpace() { return maWhiteSpace; }
1798590a0fdSAndre Fischer         void setWhiteSpace(const ::rtl::OUString& rNew) { maWhiteSpace = rNew; }
1808590a0fdSAndre Fischer 
1818590a0fdSAndre Fischer         const ::rtl::OUString& getNamespace() const { return maNamespace; }
1828590a0fdSAndre Fischer         const ::rtl::OUString& getName() const { return maName; }
183a180b29cSHerbert Dürr         WebDAVNamespace getWebDAVNamespace() const { return maWebDAVNamespace; }
184a180b29cSHerbert Dürr         WebDAVName getWebDAVName() const { return maWebDAVName; }
1858590a0fdSAndre Fischer     };
1868590a0fdSAndre Fischer 
1878590a0fdSAndre Fischer     void WebDAVContext::parseForNamespaceTokens(const uno::Reference< xml::sax::XAttributeList >& xAttribs)
1888590a0fdSAndre Fischer     {
1898590a0fdSAndre Fischer         const sal_Int16 nAttributes(xAttribs->getLength());
1908590a0fdSAndre Fischer         static ::rtl::OUString aStrXmlns(::rtl::OUString::createFromAscii("xmlns"));
1918590a0fdSAndre Fischer 
1928590a0fdSAndre Fischer         for(sal_Int16 a(0); a < nAttributes; a++)
1938590a0fdSAndre Fischer         {
1948590a0fdSAndre Fischer             const ::rtl::OUString aName(xAttribs->getNameByIndex(a));
1958590a0fdSAndre Fischer             const sal_Int32 nLen(aName.getLength());
1968590a0fdSAndre Fischer 
1978590a0fdSAndre Fischer             if(nLen)
1988590a0fdSAndre Fischer             {
1998590a0fdSAndre Fischer                 if(aName.match(aStrXmlns, 0))
2008590a0fdSAndre Fischer                 {
2018590a0fdSAndre Fischer                     const sal_Int32 nIndex(aName.indexOf(sal_Unicode(':'), 0));
2028590a0fdSAndre Fischer 
2038590a0fdSAndre Fischer                     if(-1 != nIndex && nIndex + 1 < nLen)
2048590a0fdSAndre Fischer                     {
2058590a0fdSAndre Fischer                         const ::rtl::OUString aToken(aName.copy(nIndex + 1));
2068590a0fdSAndre Fischer 
2078590a0fdSAndre Fischer                         maNamespaceMap.insert(NamespaceValueType(aToken, xAttribs->getValueByIndex(a)));
2088590a0fdSAndre Fischer                     }
2098590a0fdSAndre Fischer                 }
2108590a0fdSAndre Fischer             }
2118590a0fdSAndre Fischer         }
2128590a0fdSAndre Fischer     }
2138590a0fdSAndre Fischer 
2148590a0fdSAndre Fischer     ::rtl::OUString WebDAVContext::mapNamespaceToken(const ::rtl::OUString& rToken) const
2158590a0fdSAndre Fischer     {
2168590a0fdSAndre Fischer         NamespaceMap::const_iterator iter = maNamespaceMap.find(rToken);
2178590a0fdSAndre Fischer 
2188590a0fdSAndre Fischer         if(maNamespaceMap.end() == iter)
2198590a0fdSAndre Fischer         {
2208590a0fdSAndre Fischer             if(getParent())
2218590a0fdSAndre Fischer             {
2228590a0fdSAndre Fischer                 return getParent()->mapNamespaceToken(rToken);
2238590a0fdSAndre Fischer             }
2248590a0fdSAndre Fischer             else
2258590a0fdSAndre Fischer             {
2268590a0fdSAndre Fischer                 return rToken;
2278590a0fdSAndre Fischer             }
2288590a0fdSAndre Fischer         }
2298590a0fdSAndre Fischer         else
2308590a0fdSAndre Fischer         {
2318590a0fdSAndre Fischer             return (*iter).second;
2328590a0fdSAndre Fischer         }
2338590a0fdSAndre Fischer     }
2348590a0fdSAndre Fischer 
2358590a0fdSAndre Fischer     void WebDAVContext::splitName(const ::rtl::OUString& rSource)
2368590a0fdSAndre Fischer     {
2378590a0fdSAndre Fischer         const sal_Int32 nLen(rSource.getLength());
2388590a0fdSAndre Fischer         maNamespace = ::rtl::OUString();
2398590a0fdSAndre Fischer         maName = rSource;
2408590a0fdSAndre Fischer 
2418590a0fdSAndre Fischer         if(nLen)
2428590a0fdSAndre Fischer         {
2438590a0fdSAndre Fischer             const sal_Int32 nIndex(rSource.indexOf(sal_Unicode(':'), 0));
2448590a0fdSAndre Fischer 
2458590a0fdSAndre Fischer             if(-1 != nIndex && nIndex > 0 && nIndex + 1 < nLen)
2468590a0fdSAndre Fischer             {
2478590a0fdSAndre Fischer                 maNamespace = mapNamespaceToken(rSource.copy(0, nIndex));
2488590a0fdSAndre Fischer                 maName = rSource.copy(nIndex + 1);
2498590a0fdSAndre Fischer             }
2508590a0fdSAndre Fischer         }
2518590a0fdSAndre Fischer     }
2528590a0fdSAndre Fischer 
2538590a0fdSAndre Fischer     WebDAVContext::WebDAVContext(WebDAVContext* pParent, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs)
2548590a0fdSAndre Fischer     :   mpParent(pParent),
2558590a0fdSAndre Fischer         maNamespaceMap(),
2568590a0fdSAndre Fischer         maWhiteSpace(),
2578590a0fdSAndre Fischer         maNamespace(),
2588590a0fdSAndre Fischer         maName(),
2598590a0fdSAndre Fischer         maWebDAVNamespace(WebDAVNamespace_unknown),
2608590a0fdSAndre Fischer         maWebDAVName(WebDAVName_unknown)
2618590a0fdSAndre Fischer     {
2628590a0fdSAndre Fischer         const sal_Int16 nAttributes(xAttribs->getLength());
2638590a0fdSAndre Fischer 
2648590a0fdSAndre Fischer         if(nAttributes)
2658590a0fdSAndre Fischer         {
2668590a0fdSAndre Fischer             // parse evtl. namespace entries
2678590a0fdSAndre Fischer             parseForNamespaceTokens(xAttribs);
2688590a0fdSAndre Fischer         }
2698590a0fdSAndre Fischer 
2708590a0fdSAndre Fischer         // split name to namespace and name
2718590a0fdSAndre Fischer         splitName(aName);
2728590a0fdSAndre Fischer 
2738590a0fdSAndre Fischer         // evaluate enums for namespace and name
2748590a0fdSAndre Fischer         maWebDAVNamespace = StrToWebDAVNamespace(maNamespace);
2758590a0fdSAndre Fischer         maWebDAVName = StrToWebDAVName(maName);
2768590a0fdSAndre Fischer     }
2778590a0fdSAndre Fischer 
2788590a0fdSAndre Fischer     WebDAVContext::~WebDAVContext()
2798590a0fdSAndre Fischer     {
2808590a0fdSAndre Fischer     }
2818590a0fdSAndre Fischer } // end of anonymous namespace
2828590a0fdSAndre Fischer 
2838590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
2848590a0fdSAndre Fischer // the Xml parser itself
2858590a0fdSAndre Fischer 
2868590a0fdSAndre Fischer namespace
2878590a0fdSAndre Fischer {
2888590a0fdSAndre Fischer     enum WebDAVResponseParserMode
2898590a0fdSAndre Fischer     {
2908590a0fdSAndre Fischer         WebDAVResponseParserMode_PropFind = 0,
2918590a0fdSAndre Fischer         WebDAVResponseParserMode_PropName
2928590a0fdSAndre Fischer     };
2938590a0fdSAndre Fischer 
2948590a0fdSAndre Fischer     class WebDAVResponseParser : public cppu::WeakImplHelper1< com::sun::star::xml::sax::XDocumentHandler >
2958590a0fdSAndre Fischer     {
2968590a0fdSAndre Fischer     private:
2978590a0fdSAndre Fischer         std::vector< http_dav_ucp::DAVResource >      maResult_PropFind;
2988590a0fdSAndre Fischer         std::vector< http_dav_ucp::DAVResourceInfo >  maResult_PropName;
2998590a0fdSAndre Fischer 
3008590a0fdSAndre Fischer         WebDAVContext*                              mpContext;
3018590a0fdSAndre Fischer         ::rtl::OUString                             maHref;
3028590a0fdSAndre Fischer         ::rtl::OUString                             maStatus;
3038590a0fdSAndre Fischer         std::vector< http_dav_ucp::DAVPropertyValue > maResponseProperties;
3048590a0fdSAndre Fischer         std::vector< http_dav_ucp::DAVPropertyValue > maPropStatProperties;
3058590a0fdSAndre Fischer         std::vector< ::rtl::OUString >              maResponseNames;
3068590a0fdSAndre Fischer         std::vector< ::rtl::OUString >              maPropStatNames;
3078590a0fdSAndre Fischer         uno::Sequence< ucb::LockEntry >             maLockEntries;
3088590a0fdSAndre Fischer         ucb::LockScope                              maLockScope;
3098590a0fdSAndre Fischer         ucb::LockType                               maLockType;
3108590a0fdSAndre Fischer         WebDAVResponseParserMode                    meWebDAVResponseParserMode;
3118590a0fdSAndre Fischer 
3128590a0fdSAndre Fischer         // bitfield
3138590a0fdSAndre Fischer         bool                                        mbResourceTypeCollection : 1;
3148590a0fdSAndre Fischer         bool                                        mbLockScopeSet : 1;
3158590a0fdSAndre Fischer         bool                                        mbLockTypeSet : 1;
3168590a0fdSAndre Fischer 
3178590a0fdSAndre Fischer         // local helpers
3188590a0fdSAndre Fischer         bool whitespaceIsAvailable() const
3198590a0fdSAndre Fischer         {
3208590a0fdSAndre Fischer             return mpContext && mpContext->getWhiteSpace().getLength();
3218590a0fdSAndre Fischer         }
3228590a0fdSAndre Fischer         bool hasParent(WebDAVName aWebDAVName) const
3238590a0fdSAndre Fischer         {
3248590a0fdSAndre Fischer             return mpContext && mpContext->getParent() && aWebDAVName == mpContext->getParent()->getWebDAVName();
3258590a0fdSAndre Fischer         }
3268590a0fdSAndre Fischer         bool propertyIsReady() const
3278590a0fdSAndre Fischer         {
3288590a0fdSAndre Fischer             return hasParent(WebDAVName_prop) && whitespaceIsAvailable();
3298590a0fdSAndre Fischer         }
3308590a0fdSAndre Fischer         bool isCollectingProperties() const
3318590a0fdSAndre Fischer         {
3328590a0fdSAndre Fischer             return WebDAVResponseParserMode_PropFind == meWebDAVResponseParserMode;
3338590a0fdSAndre Fischer         }
3348590a0fdSAndre Fischer         bool isCollectingPropNames() const
3358590a0fdSAndre Fischer         {
3368590a0fdSAndre Fischer             return WebDAVResponseParserMode_PropName == meWebDAVResponseParserMode;
3378590a0fdSAndre Fischer         }
3388590a0fdSAndre Fischer         bool collectThisPropertyAsName() const
3398590a0fdSAndre Fischer         {
3408590a0fdSAndre Fischer             return isCollectingPropNames() && hasParent(WebDAVName_prop);
3418590a0fdSAndre Fischer         }
3428590a0fdSAndre Fischer         void pop_context()
3438590a0fdSAndre Fischer         {
3448590a0fdSAndre Fischer             if(mpContext)
3458590a0fdSAndre Fischer             {
3468590a0fdSAndre Fischer                 WebDAVContext* pTemp = mpContext;
3478590a0fdSAndre Fischer                 mpContext = mpContext->getParent();
3488590a0fdSAndre Fischer                 delete pTemp;
3498590a0fdSAndre Fischer             }
3508590a0fdSAndre Fischer             else
3518590a0fdSAndre Fischer             {
3528590a0fdSAndre Fischer                 OSL_ENSURE(false, "Parser context pop without context (!)");
3538590a0fdSAndre Fischer             }
3548590a0fdSAndre Fischer         }
3558590a0fdSAndre Fischer 
3568590a0fdSAndre Fischer     public:
3578590a0fdSAndre Fischer         WebDAVResponseParser(WebDAVResponseParserMode eWebDAVResponseParserMode);
3588590a0fdSAndre Fischer         ~WebDAVResponseParser();
3598590a0fdSAndre Fischer 
3608590a0fdSAndre Fischer         // Methods XDocumentHandler
3618590a0fdSAndre Fischer         virtual void SAL_CALL startDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException);
3628590a0fdSAndre Fischer         virtual void SAL_CALL endDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException);
3638590a0fdSAndre Fischer         virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw (xml::sax::SAXException, uno::RuntimeException);
3648590a0fdSAndre Fischer         virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (xml::sax::SAXException, uno::RuntimeException);
3658590a0fdSAndre Fischer         virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException);
3668590a0fdSAndre Fischer         virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (xml::sax::SAXException, uno::RuntimeException);
3678590a0fdSAndre Fischer         virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (xml::sax::SAXException, uno::RuntimeException);
3688590a0fdSAndre Fischer         virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException);
3698590a0fdSAndre Fischer 
3708590a0fdSAndre Fischer         const std::vector< http_dav_ucp::DAVResource >& getResult_PropFind() const { return maResult_PropFind; }
3718590a0fdSAndre Fischer         const std::vector< http_dav_ucp::DAVResourceInfo >& getResult_PropName() const { return maResult_PropName; }
3728590a0fdSAndre Fischer     };
3738590a0fdSAndre Fischer 
3748590a0fdSAndre Fischer     WebDAVResponseParser::WebDAVResponseParser(WebDAVResponseParserMode eWebDAVResponseParserMode)
3758590a0fdSAndre Fischer     :   maResult_PropFind(),
3768590a0fdSAndre Fischer         maResult_PropName(),
3778590a0fdSAndre Fischer         mpContext(0),
3788590a0fdSAndre Fischer         maHref(),
3798590a0fdSAndre Fischer         maStatus(),
3808590a0fdSAndre Fischer         maResponseProperties(),
3818590a0fdSAndre Fischer         maPropStatProperties(),
3828590a0fdSAndre Fischer         maResponseNames(),
3838590a0fdSAndre Fischer         maPropStatNames(),
3848590a0fdSAndre Fischer         maLockEntries(),
3858590a0fdSAndre Fischer         maLockScope(ucb::LockScope_EXCLUSIVE),
3868590a0fdSAndre Fischer         maLockType(ucb::LockType_WRITE),
3878590a0fdSAndre Fischer         meWebDAVResponseParserMode(eWebDAVResponseParserMode),
3888590a0fdSAndre Fischer         mbResourceTypeCollection(false),
3898590a0fdSAndre Fischer         mbLockScopeSet(false),
3908590a0fdSAndre Fischer         mbLockTypeSet(false)
3918590a0fdSAndre Fischer     {
3928590a0fdSAndre Fischer     }
3938590a0fdSAndre Fischer 
3948590a0fdSAndre Fischer     WebDAVResponseParser::~WebDAVResponseParser()
3958590a0fdSAndre Fischer     {
3968590a0fdSAndre Fischer         OSL_ENSURE(!mpContext, "Parser destructed with existing content (!)");
3978590a0fdSAndre Fischer         while(mpContext)
3988590a0fdSAndre Fischer         {
3998590a0fdSAndre Fischer             pop_context();
4008590a0fdSAndre Fischer         }
4018590a0fdSAndre Fischer     }
4028590a0fdSAndre Fischer 
4038590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::startDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException)
4048590a0fdSAndre Fischer     {
4058590a0fdSAndre Fischer         OSL_ENSURE(!mpContext, "Parser start with existing content (!)");
4068590a0fdSAndre Fischer     }
4078590a0fdSAndre Fischer 
4088590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::endDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException)
4098590a0fdSAndre Fischer     {
4108590a0fdSAndre Fischer         OSL_ENSURE(!mpContext, "Parser end with existing content (!)");
4118590a0fdSAndre Fischer     }
4128590a0fdSAndre Fischer 
4138590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw (xml::sax::SAXException, uno::RuntimeException)
4148590a0fdSAndre Fischer     {
4158590a0fdSAndre Fischer         const sal_Int32 nLen(aName.getLength());
4168590a0fdSAndre Fischer 
4178590a0fdSAndre Fischer         if(nLen)
4188590a0fdSAndre Fischer         {
4198590a0fdSAndre Fischer             // create new context (push)
4208590a0fdSAndre Fischer             mpContext = new WebDAVContext(mpContext, aName, xAttribs);
4218590a0fdSAndre Fischer 
4228590a0fdSAndre Fischer             if(collectThisPropertyAsName())
4238590a0fdSAndre Fischer             {
4248590a0fdSAndre Fischer                 // When collecting property names and parent is prop there is no need
4258590a0fdSAndre Fischer                 // to handle the content of this property deeper (evtl. preparations)
4268590a0fdSAndre Fischer             }
4278590a0fdSAndre Fischer             else
4288590a0fdSAndre Fischer             {
4298590a0fdSAndre Fischer                 switch(mpContext->getWebDAVNamespace())
4308590a0fdSAndre Fischer                 {
4318590a0fdSAndre Fischer                     default: // WebDAVNamespace_unknown, WebDAVNamespace_last or unhandled
4328590a0fdSAndre Fischer                     {
4338590a0fdSAndre Fischer                         break;
4348590a0fdSAndre Fischer                     }
4358590a0fdSAndre Fischer                     case WebDAVNamespace_DAV:
4368590a0fdSAndre Fischer                     {
4378590a0fdSAndre Fischer                         switch(mpContext->getWebDAVName())
4388590a0fdSAndre Fischer                         {
4398590a0fdSAndre Fischer                             default: // WebDAVName_unknown, WebDAVName_last or unhandled
4408590a0fdSAndre Fischer                             {
4418590a0fdSAndre Fischer                                 break;
4428590a0fdSAndre Fischer                             }
4438590a0fdSAndre Fischer                             case WebDAVName_propstat:
4448590a0fdSAndre Fischer                             {
4458590a0fdSAndre Fischer                                 // propstat start
4468590a0fdSAndre Fischer                                 if(isCollectingProperties())
4478590a0fdSAndre Fischer                                 {
4488590a0fdSAndre Fischer                                     // reset maPropStatProperties
4498590a0fdSAndre Fischer                                     maPropStatProperties.clear();
4508590a0fdSAndre Fischer                                 }
4518590a0fdSAndre Fischer                                 else
4528590a0fdSAndre Fischer                                 {
4538590a0fdSAndre Fischer                                     // when collecting properties reset maPropStatNames
4548590a0fdSAndre Fischer                                     maPropStatNames.clear();
4558590a0fdSAndre Fischer                                 }
4568590a0fdSAndre Fischer                                 break;
4578590a0fdSAndre Fischer                             }
4588590a0fdSAndre Fischer                             case WebDAVName_response:
4598590a0fdSAndre Fischer                             {
4608590a0fdSAndre Fischer                                 // response start, reset Href and status and maResponseProperties
4618590a0fdSAndre Fischer                                 maHref = maStatus = ::rtl::OUString();
4628590a0fdSAndre Fischer 
4638590a0fdSAndre Fischer                                 if(isCollectingProperties())
4648590a0fdSAndre Fischer                                 {
4658590a0fdSAndre Fischer                                     // reset maResponseProperties
4668590a0fdSAndre Fischer                                     maResponseProperties.clear();
4678590a0fdSAndre Fischer                                 }
4688590a0fdSAndre Fischer                                 else
4698590a0fdSAndre Fischer                                 {
4708590a0fdSAndre Fischer                                     // reset maResponseNames when collecting properties
4718590a0fdSAndre Fischer                                     maResponseNames.clear();
4728590a0fdSAndre Fischer                                 }
4738590a0fdSAndre Fischer                                 break;
4748590a0fdSAndre Fischer                             }
4758590a0fdSAndre Fischer                             case WebDAVName_resourcetype:
4768590a0fdSAndre Fischer                             {
4778590a0fdSAndre Fischer                                 // resourcetype start, reset collection
4788590a0fdSAndre Fischer                                 mbResourceTypeCollection = false;
4798590a0fdSAndre Fischer                                 break;
4808590a0fdSAndre Fischer                             }
4818590a0fdSAndre Fischer                             case WebDAVName_supportedlock:
4828590a0fdSAndre Fischer                             {
4838590a0fdSAndre Fischer                                 // supportedlock start, reset maLockEntries
4848590a0fdSAndre Fischer                                 maLockEntries.realloc(0);
4858590a0fdSAndre Fischer                                 break;
4868590a0fdSAndre Fischer                             }
4878590a0fdSAndre Fischer                             case WebDAVName_lockentry:
4888590a0fdSAndre Fischer                             {
4898590a0fdSAndre Fischer                                 // lockentry start, reset maLockEntries
4908590a0fdSAndre Fischer                                 mbLockScopeSet = false;
4918590a0fdSAndre Fischer                                 mbLockTypeSet = false;
4928590a0fdSAndre Fischer                                 break;
4938590a0fdSAndre Fischer                             }
4948590a0fdSAndre Fischer                         }
4958590a0fdSAndre Fischer                         break;
4968590a0fdSAndre Fischer                     }
4978590a0fdSAndre Fischer                     case WebDAVNamespace_ucb_openoffice_org_dav_props:
4988590a0fdSAndre Fischer                     {
4998590a0fdSAndre Fischer                         break;
5008590a0fdSAndre Fischer                     }
5018590a0fdSAndre Fischer                 }
5028590a0fdSAndre Fischer             }
5038590a0fdSAndre Fischer         }
5048590a0fdSAndre Fischer     }
5058590a0fdSAndre Fischer 
5068590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::endElement( const ::rtl::OUString& aName ) throw (xml::sax::SAXException, uno::RuntimeException)
5078590a0fdSAndre Fischer     {
5088590a0fdSAndre Fischer         const sal_Int32 nLen(aName.getLength());
5098590a0fdSAndre Fischer         OSL_ENSURE(mpContext, "Parser EndElement without content (!)");
5108590a0fdSAndre Fischer 
5118590a0fdSAndre Fischer         if(mpContext && nLen)
5128590a0fdSAndre Fischer         {
5138590a0fdSAndre Fischer             if(collectThisPropertyAsName())
5148590a0fdSAndre Fischer             {
5158590a0fdSAndre Fischer                 // When collecting property names and parent is prop, just append the prop name
5168590a0fdSAndre Fischer                 // to the collection, no need to parse deeper
5178590a0fdSAndre Fischer                 maPropStatNames.push_back(mpContext->getNamespace() + mpContext->getName());
5188590a0fdSAndre Fischer             }
5198590a0fdSAndre Fischer             else
5208590a0fdSAndre Fischer             {
5218590a0fdSAndre Fischer                 switch(mpContext->getWebDAVNamespace())
5228590a0fdSAndre Fischer                 {
5238590a0fdSAndre Fischer                     default: // WebDAVNamespace_unknown, WebDAVNamespace_last or unhandled
5248590a0fdSAndre Fischer                     {
5258590a0fdSAndre Fischer                         break;
5268590a0fdSAndre Fischer                     }
5278590a0fdSAndre Fischer                     case WebDAVNamespace_DAV:
5288590a0fdSAndre Fischer                     {
5298590a0fdSAndre Fischer                         switch(mpContext->getWebDAVName())
5308590a0fdSAndre Fischer                         {
5318590a0fdSAndre Fischer                             default: // WebDAVName_unknown, WebDAVName_last or unhandled
5328590a0fdSAndre Fischer                             {
5338590a0fdSAndre Fischer                                 break;
5348590a0fdSAndre Fischer                             }
5358590a0fdSAndre Fischer                             case WebDAVName_href:
5368590a0fdSAndre Fischer                             {
5378590a0fdSAndre Fischer                                 // href end, save it if we have whitespace
5388590a0fdSAndre Fischer                                 if(whitespaceIsAvailable())
5398590a0fdSAndre Fischer                                 {
5408590a0fdSAndre Fischer                                     maHref = mpContext->getWhiteSpace();
5418590a0fdSAndre Fischer                                 }
5428590a0fdSAndre Fischer                                 break;
5438590a0fdSAndre Fischer                             }
5448590a0fdSAndre Fischer                             case WebDAVName_status:
5458590a0fdSAndre Fischer                             {
5468590a0fdSAndre Fischer                                 // status end, save it if we have whitespace
5478590a0fdSAndre Fischer                                 if(whitespaceIsAvailable())
5488590a0fdSAndre Fischer                                 {
5498590a0fdSAndre Fischer                                     maStatus = mpContext->getWhiteSpace();
5508590a0fdSAndre Fischer                                 }
5518590a0fdSAndre Fischer                                 break;
5528590a0fdSAndre Fischer                             }
5538590a0fdSAndre Fischer                             case WebDAVName_getlastmodified:
5548590a0fdSAndre Fischer                             {
5558590a0fdSAndre Fischer                                 // getlastmodified end, safe if content is correct
5568590a0fdSAndre Fischer                                 if(propertyIsReady())
5578590a0fdSAndre Fischer                                 {
5588590a0fdSAndre Fischer                                     static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:getlastmodified"));
5598590a0fdSAndre Fischer                                     http_dav_ucp::DAVPropertyValue aDAVPropertyValue;
5608590a0fdSAndre Fischer 
5618590a0fdSAndre Fischer                                     aDAVPropertyValue.Name = aStr;
5628590a0fdSAndre Fischer                                     aDAVPropertyValue.Value <<= mpContext->getWhiteSpace();
5638590a0fdSAndre Fischer                                     maPropStatProperties.push_back(aDAVPropertyValue);
5648590a0fdSAndre Fischer                                 }
5658590a0fdSAndre Fischer                                 break;
5668590a0fdSAndre Fischer                             }
5678590a0fdSAndre Fischer                             case WebDAVName_creationdate:
5688590a0fdSAndre Fischer                             {
5698590a0fdSAndre Fischer                                 // creationdate end, safe if content is correct
5708590a0fdSAndre Fischer                                 if(propertyIsReady())
5718590a0fdSAndre Fischer                                 {
5728590a0fdSAndre Fischer                                     static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:creationdate"));
5738590a0fdSAndre Fischer                                     http_dav_ucp::DAVPropertyValue aDAVPropertyValue;
5748590a0fdSAndre Fischer 
5758590a0fdSAndre Fischer                                     aDAVPropertyValue.Name = aStr;
5768590a0fdSAndre Fischer                                     aDAVPropertyValue.Value <<= mpContext->getWhiteSpace();
5778590a0fdSAndre Fischer                                     maPropStatProperties.push_back(aDAVPropertyValue);
5788590a0fdSAndre Fischer                                 }
5798590a0fdSAndre Fischer                                 break;
5808590a0fdSAndre Fischer                             }
5818590a0fdSAndre Fischer                             case WebDAVName_collection:
5828590a0fdSAndre Fischer                             {
5838590a0fdSAndre Fischer                                 // collection end, check and set
5848590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_resourcetype))
5858590a0fdSAndre Fischer                                 {
5868590a0fdSAndre Fischer                                     mbResourceTypeCollection = true;
5878590a0fdSAndre Fischer                                 }
5888590a0fdSAndre Fischer                                 break;
5898590a0fdSAndre Fischer                             }
5908590a0fdSAndre Fischer                             case WebDAVName_resourcetype:
5918590a0fdSAndre Fischer                             {
5928590a0fdSAndre Fischer                                 // resourcetype end, check for collection
5938590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_prop))
5948590a0fdSAndre Fischer                                 {
5958590a0fdSAndre Fischer                                     static rtl::OUString aStrA(rtl::OUString::createFromAscii("DAV:resourcetype"));
5968590a0fdSAndre Fischer                                     static rtl::OUString aStrB(rtl::OUString::createFromAscii("collection"));
5978590a0fdSAndre Fischer                                     http_dav_ucp::DAVPropertyValue aDAVPropertyValue;
5988590a0fdSAndre Fischer 
5998590a0fdSAndre Fischer                                     aDAVPropertyValue.Name = aStrA;
6008590a0fdSAndre Fischer                                     aDAVPropertyValue.Value <<= (mbResourceTypeCollection ? aStrB : rtl::OUString());
6018590a0fdSAndre Fischer                                     maPropStatProperties.push_back(aDAVPropertyValue);
6028590a0fdSAndre Fischer                                 }
6038590a0fdSAndre Fischer                                 break;
6048590a0fdSAndre Fischer                             }
6058590a0fdSAndre Fischer                             case WebDAVName_getcontentlength:
6068590a0fdSAndre Fischer                             {
6078590a0fdSAndre Fischer                                 // getcontentlength end, safe if content is correct
6088590a0fdSAndre Fischer                                 if(propertyIsReady())
6098590a0fdSAndre Fischer                                 {
6108590a0fdSAndre Fischer                                     static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:getcontentlength"));
6118590a0fdSAndre Fischer                                     http_dav_ucp::DAVPropertyValue aDAVPropertyValue;
6128590a0fdSAndre Fischer 
6138590a0fdSAndre Fischer                                     aDAVPropertyValue.Name = aStr;
6148590a0fdSAndre Fischer                                     aDAVPropertyValue.Value <<= mpContext->getWhiteSpace();
6158590a0fdSAndre Fischer                                     maPropStatProperties.push_back(aDAVPropertyValue);
6168590a0fdSAndre Fischer                                 }
6178590a0fdSAndre Fischer                                 break;
6188590a0fdSAndre Fischer                             }
6198590a0fdSAndre Fischer                             case WebDAVName_getcontenttype:
6208590a0fdSAndre Fischer                             {
6218590a0fdSAndre Fischer                                 // getcontenttype end, safe if content is correct
6228590a0fdSAndre Fischer                                 if(propertyIsReady())
6238590a0fdSAndre Fischer                                 {
6248590a0fdSAndre Fischer                                     static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:getcontenttype"));
6258590a0fdSAndre Fischer                                     http_dav_ucp::DAVPropertyValue aDAVPropertyValue;
6268590a0fdSAndre Fischer 
6278590a0fdSAndre Fischer                                     aDAVPropertyValue.Name = aStr;
6288590a0fdSAndre Fischer                                     aDAVPropertyValue.Value <<= mpContext->getWhiteSpace();
6298590a0fdSAndre Fischer                                     maPropStatProperties.push_back(aDAVPropertyValue);
6308590a0fdSAndre Fischer                                 }
6318590a0fdSAndre Fischer                                 break;
6328590a0fdSAndre Fischer                             }
6338590a0fdSAndre Fischer                             case WebDAVName_supportedlock:
6348590a0fdSAndre Fischer                             {
6358590a0fdSAndre Fischer                                 // supportedlock end
6368590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_prop) && maLockEntries.hasElements())
6378590a0fdSAndre Fischer                                 {
6388590a0fdSAndre Fischer                                     static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:supportedlock"));
6398590a0fdSAndre Fischer                                     http_dav_ucp::DAVPropertyValue aDAVPropertyValue;
6408590a0fdSAndre Fischer 
6418590a0fdSAndre Fischer                                     aDAVPropertyValue.Name = aStr;
6428590a0fdSAndre Fischer                                     aDAVPropertyValue.Value <<= maLockEntries;
6438590a0fdSAndre Fischer                                     maPropStatProperties.push_back(aDAVPropertyValue);
6448590a0fdSAndre Fischer                                 }
6458590a0fdSAndre Fischer                                 break;
6468590a0fdSAndre Fischer                             }
6478590a0fdSAndre Fischer                             case WebDAVName_lockentry:
6488590a0fdSAndre Fischer                             {
6498590a0fdSAndre Fischer                                 // lockentry end
6508590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_supportedlock) && (mbLockScopeSet && mbLockTypeSet))
6518590a0fdSAndre Fischer                                 {
6528590a0fdSAndre Fischer                                     const sal_Int32 nLength(maLockEntries.getLength());
6538590a0fdSAndre Fischer                                     ucb::LockEntry aEntry;
6548590a0fdSAndre Fischer 
6558590a0fdSAndre Fischer                                     aEntry.Scope = maLockScope;
6568590a0fdSAndre Fischer                                     aEntry.Type = maLockType;
6578590a0fdSAndre Fischer                                     maLockEntries.realloc(nLength + 1);
6588590a0fdSAndre Fischer                                     maLockEntries[nLength] = aEntry;
6598590a0fdSAndre Fischer                                 }
6608590a0fdSAndre Fischer                                 break;
6618590a0fdSAndre Fischer                             }
6628590a0fdSAndre Fischer                             case WebDAVName_exclusive:
6638590a0fdSAndre Fischer                             {
6648590a0fdSAndre Fischer                                 // exclusive lockscope end
6658590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_lockscope))
6668590a0fdSAndre Fischer                                 {
6678590a0fdSAndre Fischer                                     maLockScope = ucb::LockScope_EXCLUSIVE;
6688590a0fdSAndre Fischer                                     mbLockScopeSet = true;
6698590a0fdSAndre Fischer                                 }
6708590a0fdSAndre Fischer                                 break;
6718590a0fdSAndre Fischer                             }
6728590a0fdSAndre Fischer                             case WebDAVName_shared:
6738590a0fdSAndre Fischer                             {
6748590a0fdSAndre Fischer                                 // shared lockscope end
6758590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_lockscope))
6768590a0fdSAndre Fischer                                 {
6778590a0fdSAndre Fischer                                     maLockScope = ucb::LockScope_SHARED;
6788590a0fdSAndre Fischer                                     mbLockScopeSet = true;
6798590a0fdSAndre Fischer                                 }
6808590a0fdSAndre Fischer                                 break;
6818590a0fdSAndre Fischer                             }
6828590a0fdSAndre Fischer                             case WebDAVName_write:
6838590a0fdSAndre Fischer                             {
6848590a0fdSAndre Fischer                                 // write locktype end
6858590a0fdSAndre Fischer                                 if(hasParent(WebDAVName_locktype))
6868590a0fdSAndre Fischer                                 {
6878590a0fdSAndre Fischer                                     maLockType = ucb::LockType_WRITE;
6888590a0fdSAndre Fischer                                     mbLockTypeSet = true;
6898590a0fdSAndre Fischer                                 }
6908590a0fdSAndre Fischer                                 break;
6918590a0fdSAndre Fischer                             }
6928590a0fdSAndre Fischer                             case WebDAVName_propstat:
6938590a0fdSAndre Fischer                             {
6948590a0fdSAndre Fischer                                 // propstat end, check status
6958590a0fdSAndre Fischer                                 if(maStatus.getLength())
6968590a0fdSAndre Fischer                                 {
6978590a0fdSAndre Fischer                                     static ::rtl::OUString aStrStatusOkay(::rtl::OUString::createFromAscii("HTTP/1.1 200 OK"));
6988590a0fdSAndre Fischer 
6998590a0fdSAndre Fischer                                     if(maStatus.equals(aStrStatusOkay))
7008590a0fdSAndre Fischer                                     {
7018590a0fdSAndre Fischer                                         if(isCollectingProperties())
7028590a0fdSAndre Fischer                                         {
7038590a0fdSAndre Fischer                                             if(maPropStatProperties.size())
7048590a0fdSAndre Fischer                                             {
7058590a0fdSAndre Fischer                                                 // append to maResponseProperties if okay
7068590a0fdSAndre Fischer                                                 maResponseProperties.insert(maResponseProperties.end(), maPropStatProperties.begin(), maPropStatProperties.end());
7078590a0fdSAndre Fischer                                             }
7088590a0fdSAndre Fischer                                         }
7098590a0fdSAndre Fischer                                         else
7108590a0fdSAndre Fischer                                         {
7118590a0fdSAndre Fischer                                             if(maPropStatNames.size())
7128590a0fdSAndre Fischer                                             {
7138590a0fdSAndre Fischer                                                 // when collecting properties append to
7148590a0fdSAndre Fischer                                                 maResponseNames.insert(maResponseNames.end(), maPropStatNames.begin(), maPropStatNames.end());
7158590a0fdSAndre Fischer                                             }
7168590a0fdSAndre Fischer                                         }
7178590a0fdSAndre Fischer                                     }
7188590a0fdSAndre Fischer                                 }
7198590a0fdSAndre Fischer                                 break;
7208590a0fdSAndre Fischer                             }
7218590a0fdSAndre Fischer                             case WebDAVName_response:
7228590a0fdSAndre Fischer                             {
7238590a0fdSAndre Fischer                                 // respose end
7248590a0fdSAndre Fischer                                 if(maHref.getLength())
7258590a0fdSAndre Fischer                                 {
7268590a0fdSAndre Fischer                                     if(isCollectingProperties())
7278590a0fdSAndre Fischer                                     {
7288590a0fdSAndre Fischer                                         // create DAVResource when we have content
7298590a0fdSAndre Fischer                                         if(maResponseProperties.size())
7308590a0fdSAndre Fischer                                         {
7318590a0fdSAndre Fischer                                             http_dav_ucp::DAVResource aDAVResource;
7328590a0fdSAndre Fischer 
7338590a0fdSAndre Fischer                                             aDAVResource.uri = maHref;
7348590a0fdSAndre Fischer                                             aDAVResource.properties = maResponseProperties;
7358590a0fdSAndre Fischer                                             maResult_PropFind.push_back(aDAVResource);
7368590a0fdSAndre Fischer                                         }
7378590a0fdSAndre Fischer                                     }
7388590a0fdSAndre Fischer                                     else
7398590a0fdSAndre Fischer                                     {
7408590a0fdSAndre Fischer                                         // when collecting properties add them to result when there are some
7418590a0fdSAndre Fischer                                         if(maResponseNames.size())
7428590a0fdSAndre Fischer                                         {
7438590a0fdSAndre Fischer                                             http_dav_ucp::DAVResourceInfo aDAVResourceInfo(maHref);
7448590a0fdSAndre Fischer 
7458590a0fdSAndre Fischer                                             aDAVResourceInfo.properties = maResponseNames;
7468590a0fdSAndre Fischer                                             maResult_PropName.push_back(aDAVResourceInfo);
7478590a0fdSAndre Fischer                                         }
7488590a0fdSAndre Fischer                                     }
7498590a0fdSAndre Fischer                                 }
7508590a0fdSAndre Fischer                                 break;
7518590a0fdSAndre Fischer                             }
7528590a0fdSAndre Fischer                         }
7538590a0fdSAndre Fischer                         break;
7548590a0fdSAndre Fischer                     }
7558590a0fdSAndre Fischer                     case WebDAVNamespace_ucb_openoffice_org_dav_props:
7568590a0fdSAndre Fischer                     {
7578590a0fdSAndre Fischer                         break;
7588590a0fdSAndre Fischer                     }
7598590a0fdSAndre Fischer                 }
7608590a0fdSAndre Fischer             }
7618590a0fdSAndre Fischer 
7628590a0fdSAndre Fischer             // destroy last context (pop)
7638590a0fdSAndre Fischer             pop_context();
7648590a0fdSAndre Fischer         }
7658590a0fdSAndre Fischer     }
7668590a0fdSAndre Fischer 
7678590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException)
7688590a0fdSAndre Fischer     {
7698590a0fdSAndre Fischer         // collect whitespace over evtl. several calls in mpContext
7708590a0fdSAndre Fischer         OSL_ENSURE(mpContext, "Parser characters without content (!)");
7718590a0fdSAndre Fischer         const sal_Int32 nLen(aChars.getLength());
7728590a0fdSAndre Fischer 
7738590a0fdSAndre Fischer         if(mpContext && nLen)
7748590a0fdSAndre Fischer         {
7758590a0fdSAndre Fischer             // remove leading/trailing blanks and CRLF
7768590a0fdSAndre Fischer             const ::rtl::OUString aTrimmedChars(aChars.trim());
7778590a0fdSAndre Fischer 
7788590a0fdSAndre Fischer             if(aTrimmedChars.getLength())
7798590a0fdSAndre Fischer             {
7808590a0fdSAndre Fischer                 ::rtl::OUString aNew(mpContext->getWhiteSpace());
7818590a0fdSAndre Fischer 
7828590a0fdSAndre Fischer                 if(aNew.getLength())
7838590a0fdSAndre Fischer                 {
7848590a0fdSAndre Fischer                     // add one char when appending (see html1.1 spec)
7858590a0fdSAndre Fischer                     aNew += ::rtl::OUString(sal_Unicode(' '));
7868590a0fdSAndre Fischer                 }
7878590a0fdSAndre Fischer 
7888590a0fdSAndre Fischer                 aNew += aTrimmedChars;
7898590a0fdSAndre Fischer                 mpContext->setWhiteSpace(aNew);
7908590a0fdSAndre Fischer             }
7918590a0fdSAndre Fischer         }
7928590a0fdSAndre Fischer     }
7938590a0fdSAndre Fischer 
7948590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::ignorableWhitespace( const ::rtl::OUString& /*aWhitespaces*/ ) throw (xml::sax::SAXException, uno::RuntimeException)
7958590a0fdSAndre Fischer     {
7968590a0fdSAndre Fischer     }
7978590a0fdSAndre Fischer 
7988590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::processingInstruction( const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ ) throw (xml::sax::SAXException, uno::RuntimeException)
7998590a0fdSAndre Fischer     {
8008590a0fdSAndre Fischer     }
8018590a0fdSAndre Fischer 
8028590a0fdSAndre Fischer     void SAL_CALL WebDAVResponseParser::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ ) throw (xml::sax::SAXException, uno::RuntimeException)
8038590a0fdSAndre Fischer     {
8048590a0fdSAndre Fischer     }
8058590a0fdSAndre Fischer } // end of anonymous namespace
8068590a0fdSAndre Fischer 
8078590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
8088590a0fdSAndre Fischer // wrapper for various calls to the parser
8098590a0fdSAndre Fischer 
8108590a0fdSAndre Fischer namespace
8118590a0fdSAndre Fischer {
8128590a0fdSAndre Fischer     void parseWebDAVPropNameResponse(
8138590a0fdSAndre Fischer         const uno::Reference< io::XInputStream >& xInputStream,
8148590a0fdSAndre Fischer         std::vector< http_dav_ucp::DAVResource >& rPropFind,
8158590a0fdSAndre Fischer         std::vector< http_dav_ucp::DAVResourceInfo >& rPropName,
8168590a0fdSAndre Fischer         WebDAVResponseParserMode eWebDAVResponseParserMode)
8178590a0fdSAndre Fischer     {
8188590a0fdSAndre Fischer         if(xInputStream.is())
8198590a0fdSAndre Fischer         {
8208590a0fdSAndre Fischer             try
8218590a0fdSAndre Fischer             {
8228590a0fdSAndre Fischer                 // prepare ParserInputSrouce
8238590a0fdSAndre Fischer                 xml::sax::InputSource myInputSource;
8248590a0fdSAndre Fischer                 myInputSource.aInputStream = xInputStream;
8258590a0fdSAndre Fischer 
8268590a0fdSAndre Fischer                 // get parser
8278590a0fdSAndre Fischer                 uno::Reference< xml::sax::XParser > xParser(
8288590a0fdSAndre Fischer                     comphelper::getProcessServiceFactory()->createInstance(
8298590a0fdSAndre Fischer                         rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
8308590a0fdSAndre Fischer                     uno::UNO_QUERY_THROW );
8318590a0fdSAndre Fischer 
8328590a0fdSAndre Fischer                 // create parser; connect parser and filter
8338590a0fdSAndre Fischer                 WebDAVResponseParser* pWebDAVResponseParser = new WebDAVResponseParser(eWebDAVResponseParserMode);
8348590a0fdSAndre Fischer                 uno::Reference< xml::sax::XDocumentHandler > xWebDAVHdl(pWebDAVResponseParser);
8358590a0fdSAndre Fischer                 xParser->setDocumentHandler(xWebDAVHdl);
8368590a0fdSAndre Fischer 
8378590a0fdSAndre Fischer                 // finally, parse the stream
8388590a0fdSAndre Fischer                 xParser->parseStream(myInputSource);
8398590a0fdSAndre Fischer 
8408590a0fdSAndre Fischer                 // get result
8418590a0fdSAndre Fischer                 switch(eWebDAVResponseParserMode)
8428590a0fdSAndre Fischer                 {
8438590a0fdSAndre Fischer                     case WebDAVResponseParserMode_PropFind:
8448590a0fdSAndre Fischer                     {
8458590a0fdSAndre Fischer                         rPropFind = pWebDAVResponseParser->getResult_PropFind();
8468590a0fdSAndre Fischer                         break;
8478590a0fdSAndre Fischer                     }
8488590a0fdSAndre Fischer                     case WebDAVResponseParserMode_PropName:
8498590a0fdSAndre Fischer                     {
8508590a0fdSAndre Fischer                         rPropName = pWebDAVResponseParser->getResult_PropName();
8518590a0fdSAndre Fischer                         break;
8528590a0fdSAndre Fischer                     }
8538590a0fdSAndre Fischer                 }
8548590a0fdSAndre Fischer             }
8558590a0fdSAndre Fischer             catch(uno::Exception&)
8568590a0fdSAndre Fischer             {
8578590a0fdSAndre Fischer                 OSL_ENSURE(false, "WebDAV Parse error (!)");
8588590a0fdSAndre Fischer             }
8598590a0fdSAndre Fischer         }
8608590a0fdSAndre Fischer     }
8618590a0fdSAndre Fischer } // end of anonymous namespace
8628590a0fdSAndre Fischer 
8638590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
8648590a0fdSAndre Fischer // helper to parse a XML WebDAV response
8658590a0fdSAndre Fischer 
8668590a0fdSAndre Fischer namespace http_dav_ucp
8678590a0fdSAndre Fischer {
8688590a0fdSAndre Fischer     std::vector< DAVResource > parseWebDAVPropFindResponse(const uno::Reference< io::XInputStream >& xInputStream)
8698590a0fdSAndre Fischer     {
8708590a0fdSAndre Fischer         std::vector< DAVResource > aRetval;
8718590a0fdSAndre Fischer         std::vector< DAVResourceInfo > aFoo;
8728590a0fdSAndre Fischer 
8738590a0fdSAndre Fischer         parseWebDAVPropNameResponse(xInputStream, aRetval, aFoo, WebDAVResponseParserMode_PropFind);
8748590a0fdSAndre Fischer         return aRetval;
8758590a0fdSAndre Fischer     }
8768590a0fdSAndre Fischer 
8778590a0fdSAndre Fischer     std::vector< DAVResourceInfo > parseWebDAVPropNameResponse(const uno::Reference< io::XInputStream >& xInputStream)
8788590a0fdSAndre Fischer     {
8798590a0fdSAndre Fischer         std::vector< DAVResource > aFoo;
8808590a0fdSAndre Fischer         std::vector< DAVResourceInfo > aRetval;
8818590a0fdSAndre Fischer 
8828590a0fdSAndre Fischer         parseWebDAVPropNameResponse(xInputStream, aFoo, aRetval, WebDAVResponseParserMode_PropName);
8838590a0fdSAndre Fischer         return aRetval;
8848590a0fdSAndre Fischer     }
8858590a0fdSAndre Fischer } // namespace http_dav_ucp
8868590a0fdSAndre Fischer 
8878590a0fdSAndre Fischer //////////////////////////////////////////////////////////////////////////////
8888590a0fdSAndre Fischer // eof
889