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