1*8590a0fdSAndre Fischer /************************************************************** 2*8590a0fdSAndre Fischer * 3*8590a0fdSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*8590a0fdSAndre Fischer * or more contributor license agreements. See the NOTICE file 5*8590a0fdSAndre Fischer * distributed with this work for additional information 6*8590a0fdSAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*8590a0fdSAndre Fischer * to you under the Apache License, Version 2.0 (the 8*8590a0fdSAndre Fischer * "License"); you may not use this file except in compliance 9*8590a0fdSAndre Fischer * with the License. You may obtain a copy of the License at 10*8590a0fdSAndre Fischer * 11*8590a0fdSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*8590a0fdSAndre Fischer * 13*8590a0fdSAndre Fischer * Unless required by applicable law or agreed to in writing, 14*8590a0fdSAndre Fischer * software distributed under the License is distributed on an 15*8590a0fdSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*8590a0fdSAndre Fischer * KIND, either express or implied. See the License for the 17*8590a0fdSAndre Fischer * specific language governing permissions and limitations 18*8590a0fdSAndre Fischer * under the License. 19*8590a0fdSAndre Fischer * 20*8590a0fdSAndre Fischer *************************************************************/ 21*8590a0fdSAndre Fischer 22*8590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove 23*8590a0fdSAndre Fischer #include "precompiled_ucb.hxx" 24*8590a0fdSAndre Fischer 25*8590a0fdSAndre Fischer #include <webdavresponseparser.hxx> 26*8590a0fdSAndre Fischer #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 27*8590a0fdSAndre Fischer #include <cppuhelper/implbase2.hxx> 28*8590a0fdSAndre Fischer #include <com/sun/star/xml/sax/XParser.hpp> 29*8590a0fdSAndre Fischer #include <com/sun/star/xml/sax/InputSource.hpp> 30*8590a0fdSAndre Fischer #include <comphelper/processfactory.hxx> 31*8590a0fdSAndre Fischer #include <comphelper/seqstream.hxx> 32*8590a0fdSAndre Fischer #include <com/sun/star/ucb/LockEntry.hpp> 33*8590a0fdSAndre Fischer #include <com/sun/star/ucb/LockScope.hpp> 34*8590a0fdSAndre Fischer #include <com/sun/star/ucb/LockType.hpp> 35*8590a0fdSAndre Fischer #include <map> 36*8590a0fdSAndre Fischer #include <hash_map> 37*8590a0fdSAndre Fischer 38*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 39*8590a0fdSAndre Fischer 40*8590a0fdSAndre Fischer using namespace com::sun::star; 41*8590a0fdSAndre Fischer 42*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 43*8590a0fdSAndre Fischer // WebDAVNamespace enum and StringToEnum converter 44*8590a0fdSAndre Fischer 45*8590a0fdSAndre Fischer namespace 46*8590a0fdSAndre Fischer { 47*8590a0fdSAndre Fischer enum WebDAVNamespace 48*8590a0fdSAndre Fischer { 49*8590a0fdSAndre Fischer WebDAVNamespace_unknown = 0, 50*8590a0fdSAndre Fischer WebDAVNamespace_DAV, 51*8590a0fdSAndre Fischer WebDAVNamespace_ucb_openoffice_org_dav_props, 52*8590a0fdSAndre Fischer 53*8590a0fdSAndre Fischer WebDAVNamespace_last 54*8590a0fdSAndre Fischer }; 55*8590a0fdSAndre Fischer 56*8590a0fdSAndre Fischer WebDAVNamespace StrToWebDAVNamespace(const rtl::OUString& rStr) 57*8590a0fdSAndre Fischer { 58*8590a0fdSAndre Fischer static ::rtl::OUString aStrDAV(::rtl::OUString::createFromAscii("DAV:")); 59*8590a0fdSAndre Fischer static ::rtl::OUString aStrUcbOpenofficeOrgDAVProps(::rtl::OUString::createFromAscii("http://ucb.openoffice.org/dav/props/")); 60*8590a0fdSAndre Fischer 61*8590a0fdSAndre Fischer if(rStr.equals(aStrDAV)) 62*8590a0fdSAndre Fischer { 63*8590a0fdSAndre Fischer return WebDAVNamespace_DAV; 64*8590a0fdSAndre Fischer } 65*8590a0fdSAndre Fischer else if(rStr.equals(aStrUcbOpenofficeOrgDAVProps)) 66*8590a0fdSAndre Fischer { 67*8590a0fdSAndre Fischer return WebDAVNamespace_ucb_openoffice_org_dav_props; 68*8590a0fdSAndre Fischer } 69*8590a0fdSAndre Fischer 70*8590a0fdSAndre Fischer return WebDAVNamespace_unknown; 71*8590a0fdSAndre Fischer } 72*8590a0fdSAndre Fischer } // end of anonymous namespace 73*8590a0fdSAndre Fischer 74*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 75*8590a0fdSAndre Fischer // WebDAVName enum and StringToEnum converter using hash_map 76*8590a0fdSAndre Fischer 77*8590a0fdSAndre Fischer namespace 78*8590a0fdSAndre Fischer { 79*8590a0fdSAndre Fischer enum WebDAVName 80*8590a0fdSAndre Fischer { 81*8590a0fdSAndre Fischer WebDAVName_unknown = 0, 82*8590a0fdSAndre Fischer WebDAVName_multistatus, 83*8590a0fdSAndre Fischer WebDAVName_response, 84*8590a0fdSAndre Fischer WebDAVName_href, 85*8590a0fdSAndre Fischer WebDAVName_propstat, 86*8590a0fdSAndre Fischer WebDAVName_prop, 87*8590a0fdSAndre Fischer WebDAVName_resourcetype, 88*8590a0fdSAndre Fischer WebDAVName_collection, 89*8590a0fdSAndre Fischer WebDAVName_getcontenttype, 90*8590a0fdSAndre Fischer WebDAVName_supportedlock, 91*8590a0fdSAndre Fischer WebDAVName_lockentry, 92*8590a0fdSAndre Fischer WebDAVName_lockscope, 93*8590a0fdSAndre Fischer WebDAVName_exclusive, 94*8590a0fdSAndre Fischer WebDAVName_locktype, 95*8590a0fdSAndre Fischer WebDAVName_write, 96*8590a0fdSAndre Fischer WebDAVName_shared, 97*8590a0fdSAndre Fischer WebDAVName_status, 98*8590a0fdSAndre Fischer WebDAVName_getlastmodified, 99*8590a0fdSAndre Fischer WebDAVName_creationdate, 100*8590a0fdSAndre Fischer WebDAVName_getcontentlength, 101*8590a0fdSAndre Fischer 102*8590a0fdSAndre Fischer WebDAVName_last 103*8590a0fdSAndre Fischer }; 104*8590a0fdSAndre Fischer 105*8590a0fdSAndre Fischer WebDAVName StrToWebDAVName(const rtl::OUString& rStr) 106*8590a0fdSAndre Fischer { 107*8590a0fdSAndre Fischer typedef std::hash_map< rtl::OUString, WebDAVName, rtl::OUStringHash > WebDAVNameMapper; 108*8590a0fdSAndre Fischer typedef std::pair< rtl::OUString, WebDAVName > WebDAVNameValueType; 109*8590a0fdSAndre Fischer static WebDAVNameMapper aWebDAVNameMapperList; 110*8590a0fdSAndre Fischer 111*8590a0fdSAndre Fischer if(aWebDAVNameMapperList.empty()) 112*8590a0fdSAndre Fischer { 113*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("multistatus"), WebDAVName_multistatus)); 114*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("response"), WebDAVName_response)); 115*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("href"), WebDAVName_href)); 116*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("propstat"), WebDAVName_propstat)); 117*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("prop"), WebDAVName_prop)); 118*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("resourcetype"), WebDAVName_resourcetype)); 119*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("collection"), WebDAVName_collection)); 120*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("getcontenttype"), WebDAVName_getcontenttype)); 121*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("supportedlock"), WebDAVName_supportedlock)); 122*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("lockentry"), WebDAVName_lockentry)); 123*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("lockscope"), WebDAVName_lockscope)); 124*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("exclusive"), WebDAVName_exclusive)); 125*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("locktype"), WebDAVName_locktype)); 126*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("write"), WebDAVName_write)); 127*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("shared"), WebDAVName_shared)); 128*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("status"), WebDAVName_status)); 129*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("getlastmodified"), WebDAVName_getlastmodified)); 130*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("creationdate"), WebDAVName_creationdate)); 131*8590a0fdSAndre Fischer aWebDAVNameMapperList.insert(WebDAVNameValueType(rtl::OUString::createFromAscii("getcontentlength"), WebDAVName_getcontentlength)); 132*8590a0fdSAndre Fischer } 133*8590a0fdSAndre Fischer 134*8590a0fdSAndre Fischer const WebDAVNameMapper::const_iterator aResult(aWebDAVNameMapperList.find(rStr)); 135*8590a0fdSAndre Fischer 136*8590a0fdSAndre Fischer if(aResult == aWebDAVNameMapperList.end()) 137*8590a0fdSAndre Fischer { 138*8590a0fdSAndre Fischer return WebDAVName_unknown; 139*8590a0fdSAndre Fischer } 140*8590a0fdSAndre Fischer else 141*8590a0fdSAndre Fischer { 142*8590a0fdSAndre Fischer return aResult->second; 143*8590a0fdSAndre Fischer } 144*8590a0fdSAndre Fischer } 145*8590a0fdSAndre Fischer } // end of anonymous namespace 146*8590a0fdSAndre Fischer 147*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 148*8590a0fdSAndre Fischer // WebDAVContext, holding information for each start/endElement pair 149*8590a0fdSAndre Fischer 150*8590a0fdSAndre Fischer namespace 151*8590a0fdSAndre Fischer { 152*8590a0fdSAndre Fischer typedef std::map< ::rtl::OUString, ::rtl::OUString > NamespaceMap; 153*8590a0fdSAndre Fischer typedef std::pair< const ::rtl::OUString, ::rtl::OUString > NamespaceValueType; 154*8590a0fdSAndre Fischer 155*8590a0fdSAndre Fischer class WebDAVContext 156*8590a0fdSAndre Fischer { 157*8590a0fdSAndre Fischer private: 158*8590a0fdSAndre Fischer WebDAVContext* mpParent; 159*8590a0fdSAndre Fischer NamespaceMap maNamespaceMap; 160*8590a0fdSAndre Fischer ::rtl::OUString maWhiteSpace; 161*8590a0fdSAndre Fischer 162*8590a0fdSAndre Fischer ::rtl::OUString maNamespace; 163*8590a0fdSAndre Fischer ::rtl::OUString maName; 164*8590a0fdSAndre Fischer 165*8590a0fdSAndre Fischer WebDAVNamespace maWebDAVNamespace; 166*8590a0fdSAndre Fischer WebDAVName maWebDAVName; 167*8590a0fdSAndre Fischer 168*8590a0fdSAndre Fischer // local helpers 169*8590a0fdSAndre Fischer void parseForNamespaceTokens(const uno::Reference< xml::sax::XAttributeList >& xAttribs); 170*8590a0fdSAndre Fischer ::rtl::OUString mapNamespaceToken(const ::rtl::OUString& rToken) const; 171*8590a0fdSAndre Fischer void splitName(const ::rtl::OUString& rSource); 172*8590a0fdSAndre Fischer 173*8590a0fdSAndre Fischer public: 174*8590a0fdSAndre Fischer WebDAVContext(WebDAVContext* pParent, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs); 175*8590a0fdSAndre Fischer ~WebDAVContext(); 176*8590a0fdSAndre Fischer 177*8590a0fdSAndre Fischer WebDAVContext* getParent() const { return mpParent; } 178*8590a0fdSAndre Fischer ::rtl::OUString& getWhiteSpace() { return maWhiteSpace; } 179*8590a0fdSAndre Fischer void setWhiteSpace(const ::rtl::OUString& rNew) { maWhiteSpace = rNew; } 180*8590a0fdSAndre Fischer 181*8590a0fdSAndre Fischer const ::rtl::OUString& getNamespace() const { return maNamespace; } 182*8590a0fdSAndre Fischer const ::rtl::OUString& getName() const { return maName; } 183*8590a0fdSAndre Fischer const WebDAVNamespace getWebDAVNamespace() const { return maWebDAVNamespace; } 184*8590a0fdSAndre Fischer const WebDAVName getWebDAVName() const { return maWebDAVName; } 185*8590a0fdSAndre Fischer }; 186*8590a0fdSAndre Fischer 187*8590a0fdSAndre Fischer void WebDAVContext::parseForNamespaceTokens(const uno::Reference< xml::sax::XAttributeList >& xAttribs) 188*8590a0fdSAndre Fischer { 189*8590a0fdSAndre Fischer const sal_Int16 nAttributes(xAttribs->getLength()); 190*8590a0fdSAndre Fischer static ::rtl::OUString aStrXmlns(::rtl::OUString::createFromAscii("xmlns")); 191*8590a0fdSAndre Fischer 192*8590a0fdSAndre Fischer for(sal_Int16 a(0); a < nAttributes; a++) 193*8590a0fdSAndre Fischer { 194*8590a0fdSAndre Fischer const ::rtl::OUString aName(xAttribs->getNameByIndex(a)); 195*8590a0fdSAndre Fischer const sal_Int32 nLen(aName.getLength()); 196*8590a0fdSAndre Fischer 197*8590a0fdSAndre Fischer if(nLen) 198*8590a0fdSAndre Fischer { 199*8590a0fdSAndre Fischer if(aName.match(aStrXmlns, 0)) 200*8590a0fdSAndre Fischer { 201*8590a0fdSAndre Fischer const sal_Int32 nIndex(aName.indexOf(sal_Unicode(':'), 0)); 202*8590a0fdSAndre Fischer 203*8590a0fdSAndre Fischer if(-1 != nIndex && nIndex + 1 < nLen) 204*8590a0fdSAndre Fischer { 205*8590a0fdSAndre Fischer const ::rtl::OUString aToken(aName.copy(nIndex + 1)); 206*8590a0fdSAndre Fischer 207*8590a0fdSAndre Fischer maNamespaceMap.insert(NamespaceValueType(aToken, xAttribs->getValueByIndex(a))); 208*8590a0fdSAndre Fischer } 209*8590a0fdSAndre Fischer } 210*8590a0fdSAndre Fischer } 211*8590a0fdSAndre Fischer } 212*8590a0fdSAndre Fischer } 213*8590a0fdSAndre Fischer 214*8590a0fdSAndre Fischer ::rtl::OUString WebDAVContext::mapNamespaceToken(const ::rtl::OUString& rToken) const 215*8590a0fdSAndre Fischer { 216*8590a0fdSAndre Fischer NamespaceMap::const_iterator iter = maNamespaceMap.find(rToken); 217*8590a0fdSAndre Fischer 218*8590a0fdSAndre Fischer if(maNamespaceMap.end() == iter) 219*8590a0fdSAndre Fischer { 220*8590a0fdSAndre Fischer if(getParent()) 221*8590a0fdSAndre Fischer { 222*8590a0fdSAndre Fischer return getParent()->mapNamespaceToken(rToken); 223*8590a0fdSAndre Fischer } 224*8590a0fdSAndre Fischer else 225*8590a0fdSAndre Fischer { 226*8590a0fdSAndre Fischer return rToken; 227*8590a0fdSAndre Fischer } 228*8590a0fdSAndre Fischer } 229*8590a0fdSAndre Fischer else 230*8590a0fdSAndre Fischer { 231*8590a0fdSAndre Fischer return (*iter).second; 232*8590a0fdSAndre Fischer } 233*8590a0fdSAndre Fischer } 234*8590a0fdSAndre Fischer 235*8590a0fdSAndre Fischer void WebDAVContext::splitName(const ::rtl::OUString& rSource) 236*8590a0fdSAndre Fischer { 237*8590a0fdSAndre Fischer const sal_Int32 nLen(rSource.getLength()); 238*8590a0fdSAndre Fischer maNamespace = ::rtl::OUString(); 239*8590a0fdSAndre Fischer maName = rSource; 240*8590a0fdSAndre Fischer 241*8590a0fdSAndre Fischer if(nLen) 242*8590a0fdSAndre Fischer { 243*8590a0fdSAndre Fischer const sal_Int32 nIndex(rSource.indexOf(sal_Unicode(':'), 0)); 244*8590a0fdSAndre Fischer 245*8590a0fdSAndre Fischer if(-1 != nIndex && nIndex > 0 && nIndex + 1 < nLen) 246*8590a0fdSAndre Fischer { 247*8590a0fdSAndre Fischer maNamespace = mapNamespaceToken(rSource.copy(0, nIndex)); 248*8590a0fdSAndre Fischer maName = rSource.copy(nIndex + 1); 249*8590a0fdSAndre Fischer } 250*8590a0fdSAndre Fischer } 251*8590a0fdSAndre Fischer } 252*8590a0fdSAndre Fischer 253*8590a0fdSAndre Fischer WebDAVContext::WebDAVContext(WebDAVContext* pParent, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs) 254*8590a0fdSAndre Fischer : mpParent(pParent), 255*8590a0fdSAndre Fischer maNamespaceMap(), 256*8590a0fdSAndre Fischer maWhiteSpace(), 257*8590a0fdSAndre Fischer maNamespace(), 258*8590a0fdSAndre Fischer maName(), 259*8590a0fdSAndre Fischer maWebDAVNamespace(WebDAVNamespace_unknown), 260*8590a0fdSAndre Fischer maWebDAVName(WebDAVName_unknown) 261*8590a0fdSAndre Fischer { 262*8590a0fdSAndre Fischer const sal_Int16 nAttributes(xAttribs->getLength()); 263*8590a0fdSAndre Fischer 264*8590a0fdSAndre Fischer if(nAttributes) 265*8590a0fdSAndre Fischer { 266*8590a0fdSAndre Fischer // parse evtl. namespace entries 267*8590a0fdSAndre Fischer parseForNamespaceTokens(xAttribs); 268*8590a0fdSAndre Fischer } 269*8590a0fdSAndre Fischer 270*8590a0fdSAndre Fischer // split name to namespace and name 271*8590a0fdSAndre Fischer splitName(aName); 272*8590a0fdSAndre Fischer 273*8590a0fdSAndre Fischer // evaluate enums for namespace and name 274*8590a0fdSAndre Fischer maWebDAVNamespace = StrToWebDAVNamespace(maNamespace); 275*8590a0fdSAndre Fischer maWebDAVName = StrToWebDAVName(maName); 276*8590a0fdSAndre Fischer } 277*8590a0fdSAndre Fischer 278*8590a0fdSAndre Fischer WebDAVContext::~WebDAVContext() 279*8590a0fdSAndre Fischer { 280*8590a0fdSAndre Fischer } 281*8590a0fdSAndre Fischer } // end of anonymous namespace 282*8590a0fdSAndre Fischer 283*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 284*8590a0fdSAndre Fischer // the Xml parser itself 285*8590a0fdSAndre Fischer 286*8590a0fdSAndre Fischer namespace 287*8590a0fdSAndre Fischer { 288*8590a0fdSAndre Fischer enum WebDAVResponseParserMode 289*8590a0fdSAndre Fischer { 290*8590a0fdSAndre Fischer WebDAVResponseParserMode_PropFind = 0, 291*8590a0fdSAndre Fischer WebDAVResponseParserMode_PropName 292*8590a0fdSAndre Fischer }; 293*8590a0fdSAndre Fischer 294*8590a0fdSAndre Fischer class WebDAVResponseParser : public cppu::WeakImplHelper1< com::sun::star::xml::sax::XDocumentHandler > 295*8590a0fdSAndre Fischer { 296*8590a0fdSAndre Fischer private: 297*8590a0fdSAndre Fischer std::vector< http_dav_ucp::DAVResource > maResult_PropFind; 298*8590a0fdSAndre Fischer std::vector< http_dav_ucp::DAVResourceInfo > maResult_PropName; 299*8590a0fdSAndre Fischer 300*8590a0fdSAndre Fischer WebDAVContext* mpContext; 301*8590a0fdSAndre Fischer ::rtl::OUString maHref; 302*8590a0fdSAndre Fischer ::rtl::OUString maStatus; 303*8590a0fdSAndre Fischer std::vector< http_dav_ucp::DAVPropertyValue > maResponseProperties; 304*8590a0fdSAndre Fischer std::vector< http_dav_ucp::DAVPropertyValue > maPropStatProperties; 305*8590a0fdSAndre Fischer std::vector< ::rtl::OUString > maResponseNames; 306*8590a0fdSAndre Fischer std::vector< ::rtl::OUString > maPropStatNames; 307*8590a0fdSAndre Fischer uno::Sequence< ucb::LockEntry > maLockEntries; 308*8590a0fdSAndre Fischer ucb::LockScope maLockScope; 309*8590a0fdSAndre Fischer ucb::LockType maLockType; 310*8590a0fdSAndre Fischer WebDAVResponseParserMode meWebDAVResponseParserMode; 311*8590a0fdSAndre Fischer 312*8590a0fdSAndre Fischer // bitfield 313*8590a0fdSAndre Fischer bool mbResourceTypeCollection : 1; 314*8590a0fdSAndre Fischer bool mbLockScopeSet : 1; 315*8590a0fdSAndre Fischer bool mbLockTypeSet : 1; 316*8590a0fdSAndre Fischer 317*8590a0fdSAndre Fischer // local helpers 318*8590a0fdSAndre Fischer bool whitespaceIsAvailable() const 319*8590a0fdSAndre Fischer { 320*8590a0fdSAndre Fischer return mpContext && mpContext->getWhiteSpace().getLength(); 321*8590a0fdSAndre Fischer } 322*8590a0fdSAndre Fischer bool hasParent(WebDAVName aWebDAVName) const 323*8590a0fdSAndre Fischer { 324*8590a0fdSAndre Fischer return mpContext && mpContext->getParent() && aWebDAVName == mpContext->getParent()->getWebDAVName(); 325*8590a0fdSAndre Fischer } 326*8590a0fdSAndre Fischer bool propertyIsReady() const 327*8590a0fdSAndre Fischer { 328*8590a0fdSAndre Fischer return hasParent(WebDAVName_prop) && whitespaceIsAvailable(); 329*8590a0fdSAndre Fischer } 330*8590a0fdSAndre Fischer bool isCollectingProperties() const 331*8590a0fdSAndre Fischer { 332*8590a0fdSAndre Fischer return WebDAVResponseParserMode_PropFind == meWebDAVResponseParserMode; 333*8590a0fdSAndre Fischer } 334*8590a0fdSAndre Fischer bool isCollectingPropNames() const 335*8590a0fdSAndre Fischer { 336*8590a0fdSAndre Fischer return WebDAVResponseParserMode_PropName == meWebDAVResponseParserMode; 337*8590a0fdSAndre Fischer } 338*8590a0fdSAndre Fischer bool collectThisPropertyAsName() const 339*8590a0fdSAndre Fischer { 340*8590a0fdSAndre Fischer return isCollectingPropNames() && hasParent(WebDAVName_prop); 341*8590a0fdSAndre Fischer } 342*8590a0fdSAndre Fischer void pop_context() 343*8590a0fdSAndre Fischer { 344*8590a0fdSAndre Fischer if(mpContext) 345*8590a0fdSAndre Fischer { 346*8590a0fdSAndre Fischer WebDAVContext* pTemp = mpContext; 347*8590a0fdSAndre Fischer mpContext = mpContext->getParent(); 348*8590a0fdSAndre Fischer delete pTemp; 349*8590a0fdSAndre Fischer } 350*8590a0fdSAndre Fischer else 351*8590a0fdSAndre Fischer { 352*8590a0fdSAndre Fischer OSL_ENSURE(false, "Parser context pop without context (!)"); 353*8590a0fdSAndre Fischer } 354*8590a0fdSAndre Fischer } 355*8590a0fdSAndre Fischer 356*8590a0fdSAndre Fischer public: 357*8590a0fdSAndre Fischer WebDAVResponseParser(WebDAVResponseParserMode eWebDAVResponseParserMode); 358*8590a0fdSAndre Fischer ~WebDAVResponseParser(); 359*8590a0fdSAndre Fischer 360*8590a0fdSAndre Fischer // Methods XDocumentHandler 361*8590a0fdSAndre Fischer virtual void SAL_CALL startDocument( ) throw (xml::sax::SAXException, uno::RuntimeException); 362*8590a0fdSAndre Fischer virtual void SAL_CALL endDocument( ) throw (xml::sax::SAXException, uno::RuntimeException); 363*8590a0fdSAndre Fischer virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw (xml::sax::SAXException, uno::RuntimeException); 364*8590a0fdSAndre Fischer virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (xml::sax::SAXException, uno::RuntimeException); 365*8590a0fdSAndre Fischer virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException); 366*8590a0fdSAndre Fischer virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (xml::sax::SAXException, uno::RuntimeException); 367*8590a0fdSAndre Fischer virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (xml::sax::SAXException, uno::RuntimeException); 368*8590a0fdSAndre Fischer virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException); 369*8590a0fdSAndre Fischer 370*8590a0fdSAndre Fischer const std::vector< http_dav_ucp::DAVResource >& getResult_PropFind() const { return maResult_PropFind; } 371*8590a0fdSAndre Fischer const std::vector< http_dav_ucp::DAVResourceInfo >& getResult_PropName() const { return maResult_PropName; } 372*8590a0fdSAndre Fischer }; 373*8590a0fdSAndre Fischer 374*8590a0fdSAndre Fischer WebDAVResponseParser::WebDAVResponseParser(WebDAVResponseParserMode eWebDAVResponseParserMode) 375*8590a0fdSAndre Fischer : maResult_PropFind(), 376*8590a0fdSAndre Fischer maResult_PropName(), 377*8590a0fdSAndre Fischer mpContext(0), 378*8590a0fdSAndre Fischer maHref(), 379*8590a0fdSAndre Fischer maStatus(), 380*8590a0fdSAndre Fischer maResponseProperties(), 381*8590a0fdSAndre Fischer maPropStatProperties(), 382*8590a0fdSAndre Fischer maResponseNames(), 383*8590a0fdSAndre Fischer maPropStatNames(), 384*8590a0fdSAndre Fischer maLockEntries(), 385*8590a0fdSAndre Fischer maLockScope(ucb::LockScope_EXCLUSIVE), 386*8590a0fdSAndre Fischer maLockType(ucb::LockType_WRITE), 387*8590a0fdSAndre Fischer meWebDAVResponseParserMode(eWebDAVResponseParserMode), 388*8590a0fdSAndre Fischer mbResourceTypeCollection(false), 389*8590a0fdSAndre Fischer mbLockScopeSet(false), 390*8590a0fdSAndre Fischer mbLockTypeSet(false) 391*8590a0fdSAndre Fischer { 392*8590a0fdSAndre Fischer } 393*8590a0fdSAndre Fischer 394*8590a0fdSAndre Fischer WebDAVResponseParser::~WebDAVResponseParser() 395*8590a0fdSAndre Fischer { 396*8590a0fdSAndre Fischer OSL_ENSURE(!mpContext, "Parser destructed with existing content (!)"); 397*8590a0fdSAndre Fischer while(mpContext) 398*8590a0fdSAndre Fischer { 399*8590a0fdSAndre Fischer pop_context(); 400*8590a0fdSAndre Fischer } 401*8590a0fdSAndre Fischer } 402*8590a0fdSAndre Fischer 403*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::startDocument( ) throw (xml::sax::SAXException, uno::RuntimeException) 404*8590a0fdSAndre Fischer { 405*8590a0fdSAndre Fischer OSL_ENSURE(!mpContext, "Parser start with existing content (!)"); 406*8590a0fdSAndre Fischer } 407*8590a0fdSAndre Fischer 408*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::endDocument( ) throw (xml::sax::SAXException, uno::RuntimeException) 409*8590a0fdSAndre Fischer { 410*8590a0fdSAndre Fischer OSL_ENSURE(!mpContext, "Parser end with existing content (!)"); 411*8590a0fdSAndre Fischer } 412*8590a0fdSAndre Fischer 413*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw (xml::sax::SAXException, uno::RuntimeException) 414*8590a0fdSAndre Fischer { 415*8590a0fdSAndre Fischer const sal_Int32 nLen(aName.getLength()); 416*8590a0fdSAndre Fischer 417*8590a0fdSAndre Fischer if(nLen) 418*8590a0fdSAndre Fischer { 419*8590a0fdSAndre Fischer // create new context (push) 420*8590a0fdSAndre Fischer mpContext = new WebDAVContext(mpContext, aName, xAttribs); 421*8590a0fdSAndre Fischer 422*8590a0fdSAndre Fischer if(collectThisPropertyAsName()) 423*8590a0fdSAndre Fischer { 424*8590a0fdSAndre Fischer // When collecting property names and parent is prop there is no need 425*8590a0fdSAndre Fischer // to handle the content of this property deeper (evtl. preparations) 426*8590a0fdSAndre Fischer } 427*8590a0fdSAndre Fischer else 428*8590a0fdSAndre Fischer { 429*8590a0fdSAndre Fischer switch(mpContext->getWebDAVNamespace()) 430*8590a0fdSAndre Fischer { 431*8590a0fdSAndre Fischer default: // WebDAVNamespace_unknown, WebDAVNamespace_last or unhandled 432*8590a0fdSAndre Fischer { 433*8590a0fdSAndre Fischer break; 434*8590a0fdSAndre Fischer } 435*8590a0fdSAndre Fischer case WebDAVNamespace_DAV: 436*8590a0fdSAndre Fischer { 437*8590a0fdSAndre Fischer switch(mpContext->getWebDAVName()) 438*8590a0fdSAndre Fischer { 439*8590a0fdSAndre Fischer default: // WebDAVName_unknown, WebDAVName_last or unhandled 440*8590a0fdSAndre Fischer { 441*8590a0fdSAndre Fischer break; 442*8590a0fdSAndre Fischer } 443*8590a0fdSAndre Fischer case WebDAVName_propstat: 444*8590a0fdSAndre Fischer { 445*8590a0fdSAndre Fischer // propstat start 446*8590a0fdSAndre Fischer if(isCollectingProperties()) 447*8590a0fdSAndre Fischer { 448*8590a0fdSAndre Fischer // reset maPropStatProperties 449*8590a0fdSAndre Fischer maPropStatProperties.clear(); 450*8590a0fdSAndre Fischer } 451*8590a0fdSAndre Fischer else 452*8590a0fdSAndre Fischer { 453*8590a0fdSAndre Fischer // when collecting properties reset maPropStatNames 454*8590a0fdSAndre Fischer maPropStatNames.clear(); 455*8590a0fdSAndre Fischer } 456*8590a0fdSAndre Fischer break; 457*8590a0fdSAndre Fischer } 458*8590a0fdSAndre Fischer case WebDAVName_response: 459*8590a0fdSAndre Fischer { 460*8590a0fdSAndre Fischer // response start, reset Href and status and maResponseProperties 461*8590a0fdSAndre Fischer maHref = maStatus = ::rtl::OUString(); 462*8590a0fdSAndre Fischer 463*8590a0fdSAndre Fischer if(isCollectingProperties()) 464*8590a0fdSAndre Fischer { 465*8590a0fdSAndre Fischer // reset maResponseProperties 466*8590a0fdSAndre Fischer maResponseProperties.clear(); 467*8590a0fdSAndre Fischer } 468*8590a0fdSAndre Fischer else 469*8590a0fdSAndre Fischer { 470*8590a0fdSAndre Fischer // reset maResponseNames when collecting properties 471*8590a0fdSAndre Fischer maResponseNames.clear(); 472*8590a0fdSAndre Fischer } 473*8590a0fdSAndre Fischer break; 474*8590a0fdSAndre Fischer } 475*8590a0fdSAndre Fischer case WebDAVName_resourcetype: 476*8590a0fdSAndre Fischer { 477*8590a0fdSAndre Fischer // resourcetype start, reset collection 478*8590a0fdSAndre Fischer mbResourceTypeCollection = false; 479*8590a0fdSAndre Fischer break; 480*8590a0fdSAndre Fischer } 481*8590a0fdSAndre Fischer case WebDAVName_supportedlock: 482*8590a0fdSAndre Fischer { 483*8590a0fdSAndre Fischer // supportedlock start, reset maLockEntries 484*8590a0fdSAndre Fischer maLockEntries.realloc(0); 485*8590a0fdSAndre Fischer break; 486*8590a0fdSAndre Fischer } 487*8590a0fdSAndre Fischer case WebDAVName_lockentry: 488*8590a0fdSAndre Fischer { 489*8590a0fdSAndre Fischer // lockentry start, reset maLockEntries 490*8590a0fdSAndre Fischer mbLockScopeSet = false; 491*8590a0fdSAndre Fischer mbLockTypeSet = false; 492*8590a0fdSAndre Fischer break; 493*8590a0fdSAndre Fischer } 494*8590a0fdSAndre Fischer } 495*8590a0fdSAndre Fischer break; 496*8590a0fdSAndre Fischer } 497*8590a0fdSAndre Fischer case WebDAVNamespace_ucb_openoffice_org_dav_props: 498*8590a0fdSAndre Fischer { 499*8590a0fdSAndre Fischer break; 500*8590a0fdSAndre Fischer } 501*8590a0fdSAndre Fischer } 502*8590a0fdSAndre Fischer } 503*8590a0fdSAndre Fischer } 504*8590a0fdSAndre Fischer } 505*8590a0fdSAndre Fischer 506*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::endElement( const ::rtl::OUString& aName ) throw (xml::sax::SAXException, uno::RuntimeException) 507*8590a0fdSAndre Fischer { 508*8590a0fdSAndre Fischer const sal_Int32 nLen(aName.getLength()); 509*8590a0fdSAndre Fischer OSL_ENSURE(mpContext, "Parser EndElement without content (!)"); 510*8590a0fdSAndre Fischer 511*8590a0fdSAndre Fischer if(mpContext && nLen) 512*8590a0fdSAndre Fischer { 513*8590a0fdSAndre Fischer if(collectThisPropertyAsName()) 514*8590a0fdSAndre Fischer { 515*8590a0fdSAndre Fischer // When collecting property names and parent is prop, just append the prop name 516*8590a0fdSAndre Fischer // to the collection, no need to parse deeper 517*8590a0fdSAndre Fischer maPropStatNames.push_back(mpContext->getNamespace() + mpContext->getName()); 518*8590a0fdSAndre Fischer } 519*8590a0fdSAndre Fischer else 520*8590a0fdSAndre Fischer { 521*8590a0fdSAndre Fischer switch(mpContext->getWebDAVNamespace()) 522*8590a0fdSAndre Fischer { 523*8590a0fdSAndre Fischer default: // WebDAVNamespace_unknown, WebDAVNamespace_last or unhandled 524*8590a0fdSAndre Fischer { 525*8590a0fdSAndre Fischer break; 526*8590a0fdSAndre Fischer } 527*8590a0fdSAndre Fischer case WebDAVNamespace_DAV: 528*8590a0fdSAndre Fischer { 529*8590a0fdSAndre Fischer switch(mpContext->getWebDAVName()) 530*8590a0fdSAndre Fischer { 531*8590a0fdSAndre Fischer default: // WebDAVName_unknown, WebDAVName_last or unhandled 532*8590a0fdSAndre Fischer { 533*8590a0fdSAndre Fischer break; 534*8590a0fdSAndre Fischer } 535*8590a0fdSAndre Fischer case WebDAVName_href: 536*8590a0fdSAndre Fischer { 537*8590a0fdSAndre Fischer // href end, save it if we have whitespace 538*8590a0fdSAndre Fischer if(whitespaceIsAvailable()) 539*8590a0fdSAndre Fischer { 540*8590a0fdSAndre Fischer maHref = mpContext->getWhiteSpace(); 541*8590a0fdSAndre Fischer } 542*8590a0fdSAndre Fischer break; 543*8590a0fdSAndre Fischer } 544*8590a0fdSAndre Fischer case WebDAVName_status: 545*8590a0fdSAndre Fischer { 546*8590a0fdSAndre Fischer // status end, save it if we have whitespace 547*8590a0fdSAndre Fischer if(whitespaceIsAvailable()) 548*8590a0fdSAndre Fischer { 549*8590a0fdSAndre Fischer maStatus = mpContext->getWhiteSpace(); 550*8590a0fdSAndre Fischer } 551*8590a0fdSAndre Fischer break; 552*8590a0fdSAndre Fischer } 553*8590a0fdSAndre Fischer case WebDAVName_getlastmodified: 554*8590a0fdSAndre Fischer { 555*8590a0fdSAndre Fischer // getlastmodified end, safe if content is correct 556*8590a0fdSAndre Fischer if(propertyIsReady()) 557*8590a0fdSAndre Fischer { 558*8590a0fdSAndre Fischer static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:getlastmodified")); 559*8590a0fdSAndre Fischer http_dav_ucp::DAVPropertyValue aDAVPropertyValue; 560*8590a0fdSAndre Fischer 561*8590a0fdSAndre Fischer aDAVPropertyValue.Name = aStr; 562*8590a0fdSAndre Fischer aDAVPropertyValue.Value <<= mpContext->getWhiteSpace(); 563*8590a0fdSAndre Fischer maPropStatProperties.push_back(aDAVPropertyValue); 564*8590a0fdSAndre Fischer } 565*8590a0fdSAndre Fischer break; 566*8590a0fdSAndre Fischer } 567*8590a0fdSAndre Fischer case WebDAVName_creationdate: 568*8590a0fdSAndre Fischer { 569*8590a0fdSAndre Fischer // creationdate end, safe if content is correct 570*8590a0fdSAndre Fischer if(propertyIsReady()) 571*8590a0fdSAndre Fischer { 572*8590a0fdSAndre Fischer static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:creationdate")); 573*8590a0fdSAndre Fischer http_dav_ucp::DAVPropertyValue aDAVPropertyValue; 574*8590a0fdSAndre Fischer 575*8590a0fdSAndre Fischer aDAVPropertyValue.Name = aStr; 576*8590a0fdSAndre Fischer aDAVPropertyValue.Value <<= mpContext->getWhiteSpace(); 577*8590a0fdSAndre Fischer maPropStatProperties.push_back(aDAVPropertyValue); 578*8590a0fdSAndre Fischer } 579*8590a0fdSAndre Fischer break; 580*8590a0fdSAndre Fischer } 581*8590a0fdSAndre Fischer case WebDAVName_collection: 582*8590a0fdSAndre Fischer { 583*8590a0fdSAndre Fischer // collection end, check and set 584*8590a0fdSAndre Fischer if(hasParent(WebDAVName_resourcetype)) 585*8590a0fdSAndre Fischer { 586*8590a0fdSAndre Fischer mbResourceTypeCollection = true; 587*8590a0fdSAndre Fischer } 588*8590a0fdSAndre Fischer break; 589*8590a0fdSAndre Fischer } 590*8590a0fdSAndre Fischer case WebDAVName_resourcetype: 591*8590a0fdSAndre Fischer { 592*8590a0fdSAndre Fischer // resourcetype end, check for collection 593*8590a0fdSAndre Fischer if(hasParent(WebDAVName_prop)) 594*8590a0fdSAndre Fischer { 595*8590a0fdSAndre Fischer static rtl::OUString aStrA(rtl::OUString::createFromAscii("DAV:resourcetype")); 596*8590a0fdSAndre Fischer static rtl::OUString aStrB(rtl::OUString::createFromAscii("collection")); 597*8590a0fdSAndre Fischer http_dav_ucp::DAVPropertyValue aDAVPropertyValue; 598*8590a0fdSAndre Fischer 599*8590a0fdSAndre Fischer aDAVPropertyValue.Name = aStrA; 600*8590a0fdSAndre Fischer aDAVPropertyValue.Value <<= (mbResourceTypeCollection ? aStrB : rtl::OUString()); 601*8590a0fdSAndre Fischer maPropStatProperties.push_back(aDAVPropertyValue); 602*8590a0fdSAndre Fischer } 603*8590a0fdSAndre Fischer break; 604*8590a0fdSAndre Fischer } 605*8590a0fdSAndre Fischer case WebDAVName_getcontentlength: 606*8590a0fdSAndre Fischer { 607*8590a0fdSAndre Fischer // getcontentlength end, safe if content is correct 608*8590a0fdSAndre Fischer if(propertyIsReady()) 609*8590a0fdSAndre Fischer { 610*8590a0fdSAndre Fischer static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:getcontentlength")); 611*8590a0fdSAndre Fischer http_dav_ucp::DAVPropertyValue aDAVPropertyValue; 612*8590a0fdSAndre Fischer 613*8590a0fdSAndre Fischer aDAVPropertyValue.Name = aStr; 614*8590a0fdSAndre Fischer aDAVPropertyValue.Value <<= mpContext->getWhiteSpace(); 615*8590a0fdSAndre Fischer maPropStatProperties.push_back(aDAVPropertyValue); 616*8590a0fdSAndre Fischer } 617*8590a0fdSAndre Fischer break; 618*8590a0fdSAndre Fischer } 619*8590a0fdSAndre Fischer case WebDAVName_getcontenttype: 620*8590a0fdSAndre Fischer { 621*8590a0fdSAndre Fischer // getcontenttype end, safe if content is correct 622*8590a0fdSAndre Fischer if(propertyIsReady()) 623*8590a0fdSAndre Fischer { 624*8590a0fdSAndre Fischer static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:getcontenttype")); 625*8590a0fdSAndre Fischer http_dav_ucp::DAVPropertyValue aDAVPropertyValue; 626*8590a0fdSAndre Fischer 627*8590a0fdSAndre Fischer aDAVPropertyValue.Name = aStr; 628*8590a0fdSAndre Fischer aDAVPropertyValue.Value <<= mpContext->getWhiteSpace(); 629*8590a0fdSAndre Fischer maPropStatProperties.push_back(aDAVPropertyValue); 630*8590a0fdSAndre Fischer } 631*8590a0fdSAndre Fischer break; 632*8590a0fdSAndre Fischer } 633*8590a0fdSAndre Fischer case WebDAVName_supportedlock: 634*8590a0fdSAndre Fischer { 635*8590a0fdSAndre Fischer // supportedlock end 636*8590a0fdSAndre Fischer if(hasParent(WebDAVName_prop) && maLockEntries.hasElements()) 637*8590a0fdSAndre Fischer { 638*8590a0fdSAndre Fischer static rtl::OUString aStr(rtl::OUString::createFromAscii("DAV:supportedlock")); 639*8590a0fdSAndre Fischer http_dav_ucp::DAVPropertyValue aDAVPropertyValue; 640*8590a0fdSAndre Fischer 641*8590a0fdSAndre Fischer aDAVPropertyValue.Name = aStr; 642*8590a0fdSAndre Fischer aDAVPropertyValue.Value <<= maLockEntries; 643*8590a0fdSAndre Fischer maPropStatProperties.push_back(aDAVPropertyValue); 644*8590a0fdSAndre Fischer } 645*8590a0fdSAndre Fischer break; 646*8590a0fdSAndre Fischer } 647*8590a0fdSAndre Fischer case WebDAVName_lockentry: 648*8590a0fdSAndre Fischer { 649*8590a0fdSAndre Fischer // lockentry end 650*8590a0fdSAndre Fischer if(hasParent(WebDAVName_supportedlock) && (mbLockScopeSet && mbLockTypeSet)) 651*8590a0fdSAndre Fischer { 652*8590a0fdSAndre Fischer const sal_Int32 nLength(maLockEntries.getLength()); 653*8590a0fdSAndre Fischer ucb::LockEntry aEntry; 654*8590a0fdSAndre Fischer 655*8590a0fdSAndre Fischer aEntry.Scope = maLockScope; 656*8590a0fdSAndre Fischer aEntry.Type = maLockType; 657*8590a0fdSAndre Fischer maLockEntries.realloc(nLength + 1); 658*8590a0fdSAndre Fischer maLockEntries[nLength] = aEntry; 659*8590a0fdSAndre Fischer } 660*8590a0fdSAndre Fischer break; 661*8590a0fdSAndre Fischer } 662*8590a0fdSAndre Fischer case WebDAVName_exclusive: 663*8590a0fdSAndre Fischer { 664*8590a0fdSAndre Fischer // exclusive lockscope end 665*8590a0fdSAndre Fischer if(hasParent(WebDAVName_lockscope)) 666*8590a0fdSAndre Fischer { 667*8590a0fdSAndre Fischer maLockScope = ucb::LockScope_EXCLUSIVE; 668*8590a0fdSAndre Fischer mbLockScopeSet = true; 669*8590a0fdSAndre Fischer } 670*8590a0fdSAndre Fischer break; 671*8590a0fdSAndre Fischer } 672*8590a0fdSAndre Fischer case WebDAVName_shared: 673*8590a0fdSAndre Fischer { 674*8590a0fdSAndre Fischer // shared lockscope end 675*8590a0fdSAndre Fischer if(hasParent(WebDAVName_lockscope)) 676*8590a0fdSAndre Fischer { 677*8590a0fdSAndre Fischer maLockScope = ucb::LockScope_SHARED; 678*8590a0fdSAndre Fischer mbLockScopeSet = true; 679*8590a0fdSAndre Fischer } 680*8590a0fdSAndre Fischer break; 681*8590a0fdSAndre Fischer } 682*8590a0fdSAndre Fischer case WebDAVName_write: 683*8590a0fdSAndre Fischer { 684*8590a0fdSAndre Fischer // write locktype end 685*8590a0fdSAndre Fischer if(hasParent(WebDAVName_locktype)) 686*8590a0fdSAndre Fischer { 687*8590a0fdSAndre Fischer maLockType = ucb::LockType_WRITE; 688*8590a0fdSAndre Fischer mbLockTypeSet = true; 689*8590a0fdSAndre Fischer } 690*8590a0fdSAndre Fischer break; 691*8590a0fdSAndre Fischer } 692*8590a0fdSAndre Fischer case WebDAVName_propstat: 693*8590a0fdSAndre Fischer { 694*8590a0fdSAndre Fischer // propstat end, check status 695*8590a0fdSAndre Fischer if(maStatus.getLength()) 696*8590a0fdSAndre Fischer { 697*8590a0fdSAndre Fischer static ::rtl::OUString aStrStatusOkay(::rtl::OUString::createFromAscii("HTTP/1.1 200 OK")); 698*8590a0fdSAndre Fischer 699*8590a0fdSAndre Fischer if(maStatus.equals(aStrStatusOkay)) 700*8590a0fdSAndre Fischer { 701*8590a0fdSAndre Fischer if(isCollectingProperties()) 702*8590a0fdSAndre Fischer { 703*8590a0fdSAndre Fischer if(maPropStatProperties.size()) 704*8590a0fdSAndre Fischer { 705*8590a0fdSAndre Fischer // append to maResponseProperties if okay 706*8590a0fdSAndre Fischer maResponseProperties.insert(maResponseProperties.end(), maPropStatProperties.begin(), maPropStatProperties.end()); 707*8590a0fdSAndre Fischer } 708*8590a0fdSAndre Fischer } 709*8590a0fdSAndre Fischer else 710*8590a0fdSAndre Fischer { 711*8590a0fdSAndre Fischer if(maPropStatNames.size()) 712*8590a0fdSAndre Fischer { 713*8590a0fdSAndre Fischer // when collecting properties append to 714*8590a0fdSAndre Fischer maResponseNames.insert(maResponseNames.end(), maPropStatNames.begin(), maPropStatNames.end()); 715*8590a0fdSAndre Fischer } 716*8590a0fdSAndre Fischer } 717*8590a0fdSAndre Fischer } 718*8590a0fdSAndre Fischer } 719*8590a0fdSAndre Fischer break; 720*8590a0fdSAndre Fischer } 721*8590a0fdSAndre Fischer case WebDAVName_response: 722*8590a0fdSAndre Fischer { 723*8590a0fdSAndre Fischer // respose end 724*8590a0fdSAndre Fischer if(maHref.getLength()) 725*8590a0fdSAndre Fischer { 726*8590a0fdSAndre Fischer if(isCollectingProperties()) 727*8590a0fdSAndre Fischer { 728*8590a0fdSAndre Fischer // create DAVResource when we have content 729*8590a0fdSAndre Fischer if(maResponseProperties.size()) 730*8590a0fdSAndre Fischer { 731*8590a0fdSAndre Fischer http_dav_ucp::DAVResource aDAVResource; 732*8590a0fdSAndre Fischer 733*8590a0fdSAndre Fischer aDAVResource.uri = maHref; 734*8590a0fdSAndre Fischer aDAVResource.properties = maResponseProperties; 735*8590a0fdSAndre Fischer maResult_PropFind.push_back(aDAVResource); 736*8590a0fdSAndre Fischer } 737*8590a0fdSAndre Fischer } 738*8590a0fdSAndre Fischer else 739*8590a0fdSAndre Fischer { 740*8590a0fdSAndre Fischer // when collecting properties add them to result when there are some 741*8590a0fdSAndre Fischer if(maResponseNames.size()) 742*8590a0fdSAndre Fischer { 743*8590a0fdSAndre Fischer http_dav_ucp::DAVResourceInfo aDAVResourceInfo(maHref); 744*8590a0fdSAndre Fischer 745*8590a0fdSAndre Fischer aDAVResourceInfo.properties = maResponseNames; 746*8590a0fdSAndre Fischer maResult_PropName.push_back(aDAVResourceInfo); 747*8590a0fdSAndre Fischer } 748*8590a0fdSAndre Fischer } 749*8590a0fdSAndre Fischer } 750*8590a0fdSAndre Fischer break; 751*8590a0fdSAndre Fischer } 752*8590a0fdSAndre Fischer } 753*8590a0fdSAndre Fischer break; 754*8590a0fdSAndre Fischer } 755*8590a0fdSAndre Fischer case WebDAVNamespace_ucb_openoffice_org_dav_props: 756*8590a0fdSAndre Fischer { 757*8590a0fdSAndre Fischer break; 758*8590a0fdSAndre Fischer } 759*8590a0fdSAndre Fischer } 760*8590a0fdSAndre Fischer } 761*8590a0fdSAndre Fischer 762*8590a0fdSAndre Fischer // destroy last context (pop) 763*8590a0fdSAndre Fischer pop_context(); 764*8590a0fdSAndre Fischer } 765*8590a0fdSAndre Fischer } 766*8590a0fdSAndre Fischer 767*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException) 768*8590a0fdSAndre Fischer { 769*8590a0fdSAndre Fischer // collect whitespace over evtl. several calls in mpContext 770*8590a0fdSAndre Fischer OSL_ENSURE(mpContext, "Parser characters without content (!)"); 771*8590a0fdSAndre Fischer const sal_Int32 nLen(aChars.getLength()); 772*8590a0fdSAndre Fischer 773*8590a0fdSAndre Fischer if(mpContext && nLen) 774*8590a0fdSAndre Fischer { 775*8590a0fdSAndre Fischer // remove leading/trailing blanks and CRLF 776*8590a0fdSAndre Fischer const ::rtl::OUString aTrimmedChars(aChars.trim()); 777*8590a0fdSAndre Fischer 778*8590a0fdSAndre Fischer if(aTrimmedChars.getLength()) 779*8590a0fdSAndre Fischer { 780*8590a0fdSAndre Fischer ::rtl::OUString aNew(mpContext->getWhiteSpace()); 781*8590a0fdSAndre Fischer 782*8590a0fdSAndre Fischer if(aNew.getLength()) 783*8590a0fdSAndre Fischer { 784*8590a0fdSAndre Fischer // add one char when appending (see html1.1 spec) 785*8590a0fdSAndre Fischer aNew += ::rtl::OUString(sal_Unicode(' ')); 786*8590a0fdSAndre Fischer } 787*8590a0fdSAndre Fischer 788*8590a0fdSAndre Fischer aNew += aTrimmedChars; 789*8590a0fdSAndre Fischer mpContext->setWhiteSpace(aNew); 790*8590a0fdSAndre Fischer } 791*8590a0fdSAndre Fischer } 792*8590a0fdSAndre Fischer } 793*8590a0fdSAndre Fischer 794*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::ignorableWhitespace( const ::rtl::OUString& /*aWhitespaces*/ ) throw (xml::sax::SAXException, uno::RuntimeException) 795*8590a0fdSAndre Fischer { 796*8590a0fdSAndre Fischer } 797*8590a0fdSAndre Fischer 798*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::processingInstruction( const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ ) throw (xml::sax::SAXException, uno::RuntimeException) 799*8590a0fdSAndre Fischer { 800*8590a0fdSAndre Fischer } 801*8590a0fdSAndre Fischer 802*8590a0fdSAndre Fischer void SAL_CALL WebDAVResponseParser::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ ) throw (xml::sax::SAXException, uno::RuntimeException) 803*8590a0fdSAndre Fischer { 804*8590a0fdSAndre Fischer } 805*8590a0fdSAndre Fischer } // end of anonymous namespace 806*8590a0fdSAndre Fischer 807*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 808*8590a0fdSAndre Fischer // wrapper for various calls to the parser 809*8590a0fdSAndre Fischer 810*8590a0fdSAndre Fischer namespace 811*8590a0fdSAndre Fischer { 812*8590a0fdSAndre Fischer void parseWebDAVPropNameResponse( 813*8590a0fdSAndre Fischer const uno::Reference< io::XInputStream >& xInputStream, 814*8590a0fdSAndre Fischer std::vector< http_dav_ucp::DAVResource >& rPropFind, 815*8590a0fdSAndre Fischer std::vector< http_dav_ucp::DAVResourceInfo >& rPropName, 816*8590a0fdSAndre Fischer WebDAVResponseParserMode eWebDAVResponseParserMode) 817*8590a0fdSAndre Fischer { 818*8590a0fdSAndre Fischer if(xInputStream.is()) 819*8590a0fdSAndre Fischer { 820*8590a0fdSAndre Fischer try 821*8590a0fdSAndre Fischer { 822*8590a0fdSAndre Fischer // prepare ParserInputSrouce 823*8590a0fdSAndre Fischer xml::sax::InputSource myInputSource; 824*8590a0fdSAndre Fischer myInputSource.aInputStream = xInputStream; 825*8590a0fdSAndre Fischer 826*8590a0fdSAndre Fischer // get parser 827*8590a0fdSAndre Fischer uno::Reference< xml::sax::XParser > xParser( 828*8590a0fdSAndre Fischer comphelper::getProcessServiceFactory()->createInstance( 829*8590a0fdSAndre Fischer rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ), 830*8590a0fdSAndre Fischer uno::UNO_QUERY_THROW ); 831*8590a0fdSAndre Fischer 832*8590a0fdSAndre Fischer // create parser; connect parser and filter 833*8590a0fdSAndre Fischer WebDAVResponseParser* pWebDAVResponseParser = new WebDAVResponseParser(eWebDAVResponseParserMode); 834*8590a0fdSAndre Fischer uno::Reference< xml::sax::XDocumentHandler > xWebDAVHdl(pWebDAVResponseParser); 835*8590a0fdSAndre Fischer xParser->setDocumentHandler(xWebDAVHdl); 836*8590a0fdSAndre Fischer 837*8590a0fdSAndre Fischer // finally, parse the stream 838*8590a0fdSAndre Fischer xParser->parseStream(myInputSource); 839*8590a0fdSAndre Fischer 840*8590a0fdSAndre Fischer // get result 841*8590a0fdSAndre Fischer switch(eWebDAVResponseParserMode) 842*8590a0fdSAndre Fischer { 843*8590a0fdSAndre Fischer case WebDAVResponseParserMode_PropFind: 844*8590a0fdSAndre Fischer { 845*8590a0fdSAndre Fischer rPropFind = pWebDAVResponseParser->getResult_PropFind(); 846*8590a0fdSAndre Fischer break; 847*8590a0fdSAndre Fischer } 848*8590a0fdSAndre Fischer case WebDAVResponseParserMode_PropName: 849*8590a0fdSAndre Fischer { 850*8590a0fdSAndre Fischer rPropName = pWebDAVResponseParser->getResult_PropName(); 851*8590a0fdSAndre Fischer break; 852*8590a0fdSAndre Fischer } 853*8590a0fdSAndre Fischer } 854*8590a0fdSAndre Fischer } 855*8590a0fdSAndre Fischer catch(uno::Exception&) 856*8590a0fdSAndre Fischer { 857*8590a0fdSAndre Fischer OSL_ENSURE(false, "WebDAV Parse error (!)"); 858*8590a0fdSAndre Fischer } 859*8590a0fdSAndre Fischer } 860*8590a0fdSAndre Fischer } 861*8590a0fdSAndre Fischer } // end of anonymous namespace 862*8590a0fdSAndre Fischer 863*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 864*8590a0fdSAndre Fischer // helper to parse a XML WebDAV response 865*8590a0fdSAndre Fischer 866*8590a0fdSAndre Fischer namespace http_dav_ucp 867*8590a0fdSAndre Fischer { 868*8590a0fdSAndre Fischer std::vector< DAVResource > parseWebDAVPropFindResponse(const uno::Reference< io::XInputStream >& xInputStream) 869*8590a0fdSAndre Fischer { 870*8590a0fdSAndre Fischer std::vector< DAVResource > aRetval; 871*8590a0fdSAndre Fischer std::vector< DAVResourceInfo > aFoo; 872*8590a0fdSAndre Fischer 873*8590a0fdSAndre Fischer parseWebDAVPropNameResponse(xInputStream, aRetval, aFoo, WebDAVResponseParserMode_PropFind); 874*8590a0fdSAndre Fischer return aRetval; 875*8590a0fdSAndre Fischer } 876*8590a0fdSAndre Fischer 877*8590a0fdSAndre Fischer std::vector< DAVResourceInfo > parseWebDAVPropNameResponse(const uno::Reference< io::XInputStream >& xInputStream) 878*8590a0fdSAndre Fischer { 879*8590a0fdSAndre Fischer std::vector< DAVResource > aFoo; 880*8590a0fdSAndre Fischer std::vector< DAVResourceInfo > aRetval; 881*8590a0fdSAndre Fischer 882*8590a0fdSAndre Fischer parseWebDAVPropNameResponse(xInputStream, aFoo, aRetval, WebDAVResponseParserMode_PropName); 883*8590a0fdSAndre Fischer return aRetval; 884*8590a0fdSAndre Fischer } 885*8590a0fdSAndre Fischer } // namespace http_dav_ucp 886*8590a0fdSAndre Fischer 887*8590a0fdSAndre Fischer ////////////////////////////////////////////////////////////////////////////// 888*8590a0fdSAndre Fischer // eof 889