1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_
29 #define FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_
30 
31 #include <framework/fwedllapi.h>
32 
33 //_________________________________________________________________________________________________________________
34 //	interface includes
35 //_________________________________________________________________________________________________________________
36 
37 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
38 
39 //_________________________________________________________________________________________________________________
40 //	other includes
41 //_________________________________________________________________________________________________________________
42 #include <xml/imagesconfiguration.hxx>
43 #include <threadhelp/threadhelpbase.hxx>
44 #include <rtl/ustring.hxx>
45 #include <cppuhelper/implbase1.hxx>
46 
47 #include <hash_map>
48 #include <stdtypes.h>
49 
50 
51 //_________________________________________________________________________________________________________________
52 //	namespace
53 //_________________________________________________________________________________________________________________
54 
55 namespace framework{
56 
57 //*****************************************************************************************************************
58 // Hash code function for using in all hash maps of follow implementation.
59 
60 class OReadImagesDocumentHandler : private ThreadHelpBase,	// Struct for right initalization of lock member! Must be first of baseclasses.
61 								   public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
62 {
63 	public:
64 		enum Image_XML_Entry
65 		{
66 			IMG_ELEMENT_IMAGECONTAINER,
67 			IMG_ELEMENT_IMAGES,
68 			IMG_ELEMENT_ENTRY,
69 			IMG_ELEMENT_EXTERNALIMAGES,
70 			IMG_ELEMENT_EXTERNALENTRY,
71 			IMG_ATTRIBUTE_HREF,
72 			IMG_ATTRIBUTE_MASKCOLOR,
73 			IMG_ATTRIBUTE_COMMAND,
74 			IMG_ATTRIBUTE_BITMAPINDEX,
75 			IMG_ATTRIBUTE_MASKURL,
76 			IMG_ATTRIBUTE_MASKMODE,
77 			IMG_ATTRIBUTE_HIGHCONTRASTURL,
78 			IMG_ATTRIBUTE_HIGHCONTRASTMASKURL,
79 			IMG_XML_ENTRY_COUNT
80 		};
81 
82 		enum Image_XML_Namespace
83 		{
84 			IMG_NS_IMAGE,
85 			IMG_NS_XLINK,
86 			TBL_XML_NAMESPACES_COUNT
87 		};
88 
89 		OReadImagesDocumentHandler( ImageListsDescriptor& aItems );
90 		virtual ~OReadImagesDocumentHandler();
91 
92 		// XDocumentHandler
93 		virtual void SAL_CALL startDocument(void)
94 		throw (	::com::sun::star::xml::sax::SAXException,
95 				::com::sun::star::uno::RuntimeException );
96 
97 		virtual void SAL_CALL endDocument(void)
98 		throw(	::com::sun::star::xml::sax::SAXException,
99 				::com::sun::star::uno::RuntimeException );
100 
101 		virtual void SAL_CALL startElement(
102 			const rtl::OUString& aName,
103 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
104 		throw(	::com::sun::star::xml::sax::SAXException,
105 				::com::sun::star::uno::RuntimeException );
106 
107 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
108 		throw(	::com::sun::star::xml::sax::SAXException,
109 				::com::sun::star::uno::RuntimeException );
110 
111 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
112 		throw(	::com::sun::star::xml::sax::SAXException,
113 				::com::sun::star::uno::RuntimeException );
114 
115 		virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces)
116 		throw(	::com::sun::star::xml::sax::SAXException,
117 				::com::sun::star::uno::RuntimeException );
118 
119 		virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget,
120 													const rtl::OUString& aData)
121 		throw(	::com::sun::star::xml::sax::SAXException,
122 				::com::sun::star::uno::RuntimeException );
123 
124 		virtual void SAL_CALL setDocumentLocator(
125 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator)
126 		throw(	::com::sun::star::xml::sax::SAXException,
127 				::com::sun::star::uno::RuntimeException );
128 
129 	private:
130 		::rtl::OUString getErrorLineString();
131 
132 		class ImageHashMap : public ::std::hash_map< ::rtl::OUString		,
133 													 Image_XML_Entry		,
134 													 OUStringHashCode		,
135 													 ::std::equal_to< ::rtl::OUString >	>
136 		{
137 			public:
138 				inline void free()
139 				{
140 					ImageHashMap().swap( *this );
141 				}
142 		};
143 
144 		sal_Bool																	m_bImageContainerStartFound;
145 		sal_Bool																	m_bImageContainerEndFound;
146 		sal_Bool																	m_bImagesStartFound;
147 		sal_Bool																	m_bImagesEndFound;
148 		sal_Bool																	m_bImageStartFound;
149 		sal_Bool																	m_bExternalImagesStartFound;
150 		sal_Bool																	m_bExternalImagesEndFound;
151 		sal_Bool																	m_bExternalImageStartFound;
152 		sal_Int32																	m_nHashMaskModeBitmap;
153 		sal_Int32																	m_nHashMaskModeColor;
154 		ImageHashMap																m_aImageMap;
155 		ImageListsDescriptor&														m_aImageList;
156 		ImageListItemDescriptor*													m_pImages;
157 		ExternalImageItemListDescriptor*											m_pExternalImages;
158 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >	m_xLocator;
159 };
160 
161 class OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses.
162 {
163 	public:
164 		OWriteImagesDocumentHandler(
165 			const ImageListsDescriptor& aItems,
166 			::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > );
167 		virtual ~OWriteImagesDocumentHandler();
168 
169 		void WriteImagesDocument() throw
170 			( ::com::sun::star::xml::sax::SAXException,
171 			  ::com::sun::star::uno::RuntimeException );
172 
173 	protected:
174 		virtual void WriteImageList( const ImageListItemDescriptor* ) throw
175 			( ::com::sun::star::xml::sax::SAXException,
176 			  ::com::sun::star::uno::RuntimeException );
177 
178 		virtual void WriteExternalImageList( const ExternalImageItemListDescriptor* ) throw
179 			( ::com::sun::star::xml::sax::SAXException,
180 			  ::com::sun::star::uno::RuntimeException );
181 
182 		virtual void WriteImage( const ImageItemDescriptor* ) throw
183 			( ::com::sun::star::xml::sax::SAXException,
184 			  ::com::sun::star::uno::RuntimeException );
185 
186 		virtual void WriteExternalImage( const ExternalImageItemDescriptor* ) throw
187 			( ::com::sun::star::xml::sax::SAXException,
188 			  ::com::sun::star::uno::RuntimeException );
189 
190 		const ImageListsDescriptor&															m_aImageListsItems;
191 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >	m_xWriteDocumentHandler;
192 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >		m_xEmptyList;
193 		::rtl::OUString																		m_aXMLXlinkNS;
194 		::rtl::OUString																		m_aXMLImageNS;
195 		::rtl::OUString																		m_aAttributeType;
196 		::rtl::OUString																		m_aAttributeXlinkType;
197 		::rtl::OUString																		m_aAttributeValueSimple;
198 };
199 
200 } // namespace framework
201 
202 #endif
203