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 #include "docprophandler.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyExistException.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <osl/time.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace ::com::sun::star; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace oox { 41*cdf0e10cSrcweir namespace docprop { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // ------------------------------------------------ 44*cdf0e10cSrcweir OOXMLDocPropHandler::OOXMLDocPropHandler( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< document::XDocumentProperties > xDocProp ) 45*cdf0e10cSrcweir : m_xContext( xContext ) 46*cdf0e10cSrcweir , m_xDocProp( xDocProp ) 47*cdf0e10cSrcweir , m_nState( 0 ) 48*cdf0e10cSrcweir , m_nBlock( 0 ) 49*cdf0e10cSrcweir , m_nType( 0 ) 50*cdf0e10cSrcweir , m_nInBlock( 0 ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir if ( !xContext.is() || !xDocProp.is() ) 53*cdf0e10cSrcweir throw uno::RuntimeException(); 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // ------------------------------------------------ 57*cdf0e10cSrcweir OOXMLDocPropHandler::~OOXMLDocPropHandler() 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // ------------------------------------------------ 62*cdf0e10cSrcweir void OOXMLDocPropHandler::InitNew() 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir m_nState = 0; 65*cdf0e10cSrcweir m_nBlock = 0; 66*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString(); 67*cdf0e10cSrcweir m_nType = 0; 68*cdf0e10cSrcweir m_nInBlock = 0; 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // ------------------------------------------------ 72*cdf0e10cSrcweir void OOXMLDocPropHandler::AddCustomProperty( const uno::Any& aAny ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir if ( m_aCustomPropertyName.getLength() ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir const uno::Reference< beans::XPropertyContainer > xUserProps = 77*cdf0e10cSrcweir m_xDocProp->getUserDefinedProperties(); 78*cdf0e10cSrcweir if ( !xUserProps.is() ) 79*cdf0e10cSrcweir throw uno::RuntimeException(); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir try 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir xUserProps->addProperty( m_aCustomPropertyName, 84*cdf0e10cSrcweir beans::PropertyAttribute::REMOVEABLE, aAny ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir catch( beans::PropertyExistException& ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir // conflicts with core and extended properties are possible 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir catch( uno::Exception& ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir OSL_ASSERT( "Can not add custom property!" ); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // ------------------------------------------------ 98*cdf0e10cSrcweir util::DateTime OOXMLDocPropHandler::GetDateTimeFromW3CDTF( const ::rtl::OUString& aChars ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir oslDateTime aOslDTime = { 0, 0, 0, 0, 0, 0, 0, 0 }; 101*cdf0e10cSrcweir sal_Int32 nLen = aChars.getLength(); 102*cdf0e10cSrcweir if ( nLen >= 4 ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir aOslDTime.Year = (sal_uInt16)aChars.copy( 0, 4 ).toInt32(); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir if ( nLen >= 7 && aChars.getStr()[4] == (sal_Unicode)'-' ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir aOslDTime.Month = (sal_uInt16)aChars.copy( 5, 2 ).toInt32(); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir if ( nLen >= 10 && aChars.getStr()[7] == (sal_Unicode)'-' ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir aOslDTime.Day = (sal_uInt16)aChars.copy( 8, 2 ).toInt32(); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir if ( nLen >= 16 && aChars.getStr()[10] == (sal_Unicode)'T' && aChars.getStr()[13] == (sal_Unicode)':' ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir aOslDTime.Hours = (sal_uInt16)aChars.copy( 11, 2 ).toInt32(); 117*cdf0e10cSrcweir aOslDTime.Minutes = (sal_uInt16)aChars.copy( 14, 2 ).toInt32(); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir sal_Int32 nOptTime = 0; 120*cdf0e10cSrcweir if ( nLen >= 19 && aChars.getStr()[16] == (sal_Unicode)':' ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir aOslDTime.Seconds = (sal_uInt16)aChars.copy( 17, 2 ).toInt32(); 123*cdf0e10cSrcweir nOptTime += 3; 124*cdf0e10cSrcweir if ( nLen >= 21 && aChars.getStr()[19] == (sal_Unicode)'.' ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir aOslDTime.NanoSeconds = (sal_uInt32)(aChars.copy( 20, 1 ).toInt32() * 10e8); 127*cdf0e10cSrcweir nOptTime += 2; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir sal_Int32 nModif = 0; 132*cdf0e10cSrcweir if ( nLen >= 16 + nOptTime + 6 ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir if ( ( aChars.getStr()[16 + nOptTime] == (sal_Unicode)'+' || aChars.getStr()[16 + nOptTime] == (sal_Unicode)'-' ) 135*cdf0e10cSrcweir && aChars.getStr()[16 + nOptTime + 3] == (sal_Unicode)':' ) 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir nModif = aChars.copy( 16 + nOptTime + 1, 2 ).toInt32() * 3600; 139*cdf0e10cSrcweir nModif += aChars.copy( 16 + nOptTime + 4, 2 ).toInt32() * 60; 140*cdf0e10cSrcweir if ( aChars.getStr()[16 + nOptTime] == (sal_Unicode)'-' ) 141*cdf0e10cSrcweir nModif *= -1; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir if ( nModif ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir // convert to UTC time 148*cdf0e10cSrcweir TimeValue aTmp; 149*cdf0e10cSrcweir if ( osl_getTimeValueFromDateTime( &aOslDTime, &aTmp ) ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir aTmp.Seconds += nModif; 152*cdf0e10cSrcweir osl_getDateTimeFromTimeValue( &aTmp, &aOslDTime ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir return util::DateTime( (sal_uInt16)( aOslDTime.NanoSeconds / 1e7 ), aOslDTime.Seconds, aOslDTime.Minutes, aOslDTime.Hours, aOslDTime.Day, aOslDTime.Month, aOslDTime.Year ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // ------------------------------------------------ 164*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > OOXMLDocPropHandler::GetKeywordsSet( const ::rtl::OUString& aChars ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir if ( aChars.getLength() ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aResult( 20 ); 169*cdf0e10cSrcweir sal_Int32 nCounter = 0; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir const sal_Unicode* pStr = aChars.getStr(); 172*cdf0e10cSrcweir for( sal_Int32 nInd = 0; nInd < aChars.getLength() && pStr[nInd] != 0; nInd++ ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir switch( pStr[nInd] ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir case (sal_Unicode)' ': 177*cdf0e10cSrcweir case (sal_Unicode)',': 178*cdf0e10cSrcweir case (sal_Unicode)';': 179*cdf0e10cSrcweir case (sal_Unicode)':': 180*cdf0e10cSrcweir case (sal_Unicode)'\t': 181*cdf0e10cSrcweir // this is a delimiter 182*cdf0e10cSrcweir // unfortunately I did not find any specification for the possible delimiters 183*cdf0e10cSrcweir if ( aResult[nCounter].getLength() ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir if ( nCounter >= aResult.getLength() ) 186*cdf0e10cSrcweir aResult.realloc( nCounter + 10 ); 187*cdf0e10cSrcweir nCounter++; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir break; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir default: 192*cdf0e10cSrcweir // this should be a part of keyword 193*cdf0e10cSrcweir aResult[nCounter] += ::rtl::OUString( (sal_Unicode)pStr[nInd] ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir aResult.realloc( nCounter + 1 ); 198*cdf0e10cSrcweir return aResult; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir return uno::Sequence< ::rtl::OUString >(); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir // ------------------------------------------------ 204*cdf0e10cSrcweir lang::Locale OOXMLDocPropHandler::GetLanguage( const ::rtl::OUString& aChars ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir lang::Locale aResult; 207*cdf0e10cSrcweir if ( aChars.getLength() >= 2 ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir aResult.Language = aChars.copy( 0, 2 ); 210*cdf0e10cSrcweir if ( aChars.getLength() >= 5 && aChars.getStr()[2] == (sal_Unicode)'-' ) 211*cdf0e10cSrcweir aResult.Country = aChars.copy( 3, 2 ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // TODO/LATER: the variant could be also detected 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir return aResult; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // ------------------------------------------------ 220*cdf0e10cSrcweir void OOXMLDocPropHandler::UpdateDocStatistic( const ::rtl::OUString& aChars ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aSet = m_xDocProp->getDocumentStatistics(); 223*cdf0e10cSrcweir ::rtl::OUString aName; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir switch( m_nBlock ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir case EXTPR_TOKEN( Characters ): 228*cdf0e10cSrcweir aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterCount" ) ); 229*cdf0e10cSrcweir break; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir case EXTPR_TOKEN( Pages ): 232*cdf0e10cSrcweir aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageCount" ) ); 233*cdf0e10cSrcweir break; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir case EXTPR_TOKEN( Words ): 236*cdf0e10cSrcweir aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WordCount" ) ); 237*cdf0e10cSrcweir break; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir case EXTPR_TOKEN( Paragraphs ): 240*cdf0e10cSrcweir aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphCount" ) ); 241*cdf0e10cSrcweir break; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir default: 244*cdf0e10cSrcweir OSL_ASSERT( "Unexpected statistic!" ); 245*cdf0e10cSrcweir break; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir if ( aName.getLength() ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir sal_Bool bFound = sal_False; 251*cdf0e10cSrcweir sal_Int32 nLen = aSet.getLength(); 252*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) 253*cdf0e10cSrcweir if ( aSet[nInd].Name.equals( aName ) ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir aSet[nInd].Value = uno::makeAny( aChars.toInt32() ); 256*cdf0e10cSrcweir bFound = sal_True; 257*cdf0e10cSrcweir break; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir if ( !bFound ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir aSet.realloc( nLen + 1 ); 263*cdf0e10cSrcweir aSet[nLen].Name = aName; 264*cdf0e10cSrcweir aSet[nLen].Value = uno::makeAny( aChars.toInt32() ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir m_xDocProp->setDocumentStatistics( aSet ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // ------------------------------------------------ 272*cdf0e10cSrcweir // com.sun.star.xml.sax.XFastDocumentHandler 273*cdf0e10cSrcweir // ------------------------------------------------ 274*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::startDocument() 275*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir // ------------------------------------------------ 280*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::endDocument() 281*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir InitNew(); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // ------------------------------------------------ 287*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& ) 288*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir // com.sun.star.xml.sax.XFastContextHandler 294*cdf0e10cSrcweir // ------------------------------------------------ 295*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs ) 296*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir if ( !m_nInBlock && !m_nState ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir if ( nElement == COREPR_TOKEN( coreProperties ) 301*cdf0e10cSrcweir || nElement == EXTPR_TOKEN( Properties ) 302*cdf0e10cSrcweir || nElement == CUSTPR_TOKEN( Properties ) ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir m_nState = nElement; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir else 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir OSL_ASSERT( "Unexpected file format!" ); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir else if ( m_nState && m_nInBlock == 1 ) // that tag should contain the property name 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir // Currently the attributes are ignored for the core properties since the only 314*cdf0e10cSrcweir // known attribute is xsi:type that can only be used with dcterms:created and 315*cdf0e10cSrcweir // dcterms:modified, and this element is allowed currently to have only one value dcterms:W3CDTF 316*cdf0e10cSrcweir m_nBlock = nElement; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) ) 319*cdf0e10cSrcweir m_aCustomPropertyName = xAttribs->getValue( XML_name ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir else if ( m_nState && m_nInBlock && m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir m_nType = nElement; 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir else 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir OSL_ASSERT( "For now unexpected tags are ignored!" ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir if ( m_nInBlock == SAL_MAX_INT32 ) 331*cdf0e10cSrcweir throw uno::RuntimeException(); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir m_nInBlock++; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // ------------------------------------------------ 337*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::startUnknownElement( const ::rtl::OUString& aNamespace, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XFastAttributeList >& ) 338*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir ::rtl::OUString aUnknown = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown element" ) ); 341*cdf0e10cSrcweir aUnknown += aNamespace; 342*cdf0e10cSrcweir aUnknown += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":" ) ); 343*cdf0e10cSrcweir aUnknown += aName; 344*cdf0e10cSrcweir OSL_ASSERT( ::rtl::OUStringToOString( aUnknown, RTL_TEXTENCODING_UTF8 ).getStr() ); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir if ( m_nInBlock == SAL_MAX_INT32 ) 347*cdf0e10cSrcweir throw uno::RuntimeException(); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir m_nInBlock++; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // ------------------------------------------------ 353*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::endFastElement( ::sal_Int32 ) 354*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir if ( m_nInBlock ) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir m_nInBlock--; 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir if ( !m_nInBlock ) 361*cdf0e10cSrcweir m_nState = 0; 362*cdf0e10cSrcweir else if ( m_nInBlock == 1 ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir m_nBlock = 0; 365*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString(); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir else if ( m_nInBlock == 2 ) 368*cdf0e10cSrcweir m_nType = 0; 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir // ------------------------------------------------ 373*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::endUnknownElement( const ::rtl::OUString&, const ::rtl::OUString& ) 374*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir if ( m_nInBlock ) 377*cdf0e10cSrcweir m_nInBlock--; 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir // ------------------------------------------------ 381*cdf0e10cSrcweir uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createFastChildContext( ::sal_Int32, const uno::Reference< xml::sax::XFastAttributeList >& ) 382*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir // Should the arguments be parsed? 385*cdf0e10cSrcweir return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // ------------------------------------------------ 389*cdf0e10cSrcweir uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createUnknownChildContext( const ::rtl::OUString&, const ::rtl::OUString&, const uno::Reference< xml::sax::XFastAttributeList >& ) 390*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir // ------------------------------------------------ 396*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars ) 397*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir try 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir if ( m_nState == COREPR_TOKEN( coreProperties ) ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir switch( m_nBlock ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir case COREPR_TOKEN( category ): 408*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "category" ) ); 409*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 410*cdf0e10cSrcweir break; 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir case COREPR_TOKEN( contentStatus ): 413*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentStatus" ) ); 414*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 415*cdf0e10cSrcweir break; 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir case COREPR_TOKEN( contentType ): 418*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentType" ) ); 419*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 420*cdf0e10cSrcweir break; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir case COREPR_TOKEN( identifier ): 423*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "identifier" ) ); 424*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 425*cdf0e10cSrcweir break; 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir case COREPR_TOKEN( version ): 428*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "version" ) ); 429*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 430*cdf0e10cSrcweir break; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir case DCT_TOKEN( created ): 433*cdf0e10cSrcweir if ( aChars.getLength() >= 4 ) 434*cdf0e10cSrcweir m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) ); 435*cdf0e10cSrcweir break; 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir case DC_TOKEN( creator ): 438*cdf0e10cSrcweir m_xDocProp->setAuthor( aChars ); 439*cdf0e10cSrcweir break; 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir case DC_TOKEN( description ): 442*cdf0e10cSrcweir m_xDocProp->setDescription( aChars ); 443*cdf0e10cSrcweir break; 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir case COREPR_TOKEN( keywords ): 446*cdf0e10cSrcweir m_xDocProp->setKeywords( GetKeywordsSet( aChars ) ); 447*cdf0e10cSrcweir break; 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir case DC_TOKEN( language ): 450*cdf0e10cSrcweir if ( aChars.getLength() >= 2 ) 451*cdf0e10cSrcweir m_xDocProp->setLanguage( GetLanguage( aChars ) ); 452*cdf0e10cSrcweir break; 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir case COREPR_TOKEN( lastModifiedBy ): 455*cdf0e10cSrcweir m_xDocProp->setModifiedBy( aChars ); 456*cdf0e10cSrcweir break; 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir case COREPR_TOKEN( lastPrinted ): 459*cdf0e10cSrcweir if ( aChars.getLength() >= 4 ) 460*cdf0e10cSrcweir m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) ); 461*cdf0e10cSrcweir break; 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir case DCT_TOKEN( modified ): 464*cdf0e10cSrcweir if ( aChars.getLength() >= 4 ) 465*cdf0e10cSrcweir m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) ); 466*cdf0e10cSrcweir break; 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir case COREPR_TOKEN( revision ): 469*cdf0e10cSrcweir try 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir m_xDocProp->setEditingCycles( 472*cdf0e10cSrcweir static_cast<sal_Int16>(aChars.toInt32()) ); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir catch (lang::IllegalArgumentException &) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir // ignore 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir break; 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir case DC_TOKEN( subject ): 481*cdf0e10cSrcweir m_xDocProp->setSubject( aChars ); 482*cdf0e10cSrcweir break; 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir case DC_TOKEN( title ): 485*cdf0e10cSrcweir m_xDocProp->setTitle( aChars ); 486*cdf0e10cSrcweir break; 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir default: 489*cdf0e10cSrcweir OSL_ASSERT( "Unexpected core property!" ); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir else if ( m_nState == EXTPR_TOKEN( Properties ) ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir switch( m_nBlock ) 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir case EXTPR_TOKEN( Application ): 497*cdf0e10cSrcweir m_xDocProp->setGenerator( aChars ); 498*cdf0e10cSrcweir break; 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir case EXTPR_TOKEN( Template ): 501*cdf0e10cSrcweir m_xDocProp->setTemplateName( aChars ); 502*cdf0e10cSrcweir break; 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir case EXTPR_TOKEN( TotalTime ): 505*cdf0e10cSrcweir try 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir m_xDocProp->setEditingDuration( aChars.toInt32() ); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir catch (lang::IllegalArgumentException &) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir // ignore 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir break; 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir case EXTPR_TOKEN( Characters ): 516*cdf0e10cSrcweir case EXTPR_TOKEN( Pages ): 517*cdf0e10cSrcweir case EXTPR_TOKEN( Words ): 518*cdf0e10cSrcweir case EXTPR_TOKEN( Paragraphs ): 519*cdf0e10cSrcweir UpdateDocStatistic( aChars ); 520*cdf0e10cSrcweir break; 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir case EXTPR_TOKEN( HyperlinksChanged ): 523*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinksChanged" ) ); 524*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type 525*cdf0e10cSrcweir break; 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir case EXTPR_TOKEN( LinksUpToDate ): 528*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LinksUpToDate" ) ); 529*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type 530*cdf0e10cSrcweir break; 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir case EXTPR_TOKEN( ScaleCrop ): 533*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleCrop" ) ); 534*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type 535*cdf0e10cSrcweir break; 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir case EXTPR_TOKEN( SharedDoc ): 538*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShareDoc" ) ); 539*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type 540*cdf0e10cSrcweir break; 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir case EXTPR_TOKEN( DocSecurity ): 543*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocSecurity" ) ); 544*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type 545*cdf0e10cSrcweir break; 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir case EXTPR_TOKEN( HiddenSlides ): 548*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HiddenSlides" ) ); 549*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type 550*cdf0e10cSrcweir break; 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir case EXTPR_TOKEN( MMClips ): 553*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MMClips" ) ); 554*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type 555*cdf0e10cSrcweir break; 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir case EXTPR_TOKEN( Notes ): 558*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Notes" ) ); 559*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type 560*cdf0e10cSrcweir break; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir case EXTPR_TOKEN( Slides ): 563*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Slides" ) ); 564*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type 565*cdf0e10cSrcweir break; 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir case EXTPR_TOKEN( AppVersion ): 568*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AppVersion" ) ); 569*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 570*cdf0e10cSrcweir break; 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir case EXTPR_TOKEN( Company ): 573*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Company" ) ); 574*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 575*cdf0e10cSrcweir break; 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir case EXTPR_TOKEN( HyperlinkBase ): 578*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinkBase" ) ); 579*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 580*cdf0e10cSrcweir break; 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir case EXTPR_TOKEN( Manager ): 583*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Manager" ) ); 584*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 585*cdf0e10cSrcweir break; 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir case EXTPR_TOKEN( PresentationFormat ): 588*cdf0e10cSrcweir m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PresentationFormat" ) ); 589*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type 590*cdf0e10cSrcweir break; 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir case EXTPR_TOKEN( CharactersWithSpaces ): 593*cdf0e10cSrcweir case EXTPR_TOKEN( Lines ): 594*cdf0e10cSrcweir case EXTPR_TOKEN( DigSig ): 595*cdf0e10cSrcweir case EXTPR_TOKEN( HeadingPairs ): 596*cdf0e10cSrcweir case EXTPR_TOKEN( HLinks ): 597*cdf0e10cSrcweir case EXTPR_TOKEN( TitlesOfParts ): 598*cdf0e10cSrcweir // ignored during the import currently 599*cdf0e10cSrcweir break; 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir default: 602*cdf0e10cSrcweir OSL_ASSERT( "Unexpected extended property!" ); 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir else if ( m_nState == CUSTPR_TOKEN( Properties ) ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir if ( m_nBlock == CUSTPR_TOKEN( property ) ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir // this is a custom property 610*cdf0e10cSrcweir switch( m_nType ) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir case VT_TOKEN( bool ): 613*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); 614*cdf0e10cSrcweir break; 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir case VT_TOKEN( bstr ): 617*cdf0e10cSrcweir case VT_TOKEN( lpstr ): 618*cdf0e10cSrcweir case VT_TOKEN( lpwstr ): 619*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( AttributeConversion::decodeXString( aChars ) ) ); // the property has string type 620*cdf0e10cSrcweir break; 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir case VT_TOKEN( date ): 623*cdf0e10cSrcweir case VT_TOKEN( filetime ): 624*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( GetDateTimeFromW3CDTF( aChars ) ) ); 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir case VT_TOKEN( i1 ): 627*cdf0e10cSrcweir case VT_TOKEN( i2 ): 628*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( (sal_Int16)aChars.toInt32() ) ); 629*cdf0e10cSrcweir break; 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir case VT_TOKEN( i4 ): 632*cdf0e10cSrcweir case VT_TOKEN( int ): 633*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); 634*cdf0e10cSrcweir break; 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir case VT_TOKEN( i8 ): 637*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toInt64() ) ); 638*cdf0e10cSrcweir break; 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir case VT_TOKEN( r4 ): 641*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toFloat() ) ); 642*cdf0e10cSrcweir break; 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir case VT_TOKEN( r8 ): 645*cdf0e10cSrcweir AddCustomProperty( uno::makeAny( aChars.toDouble() ) ); 646*cdf0e10cSrcweir break; 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir default: 649*cdf0e10cSrcweir // all the other types are ignored; 650*cdf0e10cSrcweir break; 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir else 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir OSL_ASSERT( "Unexpected tag in custom property!" ); 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir catch( uno::RuntimeException& ) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir throw; 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir catch( xml::sax::SAXException& ) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir throw; 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir catch( uno::Exception& e ) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir throw xml::sax::SAXException( 671*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Error while setting document property!" ) ), 672*cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 673*cdf0e10cSrcweir uno::makeAny( e ) ); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir // ------------------------------------------------ 678*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::ignorableWhitespace( const ::rtl::OUString& ) 679*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir // ------------------------------------------------ 684*cdf0e10cSrcweir void SAL_CALL OOXMLDocPropHandler::processingInstruction( const ::rtl::OUString&, const ::rtl::OUString& ) 685*cdf0e10cSrcweir throw (xml::sax::SAXException, uno::RuntimeException) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir } // namespace docprop 690*cdf0e10cSrcweir } // namespace oox 691*cdf0e10cSrcweir 692