Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
26 :
27 : #include "xmlfilterdialogstrings.hrc"
28 : #include "xmlfiltertabdialog.hxx"
29 : #include "xmlfiltertabpagebasic.hxx"
30 : #include "xmlfiltertabpagexslt.hxx"
31 : #include "xmlfiltersettingsdialog.hxx"
32 :
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;
37 :
38 0 : 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)
42 0 : , mrResMgr(rResMgr)
43 : {
44 0 : get(m_pOKBtn, "ok");
45 0 : get(m_pTabCtrl, "tabcontrol");
46 :
47 0 : mpOldInfo = pInfo;
48 0 : mpNewInfo = new filter_info_impl( *mpOldInfo );
49 :
50 0 : OUString aTitle( GetText() );
51 0 : aTitle = aTitle.replaceAll("%s", mpNewInfo->maFilterName);
52 0 : SetText( aTitle );
53 :
54 0 : m_pOKBtn->SetClickHdl( LINK( this, XMLFilterTabDialog, OkHdl ) );
55 :
56 0 : m_pTabCtrl->SetActivatePageHdl( LINK( this, XMLFilterTabDialog, ActivatePageHdl ) );
57 :
58 0 : mpBasicPage = VclPtr<XMLFilterTabPageBasic>::Create(m_pTabCtrl);
59 0 : mpBasicPage->SetInfo( mpNewInfo );
60 :
61 0 : m_nBasicPageId = m_pTabCtrl->GetPageId("general");
62 0 : m_pTabCtrl->SetTabPage(m_nBasicPageId, mpBasicPage);
63 :
64 0 : mpXSLTPage = VclPtr<XMLFilterTabPageXSLT>::Create(m_pTabCtrl);
65 0 : mpXSLTPage->SetInfo( mpNewInfo );
66 :
67 0 : m_nXSLTPageId = m_pTabCtrl->GetPageId("transformation");
68 0 : m_pTabCtrl->SetTabPage(m_nXSLTPageId, mpXSLTPage);
69 :
70 0 : ActivatePageHdl(nullptr, m_pTabCtrl);
71 0 : }
72 :
73 :
74 :
75 0 : XMLFilterTabDialog::~XMLFilterTabDialog()
76 : {
77 0 : disposeOnce();
78 0 : }
79 :
80 0 : void XMLFilterTabDialog::dispose()
81 : {
82 0 : mpBasicPage.disposeAndClear();
83 0 : mpXSLTPage.disposeAndClear();
84 0 : delete mpNewInfo;
85 0 : m_pTabCtrl.clear();
86 0 : m_pOKBtn.clear();
87 0 : TabDialog::dispose();
88 0 : }
89 :
90 :
91 :
92 0 : bool XMLFilterTabDialog::onOk()
93 : {
94 0 : mpXSLTPage->FillInfo( mpNewInfo );
95 0 : mpBasicPage->FillInfo( mpNewInfo );
96 :
97 0 : sal_uInt16 nErrorPage = 0;
98 0 : sal_uInt16 nErrorId = 0;
99 0 : vcl::Window* pFocusWindow = NULL;
100 0 : OUString aReplace1;
101 0 : OUString aReplace2;
102 :
103 : // 1. see if the filter name is ok
104 0 : if( (mpNewInfo->maFilterName.isEmpty()) || (mpNewInfo->maFilterName != mpOldInfo->maFilterName) )
105 : {
106 : // if the user deleted the filter name, we reset the original filter name
107 0 : if( mpNewInfo->maFilterName.isEmpty() )
108 : {
109 0 : mpNewInfo->maFilterName = mpOldInfo->maFilterName;
110 : }
111 : else
112 : {
113 : try
114 : {
115 0 : Reference< XNameAccess > xFilterContainer( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext ), UNO_QUERY );
116 0 : if( xFilterContainer.is() )
117 : {
118 0 : if( xFilterContainer->hasByName( mpNewInfo->maFilterName ) )
119 : {
120 0 : nErrorPage = m_nBasicPageId;
121 0 : nErrorId = STR_ERROR_FILTER_NAME_EXISTS;
122 0 : pFocusWindow = (mpBasicPage->m_pEDFilterName);
123 0 : aReplace1 = mpNewInfo->maFilterName;
124 : }
125 :
126 0 : }
127 : }
128 0 : catch( const Exception& )
129 : {
130 : OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
131 : }
132 : }
133 : }
134 :
135 : // 2. see if the interface name is ok
136 0 : if( (mpNewInfo->maInterfaceName.isEmpty()) || (mpNewInfo->maInterfaceName != mpOldInfo->maInterfaceName) )
137 : {
138 : // if the user deleted the interface name, we reset the original filter name
139 0 : if( mpNewInfo->maInterfaceName.isEmpty() )
140 : {
141 0 : mpNewInfo->maInterfaceName = mpOldInfo->maInterfaceName;
142 : }
143 : else
144 : {
145 : try
146 : {
147 0 : Reference< XNameAccess > xFilterContainer( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext ), UNO_QUERY );
148 0 : if( xFilterContainer.is() )
149 : {
150 0 : Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
151 0 : OUString* pFilterName = aFilterNames.getArray();
152 :
153 0 : const sal_Int32 nCount = aFilterNames.getLength();
154 : sal_Int32 nFilter;
155 :
156 0 : Sequence< PropertyValue > aValues;
157 0 : for( nFilter = 0; (nFilter < nCount) && (nErrorId == 0); nFilter++, pFilterName++ )
158 : {
159 0 : Any aAny( xFilterContainer->getByName( *pFilterName ) );
160 0 : if( !(aAny >>= aValues) )
161 0 : continue;
162 :
163 0 : const sal_Int32 nValueCount( aValues.getLength() );
164 0 : PropertyValue* pValues = aValues.getArray();
165 : sal_Int32 nValue;
166 :
167 0 : for( nValue = 0; (nValue < nValueCount) && (nErrorId == 0); nValue++, pValues++ )
168 : {
169 0 : if ( pValues->Name == "UIName" )
170 : {
171 0 : OUString aInterfaceName;
172 0 : pValues->Value >>= aInterfaceName;
173 0 : if( aInterfaceName == mpNewInfo->maInterfaceName )
174 : {
175 0 : nErrorPage = m_nBasicPageId;
176 0 : nErrorId = STR_ERROR_TYPE_NAME_EXISTS;
177 0 : pFocusWindow = (mpBasicPage->m_pEDInterfaceName);
178 0 : aReplace1 = mpNewInfo->maInterfaceName;
179 0 : aReplace2 = *pFilterName;
180 0 : }
181 : }
182 : }
183 0 : }
184 0 : }
185 : }
186 0 : catch( const Exception& )
187 : {
188 : OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
189 : }
190 : }
191 : }
192 :
193 0 : if( 0 == nErrorId )
194 : {
195 : // 4. see if the export xslt is valid
196 0 : if( (mpNewInfo->maExportXSLT != mpOldInfo->maExportXSLT) && isFileURL( mpNewInfo->maExportXSLT ) )
197 : {
198 0 : osl::File aFile( mpNewInfo->maExportXSLT );
199 0 : osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
200 0 : if( aRC != osl::File::E_None )
201 : {
202 0 : nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
203 0 : nErrorPage = m_nXSLTPageId;
204 0 : pFocusWindow = (mpXSLTPage->m_pEDExportXSLT);
205 0 : }
206 : }
207 : }
208 :
209 0 : if( 0 == nErrorId )
210 : {
211 : // 5. see if the import xslt is valid
212 0 : if( (mpNewInfo->maImportXSLT != mpOldInfo->maImportXSLT) && isFileURL( mpNewInfo->maImportXSLT ) )
213 : {
214 0 : osl::File aFile( mpNewInfo->maImportXSLT );
215 0 : osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
216 0 : if( aRC != osl::File::E_None )
217 : {
218 0 : nErrorId = STR_ERROR_IMPORT_XSLT_NOT_FOUND;
219 0 : nErrorPage = m_nXSLTPageId;
220 0 : pFocusWindow = (mpXSLTPage->m_pEDImportTemplate);
221 0 : }
222 : }
223 : }
224 :
225 : // see if we have at least an import or an export xslt
226 0 : if((mpNewInfo->maImportXSLT.isEmpty()) && (mpNewInfo->maExportXSLT.isEmpty()) )
227 : {
228 0 : nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
229 0 : nErrorPage = m_nXSLTPageId;
230 0 : pFocusWindow = (mpXSLTPage->m_pEDExportXSLT);
231 : }
232 :
233 0 : if( 0 == nErrorId )
234 : {
235 : // 6. see if the import template is valid
236 0 : if( (mpNewInfo->maImportTemplate != mpOldInfo->maImportTemplate) && isFileURL( mpNewInfo->maImportTemplate ) )
237 : {
238 0 : osl::File aFile( mpNewInfo->maImportTemplate );
239 0 : osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
240 0 : if( aRC != osl::File::E_None )
241 : {
242 0 : nErrorId = STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND;
243 0 : nErrorPage = m_nXSLTPageId;
244 0 : pFocusWindow = (mpXSLTPage->m_pEDImportTemplate);
245 0 : }
246 : }
247 : }
248 :
249 0 : if( 0 != nErrorId )
250 : {
251 0 : m_pTabCtrl->SetCurPageId((sal_uInt16)nErrorPage);
252 0 : ActivatePageHdl(nullptr, m_pTabCtrl);
253 :
254 0 : ResId aResId( nErrorId, mrResMgr );
255 0 : OUString aMessage( aResId );
256 :
257 0 : if( aReplace2.getLength() )
258 : {
259 0 : aMessage = aMessage.replaceAll( "%s1", aReplace1 );
260 0 : aMessage = aMessage.replaceAll( "%s2", aReplace2 );
261 : }
262 0 : else if( aReplace1.getLength() )
263 : {
264 0 : aMessage = aMessage.replaceAll( "%s", aReplace1 );
265 : }
266 :
267 0 : ScopedVclPtrInstance< MessageDialog > aBox(this, aMessage);
268 0 : aBox->Execute();
269 :
270 0 : if( pFocusWindow )
271 0 : pFocusWindow->GrabFocus();
272 :
273 0 : return false;
274 : }
275 : else
276 : {
277 0 : return true;
278 0 : }
279 : }
280 :
281 :
282 :
283 :
284 :
285 :
286 0 : IMPL_LINK_NOARG(XMLFilterTabDialog, OkHdl)
287 : {
288 0 : if( onOk() )
289 0 : EndDialog(1);
290 :
291 0 : return 0;
292 : }
293 :
294 :
295 :
296 0 : IMPL_STATIC_LINK(
297 : XMLFilterTabDialog, ActivatePageHdl, TabControl *, pTabCtrl )
298 : {
299 0 : const sal_uInt16 nId = pTabCtrl->GetCurPageId();
300 0 : TabPage* pTabPage = pTabCtrl->GetTabPage( nId );
301 0 : pTabPage->Show();
302 :
303 0 : return 0;
304 3 : }
305 :
306 :
307 :
308 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|