Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/container/XNameAccess.hpp>
30 : : #include <com/sun/star/beans/PropertyValue.hpp>
31 : : #include <tools/resid.hxx>
32 : : #include <vcl/msgbox.hxx>
33 : : #include <osl/file.hxx>
34 : :
35 : : #include "xmlfilterdialogstrings.hrc"
36 : : #include "xmlfiltertabdialog.hxx"
37 : : #include "xmlfiltertabdialog.hrc"
38 : : #include "xmlfiltertabpagebasic.hrc"
39 : : #include "xmlfiltertabpagexslt.hrc"
40 : : #include "xmlfiltertabpagebasic.hxx"
41 : : #include "xmlfiltertabpagexslt.hxx"
42 : : #include "xmlfiltersettingsdialog.hxx"
43 : : #include "xmlfiltersettingsdialog.hrc"
44 : : #include "xmlfilterhelpids.hrc"
45 : :
46 : : using namespace com::sun::star::uno;
47 : : using namespace com::sun::star::container;
48 : : using namespace com::sun::star::beans;
49 : : using namespace com::sun::star::lang;
50 : :
51 : : using ::rtl::OUString;
52 : :
53 : 0 : XMLFilterTabDialog::XMLFilterTabDialog( Window *pParent, ResMgr& rResMgr, const Reference< XMultiServiceFactory >& rxMSF, const filter_info_impl* pInfo ) :
54 : : TabDialog( pParent, ResId( DLG_XML_FILTER_TABDIALOG, rResMgr ) ),
55 : : mxMSF( rxMSF ),
56 : : mrResMgr( rResMgr ),
57 : : maTabCtrl( this, ResId( 1, rResMgr ) ),
58 : : maOKBtn( this ),
59 : : maCancelBtn( this ),
60 : 0 : maHelpBtn( this )
61 : : {
62 : 0 : FreeResource();
63 : :
64 : 0 : maTabCtrl.SetHelpId( HID_XML_FILTER_TABPAGE_CTRL );
65 : :
66 : 0 : mpOldInfo = pInfo;
67 : 0 : mpNewInfo = new filter_info_impl( *mpOldInfo );
68 : :
69 : 0 : String aTitle( GetText() );
70 : 0 : aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), mpNewInfo->maFilterName );
71 : 0 : SetText( aTitle );
72 : :
73 : 0 : maTabCtrl.Show();
74 : 0 : maOKBtn.Show();
75 : 0 : maCancelBtn.Show();
76 : 0 : maHelpBtn.Show();
77 : :
78 : 0 : maOKBtn.SetClickHdl( LINK( this, XMLFilterTabDialog, OkHdl ) );
79 : :
80 : 0 : maTabCtrl.SetActivatePageHdl( LINK( this, XMLFilterTabDialog, ActivatePageHdl ) );
81 : 0 : maTabCtrl.SetDeactivatePageHdl( LINK( this, XMLFilterTabDialog, DeactivatePageHdl ) );
82 : :
83 : 0 : mpBasicPage = new XMLFilterTabPageBasic( &maTabCtrl, mrResMgr );
84 : 0 : mpBasicPage->SetInfo( mpNewInfo );
85 : :
86 : 0 : maTabCtrl.SetTabPage( RID_XML_FILTER_TABPAGE_BASIC, mpBasicPage );
87 : :
88 : 0 : Size aSiz = mpBasicPage->GetSizePixel();
89 : 0 : Size aCtrlSiz = maTabCtrl.GetTabPageSizePixel();
90 : : // set size on TabControl only if smaller than TabPage
91 : 0 : if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
92 : : {
93 : 0 : maTabCtrl.SetTabPageSizePixel( aSiz );
94 : 0 : aCtrlSiz = aSiz;
95 : : }
96 : :
97 : 0 : mpXSLTPage = new XMLFilterTabPageXSLT( &maTabCtrl, mrResMgr, mxMSF );
98 : 0 : mpXSLTPage->SetInfo( mpNewInfo );
99 : :
100 : 0 : maTabCtrl.SetTabPage( RID_XML_FILTER_TABPAGE_XSLT, mpXSLTPage );
101 : :
102 : 0 : aSiz = mpXSLTPage->GetSizePixel();
103 : 0 : if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
104 : : {
105 : 0 : maTabCtrl.SetTabPageSizePixel( aSiz );
106 : 0 : aCtrlSiz = aSiz;
107 : : }
108 : :
109 : 0 : ActivatePageHdl( &maTabCtrl );
110 : :
111 : 0 : AdjustLayout();
112 : 0 : }
113 : :
114 : : // -----------------------------------------------------------------------
115 : :
116 : 0 : XMLFilterTabDialog::~XMLFilterTabDialog()
117 : : {
118 : 0 : delete mpBasicPage;
119 : 0 : delete mpXSLTPage;
120 : 0 : delete mpNewInfo;
121 : 0 : }
122 : :
123 : : // -----------------------------------------------------------------------
124 : :
125 : 0 : bool XMLFilterTabDialog::onOk()
126 : : {
127 : 0 : mpXSLTPage->FillInfo( mpNewInfo );
128 : 0 : mpBasicPage->FillInfo( mpNewInfo );
129 : :
130 : 0 : sal_uInt16 nErrorPage = 0;
131 : 0 : sal_uInt16 nErrorId = 0;
132 : 0 : Window* pFocusWindow = NULL;
133 : 0 : String aReplace1;
134 : 0 : String aReplace2;
135 : :
136 : : // 1. see if the filter name is ok
137 : 0 : if( (mpNewInfo->maFilterName.isEmpty()) || (mpNewInfo->maFilterName != mpOldInfo->maFilterName) )
138 : : {
139 : : // if the user deleted the filter name, we reset the original filter name
140 : 0 : if( mpNewInfo->maFilterName.isEmpty() )
141 : : {
142 : 0 : mpNewInfo->maFilterName = mpOldInfo->maFilterName;
143 : : }
144 : : else
145 : : {
146 : : try
147 : : {
148 : 0 : Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ), UNO_QUERY );
149 : 0 : if( xFilterContainer.is() )
150 : : {
151 : 0 : if( xFilterContainer->hasByName( mpNewInfo->maFilterName ) )
152 : : {
153 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_BASIC;
154 : 0 : nErrorId = STR_ERROR_FILTER_NAME_EXISTS;
155 : 0 : pFocusWindow = &(mpBasicPage->maEDFilterName);
156 : 0 : aReplace1 = mpNewInfo->maFilterName;
157 : : }
158 : :
159 : 0 : }
160 : : }
161 : 0 : catch( const Exception& )
162 : : {
163 : : OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
164 : : }
165 : : }
166 : : }
167 : :
168 : : // 2. see if the interface name is ok
169 : 0 : if( (mpNewInfo->maInterfaceName.isEmpty()) || (mpNewInfo->maInterfaceName != mpOldInfo->maInterfaceName) )
170 : : {
171 : : // if the user deleted the interface name, we reset the original filter name
172 : 0 : if( mpNewInfo->maInterfaceName.isEmpty() )
173 : : {
174 : 0 : mpNewInfo->maInterfaceName = mpOldInfo->maInterfaceName;
175 : : }
176 : : else
177 : : {
178 : : try
179 : : {
180 : 0 : Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ), UNO_QUERY );
181 : 0 : if( xFilterContainer.is() )
182 : : {
183 : 0 : Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
184 : 0 : OUString* pFilterName = aFilterNames.getArray();
185 : :
186 : 0 : const sal_Int32 nCount = aFilterNames.getLength();
187 : : sal_Int32 nFilter;
188 : :
189 : 0 : Sequence< PropertyValue > aValues;
190 : 0 : for( nFilter = 0; (nFilter < nCount) && (nErrorId == 0); nFilter++, pFilterName++ )
191 : : {
192 : 0 : Any aAny( xFilterContainer->getByName( *pFilterName ) );
193 : 0 : if( !(aAny >>= aValues) )
194 : 0 : continue;
195 : :
196 : 0 : const sal_Int32 nValueCount( aValues.getLength() );
197 : 0 : PropertyValue* pValues = aValues.getArray();
198 : : sal_Int32 nValue;
199 : :
200 : 0 : for( nValue = 0; (nValue < nValueCount) && (nErrorId == 0); nValue++, pValues++ )
201 : : {
202 : 0 : if ( pValues->Name == "UIName" )
203 : : {
204 : 0 : OUString aInterfaceName;
205 : 0 : pValues->Value >>= aInterfaceName;
206 : 0 : if( aInterfaceName == mpNewInfo->maInterfaceName )
207 : : {
208 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_BASIC;
209 : 0 : nErrorId = STR_ERROR_TYPE_NAME_EXISTS;
210 : 0 : pFocusWindow = &(mpBasicPage->maEDInterfaceName);
211 : 0 : aReplace1 = mpNewInfo->maInterfaceName;
212 : 0 : aReplace2 = *pFilterName;
213 : 0 : }
214 : : }
215 : : }
216 : 0 : }
217 : 0 : }
218 : : }
219 : 0 : catch( const Exception& )
220 : : {
221 : : OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
222 : : }
223 : : }
224 : : }
225 : :
226 : : // 3. see if the dtd is valid
227 : 0 : if( 0 == nErrorId )
228 : : {
229 : 0 : if( (mpNewInfo->maDTD != mpOldInfo->maDTD) && isFileURL( mpNewInfo->maDTD ) )
230 : : {
231 : 0 : osl::File aFile( mpNewInfo->maDTD );
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_DTD_NOT_FOUND;
236 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
237 : 0 : pFocusWindow = &(mpXSLTPage->maEDDTDSchema);
238 : 0 : }
239 : : }
240 : : }
241 : :
242 : 0 : if( 0 == nErrorId )
243 : : {
244 : : // 4. see if the export xslt is valid
245 : 0 : if( (mpNewInfo->maExportXSLT != mpOldInfo->maExportXSLT) && isFileURL( mpNewInfo->maExportXSLT ) )
246 : : {
247 : 0 : osl::File aFile( mpNewInfo->maExportXSLT );
248 : 0 : osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
249 : 0 : if( aRC != osl::File::E_None )
250 : : {
251 : 0 : nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
252 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
253 : 0 : pFocusWindow = &(mpXSLTPage->maEDExportXSLT);
254 : 0 : }
255 : : }
256 : : }
257 : :
258 : 0 : if( 0 == nErrorId )
259 : : {
260 : : // 5. see if the import xslt is valid
261 : 0 : if( (mpNewInfo->maImportXSLT != mpOldInfo->maImportXSLT) && isFileURL( mpNewInfo->maImportXSLT ) )
262 : : {
263 : 0 : osl::File aFile( mpNewInfo->maImportXSLT );
264 : 0 : osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
265 : 0 : if( aRC != osl::File::E_None )
266 : : {
267 : 0 : nErrorId = STR_ERROR_IMPORT_XSLT_NOT_FOUND;
268 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
269 : 0 : pFocusWindow = &(mpXSLTPage->maEDImportTemplate);
270 : 0 : }
271 : : }
272 : : }
273 : :
274 : : // see if we have at least an import or an export dtd
275 : 0 : if((mpNewInfo->maImportXSLT.isEmpty()) && (mpNewInfo->maExportXSLT.isEmpty()) )
276 : : {
277 : 0 : nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
278 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
279 : 0 : pFocusWindow = &(mpXSLTPage->maEDExportXSLT);
280 : : }
281 : :
282 : 0 : if( 0 == nErrorId )
283 : : {
284 : : // 6. see if the import template is valid
285 : 0 : if( (mpNewInfo->maImportTemplate != mpOldInfo->maImportTemplate) && isFileURL( mpNewInfo->maImportTemplate ) )
286 : : {
287 : 0 : osl::File aFile( mpNewInfo->maImportTemplate );
288 : 0 : osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
289 : 0 : if( aRC != osl::File::E_None )
290 : : {
291 : 0 : nErrorId = STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND;
292 : 0 : nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
293 : 0 : pFocusWindow = &(mpXSLTPage->maEDImportTemplate);
294 : 0 : }
295 : : }
296 : : }
297 : :
298 : 0 : if( 0 != nErrorId )
299 : : {
300 : 0 : maTabCtrl.SetCurPageId( (sal_uInt16)nErrorPage );
301 : 0 : ActivatePageHdl( &maTabCtrl );
302 : :
303 : 0 : ResId aResId( nErrorId, mrResMgr );
304 : 0 : String aMessage( aResId );
305 : :
306 : 0 : if( aReplace2.Len() )
307 : : {
308 : 0 : aMessage.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s1") ), aReplace1 );
309 : 0 : aMessage.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s2") ), aReplace2 );
310 : : }
311 : 0 : else if( aReplace1.Len() )
312 : : {
313 : 0 : aMessage.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), aReplace1 );
314 : : }
315 : :
316 : 0 : ErrorBox aBox(this, (WinBits)(WB_OK), aMessage );
317 : 0 : aBox.Execute();
318 : :
319 : 0 : if( pFocusWindow )
320 : 0 : pFocusWindow->GrabFocus();
321 : :
322 : 0 : return false;
323 : : }
324 : : else
325 : : {
326 : 0 : return true;
327 : 0 : }
328 : : }
329 : :
330 : : // -----------------------------------------------------------------------
331 : :
332 : 0 : filter_info_impl* XMLFilterTabDialog::getNewFilterInfo() const
333 : : {
334 : 0 : return mpNewInfo;
335 : : }
336 : :
337 : : // -----------------------------------------------------------------------
338 : :
339 : 0 : IMPL_LINK_NOARG(XMLFilterTabDialog, OkHdl)
340 : : {
341 : 0 : if( onOk() )
342 : 0 : EndDialog(1);
343 : :
344 : 0 : return 0;
345 : : }
346 : :
347 : : // -----------------------------------------------------------------------
348 : :
349 : 0 : IMPL_LINK( XMLFilterTabDialog, ActivatePageHdl, TabControl *, pTabCtrl )
350 : : {
351 : 0 : const sal_uInt16 nId = pTabCtrl->GetCurPageId();
352 : 0 : TabPage* pTabPage = pTabCtrl->GetTabPage( nId );
353 : 0 : pTabPage->Show();
354 : :
355 : 0 : return 0;
356 : : }
357 : :
358 : : // -----------------------------------------------------------------------
359 : :
360 : 0 : IMPL_LINK( XMLFilterTabDialog, DeactivatePageHdl, TabControl *, /* pTabCtrl */ )
361 : : {
362 : 0 : return sal_True;
363 : : }
364 : :
365 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|