xref: /AOO41X/main/xmloff/source/meta/xmlversion.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
33*cdf0e10cSrcweir #include <xmlversion.hxx>
34*cdf0e10cSrcweir #include <xmloff/xmlmetae.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
37*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <tools/string.hxx>
45*cdf0e10cSrcweir class SvStringsDtor;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
48*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49*cdf0e10cSrcweir using namespace ::com::sun::star;
50*cdf0e10cSrcweir using ::rtl::OUString;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // ------------------------------------------------------------------------
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir sal_Char __FAR_DATA XMLN_VERSIONSLIST[] = "VersionList.xml";
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir // ------------------------------------------------------------------------
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir // #110897#
59*cdf0e10cSrcweir XMLVersionListExport::XMLVersionListExport(
60*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
61*cdf0e10cSrcweir     const com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag >& rVersions,
62*cdf0e10cSrcweir     const OUString &rFileName,
63*cdf0e10cSrcweir     Reference< XDocumentHandler > &rHandler )
64*cdf0e10cSrcweir :   SvXMLExport( xServiceFactory, rFileName, rHandler ),
65*cdf0e10cSrcweir 	maVersions( rVersions )
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     _GetNamespaceMap().AddAtIndex( XML_NAMESPACE_DC_IDX, xmloff::token::GetXMLToken(xmloff::token::XML_NP_DC),
68*cdf0e10cSrcweir                                    xmloff::token::GetXMLToken(xmloff::token::XML_N_DC), XML_NAMESPACE_DC );
69*cdf0e10cSrcweir     _GetNamespaceMap().AddAtIndex( XML_NAMESPACE_FRAMEWORK_IDX, xmloff::token::GetXMLToken(xmloff::token::XML_NP_VERSIONS_LIST),
70*cdf0e10cSrcweir                                    xmloff::token::GetXMLToken(xmloff::token::XML_N_VERSIONS_LIST), XML_NAMESPACE_FRAMEWORK );
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir // ------------------------------------------------------------------------
74*cdf0e10cSrcweir sal_uInt32 XMLVersionListExport::exportDoc( enum ::xmloff::token::XMLTokenEnum )
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     GetDocHandler()->startDocument();
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     sal_uInt16 nPos = _GetNamespaceMap().GetIndexByKey( XML_NAMESPACE_DC );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     AddAttribute( XML_NAMESPACE_NONE, _GetNamespaceMap().GetAttrNameByIndex( nPos ),
81*cdf0e10cSrcweir                              _GetNamespaceMap().GetNameByIndex ( nPos ) );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     nPos = _GetNamespaceMap().GetIndexByKey( XML_NAMESPACE_FRAMEWORK );
84*cdf0e10cSrcweir     AddAttribute( XML_NAMESPACE_NONE, _GetNamespaceMap().GetAttrNameByIndex( nPos ),
85*cdf0e10cSrcweir                              _GetNamespaceMap().GetNameByIndex ( nPos ) );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         // the following object will write all collected attributes in its dtor
89*cdf0e10cSrcweir         SvXMLElementExport aRoot( *this, XML_NAMESPACE_FRAMEWORK, xmloff::token::XML_VERSION_LIST, sal_True, sal_True );
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         for ( sal_Int32 n=0; n<maVersions.getLength(); n++ )
92*cdf0e10cSrcweir         {
93*cdf0e10cSrcweir             const util::RevisionTag& rInfo = maVersions[n];
94*cdf0e10cSrcweir             AddAttribute( XML_NAMESPACE_FRAMEWORK,
95*cdf0e10cSrcweir                           xmloff::token::XML_TITLE,
96*cdf0e10cSrcweir                           OUString( rInfo.Identifier ) );
97*cdf0e10cSrcweir             AddAttribute( XML_NAMESPACE_FRAMEWORK,
98*cdf0e10cSrcweir                           xmloff::token::XML_COMMENT,
99*cdf0e10cSrcweir                           OUString( rInfo.Comment ) );
100*cdf0e10cSrcweir             AddAttribute( XML_NAMESPACE_FRAMEWORK,
101*cdf0e10cSrcweir                           xmloff::token::XML_CREATOR,
102*cdf0e10cSrcweir                           OUString( rInfo.Author ) );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             OUString aDateStr =
105*cdf0e10cSrcweir                 SvXMLMetaExport::GetISODateTimeString( rInfo.TimeStamp );
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir             AddAttribute( XML_NAMESPACE_DC, xmloff::token::XML_DATE_TIME, aDateStr );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir             // the following object will write all collected attributes in its dtor
110*cdf0e10cSrcweir             SvXMLElementExport aEntry( *this, XML_NAMESPACE_FRAMEWORK, xmloff::token::XML_VERSION_ENTRY, sal_True, sal_True );
111*cdf0e10cSrcweir         }
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir     GetDocHandler()->endDocument();
114*cdf0e10cSrcweir     return 0;
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir // ------------------------------------------------------------------------
118*cdf0e10cSrcweir // ------------------------------------------------------------------------
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir // #110897#
121*cdf0e10cSrcweir XMLVersionListImport::XMLVersionListImport(
122*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
123*cdf0e10cSrcweir     com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag >& rVersions )
124*cdf0e10cSrcweir :	SvXMLImport(xServiceFactory),
125*cdf0e10cSrcweir     maVersions( rVersions )
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     GetNamespaceMap().AddAtIndex( XML_NAMESPACE_FRAMEWORK_IDX, xmloff::token::GetXMLToken(xmloff::token::XML_NP_VERSIONS_LIST),
128*cdf0e10cSrcweir                                   xmloff::token::GetXMLToken(xmloff::token::XML_N_VERSIONS_LIST), XML_NAMESPACE_FRAMEWORK );
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir // ------------------------------------------------------------------------
132*cdf0e10cSrcweir XMLVersionListImport::~XMLVersionListImport( void ) throw()
133*cdf0e10cSrcweir {}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir // ------------------------------------------------------------------------
136*cdf0e10cSrcweir SvXMLImportContext *XMLVersionListImport::CreateContext(
137*cdf0e10cSrcweir         sal_uInt16 nPrefix,
138*cdf0e10cSrcweir         const OUString& rLocalName,
139*cdf0e10cSrcweir         const Reference< XAttributeList > & xAttrList )
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     if ( XML_NAMESPACE_FRAMEWORK == nPrefix &&
144*cdf0e10cSrcweir         rLocalName == xmloff::token::GetXMLToken(xmloff::token::XML_VERSION_LIST) )
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         pContext = new XMLVersionListContext( *this, nPrefix, rLocalName, xAttrList );
147*cdf0e10cSrcweir     }
148*cdf0e10cSrcweir     else
149*cdf0e10cSrcweir     {
150*cdf0e10cSrcweir         pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     return pContext;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir // ------------------------------------------------------------------------
158*cdf0e10cSrcweir // ------------------------------------------------------------------------
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir XMLVersionListContext::XMLVersionListContext( XMLVersionListImport& rImport,
161*cdf0e10cSrcweir                                         sal_uInt16 nPrefix,
162*cdf0e10cSrcweir                                         const OUString& rLocalName,
163*cdf0e10cSrcweir                                         const Reference< XAttributeList > & )
164*cdf0e10cSrcweir     : SvXMLImportContext( rImport, nPrefix, rLocalName )
165*cdf0e10cSrcweir     , rLocalRef( rImport )
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir // ------------------------------------------------------------------------
170*cdf0e10cSrcweir XMLVersionListContext::~XMLVersionListContext( void )
171*cdf0e10cSrcweir {}
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir // ------------------------------------------------------------------------
174*cdf0e10cSrcweir SvXMLImportContext *XMLVersionListContext::CreateChildContext( sal_uInt16 nPrefix,
175*cdf0e10cSrcweir                                         const OUString& rLocalName,
176*cdf0e10cSrcweir                                         const Reference< XAttributeList > & xAttrList )
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     if ( nPrefix == XML_NAMESPACE_FRAMEWORK &&
181*cdf0e10cSrcweir          rLocalName == xmloff::token::GetXMLToken(xmloff::token::XML_VERSION_ENTRY) )
182*cdf0e10cSrcweir     {
183*cdf0e10cSrcweir         pContext = new XMLVersionContext( rLocalRef, nPrefix, rLocalName, xAttrList );
184*cdf0e10cSrcweir     }
185*cdf0e10cSrcweir     else
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName );
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     return pContext;
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir // ------------------------------------------------------------------------
194*cdf0e10cSrcweir // ------------------------------------------------------------------------
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir XMLVersionContext::XMLVersionContext( XMLVersionListImport& rImport,
197*cdf0e10cSrcweir                                         sal_uInt16 nPref,
198*cdf0e10cSrcweir                                         const OUString& rLocalName,
199*cdf0e10cSrcweir                                         const Reference< XAttributeList > & xAttrList )
200*cdf0e10cSrcweir     : SvXMLImportContext( rImport, nPref, rLocalName )
201*cdf0e10cSrcweir     , rLocalRef( rImport )
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     if ( !nAttrCount )
206*cdf0e10cSrcweir         return;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     util::RevisionTag aInfo;
209*cdf0e10cSrcweir     for ( sal_Int16 i=0; i < nAttrCount; i++ )
210*cdf0e10cSrcweir     {
211*cdf0e10cSrcweir         OUString        aLocalName;
212*cdf0e10cSrcweir         const OUString& rAttrName   = xAttrList->getNameByIndex( i );
213*cdf0e10cSrcweir         sal_uInt16      nPrefix     = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         if ( XML_NAMESPACE_FRAMEWORK == nPrefix )
216*cdf0e10cSrcweir         {
217*cdf0e10cSrcweir             if ( aLocalName == xmloff::token::GetXMLToken(xmloff::token::XML_TITLE) )
218*cdf0e10cSrcweir             {
219*cdf0e10cSrcweir                 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
220*cdf0e10cSrcweir                 aInfo.Identifier = rAttrValue;
221*cdf0e10cSrcweir             }
222*cdf0e10cSrcweir             else if ( aLocalName == xmloff::token::GetXMLToken(xmloff::token::XML_COMMENT) )
223*cdf0e10cSrcweir             {
224*cdf0e10cSrcweir                 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
225*cdf0e10cSrcweir                 aInfo.Comment = rAttrValue;
226*cdf0e10cSrcweir             }
227*cdf0e10cSrcweir             else if ( aLocalName == xmloff::token::GetXMLToken(xmloff::token::XML_CREATOR) )
228*cdf0e10cSrcweir             {
229*cdf0e10cSrcweir                 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
230*cdf0e10cSrcweir                 aInfo.Author = rAttrValue;
231*cdf0e10cSrcweir             }
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir         else if ( ( XML_NAMESPACE_DC == nPrefix ) &&
234*cdf0e10cSrcweir                   ( aLocalName == xmloff::token::GetXMLToken(xmloff::token::XML_DATE_TIME) ) )
235*cdf0e10cSrcweir         {
236*cdf0e10cSrcweir             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
237*cdf0e10cSrcweir             util::DateTime aTime;
238*cdf0e10cSrcweir             if ( ParseISODateTimeString( rAttrValue, aTime ) )
239*cdf0e10cSrcweir                 aInfo.TimeStamp = aTime;
240*cdf0e10cSrcweir         }
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     uno::Sequence < util::RevisionTag >& aList = rLocalRef.GetList();
244*cdf0e10cSrcweir     sal_Int32 nLength = aList.getLength();
245*cdf0e10cSrcweir     aList.realloc( nLength+1 );
246*cdf0e10cSrcweir     aList[nLength] = aInfo;
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir // ------------------------------------------------------------------------
251*cdf0e10cSrcweir XMLVersionContext::~XMLVersionContext( void )
252*cdf0e10cSrcweir {}
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // ------------------------------------------------------------------------
255*cdf0e10cSrcweir // static
256*cdf0e10cSrcweir sal_Bool XMLVersionContext::ParseISODateTimeString(
257*cdf0e10cSrcweir                                 const rtl::OUString& rString,
258*cdf0e10cSrcweir                                 util::DateTime& rDateTime )
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     sal_Bool bSuccess = sal_True;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     OUString aDateStr, aTimeStr;
263*cdf0e10cSrcweir     sal_Int32 nPos = rString.indexOf( (sal_Unicode) 'T' );
264*cdf0e10cSrcweir     if ( nPos >= 0 )
265*cdf0e10cSrcweir     {
266*cdf0e10cSrcweir         aDateStr = rString.copy( 0, nPos );
267*cdf0e10cSrcweir         aTimeStr = rString.copy( nPos + 1 );
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir     else
270*cdf0e10cSrcweir         aDateStr = rString;         // no separator: only date part
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     sal_Int32 nYear  = 0;
273*cdf0e10cSrcweir     sal_Int32 nMonth = 1;
274*cdf0e10cSrcweir     sal_Int32 nDay   = 1;
275*cdf0e10cSrcweir     sal_Int32 nHour  = 0;
276*cdf0e10cSrcweir     sal_Int32 nMin   = 0;
277*cdf0e10cSrcweir     sal_Int32 nSec   = 0;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     const sal_Unicode* pStr = aDateStr.getStr();
280*cdf0e10cSrcweir     sal_Int32 nDateTokens = 1;
281*cdf0e10cSrcweir     while ( *pStr )
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         if ( *pStr == '-' )
284*cdf0e10cSrcweir             nDateTokens++;
285*cdf0e10cSrcweir         pStr++;
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir     if ( nDateTokens > 3 || aDateStr.getLength() == 0 )
288*cdf0e10cSrcweir         bSuccess = sal_False;
289*cdf0e10cSrcweir     else
290*cdf0e10cSrcweir     {
291*cdf0e10cSrcweir         sal_Int32 n = 0;
292*cdf0e10cSrcweir         nYear = aDateStr.getToken( 0, '-', n ).toInt32();
293*cdf0e10cSrcweir         if ( nYear > 9999 )
294*cdf0e10cSrcweir             bSuccess = sal_False;
295*cdf0e10cSrcweir         else if ( nDateTokens >= 2 )
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             nMonth = aDateStr.getToken( 0, '-', n ).toInt32();
298*cdf0e10cSrcweir             if ( nMonth > 12 )
299*cdf0e10cSrcweir                 bSuccess = sal_False;
300*cdf0e10cSrcweir             else if ( nDateTokens >= 3 )
301*cdf0e10cSrcweir             {
302*cdf0e10cSrcweir                 nDay = aDateStr.getToken( 0, '-', n ).toInt32();
303*cdf0e10cSrcweir                 if ( nDay > 31 )
304*cdf0e10cSrcweir                     bSuccess = sal_False;
305*cdf0e10cSrcweir             }
306*cdf0e10cSrcweir         }
307*cdf0e10cSrcweir     }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     if ( bSuccess && aTimeStr.getLength() > 0 )         // time is optional
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir         pStr = aTimeStr.getStr();
312*cdf0e10cSrcweir         sal_Int32 nTimeTokens = 1;
313*cdf0e10cSrcweir         while ( *pStr )
314*cdf0e10cSrcweir         {
315*cdf0e10cSrcweir             if ( *pStr == ':' )
316*cdf0e10cSrcweir                 nTimeTokens++;
317*cdf0e10cSrcweir             pStr++;
318*cdf0e10cSrcweir         }
319*cdf0e10cSrcweir         if ( nTimeTokens > 3 )
320*cdf0e10cSrcweir             bSuccess = sal_False;
321*cdf0e10cSrcweir         else
322*cdf0e10cSrcweir         {
323*cdf0e10cSrcweir             sal_Int32 n = 0;
324*cdf0e10cSrcweir             nHour = aTimeStr.getToken( 0, ':', n ).toInt32();
325*cdf0e10cSrcweir             if ( nHour > 23 )
326*cdf0e10cSrcweir                 bSuccess = sal_False;
327*cdf0e10cSrcweir             else if ( nTimeTokens >= 2 )
328*cdf0e10cSrcweir             {
329*cdf0e10cSrcweir                 nMin = aTimeStr.getToken( 0, ':', n ).toInt32();
330*cdf0e10cSrcweir                 if ( nMin > 59 )
331*cdf0e10cSrcweir                     bSuccess = sal_False;
332*cdf0e10cSrcweir                 else if ( nTimeTokens >= 3 )
333*cdf0e10cSrcweir                 {
334*cdf0e10cSrcweir                     nSec = aTimeStr.getToken( 0, ':', n ).toInt32();
335*cdf0e10cSrcweir                     if ( nSec > 59 )
336*cdf0e10cSrcweir                         bSuccess = sal_False;
337*cdf0e10cSrcweir                 }
338*cdf0e10cSrcweir             }
339*cdf0e10cSrcweir         }
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir     if ( bSuccess )
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         rDateTime.Day = sal::static_int_cast< sal_uInt16 >(nDay);
345*cdf0e10cSrcweir         rDateTime.Month = sal::static_int_cast< sal_uInt16 >(nMonth);
346*cdf0e10cSrcweir         rDateTime.Year = sal::static_int_cast< sal_uInt16 >(nYear);
347*cdf0e10cSrcweir         rDateTime.Hours = sal::static_int_cast< sal_uInt16 >(nHour);
348*cdf0e10cSrcweir         rDateTime.Minutes = sal::static_int_cast< sal_uInt16 >(nMin);
349*cdf0e10cSrcweir         rDateTime.Seconds = sal::static_int_cast< sal_uInt16 >(nSec);
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     return bSuccess;
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir // ------------------------------------------------------------------------
357*cdf0e10cSrcweir // ------------------------------------------------------------------------
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir void SAL_CALL XMLVersionListPersistence::store( const uno::Reference< embed::XStorage >& xRoot, const uno::Sequence< util::RevisionTag >& rVersions )
360*cdf0e10cSrcweir     throw (::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     // no storage, no version list!
363*cdf0e10cSrcweir     if ( xRoot.is() )
364*cdf0e10cSrcweir     {
365*cdf0e10cSrcweir         // get the services needed for writing the xml data
366*cdf0e10cSrcweir         Reference< lang::XMultiServiceFactory > xServiceFactory =
367*cdf0e10cSrcweir                 comphelper::getProcessServiceFactory();
368*cdf0e10cSrcweir         DBG_ASSERT( xServiceFactory.is(), "XMLReader::Read: got no service manager" );
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         Reference< XInterface > xWriter (xServiceFactory->createInstance(
371*cdf0e10cSrcweir                 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer"))));
372*cdf0e10cSrcweir         DBG_ASSERT( xWriter.is(), "com.sun.star.xml.sax.Writer service missing" );
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir         // check wether there's already a sub storage with the version info
375*cdf0e10cSrcweir         // and delete it
376*cdf0e10cSrcweir         OUString sVerName( RTL_CONSTASCII_USTRINGPARAM( XMLN_VERSIONSLIST ) );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         // is this really needed, we set the size to zero before doing
379*cdf0e10cSrcweir         // anything with this stream?
380*cdf0e10cSrcweir /*      if ( xRoot->IsContained( sVerName ) )
381*cdf0e10cSrcweir         {
382*cdf0e10cSrcweir             xRoot->Remove( sVerName );
383*cdf0e10cSrcweir             xRoot->Commit();
384*cdf0e10cSrcweir         }
385*cdf0e10cSrcweir */
386*cdf0e10cSrcweir 		try {
387*cdf0e10cSrcweir         	// open (create) the sub storage with the version info
388*cdf0e10cSrcweir         	uno::Reference< io::XStream > xVerStream = xRoot->openStreamElement(
389*cdf0e10cSrcweir 											sVerName,
390*cdf0e10cSrcweir 											embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
391*cdf0e10cSrcweir 			if ( !xVerStream.is() )
392*cdf0e10cSrcweir 				throw uno::RuntimeException();
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir //REMOVE	        	// SetSize should not be neccessary because OpenStream( WRITE|TRUNC ) should already
395*cdf0e10cSrcweir //REMOVE	        	// have set the size to zero
396*cdf0e10cSrcweir //REMOVE		//      xVerStream->SetSize ( 0L );
397*cdf0e10cSrcweir //REMOVE	        	xVerStream->SetBufferSize( 16*1024 );
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir         	Reference< io::XOutputStream > xOut = xVerStream->getOutputStream();
400*cdf0e10cSrcweir 			if ( !xOut.is() )
401*cdf0e10cSrcweir 				throw uno::RuntimeException(); // the stream was successfuly opened for writing already
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         	Reference< io::XActiveDataSource > xSrc( xWriter, uno::UNO_QUERY );
404*cdf0e10cSrcweir         	xSrc->setOutputStream(xOut);
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir         	Reference< XDocumentHandler > xHandler( xWriter, uno::UNO_QUERY );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir             // XMLVersionListExport aExp( pList, sVerName, xHandler );
409*cdf0e10cSrcweir             XMLVersionListExport aExp( xServiceFactory, rVersions, sVerName, xHandler );
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir         	aExp.exportDoc( ::xmloff::token::XML_VERSION );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir //REMOVE	        	xVerStream->Commit();
414*cdf0e10cSrcweir 			xVerStream = uno::Reference< io::XStream >(); // use refcounting for now to dispose
415*cdf0e10cSrcweir 	//      xRoot->Commit();
416*cdf0e10cSrcweir 		}
417*cdf0e10cSrcweir 		catch( uno::Exception& )
418*cdf0e10cSrcweir 		{
419*cdf0e10cSrcweir             // TODO: error handling
420*cdf0e10cSrcweir 		}
421*cdf0e10cSrcweir     }
422*cdf0e10cSrcweir }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir // ------------------------------------------------------------------------
425*cdf0e10cSrcweir uno::Sequence< util::RevisionTag > SAL_CALL XMLVersionListPersistence::load( const uno::Reference< embed::XStorage >& xRoot )
426*cdf0e10cSrcweir         throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir     com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag > aVersions;
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir     const OUString sDocName( RTL_CONSTASCII_USTRINGPARAM( XMLN_VERSIONSLIST ) );
431*cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xRootNames( xRoot, uno::UNO_QUERY );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	try {
434*cdf0e10cSrcweir     	if ( xRootNames.is() && xRootNames->hasByName( sDocName ) && xRoot->isStreamElement( sDocName ) )
435*cdf0e10cSrcweir     	{
436*cdf0e10cSrcweir         	Reference< lang::XMultiServiceFactory > xServiceFactory =
437*cdf0e10cSrcweir                 	comphelper::getProcessServiceFactory();
438*cdf0e10cSrcweir         	DBG_ASSERT( xServiceFactory.is(), "XMLReader::Read: got no service manager" );
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         	InputSource aParserInput;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xProps( xRoot, uno::UNO_QUERY );
443*cdf0e10cSrcweir 			OSL_ENSURE( xProps.is(), "Storage must implement XPropertySet!\n" );
444*cdf0e10cSrcweir 			if ( xProps.is() )
445*cdf0e10cSrcweir 			{
446*cdf0e10cSrcweir 				try {
447*cdf0e10cSrcweir 					xProps->getPropertyValue( ::rtl::OUString::createFromAscii( "URL" ) ) >>= aParserInput.sSystemId;
448*cdf0e10cSrcweir 				}
449*cdf0e10cSrcweir 				catch( uno::Exception& )
450*cdf0e10cSrcweir 				{}
451*cdf0e10cSrcweir 			}
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir         	uno::Reference< io::XStream > xDocStream = xRoot->openStreamElement(
454*cdf0e10cSrcweir 															sDocName,
455*cdf0e10cSrcweir 															embed::ElementModes::READ );
456*cdf0e10cSrcweir 			if ( !xDocStream.is() )
457*cdf0e10cSrcweir 				throw uno::RuntimeException();
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir //REMOVE	        	xDocStream->Seek( 0L );
460*cdf0e10cSrcweir //REMOVE	        	xDocStream->SetBufferSize( 16*1024 );
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir         	aParserInput.aInputStream = xDocStream->getInputStream();
463*cdf0e10cSrcweir 			OSL_ENSURE( aParserInput.aInputStream.is(),
464*cdf0e10cSrcweir 						"The stream was successfuly opened for reading, the input part must be accessible!\n" );
465*cdf0e10cSrcweir 			if ( !aParserInput.aInputStream.is() )
466*cdf0e10cSrcweir 				throw uno::RuntimeException();
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir         	// get parser
469*cdf0e10cSrcweir         	Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
470*cdf0e10cSrcweir             	OUString::createFromAscii("com.sun.star.xml.sax.Parser") );
471*cdf0e10cSrcweir         	DBG_ASSERT( xXMLParser.is(),
472*cdf0e10cSrcweir             		"XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir         	// get filter
475*cdf0e10cSrcweir             // Reference< XDocumentHandler > xFilter = new XMLVersionListImport( pList );
476*cdf0e10cSrcweir             Reference< XDocumentHandler > xFilter = new XMLVersionListImport( xServiceFactory, aVersions );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir         	// connect parser and filter
479*cdf0e10cSrcweir         	Reference< XParser > xParser( xXMLParser, UNO_QUERY );
480*cdf0e10cSrcweir         	xParser->setDocumentHandler( xFilter );
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir         	// parse
483*cdf0e10cSrcweir         	try
484*cdf0e10cSrcweir         	{
485*cdf0e10cSrcweir             	xParser->parseStream( aParserInput );
486*cdf0e10cSrcweir         	}
487*cdf0e10cSrcweir         	catch( SAXParseException&  ) {}
488*cdf0e10cSrcweir         	catch( SAXException&  )      {}
489*cdf0e10cSrcweir         	catch( io::IOException& )    {}
490*cdf0e10cSrcweir     	}
491*cdf0e10cSrcweir 	}
492*cdf0e10cSrcweir 	catch( uno::Exception& )
493*cdf0e10cSrcweir 	{
494*cdf0e10cSrcweir         // TODO: error handling
495*cdf0e10cSrcweir 	}
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir     return aVersions;
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL XMLVersionListPersistence_getSupportedServiceNames()
501*cdf0e10cSrcweir 	throw()
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir 	const rtl::OUString aServiceName(
504*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.DocumentRevisionListPersistence" ) );
505*cdf0e10cSrcweir 	const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
506*cdf0e10cSrcweir 	return aSeq;
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir rtl::OUString SAL_CALL XMLVersionListPersistence_getImplementationName() throw()
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLVersionListPersistence" ) );
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL XMLVersionListPersistence_createInstance(
515*cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory > &)
516*cdf0e10cSrcweir 	throw( uno::Exception )
517*cdf0e10cSrcweir {
518*cdf0e10cSrcweir     return (cppu::OWeakObject*)new XMLVersionListPersistence;
519*cdf0e10cSrcweir }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL XMLVersionImExportOOO_getSupportedServiceNames()
522*cdf0e10cSrcweir 	throw()
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir 	const rtl::OUString aServiceName(
525*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.DocumentRevisionListPersistence" ) );
526*cdf0e10cSrcweir 	const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
527*cdf0e10cSrcweir 	return aSeq;
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir rtl::OUString SAL_CALL XMLVersionImExportOOO_getImplementationName() throw()
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLVersionImExportOOo" ) );
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL XMLVersionImExportOOO_createInstance(
536*cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory > &)
537*cdf0e10cSrcweir 	throw( uno::Exception )
538*cdf0e10cSrcweir {
539*cdf0e10cSrcweir     return (cppu::OWeakObject*)new XMLVersionListPersistence;
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542