1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/container/XNameAccess.hpp>
21 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <com/sun/star/uno/XComponentContext.hpp>
23 #include <tools/resid.hxx>
24 #include <vcl/layout.hxx>
25 #include <osl/file.hxx>
27 #include "xmlfilterdialogstrings.hrc"
28 #include "xmlfiltertabdialog.hxx"
29 #include "xmlfiltertabpagebasic.hxx"
30 #include "xmlfiltertabpagexslt.hxx"
31 #include "xmlfiltersettingsdialog.hxx"
33 using namespace com::sun::star::uno
;
34 using namespace com::sun::star::container
;
35 using namespace com::sun::star::beans
;
36 using namespace com::sun::star::lang
;
38 XMLFilterTabDialog::XMLFilterTabDialog(vcl::Window
*pParent
, ResMgr
& rResMgr
,
39 const Reference
< XComponentContext
>& rxContext
, const filter_info_impl
* pInfo
)
40 : TabDialog(pParent
, "XSLTFilterDialog","filter/ui/xsltfilterdialog.ui")
41 , mxContext(rxContext
)
45 get(m_pTabCtrl
, "tabcontrol");
48 mpNewInfo
= new filter_info_impl( *mpOldInfo
);
50 OUString
aTitle( GetText() );
51 aTitle
= aTitle
.replaceAll("%s", mpNewInfo
->maFilterName
);
54 m_pOKBtn
->SetClickHdl( LINK( this, XMLFilterTabDialog
, OkHdl
) );
56 m_pTabCtrl
->SetActivatePageHdl( LINK( this, XMLFilterTabDialog
, ActivatePageHdl
) );
57 m_pTabCtrl
->SetDeactivatePageHdl( LINK( this, XMLFilterTabDialog
, DeactivatePageHdl
) );
59 mpBasicPage
= VclPtr
<XMLFilterTabPageBasic
>::Create(m_pTabCtrl
);
60 mpBasicPage
->SetInfo( mpNewInfo
);
62 m_nBasicPageId
= m_pTabCtrl
->GetPageId("general");
63 m_pTabCtrl
->SetTabPage(m_nBasicPageId
, mpBasicPage
);
65 mpXSLTPage
= VclPtr
<XMLFilterTabPageXSLT
>::Create(m_pTabCtrl
);
66 mpXSLTPage
->SetInfo( mpNewInfo
);
68 m_nXSLTPageId
= m_pTabCtrl
->GetPageId("transformation");
69 m_pTabCtrl
->SetTabPage(m_nXSLTPageId
, mpXSLTPage
);
71 ActivatePageHdl(nullptr, m_pTabCtrl
);
76 XMLFilterTabDialog::~XMLFilterTabDialog()
81 void XMLFilterTabDialog::dispose()
83 mpBasicPage
.disposeAndClear();
84 mpXSLTPage
.disposeAndClear();
93 bool XMLFilterTabDialog::onOk()
95 mpXSLTPage
->FillInfo( mpNewInfo
);
96 mpBasicPage
->FillInfo( mpNewInfo
);
98 sal_uInt16 nErrorPage
= 0;
99 sal_uInt16 nErrorId
= 0;
100 vcl::Window
* pFocusWindow
= NULL
;
104 // 1. see if the filter name is ok
105 if( (mpNewInfo
->maFilterName
.isEmpty()) || (mpNewInfo
->maFilterName
!= mpOldInfo
->maFilterName
) )
107 // if the user deleted the filter name, we reset the original filter name
108 if( mpNewInfo
->maFilterName
.isEmpty() )
110 mpNewInfo
->maFilterName
= mpOldInfo
->maFilterName
;
116 Reference
< XNameAccess
> xFilterContainer( mxContext
->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext
), UNO_QUERY
);
117 if( xFilterContainer
.is() )
119 if( xFilterContainer
->hasByName( mpNewInfo
->maFilterName
) )
121 nErrorPage
= m_nBasicPageId
;
122 nErrorId
= STR_ERROR_FILTER_NAME_EXISTS
;
123 pFocusWindow
= (mpBasicPage
->m_pEDFilterName
);
124 aReplace1
= mpNewInfo
->maFilterName
;
129 catch( const Exception
& )
131 OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
136 // 2. see if the interface name is ok
137 if( (mpNewInfo
->maInterfaceName
.isEmpty()) || (mpNewInfo
->maInterfaceName
!= mpOldInfo
->maInterfaceName
) )
139 // if the user deleted the interface name, we reset the original filter name
140 if( mpNewInfo
->maInterfaceName
.isEmpty() )
142 mpNewInfo
->maInterfaceName
= mpOldInfo
->maInterfaceName
;
148 Reference
< XNameAccess
> xFilterContainer( mxContext
->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext
), UNO_QUERY
);
149 if( xFilterContainer
.is() )
151 Sequence
< OUString
> aFilterNames( xFilterContainer
->getElementNames() );
152 OUString
* pFilterName
= aFilterNames
.getArray();
154 const sal_Int32 nCount
= aFilterNames
.getLength();
157 Sequence
< PropertyValue
> aValues
;
158 for( nFilter
= 0; (nFilter
< nCount
) && (nErrorId
== 0); nFilter
++, pFilterName
++ )
160 Any
aAny( xFilterContainer
->getByName( *pFilterName
) );
161 if( !(aAny
>>= aValues
) )
164 const sal_Int32
nValueCount( aValues
.getLength() );
165 PropertyValue
* pValues
= aValues
.getArray();
168 for( nValue
= 0; (nValue
< nValueCount
) && (nErrorId
== 0); nValue
++, pValues
++ )
170 if ( pValues
->Name
== "UIName" )
172 OUString aInterfaceName
;
173 pValues
->Value
>>= aInterfaceName
;
174 if( aInterfaceName
== mpNewInfo
->maInterfaceName
)
176 nErrorPage
= m_nBasicPageId
;
177 nErrorId
= STR_ERROR_TYPE_NAME_EXISTS
;
178 pFocusWindow
= (mpBasicPage
->m_pEDInterfaceName
);
179 aReplace1
= mpNewInfo
->maInterfaceName
;
180 aReplace2
= *pFilterName
;
187 catch( const Exception
& )
189 OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
196 // 4. see if the export xslt is valid
197 if( (mpNewInfo
->maExportXSLT
!= mpOldInfo
->maExportXSLT
) && isFileURL( mpNewInfo
->maExportXSLT
) )
199 osl::File
aFile( mpNewInfo
->maExportXSLT
);
200 osl::File::RC aRC
= aFile
.open( osl_File_OpenFlag_Read
);
201 if( aRC
!= osl::File::E_None
)
203 nErrorId
= STR_ERROR_EXPORT_XSLT_NOT_FOUND
;
204 nErrorPage
= m_nXSLTPageId
;
205 pFocusWindow
= (mpXSLTPage
->m_pEDExportXSLT
);
212 // 5. see if the import xslt is valid
213 if( (mpNewInfo
->maImportXSLT
!= mpOldInfo
->maImportXSLT
) && isFileURL( mpNewInfo
->maImportXSLT
) )
215 osl::File
aFile( mpNewInfo
->maImportXSLT
);
216 osl::File::RC aRC
= aFile
.open( osl_File_OpenFlag_Read
);
217 if( aRC
!= osl::File::E_None
)
219 nErrorId
= STR_ERROR_IMPORT_XSLT_NOT_FOUND
;
220 nErrorPage
= m_nXSLTPageId
;
221 pFocusWindow
= (mpXSLTPage
->m_pEDImportTemplate
);
226 // see if we have at least an import or an export xslt
227 if((mpNewInfo
->maImportXSLT
.isEmpty()) && (mpNewInfo
->maExportXSLT
.isEmpty()) )
229 nErrorId
= STR_ERROR_EXPORT_XSLT_NOT_FOUND
;
230 nErrorPage
= m_nXSLTPageId
;
231 pFocusWindow
= (mpXSLTPage
->m_pEDExportXSLT
);
236 // 6. see if the import template is valid
237 if( (mpNewInfo
->maImportTemplate
!= mpOldInfo
->maImportTemplate
) && isFileURL( mpNewInfo
->maImportTemplate
) )
239 osl::File
aFile( mpNewInfo
->maImportTemplate
);
240 osl::File::RC aRC
= aFile
.open( osl_File_OpenFlag_Read
);
241 if( aRC
!= osl::File::E_None
)
243 nErrorId
= STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND
;
244 nErrorPage
= m_nXSLTPageId
;
245 pFocusWindow
= (mpXSLTPage
->m_pEDImportTemplate
);
252 m_pTabCtrl
->SetCurPageId((sal_uInt16
)nErrorPage
);
253 ActivatePageHdl(nullptr, m_pTabCtrl
);
255 ResId
aResId( nErrorId
, mrResMgr
);
256 OUString
aMessage( aResId
);
258 if( aReplace2
.getLength() )
260 aMessage
= aMessage
.replaceAll( "%s1", aReplace1
);
261 aMessage
= aMessage
.replaceAll( "%s2", aReplace2
);
263 else if( aReplace1
.getLength() )
265 aMessage
= aMessage
.replaceAll( "%s", aReplace1
);
268 ScopedVclPtrInstance
< MessageDialog
> aBox(this, aMessage
);
272 pFocusWindow
->GrabFocus();
287 IMPL_LINK_NOARG(XMLFilterTabDialog
, OkHdl
)
298 XMLFilterTabDialog
, ActivatePageHdl
, TabControl
*, pTabCtrl
)
300 const sal_uInt16 nId
= pTabCtrl
->GetCurPageId();
301 TabPage
* pTabPage
= pTabCtrl
->GetTabPage( nId
);
309 IMPL_STATIC_LINK_NOARG_TYPED( XMLFilterTabDialog
, DeactivatePageHdl
, TabControl
*, bool )
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */