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