1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <xml/imagesconfiguration.hxx>
25 #include <rtl/ref.hxx>
26 #include <rtl/ustring.hxx>
27 #include <comphelper/attributelist.hxx>
28 #include <cppuhelper/implbase.hxx>
30 #include <unordered_map>
34 // Hash code function for using in all hash maps of follow implementation.
36 class OReadImagesDocumentHandler final
: public ::cppu::WeakImplHelper
< css::xml::sax::XDocumentHandler
>
41 IMG_ELEMENT_IMAGECONTAINER
,
44 IMG_ELEMENT_EXTERNALIMAGES
,
45 IMG_ELEMENT_EXTERNALENTRY
,
47 IMG_ATTRIBUTE_MASKCOLOR
,
48 IMG_ATTRIBUTE_COMMAND
,
49 IMG_ATTRIBUTE_BITMAPINDEX
,
50 IMG_ATTRIBUTE_MASKURL
,
51 IMG_ATTRIBUTE_MASKMODE
,
52 IMG_ATTRIBUTE_HIGHCONTRASTURL
,
53 IMG_ATTRIBUTE_HIGHCONTRASTMASKURL
,
57 enum Image_XML_Namespace
63 OReadImagesDocumentHandler( ImageItemDescriptorList
& aItems
);
64 virtual ~OReadImagesDocumentHandler() override
;
67 virtual void SAL_CALL
startDocument() override
;
69 virtual void SAL_CALL
endDocument() override
;
71 virtual void SAL_CALL
startElement(
72 const OUString
& aName
,
73 const css::uno::Reference
< css::xml::sax::XAttributeList
> &xAttribs
) override
;
75 virtual void SAL_CALL
endElement(const OUString
& aName
) override
;
77 virtual void SAL_CALL
characters(const OUString
& aChars
) override
;
79 virtual void SAL_CALL
ignorableWhitespace(const OUString
& aWhitespaces
) override
;
81 virtual void SAL_CALL
processingInstruction(const OUString
& aTarget
,
82 const OUString
& aData
) override
;
84 virtual void SAL_CALL
setDocumentLocator(
85 const css::uno::Reference
< css::xml::sax::XLocator
> &xLocator
) override
;
88 OUString
getErrorLineString();
90 class ImageHashMap
: public std::unordered_map
< OUString
, Image_XML_Entry
>
94 bool m_bImageContainerStartFound
;
95 bool m_bImageContainerEndFound
;
96 bool m_bImagesStartFound
;
97 ImageHashMap m_aImageMap
;
98 ImageItemDescriptorList
& m_rImageList
;
99 css::uno::Reference
< css::xml::sax::XLocator
> m_xLocator
;
102 class OWriteImagesDocumentHandler final
105 OWriteImagesDocumentHandler(
106 const ImageItemDescriptorList
& aItems
,
107 css::uno::Reference
< css::xml::sax::XDocumentHandler
> const &
108 rWriteDocumentHandler
);
109 ~OWriteImagesDocumentHandler();
111 /// @throws css::xml::sax::SAXException
112 /// @throws css::uno::RuntimeException
113 void WriteImagesDocument();
116 /// @throws css::xml::sax::SAXException
117 /// @throws css::uno::RuntimeException
118 void WriteImageList( const ImageItemDescriptorList
* );
120 /// @throws css::xml::sax::SAXException
121 /// @throws css::uno::RuntimeException
122 void WriteImage( const ImageItemDescriptor
* );
124 const ImageItemDescriptorList
& m_rImageItemList
;
125 css::uno::Reference
< css::xml::sax::XDocumentHandler
> m_xWriteDocumentHandler
;
126 OUString m_aXMLImageNS
;
127 OUString m_aAttributeXlinkType
;
128 OUString m_aAttributeValueSimple
;
131 } // namespace framework
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */