/* -*- 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 . */ #include #include #include #include #include #include #include #include #include #include #include "docstat.hxx" #include "docsh.hxx" #include #include #include "xmlimp.hxx" #include "xmlexp.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::text; using namespace ::xmloff::token; uno::Reference SwXMLImport::GetDocumentProperties() const { if (IsOrganizerMode() || IsStylesOnlyMode() || IsBlockMode() || IsInsertMode()) { return nullptr; } uno::Reference const xDPS( GetModel(), UNO_QUERY_THROW); return xDPS->getDocumentProperties(); } SvXMLImportContext *SwXMLImport::CreateMetaContext( const OUString& rLocalName ) { SvXMLImportContext *pContext = nullptr; if (getImportFlags() & SvXMLImportFlags::META) { uno::Reference const xDocProps( GetDocumentProperties()); pContext = new SvXMLMetaDocumentContext(*this, XML_NAMESPACE_OFFICE, rLocalName, xDocProps); } if( !pContext ) pContext = new SvXMLImportContext( *this, XML_NAMESPACE_OFFICE, rLocalName ); return pContext; } enum SvXMLTokenMapAttrs { XML_TOK_META_STAT_TABLE = 1, XML_TOK_META_STAT_IMAGE = 2, XML_TOK_META_STAT_OLE = 4, XML_TOK_META_STAT_PAGE = 8, XML_TOK_META_STAT_PARA = 16, XML_TOK_META_STAT_WORD = 32, XML_TOK_META_STAT_CHAR = 64, XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR = 128, XML_TOK_META_STAT_END=XML_TOK_UNKNOWN }; struct statistic { SvXMLTokenMapAttrs token; const char* name; sal_uInt16 SwDocStat::* target16; sal_uLong SwDocStat::* target32; /* or 64, on LP64 platforms */ }; static const struct statistic s_stats [] = { { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTable, nullptr }, { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf, nullptr }, { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE, nullptr }, { XML_TOK_META_STAT_PAGE, "PageCount", nullptr, &SwDocStat::nPage }, { XML_TOK_META_STAT_PARA, "ParagraphCount", nullptr, &SwDocStat::nPara }, { XML_TOK_META_STAT_WORD, "WordCount", nullptr, &SwDocStat::nWord }, { XML_TOK_META_STAT_CHAR, "CharacterCount", nullptr, &SwDocStat::nChar }, { XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR, "NonWhitespaceCharacterCount", nullptr, &SwDocStat::nCharExcludingSpaces }, { XML_TOK_META_STAT_END, nullptr, nullptr, nullptr } }; void SwXMLImport::SetStatistics( const Sequence< beans::NamedValue > & i_rStats) { if( IsStylesOnlyMode() || IsInsertMode() ) return; SvXMLImport::SetStatistics(i_rStats); SwDoc *pDoc = SwImport::GetDocFromXMLImport( *this ); SwDocStat aDocStat( pDoc->getIDocumentStatistics().GetDocStat() ); sal_uInt32 nTokens = 0; for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) { for (struct statistic const* pStat = s_stats; pStat->name != nullptr; ++pStat) { if (i_rStats[i].Name.equalsAscii(pStat->name)) { sal_Int32 val = 0; if (i_rStats[i].Value >>= val) { if (pStat->target16 != nullptr) { aDocStat.*(pStat->target16) = static_cast (val); } else { aDocStat.*(pStat->target32) = static_cast (val); } nTokens |= pStat->token; } else { OSL_FAIL("SwXMLImport::SetStatistics: invalid entry"); } } } } if( nTokens ) pDoc->getIDocumentStatistics().SetDocStat( aDocStat ); // set progress bar reference to #paragraphs. If not available, // use #pages*10, or guesstimate 250 paragraphs. Additionally // guesstimate PROGRESS_BAR_STEPS each for meta+settings, styles, // and autostyles. sal_Int32 nProgressReference = 250; if( nTokens & XML_TOK_META_STAT_PARA ) nProgressReference = (sal_Int32)aDocStat.nPara; else if ( nTokens & XML_TOK_META_STAT_PAGE ) nProgressReference = 10 * (sal_Int32)aDocStat.nPage; ProgressBarHelper* pProgress = GetProgressBarHelper(); pProgress->SetReference( nProgressReference + 3*PROGRESS_BAR_STEP ); pProgress->SetValue( 0 ); } void SwXMLExport::ExportMeta_() { SvXMLExport::ExportMeta_(); if( !IsBlockMode() ) { if( IsShowProgress() ) { ProgressBarHelper *pProgress = GetProgressBarHelper(); pProgress->SetValue( pProgress->GetValue() + 2 ); } } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */