diff options
Diffstat (limited to '')
-rw-r--r-- | shell/source/win32/ooofilereader/autostyletag.cxx | 91 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/autostyletag.hxx | 66 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/basereader.cxx | 83 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/contentreader.cxx | 218 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/dummytag.hxx | 55 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/itag.hxx | 46 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/keywordstag.cxx | 55 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/keywordstag.hxx | 48 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/metainforeader.cxx | 285 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/simpletag.cxx | 57 | ||||
-rw-r--r-- | shell/source/win32/ooofilereader/simpletag.hxx | 52 |
11 files changed, 1056 insertions, 0 deletions
diff --git a/shell/source/win32/ooofilereader/autostyletag.cxx b/shell/source/win32/ooofilereader/autostyletag.cxx new file mode 100644 index 000000000..f2220d915 --- /dev/null +++ b/shell/source/win32/ooofilereader/autostyletag.cxx @@ -0,0 +1,91 @@ +/* -*- 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 "autostyletag.hxx" + +/*********************** CAutoStyleTag ***********************/ + +CAutoStyleTag::CAutoStyleTag( const XmlTagAttributes_t& attributes ): + m_CurrentStyleLocalePair( EMPTY_STYLELOCALE_PAIR ) +{ + addAttributes( attributes); +}; + +void CAutoStyleTag::startTag() +{ +} + +void CAutoStyleTag::endTag() +{ +} + +void CAutoStyleTag::addCharacters(const std::wstring&) +{ +} + +void CAutoStyleTag::addAttributes(const XmlTagAttributes_t& attributes) +{ + if ( EMPTY_STYLELOCALE_PAIR == m_CurrentStyleLocalePair ) + { + // the style-locale pair should be empty when entering STYLE_STYLE + // tag, and otherwise should be STYLE_PROPERTIES. + + XmlTagAttributes_t::const_iterator iter = attributes.find(CONTENT_STYLE_STYLE_NAME); + + if ( iter != attributes.end()) + setStyle( iter->second ); + } + else + { + // tag STYLE_PROPERTIES entered. + + XmlTagAttributes_t::const_iterator iter_lan = attributes.find(CONTENT_STYLE_PROPERTIES_LANGUAGE); + XmlTagAttributes_t::const_iterator iter_con = attributes.find(CONTENT_STYLE_PROPERTIES_COUNTRY); + XmlTagAttributes_t::const_iterator iter_lan_asain = attributes.find(CONTENT_STYLE_PROPERTIES_LANGUAGEASIAN); + XmlTagAttributes_t::const_iterator iter_con_asain = attributes.find(CONTENT_STYLE_PROPERTIES_COUNTRYASIAN); + + // if style:properties | fo:language or style:language-asian is exist, + // set the locale field, otherwise clear the style-locale pair; + if ( ( iter_lan!= attributes.end() ) && ( iter_con != attributes.end() ) ) + setLocale( ::std::make_pair( iter_lan->second,iter_con->second ) ); + else if ( ( iter_lan_asain!= attributes.end() ) && ( iter_con_asain != attributes.end() ) ) + setLocale( ::std::make_pair( iter_lan_asain->second,iter_con_asain->second ) ); + else + clearStyleLocalePair(); + } + +} + +void CAutoStyleTag::setStyle( ::std::wstring const & Style ) +{ + m_CurrentStyleLocalePair.first = Style; +} + +void CAutoStyleTag::setLocale(const LocaleSet_t& Locale) +{ + m_CurrentStyleLocalePair.second = Locale; +} + +void CAutoStyleTag::clearStyleLocalePair( ) +{ + m_CurrentStyleLocalePair = EMPTY_STYLELOCALE_PAIR; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/autostyletag.hxx b/shell/source/win32/ooofilereader/autostyletag.hxx new file mode 100644 index 000000000..2bfe4f8f4 --- /dev/null +++ b/shell/source/win32/ooofilereader/autostyletag.hxx @@ -0,0 +1,66 @@ +/* -*- 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 . + */ + + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_AUTOSTYLETAG_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_AUTOSTYLETAG_HXX + +#include "itag.hxx" + +/*************************** CAutoStyleTag tag readers ***************************/ + +/** Implements the ITag interface for + building a Style-Locale list + + Usage sample: + + LocaleSet_t locale = meta_info_accessor.getDefaultLocale(); + CContentReader content( m_szFileName, locale ); + CStyleMap map = content.getStyleMap(); +*/ +class CAutoStyleTag : public ITag +{ + public: + CAutoStyleTag():m_CurrentStyleLocalePair( EMPTY_STYLELOCALE_PAIR ){} + explicit CAutoStyleTag(const XmlTagAttributes_t& attributes); + + virtual void startTag() override; + virtual void endTag() override; + virtual void addCharacters(const std::wstring& characters) override; + virtual void addAttributes(const XmlTagAttributes_t& attributes) override; + virtual std::wstring getTagContent() override { return EMPTY_STRING; }; + virtual ::std::wstring getTagAttribute( ::std::wstring const & /*attrname*/ ) override { return ::std::wstring() ; } + + void setStyle( ::std::wstring const & Style ); + void setLocale(const LocaleSet_t& Locale); + void clearStyleLocalePair(); + StyleLocalePair_t getStyleLocalePair() const{ return m_CurrentStyleLocalePair; } + bool isFull() const + { + return (( m_CurrentStyleLocalePair.first != EMPTY_STRING )&& + ( m_CurrentStyleLocalePair.second != EMPTY_LOCALE)); + } + + private: + StyleLocalePair_t m_CurrentStyleLocalePair; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/basereader.cxx b/shell/source/win32/ooofilereader/basereader.cxx new file mode 100644 index 000000000..7bf53b275 --- /dev/null +++ b/shell/source/win32/ooofilereader/basereader.cxx @@ -0,0 +1,83 @@ +/* -*- 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 <basereader.hxx> + +#include <xml_parser.hxx> + +#include <assert.h> +#include <memory> + +/** constructor of CBaseReader. +*/ +CBaseReader::CBaseReader(const Filepath_t& DocumentName): +m_ZipFile( DocumentName ) +{ +} + + +CBaseReader::CBaseReader(StreamInterface * sw): +m_ZipFile( sw ) +{ +} + + +CBaseReader::~CBaseReader() +{ +} + + +void CBaseReader::start_document() +{ +} + + +void CBaseReader::end_document() +{ +} + +/** Read interested tag content into respective structure then start parsing process. + @param ContentName + the xml file name in the zipped document which we interest. +*/ +void CBaseReader::Initialize( const std::string& ContentName) +{ + try + { + if (m_ZipContent.empty()) + m_ZipFile.GetUncompressedContent( ContentName, m_ZipContent ); + + if (!m_ZipContent.empty()) + { + xml_parser parser; + parser.set_document_handler(this); // pass current reader as reader to the sax parser + parser.parse(m_ZipContent.data(), m_ZipContent.size(), true/*IsFinal*/); + } + } + catch(std::exception&) + { + // OSL_ENSURE( false, ex.what() ); + } + catch(...) + { + // OSL_ENSURE(false, "Unknown error"); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/contentreader.cxx b/shell/source/win32/ooofilereader/contentreader.cxx new file mode 100644 index 000000000..efdf5ba1e --- /dev/null +++ b/shell/source/win32/ooofilereader/contentreader.cxx @@ -0,0 +1,218 @@ +/* -*- 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 <contentreader.hxx> +#include "dummytag.hxx" +#include "simpletag.hxx" +#include "autostyletag.hxx" + +#include <assert.h> + +/** constructor. +*/ +CContentReader::CContentReader( const Filepath_t& DocumentName, LocaleSet_t const & DocumentLocale ): +CBaseReader( DocumentName ) +{ + try + { + m_DefaultLocale = DocumentLocale; + Initialize( DOC_CONTENT_NAME ); + } + catch(xml_parser_exception&) + { + // OSL_ENSURE(false, ex.what()); + } + catch(...) + { + // OSL_ENSURE(false, "Unknown error"); + } +} + +CContentReader::CContentReader( StreamInterface* stream, LocaleSet_t const & DocumentLocale ) : +CBaseReader( stream ) +{ +try + { + m_DefaultLocale = DocumentLocale; + Initialize( DOC_CONTENT_NAME ); + } + catch(xml_parser_exception&) + { + // OSL_ENSURE(false, ex.what()); + } + catch(...) + { + // OSL_ENSURE(false, "Unknown error"); + } +} + + +/** destructor. +*/ + +CContentReader::~CContentReader() +{ +} + +/*********************** helper functions ***********************/ + +/** choose an appropriate tag reader +*/ + +ITag* CContentReader::chooseTagReader( const std::wstring& tag_name, const XmlTagAttributes_t& XmlAttributes ) +{ + if (( tag_name == CONTENT_TEXT_A )||( tag_name == CONTENT_TEXT_P )|| + ( tag_name == CONTENT_TEXT_SPAN ) ||( tag_name == CONTENT_TEXT_H )|| + ( tag_name == CONTENT_TEXT_SEQUENCE ) ||( tag_name == CONTENT_TEXT_BOOKMARK_REF )|| + ( tag_name == CONTENT_TEXT_INDEX_TITLE_TEMPLATE ) ) + return new CSimpleTag(XmlAttributes); + else if ( tag_name == CONTENT_STYLE_STYLE ) + { + // if style:style | style:name is exist,, fill the style field, otherwise do nothing; + if ( XmlAttributes.find(CONTENT_STYLE_STYLE_NAME) != XmlAttributes.end()) + return new CAutoStyleTag(XmlAttributes); + else + return new CDummyTag; + } + else if ( ( tag_name == CONTENT_STYLE_PROPERTIES ) || ( tag_name == CONTENT_TEXT_STYLE_PROPERTIES ) ) + { + assert( !m_TagBuilderStack.empty() ); + + //here we presume that if CONTENT_STYLE_PROPERTIES tag is present, it just follow CONTENT_STYLE_STYLE; + ITag* pTagBuilder = m_TagBuilderStack.top(); + pTagBuilder->addAttributes( XmlAttributes ); + + return new CDummyTag; + } + else + return new CDummyTag; +} + +/** get style of the current content. +*/ +::std::wstring CContentReader::getCurrentContentStyle() +{ + assert( !m_TagBuilderStack.empty() ); + ITag* pTagBuilder = m_TagBuilderStack.top(); + + return pTagBuilder->getTagAttribute(CONTENT_TEXT_STYLENAME); +} + +/** add chunk into Chunk Buffer. +*/ +void CContentReader::addChunk( LocaleSet_t const & Locale, Content_t const & Content ) +{ + if ( Content == EMPTY_STRING ) + return; + + if ( ( ( m_ChunkBuffer.empty() ) || ( m_ChunkBuffer.back().first != Locale ) ) && + ( ( Content != SPACE ) && ( Content != LF ) ) ) + { + // if met a new locale, add a blank new chunk; + Chunk_t Chunk; + Chunk.first = Locale; + Chunk.second = EMPTY_STRING; + m_ChunkBuffer.push_back( Chunk ); + } + + if ( !m_ChunkBuffer.empty() ) + m_ChunkBuffer.back().second += Content; +} + +/** get a style's locale field. +*/ + +LocaleSet_t const & CContentReader::getLocale( const StyleName_t& Style ) +{ + if ( m_StyleMap.empty() ) + return m_DefaultLocale; + + StyleLocaleMap_t::const_iterator style_Iter; + + if ( ( style_Iter = m_StyleMap.find( Style ) ) == m_StyleMap.end( ) ) + return m_DefaultLocale; + else + return style_Iter->second; + +} + +/*********************** event handler functions ***********************/ + + +// start_element occurs when a tag is start + + +void CContentReader::start_element( + const string_t& /*raw_name*/, + const string_t& local_name, + const xml_tag_attribute_container_t& attributes) +{ + //get appropriate Xml Tag Builder using MetaInfoBuilderFactory; + ITag* pTagBuilder = chooseTagReader( local_name,attributes ); + assert( pTagBuilder != nullptr ); + pTagBuilder->startTag( ); + m_TagBuilderStack.push( pTagBuilder ); + +} + + +// end_element occurs when a tag is closed + + +void CContentReader::end_element(const string_t& /*raw_name*/, const string_t& local_name) +{ + assert( !m_TagBuilderStack.empty() ); + ITag* pTagBuilder = m_TagBuilderStack.top(); + + if ( local_name == CONTENT_STYLE_STYLE ) + { + StyleLocalePair_t StyleLocalePair = static_cast<CAutoStyleTag * >( pTagBuilder)->getStyleLocalePair(); + if ( ( static_cast<CAutoStyleTag * >( pTagBuilder)->isFull() ) && ( StyleLocalePair.second != m_DefaultLocale ) ) + m_StyleMap.insert( StyleLocalePair ); + } + if (( local_name == CONTENT_TEXT_A )||( local_name == CONTENT_TEXT_SPAN ) || + ( local_name == CONTENT_TEXT_SEQUENCE )||( local_name == CONTENT_TEXT_BOOKMARK_REF )) + addChunk( getLocale( getCurrentContentStyle() ), ::std::wstring( SPACE ) ); + if ((( local_name == CONTENT_TEXT_P )||( local_name == CONTENT_TEXT_H ) || + ( local_name == CONTENT_TEXT_INDEX_TITLE_TEMPLATE ) )&& + ( EMPTY_STRING != pTagBuilder->getTagContent( ) ) ) + addChunk( getLocale( getCurrentContentStyle() ), ::std::wstring( LF ) ); + + m_TagBuilderStack.pop(); + pTagBuilder->endTag(); + delete pTagBuilder; + +} + + +// characters occurs when receiving characters + + +void CContentReader::characters( const string_t& character ) +{ + if ( character.length() > 0 && !HasOnlySpaces( character ) ) + { + addChunk( getLocale( getCurrentContentStyle() ), character ); + + ITag* pTagBuilder = m_TagBuilderStack.top(); + pTagBuilder->addCharacters( character ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/dummytag.hxx b/shell/source/win32/ooofilereader/dummytag.hxx new file mode 100644 index 000000000..8af406d35 --- /dev/null +++ b/shell/source/win32/ooofilereader/dummytag.hxx @@ -0,0 +1,55 @@ +/* -*- 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 . + */ + + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_DUMMYTAG_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_DUMMYTAG_HXX + +#include "itag.hxx" + +/*************************** dummy tag readers ***************************/ + +/** Implements the ITag interface but does + nothing (Null object pattern), may be used for + tags we are not interested in to avoid if-else + branches. +*/ +class CDummyTag : public ITag +{ + public: + virtual void startTag() override {}; + + virtual void endTag() override {}; + + virtual void addCharacters(const std::wstring& /*characters*/) override {}; + + virtual void addAttributes(const XmlTagAttributes_t& /*attributes*/) override {}; + + virtual std::wstring getTagContent() override + { + return EMPTY_STRING; + }; + + virtual ::std::wstring getTagAttribute( ::std::wstring const & /*attrname*/ ) override { return ::std::wstring(EMPTY_STRING); }; +}; + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/itag.hxx b/shell/source/win32/ooofilereader/itag.hxx new file mode 100644 index 000000000..64a3f8bd7 --- /dev/null +++ b/shell/source/win32/ooofilereader/itag.hxx @@ -0,0 +1,46 @@ +/* -*- 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 . + */ + + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_ITAG_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_ITAG_HXX + +#include <config.hxx> +#include <types.hxx> + +/*************************** interface of tag readers ***************************/ + +/** Interface for a xml tag character builder +*/ +class ITag +{ + public: + virtual ~ITag() {}; + + virtual void startTag() = 0; + virtual void endTag() = 0; + virtual void addCharacters(const std::wstring& characters) = 0; + virtual void addAttributes(const XmlTagAttributes_t& attributes) = 0; + virtual ::std::wstring getTagContent() = 0; + virtual ::std::wstring getTagAttribute( ::std::wstring const & attrname ) = 0; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/keywordstag.cxx b/shell/source/win32/ooofilereader/keywordstag.cxx new file mode 100644 index 000000000..8a8600e28 --- /dev/null +++ b/shell/source/win32/ooofilereader/keywordstag.cxx @@ -0,0 +1,55 @@ +/* -*- 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 "keywordstag.hxx" + +/*********************** CKeywordsTag ***********************/ + +void CKeywordsTag::startTag() +{ + m_sCurrentKeyword.clear(); +} + +void CKeywordsTag::endTag() +{ + m_slKeywords.push_back(m_sCurrentKeyword); +} + +void CKeywordsTag::addCharacters(const std::wstring& characters) +{ + m_sCurrentKeyword += characters; +} + +void CKeywordsTag::addAttributes(const XmlTagAttributes_t& /*attributes*/) +{ + // there are no attributes for keywords +} + +std::wstring CKeywordsTag::getTagContent( ) +{ + auto keywords_Iter= m_slKeywords.cbegin( ); + auto keywords_Iter_end = m_slKeywords.cend( ); + + std::wstring ret_KeyWord_String = ( keywords_Iter != keywords_Iter_end) ? *keywords_Iter++ : L""; + for ( ; keywords_Iter != keywords_Iter_end; ++keywords_Iter) + ret_KeyWord_String += L"," + *keywords_Iter; + return ret_KeyWord_String; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/keywordstag.hxx b/shell/source/win32/ooofilereader/keywordstag.hxx new file mode 100644 index 000000000..2ec3de1cf --- /dev/null +++ b/shell/source/win32/ooofilereader/keywordstag.hxx @@ -0,0 +1,48 @@ +/* -*- 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 . + */ + + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_KEYWORDSTAG_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_KEYWORDSTAG_HXX + +#include "itag.hxx" + +/*************************** metainfo tag readers ***************************/ + +/** Implements the ITag interface for + building a keyword list +*/ +class CKeywordsTag : public ITag +{ + public: + virtual void startTag() override; + virtual void endTag() override; + virtual void addCharacters(const std::wstring& characters) override; + virtual void addAttributes(const XmlTagAttributes_t& attributes) override; + virtual std::wstring getTagContent() override; + virtual ::std::wstring getTagAttribute( ::std::wstring const & /*attrname*/ ) override { return ::std::wstring(); }; + + private: + std::vector<std::wstring> m_slKeywords; + std::wstring m_sCurrentKeyword; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/metainforeader.cxx b/shell/source/win32/ooofilereader/metainforeader.cxx new file mode 100644 index 000000000..9eab4d5e0 --- /dev/null +++ b/shell/source/win32/ooofilereader/metainforeader.cxx @@ -0,0 +1,285 @@ +/* -*- 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 <metainforeader.hxx> +#include "dummytag.hxx" +#include "simpletag.hxx" +#include "keywordstag.hxx" + +#include <assert.h> + +/** constructor. +*/ +CMetaInfoReader::CMetaInfoReader( const Filepath_t& DocumentName ): +CBaseReader( DocumentName ) +{ + try + { + m_pKeywords_Builder = new CKeywordsTag; + m_pSimple_Builder = new CSimpleTag( ); + m_pDummy_Builder = new CDummyTag; + + //retrieve all information that is useful + m_AllMetaInfo[META_INFO_AUTHOR] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_TITLE] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_SUBJECT] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_KEYWORDS] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_DESCRIPTION] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_DOCUMENT_STATISTIC] = EMPTY_XML_TAG; + + m_AllMetaInfo[META_INFO_GENERATOR] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_CREATION] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_CREATOR] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_MODIFIED] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_LANGUAGE] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_DOCUMENT_NUMBER] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_EDITING_TIME] = EMPTY_XML_TAG; + + Initialize( META_CONTENT_NAME ); + } + catch(xml_parser_exception&) + { + // OSL_ENSURE(false, ex.what()); + } + catch(...) + { + // OSL_ENSURE(false, "Unknown error"); + } +} + +CMetaInfoReader::CMetaInfoReader( StreamInterface* stream ) : +CBaseReader( stream ) +{ +try + { + m_pKeywords_Builder = new CKeywordsTag; + m_pSimple_Builder = new CSimpleTag( ); + m_pDummy_Builder = new CDummyTag; + + //retrieve all information that is useful + m_AllMetaInfo[META_INFO_AUTHOR] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_TITLE] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_SUBJECT] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_KEYWORDS] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_DESCRIPTION] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_DOCUMENT_STATISTIC] = EMPTY_XML_TAG; + + m_AllMetaInfo[META_INFO_GENERATOR] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_CREATION] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_CREATOR] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_MODIFIED] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_LANGUAGE] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_DOCUMENT_NUMBER] = EMPTY_XML_TAG; + m_AllMetaInfo[META_INFO_EDITING_TIME] = EMPTY_XML_TAG; + + Initialize( META_CONTENT_NAME ); + } + catch(xml_parser_exception&) + { + // OSL_ENSURE(false, ex.what()); + } + catch(...) + { + // OSL_ENSURE(false, "Unknown error"); + } + +} + +/** destructor. +*/ + +CMetaInfoReader::~CMetaInfoReader() +{ + delete m_pKeywords_Builder; + delete m_pSimple_Builder; + delete m_pDummy_Builder; +} + + +/*********************** export functions ***********************/ + +/** check if the Tag is in the target meta.xml file. + + @param TagName + the name of the tag that will be retrieve. +*/ +bool CMetaInfoReader::hasTag(const std::wstring& TagName) const +{ + return ( m_AllMetaInfo.find(TagName) != m_AllMetaInfo.end()); +} + +/** Get a specific tag content, compound tags will be returned as comma separated list. + + @param TagName + the name of the tag that will be retrieve. +*/ +std::wstring CMetaInfoReader::getTagData( const std::wstring& TagName) +{ + if( hasTag( TagName ) ) + return m_AllMetaInfo[TagName].first; + else + return EMPTY_STRING; +} + +/** check if the a tag has the specific attribute. + + @param TagName + the name of the tag. + @param AttributeName + the name of the attribute. +*/ +bool CMetaInfoReader::hasTagAttribute(const std::wstring& TagName, const std::wstring& AttributeName) +{ + return ( m_AllMetaInfo[TagName].second.find( AttributeName) != m_AllMetaInfo[TagName].second.end() ); +} + +/** Get a specific attribute content. + + @param TagName + the name of the tag. + @param AttributeName + the name of the attribute. +*/ +std::wstring CMetaInfoReader::getTagAttribute(const std::wstring& TagName, const std::wstring& AttributeName) +{ + if (hasTagAttribute(TagName, AttributeName)) + return m_AllMetaInfo[ TagName ].second[AttributeName]; + else + return EMPTY_STRING; +} + +/** helper function for getDefaultLocale(). +*/ +const LocaleSet_t EN_US_LOCALE( ::std::make_pair( ::std::wstring( L"en" ), ::std::wstring( L"US" ))); + +static bool isValidLocale(const ::std::wstring& Locale) +{ + return ( Locale.length() == 5 ); +} + +/** Get the default language of the whole document, if no such field, en-US is returned. +*/ +LocaleSet_t CMetaInfoReader::getDefaultLocale() +{ + if (hasTag(META_INFO_LANGUAGE)) + { + ::std::wstring locale = m_AllMetaInfo[META_INFO_LANGUAGE].first; + return isValidLocale(locale) ? ::std::make_pair(locale.substr( 0,2), locale.substr( 3,2)) : EN_US_LOCALE; + } + else + return EN_US_LOCALE; +} + +/*********************** tag related functions ***********************/ + +/** choose an appropriate tag reader +*/ + +ITag* CMetaInfoReader::chooseTagReader( const std::wstring& tag_name, const XmlTagAttributes_t& XmlAttributes ) +{ + if ( tag_name == META_INFO_KEYWORD ) + { + m_AllMetaInfo[META_INFO_KEYWORDS].second = XmlAttributes; + return m_pKeywords_Builder; + } + if (( tag_name == META_INFO_TITLE )||( tag_name == META_INFO_AUTHOR )||( tag_name == META_INFO_SUBJECT )||( tag_name == META_INFO_DESCRIPTION )|| + ( tag_name == META_INFO_DOCUMENT_STATISTIC )||( tag_name == META_INFO_GENERATOR )||( tag_name == META_INFO_CREATION )||( tag_name == META_INFO_CREATOR )|| + ( tag_name == META_INFO_MODIFIED )||( tag_name == META_INFO_LANGUAGE )||( tag_name == META_INFO_DOCUMENT_NUMBER )||( tag_name == META_INFO_EDITING_TIME ) ) + { + m_AllMetaInfo[tag_name].second = XmlAttributes; + return m_pSimple_Builder; + } + else + return m_pDummy_Builder; + +} + + +// save the received content into structure. + +void CMetaInfoReader::saveTagContent( const std::wstring& tag_name ) +{ + ITag* pTagBuilder; + if ( tag_name == META_INFO_KEYWORDS ) + pTagBuilder = m_pKeywords_Builder; + else if ( tag_name == META_INFO_KEYWORD ) + { + // added for support for OASIS xml file format. + m_AllMetaInfo[META_INFO_KEYWORDS].first =m_pKeywords_Builder->getTagContent( ); + return; + } + else if (( tag_name == META_INFO_TITLE )||( tag_name == META_INFO_AUTHOR )||( tag_name == META_INFO_SUBJECT )||( tag_name == META_INFO_DESCRIPTION )|| + ( tag_name == META_INFO_DOCUMENT_STATISTIC )||( tag_name == META_INFO_GENERATOR )||( tag_name == META_INFO_CREATION )||( tag_name == META_INFO_CREATOR )|| + ( tag_name == META_INFO_MODIFIED )||( tag_name == META_INFO_LANGUAGE )||( tag_name == META_INFO_DOCUMENT_NUMBER )||( tag_name == META_INFO_EDITING_TIME ) ) + pTagBuilder = m_pSimple_Builder; + else + pTagBuilder = m_pDummy_Builder; + + m_AllMetaInfo[tag_name].first =pTagBuilder->getTagContent( ); +} + + +/*********************** event handler functions ***********************/ + + +// start_element occurs when a tag is start + + +void CMetaInfoReader::start_element( + const string_t& /*raw_name*/, + const string_t& local_name, + const xml_tag_attribute_container_t& attributes) +{ + //get appropriate Xml Tag Builder using MetaInfoBuilderFactory; + ITag* pTagBuilder = chooseTagReader( local_name,attributes ); + assert( pTagBuilder!= nullptr ); + pTagBuilder->startTag( ); + m_TagBuilderStack.push( pTagBuilder ); + +} + + +// end_element occurs when a tag is closed + + +void CMetaInfoReader::end_element(const string_t& /*raw_name*/, const string_t& local_name) +{ + assert( !m_TagBuilderStack.empty() ); + ITag* pTagBuilder = m_TagBuilderStack.top(); + m_TagBuilderStack.pop(); + pTagBuilder->endTag(); + + saveTagContent( local_name ); + +} + + +// characters occurs when receiving characters + + +void CMetaInfoReader::characters( const string_t& character ) +{ + if ( character.length() > 0 && !HasOnlySpaces( character ) ) + { + ITag* pTagBuilder = m_TagBuilderStack.top(); + pTagBuilder->addCharacters( character ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/simpletag.cxx b/shell/source/win32/ooofilereader/simpletag.cxx new file mode 100644 index 000000000..82b85aec5 --- /dev/null +++ b/shell/source/win32/ooofilereader/simpletag.cxx @@ -0,0 +1,57 @@ +/* -*- 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 "simpletag.hxx" + +/*********************** CSimpleTag ***********************/ +void CSimpleTag::startTag() +{ + m_SimpleContent = L""; +} + + +void CSimpleTag::endTag() +{ + +} + +void CSimpleTag::addCharacters(const std::wstring& characters) +{ + m_SimpleContent += characters; +} + +void CSimpleTag::addAttributes(const XmlTagAttributes_t& attributes ) +{ + m_SimpleAttributes = attributes; +} + +std::wstring CSimpleTag::getTagContent( ) +{ + return m_SimpleContent; +} + +::std::wstring CSimpleTag::getTagAttribute( ::std::wstring const & attrname ) +{ + if ( m_SimpleAttributes.find(attrname) != m_SimpleAttributes.end()) + return m_SimpleAttributes[attrname]; + else + return ( ::std::wstring( EMPTY_STRING ) ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/ooofilereader/simpletag.hxx b/shell/source/win32/ooofilereader/simpletag.hxx new file mode 100644 index 000000000..4d878fc48 --- /dev/null +++ b/shell/source/win32/ooofilereader/simpletag.hxx @@ -0,0 +1,52 @@ +/* -*- 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 . + */ + + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_SIMPLETAG_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_OOOFILEREADER_SIMPLETAG_HXX + +#include "itag.hxx" + +/*************************** simple tag readers ***************************/ + +/** Implements the ITag interface for + building a general info that is not a compound tag. +*/ +class CSimpleTag : public ITag +{ + public: + CSimpleTag(){}; + explicit CSimpleTag( const XmlTagAttributes_t& attributes ):m_SimpleAttributes(attributes){} + + virtual void startTag() override; + virtual void endTag() override; + virtual void addCharacters(const std::wstring& characters) override; + virtual void addAttributes(const XmlTagAttributes_t& attributes) override; + virtual std::wstring getTagContent() override; + + virtual ::std::wstring getTagAttribute( ::std::wstring const & attrname ) override; + + private: + std::wstring m_SimpleContent; + XmlTagAttributes_t m_SimpleAttributes; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |