1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LockEntrySequence.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
36 #include "LockEntrySequence.hxx"
38 using namespace webdav_ucp
;
39 using namespace com::sun::star
;
41 //////////////////////////////////////////////////////////////////////////
43 struct LockEntrySequenceParseContext
45 ucb::LockEntry
* pEntry
;
49 LockEntrySequenceParseContext()
50 : pEntry( 0 ), hasScope( false ), hasType( false ) {}
51 ~LockEntrySequenceParseContext() { delete pEntry
; }
56 #define STATE_LOCKENTRY (STATE_TOP)
57 #define STATE_LOCKSCOPE (STATE_TOP + 1)
58 #define STATE_EXCLUSIVE (STATE_TOP + 2)
59 #define STATE_SHARED (STATE_TOP + 3)
60 #define STATE_LOCKTYPE (STATE_TOP + 4)
61 #define STATE_WRITE (STATE_TOP + 5)
63 //////////////////////////////////////////////////////////////////////////
64 extern "C" int LockEntrySequence_startelement_callback(
72 ( ( nspace
== 0 ) || ( strcmp( nspace
, "" ) == 0 ) ) )
76 case NE_XML_STATEROOT
:
77 if ( strcmp( name
, "lockentry" ) == 0 )
78 return STATE_LOCKENTRY
;
82 if ( strcmp( name
, "lockscope" ) == 0 )
83 return STATE_LOCKSCOPE
;
84 else if ( strcmp( name
, "locktype" ) == 0 )
85 return STATE_LOCKTYPE
;
89 if ( strcmp( name
, "exclusive" ) == 0 )
90 return STATE_EXCLUSIVE
;
91 else if ( strcmp( name
, "shared" ) == 0 )
96 if ( strcmp( name
, "write" ) == 0 )
101 return NE_XML_DECLINE
;
104 //////////////////////////////////////////////////////////////////////////
105 extern "C" int LockEntrySequence_chardata_callback(
111 return 0; // zero to continue, non-zero to abort parsing
114 //////////////////////////////////////////////////////////////////////////
115 extern "C" int LockEntrySequence_endelement_callback(
121 LockEntrySequenceParseContext
* pCtx
122 = static_cast< LockEntrySequenceParseContext
* >( userdata
);
124 pCtx
->pEntry
= new ucb::LockEntry
;
128 case STATE_EXCLUSIVE
:
129 pCtx
->pEntry
->Scope
= ucb::LockScope_EXCLUSIVE
;
130 pCtx
->hasScope
= true;
134 pCtx
->pEntry
->Scope
= ucb::LockScope_SHARED
;
135 pCtx
->hasScope
= true;
139 pCtx
->pEntry
->Type
= ucb::LockType_WRITE
;
140 pCtx
->hasType
= true;
143 case STATE_LOCKSCOPE
:
144 if ( !pCtx
->hasScope
)
149 if ( !pCtx
->hasType
)
153 case STATE_LOCKENTRY
:
154 if ( !pCtx
->hasType
|| !pCtx
->hasType
)
161 return 0; // zero to continue, non-zero to abort parsing
164 //////////////////////////////////////////////////////////////////////////
166 bool LockEntrySequence::createFromXML( const rtl::OString
& rInData
,
168 ucb::LockEntry
> & rOutData
)
170 const sal_Int32 TOKEN_LENGTH
= 12; // </lockentry>
173 // rInData may contain multiple <lockentry>...</lockentry> tags.
174 sal_Int32 nCount
= 0;
175 sal_Int32 nStart
= 0;
176 sal_Int32 nEnd
= rInData
.indexOf( "</lockentry>" );
179 ne_xml_parser
* parser
= ne_xml_create();
186 LockEntrySequenceParseContext aCtx
;
187 ne_xml_push_handler( parser
,
188 LockEntrySequence_startelement_callback
,
189 LockEntrySequence_chardata_callback
,
190 LockEntrySequence_endelement_callback
,
193 ne_xml_parse( parser
,
194 rInData
.getStr() + nStart
,
195 nEnd
- nStart
+ TOKEN_LENGTH
);
197 #if NEON_VERSION >= 0x0250
198 success
= !ne_xml_failed( parser
);
200 success
= !!ne_xml_valid( parser
);
203 ne_xml_destroy( parser
);
211 if ( nCount
> rOutData
.getLength() )
212 rOutData
.realloc( rOutData
.getLength() + 2 );
214 rOutData
[ nCount
- 1 ] = *aCtx
.pEntry
;
217 nStart
= nEnd
+ TOKEN_LENGTH
+ 1;
218 nEnd
= rInData
.indexOf( "</lockentry>", nStart
);
221 rOutData
.realloc( nCount
);