1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ 25 #define FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ 26 27 #include <framework/fwedllapi.h> 28 29 //_________________________________________________________________________________________________________________ 30 // interface includes 31 //_________________________________________________________________________________________________________________ 32 33 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 34 35 //_________________________________________________________________________________________________________________ 36 // other includes 37 //_________________________________________________________________________________________________________________ 38 #include <xml/imagesconfiguration.hxx> 39 #include <threadhelp/threadhelpbase.hxx> 40 #include <rtl/ustring.hxx> 41 #include <cppuhelper/implbase1.hxx> 42 43 #include <hash_map> 44 #include <stdtypes.h> 45 46 47 //_________________________________________________________________________________________________________________ 48 // namespace 49 //_________________________________________________________________________________________________________________ 50 51 namespace framework{ 52 53 //***************************************************************************************************************** 54 // Hash code function for using in all hash maps of follow implementation. 55 56 class OReadImagesDocumentHandler : private ThreadHelpBase, // Struct for right initialization of lock member! Must be first of baseclasses. 57 public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler > 58 { 59 public: 60 enum Image_XML_Entry 61 { 62 IMG_ELEMENT_IMAGECONTAINER, 63 IMG_ELEMENT_IMAGES, 64 IMG_ELEMENT_ENTRY, 65 IMG_ELEMENT_EXTERNALIMAGES, 66 IMG_ELEMENT_EXTERNALENTRY, 67 IMG_ATTRIBUTE_HREF, 68 IMG_ATTRIBUTE_MASKCOLOR, 69 IMG_ATTRIBUTE_COMMAND, 70 IMG_ATTRIBUTE_BITMAPINDEX, 71 IMG_ATTRIBUTE_MASKURL, 72 IMG_ATTRIBUTE_MASKMODE, 73 IMG_ATTRIBUTE_HIGHCONTRASTURL, 74 IMG_ATTRIBUTE_HIGHCONTRASTMASKURL, 75 IMG_XML_ENTRY_COUNT 76 }; 77 78 enum Image_XML_Namespace 79 { 80 IMG_NS_IMAGE, 81 IMG_NS_XLINK, 82 TBL_XML_NAMESPACES_COUNT 83 }; 84 85 OReadImagesDocumentHandler( ImageListsDescriptor& aItems ); 86 virtual ~OReadImagesDocumentHandler(); 87 88 // XDocumentHandler 89 virtual void SAL_CALL startDocument(void); 90 91 virtual void SAL_CALL endDocument(void); 92 93 virtual void SAL_CALL startElement( 94 const rtl::OUString& aName, 95 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs); 96 97 virtual void SAL_CALL endElement(const rtl::OUString& aName); 98 99 virtual void SAL_CALL characters(const rtl::OUString& aChars); 100 101 virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces); 102 103 virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget, 104 const rtl::OUString& aData); 105 106 virtual void SAL_CALL setDocumentLocator( 107 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator); 108 109 private: 110 ::rtl::OUString getErrorLineString(); 111 112 class ImageHashMap : public ::std::hash_map< ::rtl::OUString , 113 Image_XML_Entry , 114 rtl::OUStringHash, 115 ::std::equal_to< ::rtl::OUString > > 116 { 117 public: free()118 inline void free() 119 { 120 ImageHashMap().swap( *this ); 121 } 122 }; 123 124 sal_Bool m_bImageContainerStartFound; 125 sal_Bool m_bImageContainerEndFound; 126 sal_Bool m_bImagesStartFound; 127 sal_Bool m_bImagesEndFound; 128 sal_Bool m_bImageStartFound; 129 sal_Bool m_bExternalImagesStartFound; 130 sal_Bool m_bExternalImagesEndFound; 131 sal_Bool m_bExternalImageStartFound; 132 sal_Int32 m_nHashMaskModeBitmap; 133 sal_Int32 m_nHashMaskModeColor; 134 ImageHashMap m_aImageMap; 135 ImageListsDescriptor& m_aImageList; 136 ImageListItemDescriptor* m_pImages; 137 ExternalImageItemListDescriptor* m_pExternalImages; 138 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator; 139 }; 140 141 class OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initialization of lock member! Must be first of baseclasses. 142 { 143 public: 144 OWriteImagesDocumentHandler( 145 const ImageListsDescriptor& aItems, 146 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > ); 147 virtual ~OWriteImagesDocumentHandler(); 148 149 void WriteImagesDocument(); 150 151 protected: 152 virtual void WriteImageList( const ImageListItemDescriptor* ); 153 154 virtual void WriteExternalImageList( const ExternalImageItemListDescriptor* ); 155 156 virtual void WriteImage( const ImageItemDescriptor* ); 157 158 virtual void WriteExternalImage( const ExternalImageItemDescriptor* ); 159 160 const ImageListsDescriptor& m_aImageListsItems; 161 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xWriteDocumentHandler; 162 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xEmptyList; 163 ::rtl::OUString m_aXMLXlinkNS; 164 ::rtl::OUString m_aXMLImageNS; 165 ::rtl::OUString m_aAttributeType; 166 ::rtl::OUString m_aAttributeXlinkType; 167 ::rtl::OUString m_aAttributeValueSimple; 168 }; 169 170 } // namespace framework 171 172 #endif 173