1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfiltertabdialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
35 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <tools/resid.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <osl/file.hxx>
41 #include "xmlfilterdialogstrings.hrc"
42 #include "xmlfiltertabdialog.hxx"
43 #include "xmlfiltertabdialog.hrc"
44 #include "xmlfiltertabpagebasic.hrc"
45 #include "xmlfiltertabpagexslt.hrc"
46 #include "xmlfiltertabpagebasic.hxx"
47 #include "xmlfiltertabpagexslt.hxx"
48 #include "xmlfiltersettingsdialog.hxx"
49 #include "xmlfiltersettingsdialog.hrc"
50 #include "xmlfilterhelpids.hrc"
53 using namespace com::sun::star::uno
;
54 using namespace com::sun::star::container
;
55 using namespace com::sun::star::beans
;
56 using namespace com::sun::star::lang
;
58 XMLFilterTabDialog::XMLFilterTabDialog( Window
*pParent
, ResMgr
& rResMgr
, const Reference
< XMultiServiceFactory
>& rxMSF
, const filter_info_impl
* pInfo
) :
59 TabDialog( pParent
, ResId( DLG_XML_FILTER_TABDIALOG
, rResMgr
) ),
62 maTabCtrl( this, ResId( 1, rResMgr
) ),
69 maTabCtrl
.SetHelpId( HID_XML_FILTER_TABPAGE_CTRL
);
72 mpNewInfo
= new filter_info_impl( *mpOldInfo
);
74 String
aTitle( GetText() );
75 aTitle
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), mpNewInfo
->maFilterName
);
83 maOKBtn
.SetClickHdl( LINK( this, XMLFilterTabDialog
, OkHdl
) );
85 maTabCtrl
.SetActivatePageHdl( LINK( this, XMLFilterTabDialog
, ActivatePageHdl
) );
86 maTabCtrl
.SetDeactivatePageHdl( LINK( this, XMLFilterTabDialog
, DeactivatePageHdl
) );
88 mpBasicPage
= new XMLFilterTabPageBasic( &maTabCtrl
, mrResMgr
);
89 mpBasicPage
->SetInfo( mpNewInfo
);
91 maTabCtrl
.SetTabPage( RID_XML_FILTER_TABPAGE_BASIC
, mpBasicPage
);
93 Size aSiz
= mpBasicPage
->GetSizePixel();
94 Size aCtrlSiz
= maTabCtrl
.GetTabPageSizePixel();
95 // set size on TabControl only if smaller than TabPage
96 if ( aCtrlSiz
.Width() < aSiz
.Width() || aCtrlSiz
.Height() < aSiz
.Height() )
98 maTabCtrl
.SetTabPageSizePixel( aSiz
);
102 mpXSLTPage
= new XMLFilterTabPageXSLT( &maTabCtrl
, mrResMgr
, mxMSF
);
103 mpXSLTPage
->SetInfo( mpNewInfo
);
105 maTabCtrl
.SetTabPage( RID_XML_FILTER_TABPAGE_XSLT
, mpXSLTPage
);
107 aSiz
= mpXSLTPage
->GetSizePixel();
108 if ( aCtrlSiz
.Width() < aSiz
.Width() || aCtrlSiz
.Height() < aSiz
.Height() )
110 maTabCtrl
.SetTabPageSizePixel( aSiz
);
114 ActivatePageHdl( &maTabCtrl
);
119 // -----------------------------------------------------------------------
121 XMLFilterTabDialog::~XMLFilterTabDialog()
128 // -----------------------------------------------------------------------
130 bool XMLFilterTabDialog::onOk()
132 mpXSLTPage
->FillInfo( mpNewInfo
);
133 mpBasicPage
->FillInfo( mpNewInfo
);
135 sal_uInt16 nErrorPage
= 0;
136 sal_uInt16 nErrorId
= 0;
137 Window
* pFocusWindow
= NULL
;
141 // 1. see if the filter name is ok
142 if( (mpNewInfo
->maFilterName
.getLength() == 0) || (mpNewInfo
->maFilterName
!= mpOldInfo
->maFilterName
) )
144 // if the user deleted the filter name, we reset the original filter name
145 if( mpNewInfo
->maFilterName
.getLength() == 0 )
147 mpNewInfo
->maFilterName
= mpOldInfo
->maFilterName
;
153 Reference
< XNameAccess
> xFilterContainer( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY
);
154 if( xFilterContainer
.is() )
156 if( xFilterContainer
->hasByName( mpNewInfo
->maFilterName
) )
158 nErrorPage
= RID_XML_FILTER_TABPAGE_BASIC
;
159 nErrorId
= STR_ERROR_FILTER_NAME_EXISTS
;
160 pFocusWindow
= &(mpBasicPage
->maEDFilterName
);
161 aReplace1
= mpNewInfo
->maFilterName
;
168 DBG_ERROR( "XMLFilterTabDialog::onOk exception catched!" );
173 // 2. see if the interface name is ok
174 if( (mpNewInfo
->maInterfaceName
.getLength() == 0) || (mpNewInfo
->maInterfaceName
!= mpOldInfo
->maInterfaceName
) )
176 // if the user deleted the interface name, we reset the original filter name
177 if( mpNewInfo
->maInterfaceName
.getLength() == 0 )
179 mpNewInfo
->maInterfaceName
= mpOldInfo
->maInterfaceName
;
185 Reference
< XNameAccess
> xFilterContainer( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY
);
186 if( xFilterContainer
.is() )
188 Sequence
< OUString
> aFilterNames( xFilterContainer
->getElementNames() );
189 OUString
* pFilterName
= aFilterNames
.getArray();
191 const sal_Int32 nCount
= aFilterNames
.getLength();
194 Sequence
< PropertyValue
> aValues
;
195 for( nFilter
= 0; (nFilter
< nCount
) && (nErrorId
== 0); nFilter
++, pFilterName
++ )
197 Any
aAny( xFilterContainer
->getByName( *pFilterName
) );
198 if( !(aAny
>>= aValues
) )
201 const sal_Int32
nValueCount( aValues
.getLength() );
202 PropertyValue
* pValues
= aValues
.getArray();
205 for( nValue
= 0; (nValue
< nValueCount
) && (nErrorId
== 0); nValue
++, pValues
++ )
207 if( pValues
->Name
.equalsAscii( "UIName" ) )
209 OUString aInterfaceName
;
210 pValues
->Value
>>= aInterfaceName
;
211 if( aInterfaceName
== mpNewInfo
->maInterfaceName
)
213 nErrorPage
= RID_XML_FILTER_TABPAGE_BASIC
;
214 nErrorId
= STR_ERROR_TYPE_NAME_EXISTS
;
215 pFocusWindow
= &(mpBasicPage
->maEDInterfaceName
);
216 aReplace1
= mpNewInfo
->maInterfaceName
;
217 aReplace2
= *pFilterName
;
226 DBG_ERROR( "XMLFilterTabDialog::onOk exception catched!" );
231 // 3. see if the dtd is valid
234 if( (mpNewInfo
->maDTD
!= mpOldInfo
->maDTD
) && isFileURL( mpNewInfo
->maDTD
) )
236 osl::File
aFile( mpNewInfo
->maDTD
);
237 osl::File::RC aRC
= aFile
.open( OpenFlag_Read
);
238 if( aRC
!= osl::File::E_None
)
240 nErrorId
= STR_ERROR_DTD_NOT_FOUND
;
241 nErrorPage
= RID_XML_FILTER_TABPAGE_XSLT
;
242 pFocusWindow
= &(mpXSLTPage
->maEDDTDSchema
);
249 // 4. see if the export xslt is valid
250 if( (mpNewInfo
->maExportXSLT
!= mpOldInfo
->maExportXSLT
) && isFileURL( mpNewInfo
->maExportXSLT
) )
252 osl::File
aFile( mpNewInfo
->maExportXSLT
);
253 osl::File::RC aRC
= aFile
.open( OpenFlag_Read
);
254 if( aRC
!= osl::File::E_None
)
256 nErrorId
= STR_ERROR_EXPORT_XSLT_NOT_FOUND
;
257 nErrorPage
= RID_XML_FILTER_TABPAGE_XSLT
;
258 pFocusWindow
= &(mpXSLTPage
->maEDExportXSLT
);
265 // 5. see if the import xslt is valid
266 if( (mpNewInfo
->maImportXSLT
!= mpOldInfo
->maImportXSLT
) && isFileURL( mpNewInfo
->maImportXSLT
) )
268 osl::File
aFile( mpNewInfo
->maImportXSLT
);
269 osl::File::RC aRC
= aFile
.open( OpenFlag_Read
);
270 if( aRC
!= osl::File::E_None
)
272 nErrorId
= STR_ERROR_IMPORT_XSLT_NOT_FOUND
;
273 nErrorPage
= RID_XML_FILTER_TABPAGE_XSLT
;
274 pFocusWindow
= &(mpXSLTPage
->maEDImportTemplate
);
279 // see if we have at least an import or an export dtd
280 if((mpNewInfo
->maImportXSLT
.getLength() == 0) && (mpNewInfo
->maExportXSLT
.getLength() == 0) )
282 nErrorId
= STR_ERROR_EXPORT_XSLT_NOT_FOUND
;
283 nErrorPage
= RID_XML_FILTER_TABPAGE_XSLT
;
284 pFocusWindow
= &(mpXSLTPage
->maEDExportXSLT
);
289 // 6. see if the import template is valid
290 if( (mpNewInfo
->maImportTemplate
!= mpOldInfo
->maImportTemplate
) && isFileURL( mpNewInfo
->maImportTemplate
) )
292 osl::File
aFile( mpNewInfo
->maImportTemplate
);
293 osl::File::RC aRC
= aFile
.open( OpenFlag_Read
);
294 if( aRC
!= osl::File::E_None
)
296 nErrorId
= STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND
;
297 nErrorPage
= RID_XML_FILTER_TABPAGE_XSLT
;
298 pFocusWindow
= &(mpXSLTPage
->maEDImportTemplate
);
305 maTabCtrl
.SetCurPageId( (USHORT
)nErrorPage
);
306 ActivatePageHdl( &maTabCtrl
);
308 ResId
aResId( nErrorId
, mrResMgr
);
309 String
aMessage( aResId
);
311 if( aReplace2
.Len() )
313 aMessage
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s1") ), aReplace1
);
314 aMessage
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s2") ), aReplace2
);
316 else if( aReplace1
.Len() )
318 aMessage
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), aReplace1
);
321 ErrorBox
aBox(this, (WinBits
)(WB_OK
), aMessage
);
325 pFocusWindow
->GrabFocus();
335 // -----------------------------------------------------------------------
337 filter_info_impl
* XMLFilterTabDialog::getNewFilterInfo() const
342 // -----------------------------------------------------------------------
344 IMPL_LINK( XMLFilterTabDialog
, CancelHdl
, Button
*, /* pButton */ )
350 // -----------------------------------------------------------------------
352 IMPL_LINK( XMLFilterTabDialog
, OkHdl
, Button
*, EMPTYARG
)
360 // -----------------------------------------------------------------------
362 IMPL_LINK( XMLFilterTabDialog
, ActivatePageHdl
, TabControl
*, pTabCtrl
)
364 const USHORT nId
= pTabCtrl
->GetCurPageId();
365 TabPage
* pTabPage
= pTabCtrl
->GetTabPage( nId
);
371 // -----------------------------------------------------------------------
373 IMPL_LINK( XMLFilterTabDialog
, DeactivatePageHdl
, TabControl
*, /* pTabCtrl */ )