/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
{ if ( !m_nInBlock && !m_nState )
{ if ( nElement == COREPR_TOKEN( coreProperties )
|| nElement == EXTPR_TOKEN( Properties )
|| nElement == CUSTPR_TOKEN( Properties ) )
{
m_nState = nElement;
} else
{
OSL_FAIL( "Unexpected file format!" );
}
} elseif ( m_nState && m_nInBlock == 1 ) // that tag should contain the property name
{ // Currently the attributes are ignored for the core properties since the only // known attribute is xsi:type that can only be used with dcterms:created and // dcterms:modified, and this element is allowed currently to have only one value dcterms:W3CDTF
m_nBlock = nElement;
if ( !m_nInBlock )
m_nState = 0; elseif ( m_nInBlock == 1 )
{
m_nBlock = 0;
m_aCustomPropertyName.clear();
} elseif ( m_nInBlock == 2 )
{ if ( m_nState == CUSTPR_TOKEN(Properties)
&& m_nBlock == CUSTPR_TOKEN(property))
{ switch (m_nType)
{ case VT_TOKEN(bstr): case VT_TOKEN(lpstr): case VT_TOKEN(lpwstr): if (!m_aCustomPropertyName.isEmpty() &&
INSERTED != m_CustomStringPropertyState)
{ // the property has string type, so it is valid // even with an empty value - characters() has // not been called in that case
AddCustomProperty(uno::Any(OUString()));
} break;
}
}
m_CustomStringPropertyState = NONE;
m_nType = 0;
}
}
void SAL_CALL OOXMLDocPropHandler::characters( const OUString& aChars )
{ try
{ if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) )
{ if ( m_nState == COREPR_TOKEN( coreProperties ) )
{ switch( m_nBlock )
{ case COREPR_TOKEN( category ):
m_aCustomPropertyName = "OOXMLCorePropertyCategory";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case COREPR_TOKEN( contentStatus ):
m_aCustomPropertyName = "OOXMLCorePropertyContentStatus";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case COREPR_TOKEN( contentType ):
m_aCustomPropertyName = "OOXMLCorePropertyContentType";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case DC_TOKEN( identifier ):
m_aCustomPropertyName = "OOXMLCorePropertyIdentifier";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case COREPR_TOKEN( version ):
m_aCustomPropertyName = "OOXMLCorePropertyVersion";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case DCT_TOKEN( created ): if ( aChars.getLength() >= 4 )
m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) ); break;
case DC_TOKEN( creator ):
m_xDocProp->setAuthor( aChars ); break;
case DC_TOKEN( description ):
m_xDocProp->setDescription( aChars ); break;
case COREPR_TOKEN( keywords ):
m_xDocProp->setKeywords( GetKeywordsSet( aChars ) ); break;
case DC_TOKEN( language ): if ( aChars.getLength() >= 2 )
m_xDocProp->setLanguage( LanguageTag::convertToLocale( aChars) ); break;
case COREPR_TOKEN( lastModifiedBy ):
m_xDocProp->setModifiedBy( aChars ); break;
case COREPR_TOKEN( lastPrinted ): if ( aChars.getLength() >= 4 )
m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) ); break;
case DCT_TOKEN( modified ): if ( aChars.getLength() >= 4 )
m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) ); break;
case EXTPR_TOKEN( Template ):
m_xDocProp->setTemplateName( aChars ); break;
case EXTPR_TOKEN( TotalTime ):
{
sal_Int32 nDuration; if (!o3tl::checked_multiply<sal_Int32>(aChars.toInt32(), 60, nDuration))
{ try
{ // The TotalTime is in mins as per ECMA specification.
m_xDocProp->setEditingDuration(nDuration);
} catch (const lang::IllegalArgumentException&)
{ // ignore
}
} break;
} case EXTPR_TOKEN( Characters ): case EXTPR_TOKEN( CharactersWithSpaces ): case EXTPR_TOKEN( Pages ): case EXTPR_TOKEN( Words ): case EXTPR_TOKEN( Paragraphs ):
UpdateDocStatistic( aChars ); break;
case EXTPR_TOKEN( HyperlinksChanged ):
m_aCustomPropertyName = "HyperlinksChanged"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toBoolean() )
AddCustomProperty( uno::Any( aChars.toBoolean() ) ); // the property has boolean type break;
case EXTPR_TOKEN( LinksUpToDate ):
m_aCustomPropertyName = "LinksUpToDate"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toBoolean() )
AddCustomProperty( uno::Any( aChars.toBoolean() ) ); // the property has boolean type break;
case EXTPR_TOKEN( ScaleCrop ):
m_aCustomPropertyName = "ScaleCrop"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toBoolean() )
AddCustomProperty( uno::Any( aChars.toBoolean() ) ); // the property has boolean type break;
case EXTPR_TOKEN( SharedDoc ):
m_aCustomPropertyName = "ShareDoc"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toBoolean() )
AddCustomProperty( uno::Any( aChars.toBoolean() ) ); // the property has boolean type break;
case EXTPR_TOKEN( DocSecurity ):
m_aCustomPropertyName = "DocSecurity"; // tdf#103987 Don't create custom property if the value is default // OOXTODO Instead of storing value, enable security // 1 - password protected, 2 - recommended read-only // 4 - enforced read-only, 8 - locked for annotation if ( aChars.toInt32() != 0 )
AddCustomProperty( uno::Any( aChars.toInt32() ) ); // the property has sal_Int32 type break;
case EXTPR_TOKEN( HiddenSlides ):
m_aCustomPropertyName = "HiddenSlides"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toInt32() != 0 )
AddCustomProperty( uno::Any( aChars.toInt32() ) ); // the property has sal_Int32 type break;
case EXTPR_TOKEN( MMClips ):
m_aCustomPropertyName = "MMClips"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toInt32() != 0 )
AddCustomProperty( uno::Any( aChars.toInt32() ) ); // the property has sal_Int32 type break;
case EXTPR_TOKEN( Notes ):
m_aCustomPropertyName = "Notes"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toInt32() != 0 )
AddCustomProperty( uno::Any( aChars.toInt32() ) ); // the property has sal_Int32 type break;
case EXTPR_TOKEN( Slides ):
m_aCustomPropertyName = "Slides"; // tdf#103987 Don't create custom property if the value is default if ( aChars.toInt32() != 0 )
AddCustomProperty( uno::Any( aChars.toInt32() ) ); // the property has sal_Int32 type break;
case EXTPR_TOKEN( AppVersion ):
m_aCustomPropertyName = "AppVersion";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case EXTPR_TOKEN( Company ):
m_aCustomPropertyName = "Company";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case EXTPR_TOKEN( HyperlinkBase ):
m_aCustomPropertyName = "HyperlinkBase";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case EXTPR_TOKEN( Manager ):
m_aCustomPropertyName = "Manager";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case EXTPR_TOKEN( PresentationFormat ):
m_aCustomPropertyName = "PresentationFormat";
AddCustomProperty( uno::Any( aChars ) ); // the property has string type break;
case EXTPR_TOKEN( Lines ): case EXTPR_TOKEN( DigSig ): case EXTPR_TOKEN( HeadingPairs ): case EXTPR_TOKEN( HLinks ): case EXTPR_TOKEN( TitlesOfParts ): // ignored during the import currently break;
default:
OSL_FAIL( "Unexpected extended property!" );
}
} elseif ( m_nState == CUSTPR_TOKEN( Properties ) )
{ if ( m_nBlock == CUSTPR_TOKEN( property ) )
{ // this is a custom property switch( m_nType )
{ case VT_TOKEN( bool ):
AddCustomProperty( uno::Any( aChars.toBoolean() ) ); break;
case VT_TOKEN( bstr ): case VT_TOKEN( lpstr ): case VT_TOKEN( lpwstr ): // the property has string type
AddCustomProperty( uno::Any( AttributeConversion::decodeXString( aChars ) ) );
m_CustomStringPropertyState = INSERTED; break;
case VT_TOKEN( date ): case VT_TOKEN( filetime ):
AddCustomProperty( uno::Any( GetDateTimeFromW3CDTF( aChars ) ) ); break;
case VT_TOKEN( i1 ): case VT_TOKEN( i2 ):
AddCustomProperty( uno::Any( static_cast<sal_Int16>(aChars.toInt32()) ) ); break;
case VT_TOKEN( i4 ): case VT_TOKEN( int ):
AddCustomProperty( uno::Any( aChars.toInt32() ) ); break;
case VT_TOKEN( i8 ):
AddCustomProperty( uno::Any( aChars.toInt64() ) ); break;
case VT_TOKEN( r4 ):
AddCustomProperty( uno::Any( aChars.toFloat() ) ); break;
case VT_TOKEN( r8 ):
AddCustomProperty( uno::Any( aChars.toDouble() ) ); break;
default: // all the other types are ignored; break;
}
} else
{
OSL_FAIL( "Unexpected tag in custom property!" );
}
}
}
} catch( uno::RuntimeException& )
{ throw;
} catch( xml::sax::SAXException& )
{ throw;
} catch( uno::Exception& )
{
css::uno::Any anyEx = cppu::getCaughtException(); throw xml::sax::SAXException(
u"Error while setting document property!"_ustr,
uno::Reference< uno::XInterface >(),
anyEx );
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.