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 _T602FILTER_HXX 29 #define _T602FILTER_HXX 30 31 #include <com/sun/star/document/XFilter.hpp> 32 #include <com/sun/star/document/XImporter.hpp> 33 #include <com/sun/star/document/XExtendedFilterDetection.hpp> 34 #include <com/sun/star/io/XInputStream.hpp> 35 #include <com/sun/star/lang/XInitialization.hpp> 36 #include <com/sun/star/lang/XServiceInfo.hpp> 37 #include <com/sun/star/lang/XLocalizable.hpp> 38 #include <com/sun/star/beans/XPropertyAccess.hpp> 39 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 40 #include <cppuhelper/implbase5.hxx> 41 #include <cppuhelper/implbase4.hxx> 42 #include <xmloff/attrlist.hxx> 43 #include <tools/resmgr.hxx> 44 45 namespace T602ImportFilter { 46 47 typedef enum {L2,KAM,KOI} tcode; 48 49 typedef enum { 50 standard, // default 51 fat, // bold 52 cursive, // italic 53 bold, // wide 54 tall, // high 55 big, // big 56 lindex, // lower index 57 hindex, // upper index 58 err, // not set yet 59 chngul // change underline 60 } fonts; 61 62 typedef enum {START,READCH,EOL,POCMD,EXPCMD,SETCMD,SETCH,WRITE,EEND,QUIT} tnode; 63 64 ::rtl::OUString getImplementationName() 65 throw ( ::com::sun::star::uno::RuntimeException ); 66 67 ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames() 68 throw ( ::com::sun::star::uno::RuntimeException ); 69 70 71 ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL 72 CreateInstance( const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &r) 73 throw ( ::com::sun::star::uno::Exception ); 74 75 76 // 77 // class T602ImportFilter 78 // 79 80 struct inistruct 81 { 82 bool showcomm; // true show comment lines 83 bool forcecode; // false the user has changed the encoding with something else than @CT 84 tcode xcode; // KAM encoding set - forced 85 bool ruscode; // false Russian tables turned on 86 bool reformatpars; // false Reformat paragraphs (whitespaces and line breaks) 87 sal_Int16 fontsize; // font size in points 88 89 inistruct() 90 : showcomm( true ) 91 , forcecode( false ) 92 , xcode ( KAM ) 93 , ruscode ( false ) 94 , reformatpars ( false ) 95 , fontsize (10) 96 { 97 }; 98 }; 99 100 class T602ImportFilterDialog : public cppu::WeakImplHelper4 < 101 com::sun::star::ui::dialogs::XExecutableDialog, 102 com::sun::star::lang::XLocalizable, 103 com::sun::star::lang::XServiceInfo, 104 com::sun::star::beans::XPropertyAccess 105 > 106 { 107 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; 108 com::sun::star::lang::Locale meLocale; 109 ResMgr *mpResMgr; 110 sal_Bool OptionsDlg(); 111 ResMgr* getResMgr(); 112 rtl::OUString getResStr( sal_Int16 resid ); 113 void initLocale(); 114 115 ~T602ImportFilterDialog(); 116 117 // XExecutableDialog 118 virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) 119 throw (::com::sun::star::uno::RuntimeException); 120 virtual sal_Int16 SAL_CALL execute() 121 throw (::com::sun::star::uno::RuntimeException); 122 123 // XLocalizable 124 virtual void SAL_CALL setLocale( const com::sun::star::lang::Locale& eLocale ) 125 throw(::com::sun::star::uno::RuntimeException); 126 virtual com::sun::star::lang::Locale SAL_CALL getLocale() 127 throw(::com::sun::star::uno::RuntimeException); 128 129 // XServiceInfo 130 virtual ::rtl::OUString SAL_CALL getImplementationName( ) 131 throw (::com::sun::star::uno::RuntimeException); 132 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 133 throw (::com::sun::star::uno::RuntimeException); 134 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 135 throw (::com::sun::star::uno::RuntimeException); 136 137 // XPropertyAccess 138 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > 139 SAL_CALL getPropertyValues() throw (::com::sun::star::uno::RuntimeException); 140 virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< 141 ::com::sun::star::beans::PropertyValue >& aProps ) 142 throw (::com::sun::star::beans::UnknownPropertyException, 143 ::com::sun::star::beans::PropertyVetoException, 144 ::com::sun::star::lang::IllegalArgumentException, 145 ::com::sun::star::lang::WrappedTargetException, 146 ::com::sun::star::uno::RuntimeException); 147 148 public: 149 T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ); 150 151 }; 152 153 154 class T602ImportFilter : public cppu::WeakImplHelper5 < 155 com::sun::star::document::XFilter, 156 com::sun::star::document::XImporter, 157 com::sun::star::document::XExtendedFilterDetection, 158 com::sun::star::lang::XInitialization, 159 com::sun::star::lang::XServiceInfo 160 > 161 { 162 private: 163 // ::com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream; 164 ::com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> mxHandler; 165 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; 166 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc; 167 ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > mxInputStream; 168 ::rtl::OUString msFilterName; 169 170 SvXMLAttributeList *mpAttrList; 171 172 tnode node; // START 173 174 struct { 175 sal_Int16 mt; // row for header 176 sal_Int16 mb; // row for footer 177 sal_Int16 tb; // tabs 178 sal_Int16 ct; // encoding (0-kamenik, 1-latin2, 2-koi8) 179 sal_Int16 pn; // from page number 180 sal_Int16 lh; // linespacing 3-2x, 4-1.5x, 6-1x 181 sal_Int16 lm; // left border 182 sal_Int16 rm; // right border 183 sal_Int16 pl; // page length 184 } format602; 185 186 // Initialisation constants - they are not changed during the conversion 187 188 inistruct ini; 189 190 // Font state - changes based on font 191 192 struct { 193 fonts nowfnt; // current font 194 fonts oldfnt; // previous font 195 bool uline; // underlined 196 bool olduline; // previous value of uline (font change) 197 } fst; 198 199 // Paragraph state 200 201 struct { 202 sal_Int16 pars; // the number of line endings times linespacing on the current page 203 bool comment; // in comments 204 sal_Int16 wasspace; // 0 there was a space - for reformatting 205 bool wasfdash; // 0 formatting dash 206 bool ccafterln; // false 207 bool willbeeop; // false 208 bool waspar; // false 209 } pst; 210 211 void Reset602(); 212 unsigned char Readchar602(); 213 void Read602(); 214 void par602(bool endofpage); 215 void inschr(unsigned char ch); 216 void inschrdef(unsigned char ch); 217 unsigned char Setformat602(char *cmd); 218 sal_Int16 readnum(unsigned char *ch, bool show); 219 tnode PointCmd602(unsigned char *ch); 220 void setfnt(fonts fnt,bool mustwrite); 221 void wrtfnt(); 222 223 sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) 224 throw (::com::sun::star::uno::RuntimeException); 225 226 public: 227 T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ); 228 ~T602ImportFilter(); 229 230 // XFilter 231 virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) 232 throw (::com::sun::star::uno::RuntimeException); 233 virtual void SAL_CALL cancel( ) 234 throw (::com::sun::star::uno::RuntimeException) {}; 235 236 // XImporter 237 virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) 238 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 239 240 // XExtendedTypeDetection 241 virtual ::rtl::OUString SAL_CALL detect( 242 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor ) 243 throw( com::sun::star::uno::RuntimeException ); 244 245 // XInitialization 246 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 247 throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 248 249 // XServiceInfo 250 virtual ::rtl::OUString SAL_CALL getImplementationName( ) 251 throw (::com::sun::star::uno::RuntimeException); 252 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 253 throw (::com::sun::star::uno::RuntimeException); 254 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 255 throw (::com::sun::star::uno::RuntimeException); 256 }; 257 258 ::rtl::OUString T602ImportFilter_getImplementationName() 259 throw ( ::com::sun::star::uno::RuntimeException ); 260 261 sal_Bool SAL_CALL T602ImportFilter_supportsService( const ::rtl::OUString& ServiceName ) 262 throw ( ::com::sun::star::uno::RuntimeException ); 263 264 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames( ) 265 throw ( ::com::sun::star::uno::RuntimeException ); 266 267 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 268 SAL_CALL T602ImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) 269 throw ( ::com::sun::star::uno::Exception ); 270 271 ::rtl::OUString T602ImportFilterDialog_getImplementationName() 272 throw ( ::com::sun::star::uno::RuntimeException ); 273 274 sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const ::rtl::OUString& ServiceName ) 275 throw ( ::com::sun::star::uno::RuntimeException ); 276 277 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames( ) 278 throw ( ::com::sun::star::uno::RuntimeException ); 279 280 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 281 SAL_CALL T602ImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) 282 throw ( ::com::sun::star::uno::Exception ); 283 284 } 285 286 #endif 287