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 initalization 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 throw ( ::com::sun::star::xml::sax::SAXException, 91 ::com::sun::star::uno::RuntimeException ); 92 93 virtual void SAL_CALL endDocument(void) 94 throw( ::com::sun::star::xml::sax::SAXException, 95 ::com::sun::star::uno::RuntimeException ); 96 97 virtual void SAL_CALL startElement( 98 const rtl::OUString& aName, 99 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs) 100 throw( ::com::sun::star::xml::sax::SAXException, 101 ::com::sun::star::uno::RuntimeException ); 102 103 virtual void SAL_CALL endElement(const rtl::OUString& aName) 104 throw( ::com::sun::star::xml::sax::SAXException, 105 ::com::sun::star::uno::RuntimeException ); 106 107 virtual void SAL_CALL characters(const rtl::OUString& aChars) 108 throw( ::com::sun::star::xml::sax::SAXException, 109 ::com::sun::star::uno::RuntimeException ); 110 111 virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces) 112 throw( ::com::sun::star::xml::sax::SAXException, 113 ::com::sun::star::uno::RuntimeException ); 114 115 virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget, 116 const rtl::OUString& aData) 117 throw( ::com::sun::star::xml::sax::SAXException, 118 ::com::sun::star::uno::RuntimeException ); 119 120 virtual void SAL_CALL setDocumentLocator( 121 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator) 122 throw( ::com::sun::star::xml::sax::SAXException, 123 ::com::sun::star::uno::RuntimeException ); 124 125 private: 126 ::rtl::OUString getErrorLineString(); 127 128 class ImageHashMap : public ::std::hash_map< ::rtl::OUString , 129 Image_XML_Entry , 130 rtl::OUStringHash, 131 ::std::equal_to< ::rtl::OUString > > 132 { 133 public: free()134 inline void free() 135 { 136 ImageHashMap().swap( *this ); 137 } 138 }; 139 140 sal_Bool m_bImageContainerStartFound; 141 sal_Bool m_bImageContainerEndFound; 142 sal_Bool m_bImagesStartFound; 143 sal_Bool m_bImagesEndFound; 144 sal_Bool m_bImageStartFound; 145 sal_Bool m_bExternalImagesStartFound; 146 sal_Bool m_bExternalImagesEndFound; 147 sal_Bool m_bExternalImageStartFound; 148 sal_Int32 m_nHashMaskModeBitmap; 149 sal_Int32 m_nHashMaskModeColor; 150 ImageHashMap m_aImageMap; 151 ImageListsDescriptor& m_aImageList; 152 ImageListItemDescriptor* m_pImages; 153 ExternalImageItemListDescriptor* m_pExternalImages; 154 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator; 155 }; 156 157 class OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses. 158 { 159 public: 160 OWriteImagesDocumentHandler( 161 const ImageListsDescriptor& aItems, 162 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > ); 163 virtual ~OWriteImagesDocumentHandler(); 164 165 void WriteImagesDocument() throw 166 ( ::com::sun::star::xml::sax::SAXException, 167 ::com::sun::star::uno::RuntimeException ); 168 169 protected: 170 virtual void WriteImageList( const ImageListItemDescriptor* ) throw 171 ( ::com::sun::star::xml::sax::SAXException, 172 ::com::sun::star::uno::RuntimeException ); 173 174 virtual void WriteExternalImageList( const ExternalImageItemListDescriptor* ) throw 175 ( ::com::sun::star::xml::sax::SAXException, 176 ::com::sun::star::uno::RuntimeException ); 177 178 virtual void WriteImage( const ImageItemDescriptor* ) throw 179 ( ::com::sun::star::xml::sax::SAXException, 180 ::com::sun::star::uno::RuntimeException ); 181 182 virtual void WriteExternalImage( const ExternalImageItemDescriptor* ) throw 183 ( ::com::sun::star::xml::sax::SAXException, 184 ::com::sun::star::uno::RuntimeException ); 185 186 const ImageListsDescriptor& m_aImageListsItems; 187 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xWriteDocumentHandler; 188 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xEmptyList; 189 ::rtl::OUString m_aXMLXlinkNS; 190 ::rtl::OUString m_aXMLImageNS; 191 ::rtl::OUString m_aAttributeType; 192 ::rtl::OUString m_aAttributeXlinkType; 193 ::rtl::OUString m_aAttributeValueSimple; 194 }; 195 196 } // namespace framework 197 198 #endif 199