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/frame/XConfigManager.hpp>
30 : : #include <com/sun/star/container/XNameAccess.hpp>
31 : : #include <com/sun/star/util/XFlushable.hpp>
32 : :
33 : : #include <com/sun/star/beans/PropertyValue.hpp>
34 : :
35 : : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
36 : : #include <tools/urlobj.hxx>
37 : : #include <svtools/headbar.hxx>
38 : : #include <unotools/streamwrap.hxx>
39 : : #include <osl/file.hxx>
40 : : #include <vcl/msgbox.hxx>
41 : : #include <sfx2/filedlghelper.hxx>
42 : :
43 : : #include <rtl/uri.hxx>
44 : :
45 : : #include <algorithm>
46 : :
47 : : #include "xmlfilterdialogstrings.hrc"
48 : : #include "xmlfiltersettingsdialog.hxx"
49 : : #include "xmlfiltersettingsdialog.hrc"
50 : : #include "xmlfiltertabdialog.hxx"
51 : : #include "xmlfiltertestdialog.hxx"
52 : : #include "xmlfilterjar.hxx"
53 : : #include "xmlfilterhelpids.hrc"
54 : :
55 : : using namespace osl;
56 : : using namespace com::sun::star::lang;
57 : : using namespace com::sun::star::uno;
58 : : using namespace com::sun::star::io;
59 : : using namespace com::sun::star::frame;
60 : : using namespace com::sun::star::container;
61 : : using namespace com::sun::star::beans;
62 : : using namespace com::sun::star::util;
63 : :
64 : : using ::rtl::OUString;
65 : : using ::rtl::Uri;
66 : :
67 : : ResMgr* XMLFilterSettingsDialog::mpResMgr = NULL;
68 : :
69 : 0 : XMLFilterSettingsDialog::XMLFilterSettingsDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ) :
70 : : WorkWindow( pParent, ResId( DLG_XML_FILTER_SETTINGS_DIALOG, rResMgr ) ),
71 : : mxMSF( rxMSF ),
72 : : maCtrlFilterList( this, ResId( CTRL_XML_FILTER_LIST, rResMgr ) ),
73 : : maPBNew( this, ResId( PB_XML_FILTER_NEW, rResMgr ) ),
74 : : maPBEdit( this, ResId( PB_XML_FILTER_EDIT, rResMgr ) ),
75 : : maPBTest( this, ResId( PB_XML_FILTER_TEST, rResMgr ) ),
76 : : maPBDelete( this, ResId( PB_XML_FILTER_DELETE, rResMgr ) ),
77 : : maPBSave( this, ResId( PB_XML_FILTER_SAVE, rResMgr ) ),
78 : : maPBOpen( this, ResId( PB_XML_FILTER_OPEN, rResMgr ) ),
79 : : maPBHelp( this, ResId( BTN_XML_FILTER_HELP, rResMgr ) ),
80 : : maPBClose( this, ResId( PB_XML_FILTER_CLOSE, rResMgr ) ),
81 : : mbIsClosable(true),
82 : : sTemplatePath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/template/") ),
83 : 0 : sDocTypePrefix( RTL_CONSTASCII_USTRINGPARAM( "doctype:") )
84 : : {
85 : 0 : FreeResource();
86 : :
87 : 0 : mpResMgr = &rResMgr;
88 : :
89 : 0 : mpFilterListBox = new XMLFilterListBox( &maCtrlFilterList );
90 : 0 : mpFilterListBox->SetSelectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) );
91 : 0 : mpFilterListBox->SetDeselectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) );
92 : 0 : mpFilterListBox->SetDoubleClickHdl( LINK( this, XMLFilterSettingsDialog, DoubleClickHdl_Impl ) );
93 : 0 : mpFilterListBox->SetAccessibleName(String( RESID( STR_XML_FILTER_LISTBOX )));
94 : 0 : maCtrlFilterList.SetAccessibleName(String( RESID( STR_XML_FILTER_LISTBOX )));
95 : 0 : mpFilterListBox->SetHelpId( HID_XML_FILTER_LIST );
96 : :
97 : 0 : maPBNew.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
98 : 0 : maPBEdit.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
99 : 0 : maPBTest.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
100 : 0 : maPBDelete.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
101 : 0 : maPBSave.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
102 : 0 : maPBOpen.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
103 : 0 : maPBClose.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
104 : :
105 : : try
106 : : {
107 : 0 : mxFilterContainer = Reference< XNameContainer >::query( rxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ) );
108 : 0 : mxTypeDetection = Reference< XNameContainer >::query( rxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" )) ));
109 : 0 : mxExtendedTypeDetection = Reference< XNameContainer >::query( rxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.ExtendedTypeDetectionFactory" )) ) );
110 : :
111 : 0 : Reference< XConfigManager > xCfgMgr( mxMSF->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.config.SpecialConfigManager" )) ), UNO_QUERY );
112 : 0 : if( xCfgMgr.is() )
113 : : {
114 : 0 : sTemplatePath = xCfgMgr->substituteVariables( sTemplatePath );
115 : 0 : }
116 : : }
117 : 0 : catch(const Exception&)
118 : : {
119 : : OSL_FAIL( "XMLFilterSettingsDialog::XMLFilterSettingsDialog exception catched!" );
120 : : }
121 : 0 : }
122 : :
123 : : // -----------------------------------------------------------------------
124 : :
125 : 0 : XMLFilterSettingsDialog::~XMLFilterSettingsDialog()
126 : : {
127 : 0 : delete mpFilterListBox;
128 : 0 : }
129 : :
130 : : // -----------------------------------------------------------------------
131 : :
132 : 0 : IMPL_LINK(XMLFilterSettingsDialog, ClickHdl_Impl, PushButton *, pButton )
133 : : {
134 : 0 : mbIsClosable = false;
135 : :
136 : 0 : if( &maPBNew == pButton )
137 : : {
138 : 0 : onNew();
139 : : }
140 : 0 : else if( &maPBEdit == pButton )
141 : : {
142 : 0 : onEdit();
143 : : }
144 : 0 : else if( &maPBTest == pButton )
145 : : {
146 : 0 : onTest();
147 : : }
148 : 0 : else if( &maPBDelete == pButton )
149 : : {
150 : 0 : onDelete();
151 : : }
152 : 0 : else if( &maPBSave == pButton )
153 : : {
154 : 0 : onSave();
155 : : }
156 : 0 : else if( &maPBOpen == pButton )
157 : : {
158 : 0 : onOpen();
159 : : }
160 : 0 : else if( &maPBClose == pButton )
161 : : {
162 : 0 : onClose();
163 : : }
164 : :
165 : 0 : mbIsClosable = true;
166 : 0 : return 0;
167 : : }
168 : :
169 : : // -----------------------------------------------------------------------
170 : :
171 : 0 : IMPL_LINK_NOARG(XMLFilterSettingsDialog, SelectionChangedHdl_Impl)
172 : : {
173 : 0 : updateStates();
174 : 0 : return 0;
175 : : }
176 : :
177 : : // -----------------------------------------------------------------------
178 : :
179 : 0 : IMPL_LINK_NOARG(XMLFilterSettingsDialog, DoubleClickHdl_Impl)
180 : : {
181 : 0 : onEdit();
182 : 0 : return 0;
183 : : }
184 : :
185 : 0 : bool XMLFilterSettingsDialog::isClosable()
186 : : {
187 : 0 : return mbIsClosable;
188 : : }
189 : :
190 : : // -----------------------------------------------------------------------
191 : :
192 : 0 : void XMLFilterSettingsDialog::ShowWindow()
193 : : {
194 : 0 : maCtrlFilterList.GrabFocus();
195 : 0 : disposeFilterList();
196 : 0 : mpFilterListBox->Clear();
197 : 0 : initFilterList();
198 : 0 : updateStates();
199 : 0 : mpFilterListBox->Reset();
200 : :
201 : 0 : WorkWindow::Show( sal_True );
202 : 0 : }
203 : :
204 : : // -----------------------------------------------------------------------
205 : :
206 : 0 : void XMLFilterSettingsDialog::updateStates()
207 : : {
208 : 0 : SvLBoxEntry* pSelectedEntry = mpFilterListBox->FirstSelected();
209 : :
210 : 0 : bool bHasSelection = pSelectedEntry != NULL;
211 : :
212 : 0 : bool bMultiSelection = bHasSelection && (mpFilterListBox->NextSelected( pSelectedEntry ) != NULL );
213 : 0 : bool bIsReadonly = false;
214 : 0 : bool bIsDefault = false;
215 : 0 : if(pSelectedEntry)
216 : : {
217 : 0 : filter_info_impl* pInfo = (filter_info_impl*)pSelectedEntry->GetUserData();
218 : 0 : bIsReadonly = 0 != pInfo->mbReadonly;
219 : :
220 : 0 : sal_Int32 nFact = SvtModuleOptions::E_WRITER;
221 : 0 : while(nFact <= SvtModuleOptions::E_BASIC)
222 : : {
223 : 0 : ::rtl::OUString sDefault = maModuleOpt.GetFactoryDefaultFilter((SvtModuleOptions::EFactory)nFact);
224 : 0 : if( sDefault == pInfo->maFilterName )
225 : : {
226 : 0 : bIsDefault = true;
227 : : break;
228 : : }
229 : 0 : ++nFact;
230 : 0 : }
231 : : }
232 : 0 : maPBEdit.Enable( bHasSelection && !bMultiSelection && !bIsReadonly);
233 : 0 : maPBTest.Enable( bHasSelection && !bMultiSelection );
234 : 0 : maPBDelete.Enable( bHasSelection && !bMultiSelection && !bIsReadonly && !bIsDefault);
235 : 0 : maPBSave.Enable( bHasSelection );
236 : 0 : }
237 : :
238 : : // -----------------------------------------------------------------------
239 : :
240 : : /** is called when the user clicks on the "New" button */
241 : 0 : void XMLFilterSettingsDialog::onNew()
242 : : {
243 : 0 : filter_info_impl aTempInfo;
244 : :
245 : : // create a unique filter name
246 : 0 : aTempInfo.maFilterName = createUniqueFilterName( String( RESID( STR_DEFAULT_FILTER_NAME ) ) );
247 : :
248 : : // init default extension
249 : 0 : String aDefaultExtension( RESID( STR_DEFAULT_EXTENSION ) );
250 : 0 : aTempInfo.maExtension = aDefaultExtension;
251 : :
252 : : // set default ui name
253 : 0 : aTempInfo.maInterfaceName = createUniqueInterfaceName( String( RESID( STR_DEFAULT_UI_NAME ) ) );
254 : :
255 : : // set default application
256 : 0 : aTempInfo.maDocumentService = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ));
257 : :
258 : : // execute XML Filter Dialog
259 : 0 : XMLFilterTabDialog aDlg( this, *mpResMgr, mxMSF, &aTempInfo );
260 : 0 : if ( aDlg.Execute() == RET_OK )
261 : : {
262 : : // insert the new filter
263 : 0 : insertOrEdit( aDlg.getNewFilterInfo() );
264 : 0 : }
265 : 0 : }
266 : :
267 : : // -----------------------------------------------------------------------
268 : :
269 : : /** is called when the user clicks on the "Edit" Button */
270 : 0 : void XMLFilterSettingsDialog::onEdit()
271 : : {
272 : : // get selected filter entry
273 : 0 : SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
274 : 0 : if( pEntry )
275 : : {
276 : : // get its filter info
277 : 0 : filter_info_impl* pOldInfo = (filter_info_impl*)pEntry->GetUserData();
278 : :
279 : : // execute XML Filter Dialog
280 : 0 : XMLFilterTabDialog aDlg( this, *mpResMgr, mxMSF, pOldInfo );
281 : 0 : if ( aDlg.Execute() == RET_OK )
282 : : {
283 : 0 : filter_info_impl* pNewInfo = aDlg.getNewFilterInfo();
284 : :
285 : 0 : if( !(*pOldInfo == *pNewInfo) )
286 : : {
287 : : // change filter
288 : 0 : insertOrEdit( pNewInfo, pOldInfo );
289 : : }
290 : 0 : }
291 : : }
292 : 0 : }
293 : :
294 : : // -----------------------------------------------------------------------
295 : :
296 : : /** helper to create a sequence of strings from an extensions strings
297 : : "ext1;ext2;ext3" will become { "ext1", "ext2", "ext3" } */
298 : 0 : static Sequence< OUString > createExtensionsSequence( const rtl::OUString& rExtensions )
299 : : {
300 : : // first count how many extensions we have inside the string
301 : 0 : int nExtensions = 0;
302 : :
303 : 0 : int nLength = rExtensions.getLength();
304 : 0 : if( nLength )
305 : : {
306 : : // a non empty string has at least one extension
307 : 0 : nExtensions++;
308 : :
309 : : // now count the delimeters ';'
310 : 0 : const sal_Unicode * pString = rExtensions.getStr();
311 : : int i;
312 : 0 : for( i = 0; i < nLength; i++, pString++ )
313 : : {
314 : 0 : if( *pString == sal_Unicode( ';' ) )
315 : 0 : nExtensions++;
316 : : }
317 : : }
318 : :
319 : 0 : Sequence< OUString > aExtensions( nExtensions );
320 : :
321 : : // extract the extensions from the source string and fill the sequence
322 : :
323 : 0 : int nLastIndex = 0;
324 : 0 : int nCurrentIndex = 0;
325 : : int i;
326 : :
327 : 0 : for( i = 0; i < nExtensions; i++ )
328 : : {
329 : 0 : nLastIndex = rExtensions.indexOf( sal_Unicode( ';' ), nLastIndex );
330 : :
331 : 0 : if( nLastIndex == -1 )
332 : : {
333 : 0 : aExtensions[i] = rExtensions.copy( nCurrentIndex );
334 : 0 : break;
335 : : }
336 : : else
337 : : {
338 : 0 : aExtensions[i] = rExtensions.copy( nCurrentIndex, nLastIndex - nCurrentIndex );
339 : 0 : nCurrentIndex = nLastIndex + 1;
340 : 0 : nLastIndex = nCurrentIndex;
341 : : }
342 : : }
343 : :
344 : 0 : return aExtensions;
345 : : }
346 : :
347 : : // -----------------------------------------------------------------------
348 : :
349 : : /** checks if the given name is unique inside the filter factory. If not,
350 : : numbers are added until the returned name is unique */
351 : 0 : OUString XMLFilterSettingsDialog::createUniqueFilterName( const OUString& rFilterName )
352 : : {
353 : 0 : OUString aFilterName( rFilterName );
354 : 0 : OUString aSpace( sal_Unicode( ' ' ) );
355 : :
356 : 0 : sal_Int32 nId = 2;
357 : :
358 : 0 : while( mxFilterContainer->hasByName( aFilterName ) )
359 : : {
360 : 0 : aFilterName = rFilterName;
361 : 0 : aFilterName += aSpace;
362 : 0 : aFilterName += OUString::valueOf( nId++ );
363 : : }
364 : :
365 : 0 : return aFilterName;
366 : : }
367 : :
368 : : // -----------------------------------------------------------------------
369 : :
370 : : /** checks if the given name is unique inside the type detection. If not,
371 : : numbers are added until the returned name is unique */
372 : 0 : OUString XMLFilterSettingsDialog::createUniqueTypeName( const OUString& rTypeName )
373 : : {
374 : 0 : OUString aTypeName( rTypeName );
375 : 0 : OUString aSpace( sal_Unicode( ' ' ) );
376 : :
377 : 0 : sal_Int32 nId = 2;
378 : :
379 : 0 : while( mxFilterContainer->hasByName( aTypeName ) )
380 : : {
381 : 0 : aTypeName = rTypeName;
382 : 0 : aTypeName += aSpace;
383 : 0 : aTypeName += OUString::valueOf( nId++ );
384 : : }
385 : :
386 : 0 : return aTypeName;
387 : : }
388 : :
389 : : /** checks if the given name is a unique ui name inside the filter factory. If not,
390 : : numbers are added until the returned name is unique */
391 : 0 : OUString XMLFilterSettingsDialog::createUniqueInterfaceName( const OUString& rInterfaceName )
392 : : {
393 : 0 : sal_Int32 nDefaultNumber = 0;
394 : :
395 : : try
396 : : {
397 : 0 : Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
398 : 0 : OUString* pFilterName = aFilterNames.getArray();
399 : :
400 : 0 : const sal_Int32 nCount = aFilterNames.getLength();
401 : : sal_Int32 nFilter;
402 : :
403 : 0 : Sequence< PropertyValue > aValues;
404 : 0 : for( nFilter = 0; (nFilter < nCount); nFilter++, pFilterName++ )
405 : : {
406 : 0 : Any aAny( mxFilterContainer->getByName( *pFilterName ) );
407 : 0 : if( !(aAny >>= aValues) )
408 : 0 : continue;
409 : :
410 : 0 : const sal_Int32 nValueCount( aValues.getLength() );
411 : 0 : PropertyValue* pValues = aValues.getArray();
412 : : sal_Int32 nValue;
413 : :
414 : 0 : for( nValue = 0; nValue < nValueCount; nValue++, pValues++ )
415 : : {
416 : 0 : if ( pValues->Name == "UIName" )
417 : : {
418 : 0 : OUString aInterfaceName;
419 : 0 : pValues->Value >>= aInterfaceName;
420 : :
421 : :
422 : : // see if this filter matches our default filter name
423 : 0 : if( aInterfaceName.match( rInterfaceName ) )
424 : : {
425 : : // if yes, make sure we generate a unique name with a higher number
426 : : // this is dump but fast
427 : 0 : sal_Int32 nNumber = aInterfaceName.copy( rInterfaceName.getLength() ).toInt32();
428 : 0 : if( nNumber >= nDefaultNumber )
429 : 0 : nDefaultNumber = nNumber + 1;
430 : 0 : }
431 : : }
432 : : }
433 : 0 : }
434 : : }
435 : 0 : catch( const Exception& )
436 : : {
437 : : OSL_FAIL( "XMLFilterSettingsDialog::createUniqueInterfaceName exception catched!" );
438 : : }
439 : :
440 : 0 : OUString aInterfaceName( rInterfaceName );
441 : 0 : if( nDefaultNumber )
442 : : {
443 : 0 : aInterfaceName += OUString( sal_Unicode( ' ' ) );
444 : 0 : aInterfaceName += String::CreateFromInt32( nDefaultNumber );
445 : : }
446 : :
447 : 0 : return aInterfaceName;
448 : : }
449 : :
450 : : // -----------------------------------------------------------------------
451 : :
452 : : /** inserts a new filter into the ui and configuration if pOldInfo is NULL.
453 : : If pOldInfo is not null, the old filter will be replaced with the new settings */
454 : 0 : bool XMLFilterSettingsDialog::insertOrEdit( filter_info_impl* pNewInfo, const filter_info_impl* pOldInfo )
455 : : {
456 : 0 : bool bOk = true;
457 : :
458 : 0 : if( pOldInfo )
459 : : {
460 : : // see if we need to update the type name
461 : 0 : if( pOldInfo->maFilterName != pNewInfo->maFilterName )
462 : : {
463 : 0 : if( pOldInfo->maType == pOldInfo->maFilterName )
464 : : {
465 : 0 : pNewInfo->maType = OUString();
466 : : }
467 : : }
468 : :
469 : : // see if we need to clean up old stuff first
470 : : try
471 : : {
472 : : // if filter name changed, we need to remove the old filter first
473 : 0 : if( pOldInfo->maFilterName != pNewInfo->maFilterName )
474 : 0 : mxFilterContainer->removeByName( pOldInfo->maFilterName );
475 : :
476 : : // if type name changed, we need to remove the old type first
477 : 0 : if( pOldInfo->maType != pNewInfo->maType )
478 : 0 : mxTypeDetection->removeByName( pOldInfo->maType );
479 : : }
480 : 0 : catch( const Exception& )
481 : : {
482 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
483 : 0 : bOk = false;
484 : : }
485 : : }
486 : :
487 : 0 : filter_info_impl* pFilterEntry( NULL );
488 : :
489 : 0 : if( bOk )
490 : : {
491 : : // create or copy filter info
492 : 0 : if( pOldInfo )
493 : : {
494 : : // change existing filter entry in filter list box
495 : 0 : pFilterEntry = const_cast<filter_info_impl*>(pOldInfo);
496 : 0 : *pFilterEntry = *pNewInfo;
497 : : }
498 : : else
499 : : {
500 : : // add new entry to filter list box
501 : 0 : pFilterEntry = new filter_info_impl( *pNewInfo );
502 : : }
503 : : }
504 : :
505 : : // check if we need to copy the template
506 : 0 : if( !pFilterEntry->maImportTemplate.isEmpty() )
507 : : {
508 : 0 : if( !pFilterEntry->maImportTemplate.matchIgnoreAsciiCase( sTemplatePath ) )
509 : : {
510 : 0 : INetURLObject aSourceURL( pFilterEntry->maImportTemplate );
511 : 0 : if( !aSourceURL.GetName().isEmpty() )
512 : : {
513 : 0 : OUString aDestURL( sTemplatePath );
514 : 0 : aDestURL += pFilterEntry->maFilterName;
515 : 0 : aDestURL += OUString( sal_Unicode('/') );
516 : 0 : if( createDirectory( aDestURL ) )
517 : : {
518 : 0 : aDestURL += aSourceURL.GetName();
519 : :
520 : 0 : SvFileStream aInputStream(pFilterEntry->maImportTemplate, STREAM_READ );
521 : 0 : Reference< XInputStream > xIS( new utl::OInputStreamWrapper( aInputStream ) );
522 : 0 : SvFileStream aOutputStream(aDestURL, STREAM_WRITE );
523 : 0 : Reference< XOutputStream > xOS( new utl::OOutputStreamWrapper( aOutputStream ) );
524 : :
525 : 0 : if( copyStreams( xIS, xOS ) )
526 : 0 : pFilterEntry->maImportTemplate = aDestURL;
527 : 0 : }
528 : 0 : }
529 : : }
530 : : }
531 : :
532 : 0 : if( bOk )
533 : : {
534 : 0 : if( pFilterEntry->maType.isEmpty() )
535 : : {
536 : 0 : pFilterEntry->maType = createUniqueTypeName( pNewInfo->maFilterName );
537 : : }
538 : :
539 : : // update import/export flags
540 : 0 : if( !pFilterEntry->maImportXSLT.isEmpty() )
541 : : {
542 : 0 : pFilterEntry->maFlags |= 1;
543 : : }
544 : : else
545 : : {
546 : 0 : pFilterEntry->maFlags &= ~1;
547 : : }
548 : :
549 : 0 : if( !pFilterEntry->maExportXSLT.isEmpty() )
550 : : {
551 : 0 : pFilterEntry->maFlags |= 2;
552 : : }
553 : : else
554 : : {
555 : 0 : pFilterEntry->maFlags &= ~2;
556 : : }
557 : 0 : pFilterEntry->maFlags |= 0x80040;
558 : :
559 : : // 2. create user data for filter entry
560 : 0 : Sequence< OUString > aUserData( pFilterEntry->getFilterUserData());
561 : :
562 : : // 3. create property values for filter entry
563 : 0 : Sequence< PropertyValue > aFilterData( 8 );
564 : :
565 : 0 : aFilterData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ) );
566 : 0 : aFilterData[0].Value <<= pFilterEntry->maType;
567 : :
568 : 0 : aFilterData[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) );
569 : 0 : aFilterData[1].Value <<= pFilterEntry->maInterfaceName;
570 : :
571 : 0 : aFilterData[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ) );
572 : 0 : aFilterData[2].Value <<= pFilterEntry->maDocumentService;
573 : :
574 : 0 : aFilterData[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterService" ) );
575 : 0 : aFilterData[3].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) );
576 : :
577 : 0 : aFilterData[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Flags" ) );
578 : 0 : aFilterData[4].Value <<= pFilterEntry->maFlags;
579 : :
580 : 0 : aFilterData[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UserData" ) );
581 : 0 : aFilterData[5].Value <<= aUserData;
582 : :
583 : 0 : aFilterData[6].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileFormatVersion" ) );
584 : 0 : aFilterData[6].Value <<= pFilterEntry->maFileFormatVersion;
585 : :
586 : 0 : aFilterData[7].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateName" ) );
587 : 0 : aFilterData[7].Value <<= pFilterEntry->maImportTemplate;
588 : :
589 : : // 4. insert new or replace existing filter
590 : : try
591 : : {
592 : 0 : Any aAny( makeAny( aFilterData ) );
593 : 0 : if( mxFilterContainer->hasByName( pFilterEntry->maFilterName ) )
594 : : {
595 : 0 : mxFilterContainer->replaceByName( pFilterEntry->maFilterName, aAny );
596 : : }
597 : : else
598 : : {
599 : 0 : mxFilterContainer->insertByName( pFilterEntry->maFilterName, aAny );
600 : 0 : }
601 : : }
602 : 0 : catch( const Exception& )
603 : : {
604 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
605 : 0 : bOk = false;
606 : 0 : }
607 : : }
608 : :
609 : : // 5. prepare type information
610 : 0 : if( bOk )
611 : : {
612 : 0 : Sequence< PropertyValue > aValues(4);
613 : :
614 : 0 : aValues[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) );
615 : 0 : aValues[0].Value <<= pFilterEntry->maInterfaceName;
616 : 0 : aValues[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "ClipboardFormat" ) );
617 : 0 : OUString aDocType;
618 : 0 : if( !pFilterEntry->maDocType.match( sDocTypePrefix ) )
619 : : {
620 : 0 : aDocType = sDocTypePrefix;
621 : 0 : aDocType += pFilterEntry->maDocType;
622 : : }
623 : : else
624 : : {
625 : 0 : aDocType = pFilterEntry->maDocType;
626 : : }
627 : 0 : if (aDocType == sDocTypePrefix)
628 : 0 : aValues[1].Value <<= OUString();
629 : : else
630 : 0 : aValues[1].Value <<= aDocType;
631 : :
632 : 0 : aValues[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentIconID" ) );
633 : 0 : aValues[2].Value <<= pFilterEntry->mnDocumentIconID;
634 : :
635 : 0 : aValues[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Extensions" ) );
636 : 0 : aValues[3].Value <<= createExtensionsSequence( pFilterEntry->maExtension );
637 : :
638 : : // the detect service will only be registered, if a doctype/search token was specified
639 : 0 : if (aDocType.getLength() > sDocTypePrefix.getLength())
640 : : {
641 : 0 : aValues.realloc(5);
642 : 0 : aValues[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DetectService" ) );
643 : 0 : aValues[4].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.filters.XMLFilterDetect" ) );
644 : : }
645 : :
646 : : // 6. insert new or replace existing type information
647 : 0 : if( mxTypeDetection.is() )
648 : : {
649 : : try
650 : : {
651 : 0 : Any aAny( makeAny( aValues ) );
652 : 0 : if( mxTypeDetection->hasByName( pFilterEntry->maType ) )
653 : : {
654 : 0 : mxTypeDetection->replaceByName( pFilterEntry->maType, aAny );
655 : : }
656 : : else
657 : : {
658 : 0 : mxTypeDetection->insertByName( pFilterEntry->maType, aAny );
659 : 0 : }
660 : : }
661 : 0 : catch( const Exception& )
662 : : {
663 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
664 : 0 : bOk = false;
665 : : }
666 : : }
667 : :
668 : 0 : if( bOk )
669 : : {
670 : : try
671 : : {
672 : 0 : Reference< XFlushable > xFlushable = Reference< XFlushable >::query( mxTypeDetection );
673 : 0 : if( xFlushable.is() )
674 : 0 : xFlushable->flush();
675 : : }
676 : 0 : catch( const Exception& )
677 : : {
678 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
679 : 0 : bOk = false;
680 : : }
681 : : }
682 : :
683 : 0 : if( !bOk )
684 : : {
685 : : // we failed to add the type, so lets remove the filter
686 : : try
687 : : {
688 : 0 : mxFilterContainer->removeByName( pFilterEntry->maFilterName );
689 : : }
690 : 0 : catch( const Exception& )
691 : : {
692 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
693 : 0 : bOk = false;
694 : : }
695 : : }
696 : : else
697 : : {
698 : 0 : if( bOk )
699 : : {
700 : : try
701 : : {
702 : 0 : Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY );
703 : 0 : if( xFlushable.is() )
704 : 0 : xFlushable->flush();
705 : : }
706 : 0 : catch( const Exception& )
707 : : {
708 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
709 : 0 : bOk = false;
710 : : }
711 : :
712 : 0 : if( !bOk )
713 : : {
714 : : // we failed to add the filter, so lets remove the type
715 : : try
716 : : {
717 : 0 : mxTypeDetection->removeByName( pFilterEntry->maType );
718 : : }
719 : 0 : catch( const Exception& )
720 : : {
721 : : OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
722 : : }
723 : : }
724 : :
725 : : }
726 : 0 : }
727 : : }
728 : :
729 : 0 : if( bOk )
730 : : {
731 : 0 : if( mxExtendedTypeDetection.is() )
732 : : {
733 : 0 : OUString sFilterDetectService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.filters.XMLFilterDetect") );
734 : 0 : if( mxExtendedTypeDetection->hasByName( sFilterDetectService ) )
735 : : {
736 : 0 : Sequence< PropertyValue > aSequence;
737 : 0 : if( mxExtendedTypeDetection->getByName( sFilterDetectService ) >>= aSequence )
738 : : {
739 : 0 : sal_Int32 nCount = aSequence.getLength();
740 : : sal_Int32 nIndex;
741 : 0 : for( nIndex = 0; nIndex < nCount; nIndex++ )
742 : : {
743 : 0 : if ( aSequence[nIndex].Name == "Types" )
744 : : {
745 : 0 : Sequence< OUString > aTypes;
746 : 0 : if( aSequence[nIndex].Value >>= aTypes )
747 : : {
748 : 0 : sal_Int32 nStrCount = aTypes.getLength();
749 : : sal_Int32 nStr;
750 : 0 : for( nStr = 0; nStr < nStrCount; nStr++ )
751 : : {
752 : 0 : OUString aType( aTypes[nStr] );
753 : 0 : if( aTypes[nStr] == pFilterEntry->maType )
754 : : break;
755 : 0 : }
756 : :
757 : 0 : if( nStr == nStrCount )
758 : : {
759 : 0 : aTypes.realloc( nStrCount + 1 );
760 : 0 : aTypes[nStrCount] = pFilterEntry->maType;
761 : :
762 : 0 : aSequence[nIndex].Value <<= aTypes;
763 : :
764 : 0 : mxExtendedTypeDetection->replaceByName( sFilterDetectService, makeAny( aSequence ) );
765 : :
766 : 0 : Reference< XFlushable > xFlushable( mxExtendedTypeDetection, UNO_QUERY );
767 : 0 : if( xFlushable.is() )
768 : 0 : xFlushable->flush();
769 : : }
770 : : }
771 : :
772 : 0 : break;
773 : : }
774 : : }
775 : 0 : }
776 : 0 : }
777 : : }
778 : : }
779 : :
780 : : // update ui
781 : 0 : if( bOk )
782 : : {
783 : 0 : if( pOldInfo )
784 : : {
785 : 0 : mpFilterListBox->changeEntry( pFilterEntry );
786 : : }
787 : : else
788 : : {
789 : 0 : mpFilterListBox->addFilterEntry( pFilterEntry );
790 : 0 : maFilterVector.push_back( pFilterEntry );
791 : : }
792 : : }
793 : :
794 : 0 : return bOk;
795 : : }
796 : :
797 : : // -----------------------------------------------------------------------
798 : :
799 : : /** is called when the user clicks the "Test" button */
800 : 0 : void XMLFilterSettingsDialog::onTest()
801 : : {
802 : : // get the first selected filter
803 : 0 : SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
804 : 0 : if( pEntry )
805 : : {
806 : 0 : filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData();
807 : :
808 : 0 : XMLFilterTestDialog aDlg( this, *mpResMgr, mxMSF );
809 : 0 : aDlg.test( *pInfo );
810 : : }
811 : 0 : }
812 : :
813 : : // -----------------------------------------------------------------------
814 : :
815 : 0 : void XMLFilterSettingsDialog::onDelete()
816 : : {
817 : 0 : SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
818 : 0 : if( pEntry )
819 : : {
820 : 0 : filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData();
821 : :
822 : 0 : String aPlaceHolder( RTL_CONSTASCII_USTRINGPARAM("%s") );
823 : 0 : String aMessage(RESID(STR_WARN_DELETE));
824 : 0 : aMessage.SearchAndReplace( aPlaceHolder, pInfo->maFilterName );
825 : :
826 : 0 : WarningBox aWarnBox(this, (WinBits)(WB_YES_NO | WB_DEF_YES), aMessage );
827 : 0 : if( aWarnBox.Execute() == RET_YES )
828 : : {
829 : : try
830 : : {
831 : 0 : if( mxFilterContainer->hasByName( pInfo->maFilterName ) )
832 : : {
833 : 0 : mxFilterContainer->removeByName( pInfo->maFilterName );
834 : :
835 : 0 : bool bTypeStillUsed = false;
836 : :
837 : : // now loop over all filter and see if someone else uses the same type
838 : 0 : Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
839 : 0 : OUString* pFilterName = aFilterNames.getArray();
840 : :
841 : 0 : const sal_Int32 nCount = aFilterNames.getLength();
842 : : sal_Int32 nFilter;
843 : 0 : Sequence< PropertyValue > aValues;
844 : :
845 : 0 : for( nFilter = 0; (nFilter < nCount) && !bTypeStillUsed; nFilter++, pFilterName++ )
846 : : {
847 : 0 : Any aAny( mxFilterContainer->getByName( *pFilterName ) );
848 : 0 : if( !(aAny >>= aValues) )
849 : 0 : continue;
850 : :
851 : 0 : const sal_Int32 nValueCount( aValues.getLength() );
852 : 0 : PropertyValue* pValues = aValues.getArray();
853 : : sal_Int32 nValue;
854 : :
855 : 0 : for( nValue = 0; (nValue < nValueCount) && !bTypeStillUsed; nValue++, pValues++ )
856 : : {
857 : 0 : if ( pValues->Name == "Type" )
858 : : {
859 : 0 : OUString aType;
860 : 0 : pValues->Value >>= aType;
861 : 0 : if( aType == pInfo->maType )
862 : 0 : bTypeStillUsed = true;
863 : :
864 : 0 : break;
865 : : }
866 : : }
867 : 0 : }
868 : :
869 : : // if the type is not used anymore, remove it also
870 : 0 : if( !bTypeStillUsed )
871 : : {
872 : 0 : if( mxTypeDetection->hasByName( pInfo->maType ) )
873 : : {
874 : 0 : mxTypeDetection->removeByName( pInfo->maType );
875 : : }
876 : : }
877 : :
878 : 0 : Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY );
879 : 0 : if( xFlushable.is() )
880 : 0 : xFlushable->flush();
881 : :
882 : 0 : xFlushable = Reference< XFlushable >::query( mxTypeDetection );
883 : 0 : if( xFlushable.is() )
884 : 0 : xFlushable->flush();
885 : :
886 : : // now remove entry from ui
887 : 0 : mpFilterListBox->RemoveSelection();
888 : :
889 : : // and delete the filter entry
890 : 0 : maFilterVector.erase(std::find( maFilterVector.begin(), maFilterVector.end(), pInfo ));
891 : :
892 : 0 : delete pInfo;
893 : : }
894 : : }
895 : 0 : catch( const Exception& )
896 : : {
897 : : OSL_FAIL( "XMLFilterSettingsDialog::onDelete exception catched!" );
898 : : }
899 : 0 : }
900 : : }
901 : :
902 : 0 : updateStates();
903 : 0 : }
904 : :
905 : : // -----------------------------------------------------------------------
906 : :
907 : 0 : void XMLFilterSettingsDialog::onSave()
908 : : {
909 : 0 : XMLFilterVector aFilters;
910 : :
911 : 0 : int nFilters = 0;
912 : :
913 : 0 : SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
914 : 0 : while( pEntry )
915 : : {
916 : 0 : filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData();
917 : 0 : aFilters.push_back( pInfo );
918 : 0 : pEntry = mpFilterListBox->NextSelected( pEntry );
919 : 0 : nFilters++;
920 : : }
921 : :
922 : : // Open Fileopen-Dialog
923 : : ::sfx2::FileDialogHelper aDlg(
924 : : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
925 : 0 : 0 );
926 : :
927 : 0 : String aExtensions( RTL_CONSTASCII_USTRINGPARAM("*.jar") );
928 : 0 : String aFilterName( RESID( STR_FILTER_PACKAGE ) );
929 : 0 : aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") );
930 : 0 : aFilterName += aExtensions;
931 : 0 : aFilterName += sal_Unicode(')');
932 : :
933 : 0 : aDlg.AddFilter( aFilterName, aExtensions );
934 : :
935 : 0 : if ( aDlg.Execute() == ERRCODE_NONE )
936 : : {
937 : 0 : XMLFilterJarHelper aJarHelper( mxMSF );
938 : 0 : aJarHelper.savePackage( aDlg.GetPath(), aFilters );
939 : :
940 : 0 : INetURLObject aURL( aDlg.GetPath() );
941 : :
942 : 0 : String sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) );
943 : :
944 : 0 : String aMsg;
945 : 0 : if( nFilters > 0 )
946 : : {
947 : 0 : aMsg = String( RESID( STR_FILTERS_HAVE_BEEN_SAVED ) );
948 : 0 : aMsg.SearchAndReplace( sPlaceholder, String::CreateFromInt32(nFilters) );
949 : 0 : aMsg.SearchAndReplace( sPlaceholder, aURL.GetName() );
950 : : }
951 : : else
952 : : {
953 : 0 : aMsg = String( RESID( STR_FILTER_HAS_BEEN_SAVED ) );
954 : 0 : aMsg.SearchAndReplace( sPlaceholder, (*aFilters.begin())->maFilterName );
955 : 0 : aMsg.SearchAndReplace( sPlaceholder, aURL.GetName() );
956 : : }
957 : :
958 : 0 : InfoBox aBox(this, aMsg );
959 : 0 : aBox.Execute();
960 : 0 : }
961 : 0 : }
962 : :
963 : : // -----------------------------------------------------------------------
964 : :
965 : 0 : void XMLFilterSettingsDialog::onOpen()
966 : : {
967 : 0 : XMLFilterVector aFilters;
968 : :
969 : : // Open Fileopen-Dialog
970 : : ::sfx2::FileDialogHelper aDlg(
971 : 0 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
972 : :
973 : 0 : String aExtensions( RTL_CONSTASCII_USTRINGPARAM("*.jar") );
974 : 0 : String aFilterName( RESID( STR_FILTER_PACKAGE ) );
975 : 0 : aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") );
976 : 0 : aFilterName += aExtensions;
977 : 0 : aFilterName += sal_Unicode(')');
978 : :
979 : 0 : aDlg.AddFilter( aFilterName, aExtensions );
980 : :
981 : 0 : if ( aDlg.Execute() == ERRCODE_NONE )
982 : : {
983 : 0 : OUString aURL( aDlg.GetPath() );
984 : :
985 : 0 : XMLFilterJarHelper aJarHelper( mxMSF );
986 : 0 : aJarHelper.openPackage( aURL, aFilters );
987 : :
988 : 0 : int nFilters = 0;
989 : 0 : XMLFilterVector::iterator aIter( aFilters.begin() );
990 : 0 : while( aIter != aFilters.end() )
991 : : {
992 : 0 : filter_info_impl* pInfo = (*aIter++);
993 : :
994 : 0 : if( insertOrEdit( pInfo ) )
995 : : {
996 : 0 : aFilterName = pInfo->maFilterName;
997 : 0 : nFilters++;
998 : : }
999 : :
1000 : 0 : delete pInfo;
1001 : : }
1002 : :
1003 : 0 : disposeFilterList();
1004 : 0 : initFilterList();
1005 : :
1006 : 0 : String sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) );
1007 : 0 : String aMsg;
1008 : 0 : if( nFilters == 0 )
1009 : : {
1010 : 0 : INetURLObject aURLObj( aURL );
1011 : 0 : aMsg = String( RESID( STR_NO_FILTERS_FOUND ) );
1012 : 0 : aMsg.SearchAndReplace( sPlaceholder, aURLObj.GetName() );
1013 : : }
1014 : 0 : else if( nFilters == 1 )
1015 : : {
1016 : 0 : aMsg = String( RESID( STR_FILTER_INSTALLED ) );
1017 : 0 : aMsg.SearchAndReplace( sPlaceholder, aFilterName );
1018 : :
1019 : : }
1020 : : else
1021 : : {
1022 : 0 : aMsg = String( RESID( STR_FILTERS_INSTALLED ) );
1023 : 0 : aMsg.SearchAndReplace( sPlaceholder, String::CreateFromInt32(nFilters) );
1024 : : }
1025 : :
1026 : 0 : InfoBox aBox(this, aMsg );
1027 : 0 : aBox.Execute();
1028 : 0 : }
1029 : 0 : }
1030 : :
1031 : : // -----------------------------------------------------------------------
1032 : :
1033 : 0 : void XMLFilterSettingsDialog::onClose()
1034 : : {
1035 : 0 : Close();
1036 : 0 : }
1037 : :
1038 : 0 : long XMLFilterSettingsDialog::Notify( NotifyEvent& rNEvt )
1039 : : {
1040 : : // Zuerst Basisklasse rufen wegen TabSteuerung
1041 : 0 : long nRet = WorkWindow::Notify( rNEvt );
1042 : 0 : if ( !nRet )
1043 : : {
1044 : 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
1045 : : {
1046 : 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1047 : 0 : KeyCode aKeyCode = pKEvt->GetKeyCode();
1048 : 0 : sal_uInt16 nKeyCode = aKeyCode.GetCode();
1049 : 0 : sal_Bool bMod1 = pKEvt->GetKeyCode().IsMod1();
1050 : :
1051 : 0 : if( nKeyCode == KEY_ESCAPE || (bMod1 && (nKeyCode == KEY_W)))
1052 : : {
1053 : 0 : Close();
1054 : 0 : return sal_True;
1055 : : }
1056 : : }
1057 : : }
1058 : :
1059 : 0 : return nRet;
1060 : : }
1061 : :
1062 : : // -----------------------------------------------------------------------
1063 : :
1064 : 0 : void XMLFilterSettingsDialog::disposeFilterList()
1065 : : {
1066 : 0 : std::vector< filter_info_impl* >::iterator aIter( maFilterVector.begin() );
1067 : 0 : while( aIter != maFilterVector.end() )
1068 : : {
1069 : 0 : delete (*aIter++);
1070 : : }
1071 : 0 : maFilterVector.clear();
1072 : :
1073 : 0 : mpFilterListBox->Clear();
1074 : 0 : }
1075 : :
1076 : : // -----------------------------------------------------------------------
1077 : :
1078 : 0 : void XMLFilterSettingsDialog::initFilterList()
1079 : : {
1080 : 0 : if( mxFilterContainer.is() )
1081 : : {
1082 : 0 : Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
1083 : 0 : OUString* pFilterName = aFilterNames.getArray();
1084 : :
1085 : 0 : const sal_Int32 nCount = aFilterNames.getLength();
1086 : : sal_Int32 nFilter;
1087 : :
1088 : 0 : Sequence< PropertyValue > aValues;
1089 : :
1090 : 0 : filter_info_impl* pTempFilter = new filter_info_impl;
1091 : 0 : Sequence< OUString > aUserData;
1092 : :
1093 : 0 : for( nFilter = 0; nFilter < nCount; nFilter++, pFilterName++ )
1094 : : {
1095 : 0 : aUserData.realloc(0);
1096 : :
1097 : : try
1098 : : {
1099 : 0 : Any aAny( mxFilterContainer->getByName( *pFilterName ) );
1100 : 0 : if( !(aAny >>= aValues) )
1101 : 0 : continue;
1102 : :
1103 : 0 : OUString aFilterService;
1104 : 0 : pTempFilter->maFilterName = *pFilterName;
1105 : :
1106 : 0 : const sal_Int32 nValueCount( aValues.getLength() );
1107 : 0 : PropertyValue* pValues = aValues.getArray();
1108 : : sal_Int32 nValue;
1109 : :
1110 : 0 : for( nValue = 0; nValue < nValueCount; nValue++, pValues++ )
1111 : : {
1112 : 0 : if ( pValues->Name == "Type" )
1113 : : {
1114 : 0 : pValues->Value >>= pTempFilter->maType;
1115 : : }
1116 : 0 : else if ( pValues->Name == "UIName" )
1117 : : {
1118 : 0 : pValues->Value >>= pTempFilter->maInterfaceName;
1119 : : }
1120 : 0 : else if ( pValues->Name == "DocumentService" )
1121 : : {
1122 : 0 : pValues->Value >>= pTempFilter->maDocumentService;
1123 : : }
1124 : 0 : else if ( pValues->Name == "FilterService" )
1125 : : {
1126 : 0 : pValues->Value >>= aFilterService;
1127 : : }
1128 : 0 : else if ( pValues->Name == "Flags" )
1129 : : {
1130 : 0 : pValues->Value >>= pTempFilter->maFlags;
1131 : : }
1132 : 0 : else if ( pValues->Name == "UserData" )
1133 : : {
1134 : 0 : pValues->Value >>= aUserData;
1135 : : }
1136 : 0 : else if ( pValues->Name == "FileFormatVersion" )
1137 : : {
1138 : 0 : pValues->Value >>= pTempFilter->maFileFormatVersion;
1139 : : }
1140 : 0 : else if ( pValues->Name == "TemplateName" )
1141 : : {
1142 : 0 : pValues->Value >>= pTempFilter->maImportTemplate;
1143 : : }
1144 : 0 : else if ( pValues->Name == "Finalized" )
1145 : : {
1146 : 0 : pValues->Value >>= pTempFilter->mbReadonly;
1147 : : }
1148 : : }
1149 : :
1150 : : // if this is not a XmlFilterAdaptor entry, skip it
1151 : 0 : if( !aFilterService.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) ) )
1152 : 0 : continue;
1153 : :
1154 : :
1155 : : // if we don't have the needed user data, skip it
1156 : 0 : if( aUserData.getLength() < 6 )
1157 : 0 : continue;
1158 : :
1159 : : // if this is not an XSLTFilter entry, skip it
1160 : 0 : if( aUserData[0] != "com.sun.star.documentconversion.XSLTFilter" )
1161 : 0 : continue;
1162 : :
1163 : : // get filter information from userdata
1164 : 0 : pTempFilter->maXSLTTransformerImpl = aUserData[1];
1165 : 0 : pTempFilter->maImportService = aUserData[2];
1166 : 0 : pTempFilter->maExportService = aUserData[3];
1167 : 0 : pTempFilter->maImportXSLT = aUserData[4];
1168 : 0 : pTempFilter->maExportXSLT = aUserData[5];
1169 : 0 : if( aUserData.getLength() >= 7 )
1170 : 0 : pTempFilter->maDTD = aUserData[6];
1171 : 0 : if( aUserData.getLength() >= 8 )
1172 : 0 : pTempFilter->maComment = aUserData[7];
1173 : :
1174 : : // get type information
1175 : 0 : if( mxTypeDetection.is() )
1176 : : {
1177 : : try
1178 : : {
1179 : 0 : aAny = mxTypeDetection->getByName( pTempFilter->maType );
1180 : 0 : Sequence< PropertyValue > aValues2;
1181 : :
1182 : 0 : if( aAny >>= aValues2 )
1183 : : {
1184 : 0 : const sal_Int32 nValueCount2( aValues2.getLength() );
1185 : 0 : PropertyValue* pValues2 = aValues2.getArray();
1186 : : sal_Int32 nValue2;
1187 : :
1188 : 0 : for( nValue2 = 0; nValue2 < nValueCount2; nValue2++, pValues2++ )
1189 : : {
1190 : 0 : if ( pValues2->Name == "ClipboardFormat" )
1191 : : {
1192 : 0 : OUString aDocType;
1193 : 0 : pValues2->Value >>= aDocType;
1194 : :
1195 : 0 : if( aDocType.match( sDocTypePrefix ) )
1196 : 0 : aDocType = aDocType.copy( sDocTypePrefix.getLength() );
1197 : :
1198 : 0 : pTempFilter->maDocType = aDocType;
1199 : : }
1200 : 0 : else if ( pValues2->Name == "Extensions" )
1201 : : {
1202 : 0 : Sequence< OUString > aExtensions;
1203 : 0 : if( pValues2->Value >>= aExtensions )
1204 : : {
1205 : 0 : pTempFilter->maExtension = OUString();
1206 : :
1207 : 0 : sal_Int32 nCount3( aExtensions.getLength() );
1208 : 0 : OUString* pExtensions = aExtensions.getArray();
1209 : : sal_Int32 n;
1210 : 0 : for( n = 0; n < nCount3; n++ )
1211 : : {
1212 : 0 : if( n > 0 )
1213 : 0 : pTempFilter->maExtension += OUString( sal_Unicode(';') );
1214 : 0 : pTempFilter->maExtension += (*pExtensions++);
1215 : : }
1216 : 0 : }
1217 : : }
1218 : 0 : else if ( pValues2->Name == "DocumentIconID" )
1219 : : {
1220 : 0 : pValues2->Value >>= pTempFilter->mnDocumentIconID;
1221 : : }
1222 : 0 : else if ( pValues2->Name == "Finalized" )
1223 : : {
1224 : : // both the filter and the type may be finalized
1225 : 0 : sal_Bool bTemp = sal_False;
1226 : 0 : pValues2->Value >>= bTemp;
1227 : 0 : pTempFilter->mbReadonly |= bTemp;
1228 : : }
1229 : : }
1230 : 0 : }
1231 : : }
1232 : 0 : catch( const ::com::sun::star::container::NoSuchElementException& )
1233 : : {
1234 : : OSL_FAIL( "Type not found, user error?" ); // TODO: error?
1235 : : }
1236 : : }
1237 : :
1238 : : // add entry to internal container and to ui filter list box
1239 : 0 : maFilterVector.push_back( pTempFilter );
1240 : 0 : mpFilterListBox->addFilterEntry( pTempFilter );
1241 : :
1242 : :
1243 : 0 : pTempFilter = new filter_info_impl;
1244 : : }
1245 : 0 : catch( const Exception& )
1246 : : {
1247 : : OSL_FAIL( "XMLFilterSettingsDialog::initFilterList exception catched!" );
1248 : : }
1249 : :
1250 : : }
1251 : :
1252 : 0 : delete pTempFilter;
1253 : : }
1254 : :
1255 : 0 : SvLBoxEntry* pEntry = mpFilterListBox->GetEntry( 0 );
1256 : 0 : if( pEntry )
1257 : 0 : mpFilterListBox->Select( pEntry );
1258 : 0 : }
1259 : :
1260 : : // -----------------------------------------------------------------------
1261 : :
1262 : : // -----------------------------------------------------------------------
1263 : :
1264 : 0 : application_info_impl::application_info_impl( const sal_Char * pDocumentService, ResId& rUINameRes, const sal_Char * mpXMLImporter, const sal_Char * mpXMLExporter )
1265 : 0 : : maDocumentService( pDocumentService, strlen( pDocumentService ), RTL_TEXTENCODING_ASCII_US ),
1266 : : maDocumentUIName( String( rUINameRes ) ),
1267 : 0 : maXMLImporter( mpXMLImporter, strlen( mpXMLImporter ), RTL_TEXTENCODING_ASCII_US ),
1268 : 0 : maXMLExporter( mpXMLExporter, strlen( mpXMLExporter ), RTL_TEXTENCODING_ASCII_US )
1269 : : {
1270 : 0 : }
1271 : :
1272 : : // -----------------------------------------------------------------------
1273 : :
1274 : 0 : std::vector< application_info_impl* >& getApplicationInfos()
1275 : : {
1276 : 0 : static std::vector< application_info_impl* > aInfos;
1277 : :
1278 : 0 : if( aInfos.empty() )
1279 : : {
1280 : 0 : ResId aResId1( STR_APPL_NAME_WRITER, *getXSLTDialogResMgr() );
1281 : : aInfos.push_back( new application_info_impl(
1282 : : "com.sun.star.text.TextDocument",
1283 : : aResId1,
1284 : : "com.sun.star.comp.Writer.XMLImporter",
1285 : 0 : "com.sun.star.comp.Writer.XMLExporter" ) );
1286 : :
1287 : 0 : ResId aResId2( STR_APPL_NAME_CALC, *getXSLTDialogResMgr() );
1288 : : aInfos.push_back( new application_info_impl(
1289 : : "com.sun.star.sheet.SpreadsheetDocument",
1290 : : aResId2,
1291 : : "com.sun.star.comp.Calc.XMLImporter",
1292 : 0 : "com.sun.star.comp.Calc.XMLExporter" ) );
1293 : :
1294 : 0 : ResId aResId3( STR_APPL_NAME_IMPRESS, *getXSLTDialogResMgr() );
1295 : : aInfos.push_back( new application_info_impl(
1296 : : "com.sun.star.presentation.PresentationDocument",
1297 : : aResId3,
1298 : : "com.sun.star.comp.Impress.XMLImporter",
1299 : 0 : "com.sun.star.comp.Impress.XMLExporter" ) );
1300 : :
1301 : 0 : ResId aResId4( STR_APPL_NAME_DRAW, *getXSLTDialogResMgr() );
1302 : : aInfos.push_back( new application_info_impl(
1303 : : "com.sun.star.drawing.DrawingDocument",
1304 : : aResId4,
1305 : : "com.sun.star.comp.Draw.XMLImporter",
1306 : 0 : "com.sun.star.comp.Draw.XMLExporter" ) );
1307 : :
1308 : : // --- oasis file formats...
1309 : 0 : ResId aResId5( STR_APPL_NAME_OASIS_WRITER, *getXSLTDialogResMgr() );
1310 : : aInfos.push_back( new application_info_impl(
1311 : : "com.sun.star.text.TextDocument",
1312 : : aResId5,
1313 : : "com.sun.star.comp.Writer.XMLOasisImporter",
1314 : 0 : "com.sun.star.comp.Writer.XMLOasisExporter" ) );
1315 : :
1316 : 0 : ResId aResId6( STR_APPL_NAME_OASIS_CALC, *getXSLTDialogResMgr() );
1317 : : aInfos.push_back( new application_info_impl(
1318 : : "com.sun.star.sheet.SpreadsheetDocument",
1319 : : aResId6,
1320 : : "com.sun.star.comp.Calc.XMLOasisImporter",
1321 : 0 : "com.sun.star.comp.Calc.XMLOasisExporter" ) );
1322 : :
1323 : 0 : ResId aResId7( STR_APPL_NAME_OASIS_IMPRESS, *getXSLTDialogResMgr() );
1324 : : aInfos.push_back( new application_info_impl(
1325 : : "com.sun.star.presentation.PresentationDocument",
1326 : : aResId7,
1327 : : "com.sun.star.comp.Impress.XMLOasisImporter",
1328 : 0 : "com.sun.star.comp.Impress.XMLOasisExporter" ) );
1329 : :
1330 : 0 : ResId aResId8( STR_APPL_NAME_OASIS_DRAW, *getXSLTDialogResMgr() );
1331 : : aInfos.push_back( new application_info_impl(
1332 : : "com.sun.star.drawing.DrawingDocument",
1333 : : aResId8,
1334 : : "com.sun.star.comp.Draw.XMLOasisImporter",
1335 : 0 : "com.sun.star.comp.Draw.XMLOasisExporter" ) );
1336 : : }
1337 : :
1338 : 0 : return aInfos;
1339 : : }
1340 : :
1341 : : // -----------------------------------------------------------------------
1342 : :
1343 : 0 : const application_info_impl* getApplicationInfo( const OUString& rServiceName )
1344 : : {
1345 : 0 : std::vector< application_info_impl* >& rInfos = getApplicationInfos();
1346 : 0 : std::vector< application_info_impl* >::iterator aIter( rInfos.begin() );
1347 : 0 : while( aIter != rInfos.end() )
1348 : : {
1349 : : // if( rServiceName == (*aIter)->maDocumentService )
1350 : 0 : if( rServiceName == (*aIter)->maXMLExporter ||
1351 : 0 : rServiceName == (*aIter)->maXMLImporter)
1352 : : {
1353 : 0 : return (*aIter);
1354 : : }
1355 : 0 : ++aIter;
1356 : : }
1357 : 0 : return NULL;
1358 : : }
1359 : :
1360 : : // -----------------------------------------------------------------------
1361 : :
1362 : 0 : OUString getApplicationUIName( const OUString& rServiceName )
1363 : : {
1364 : 0 : const application_info_impl* pInfo = getApplicationInfo( rServiceName );
1365 : 0 : if( pInfo )
1366 : : {
1367 : 0 : return pInfo->maDocumentUIName;
1368 : : }
1369 : : else
1370 : : {
1371 : 0 : OUString aRet = String( RESID( STR_UNKNOWN_APPLICATION ) );
1372 : 0 : if( !rServiceName.isEmpty() )
1373 : : {
1374 : 0 : aRet += OUString( RTL_CONSTASCII_USTRINGPARAM( " (" ));
1375 : 0 : aRet += rServiceName;
1376 : 0 : aRet += OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ));
1377 : : }
1378 : 0 : return aRet;
1379 : : }
1380 : : }
1381 : :
1382 : : // -----------------------------------------------------------------------
1383 : :
1384 : 0 : ResMgr* getXSLTDialogResMgr()
1385 : : {
1386 : 0 : return XMLFilterSettingsDialog::mpResMgr;
1387 : : }
1388 : :
1389 : : // -----------------------------------------------------------------------
1390 : :
1391 : : // -----------------------------------------------------------------------
1392 : :
1393 : 0 : long SvxPathControl_Impl::Notify( NotifyEvent& rNEvt )
1394 : : {
1395 : 0 : long nRet = Control::Notify( rNEvt );
1396 : :
1397 : 0 : if ( m_pFocusCtrl && rNEvt.GetWindow() != m_pFocusCtrl && rNEvt.GetType() == EVENT_GETFOCUS )
1398 : 0 : m_pFocusCtrl->GrabFocus();
1399 : 0 : return nRet;
1400 : : }
1401 : :
1402 : : #define ITEMID_NAME 1
1403 : : #define ITEMID_TYPE 2
1404 : :
1405 : 0 : XMLFilterListBox::XMLFilterListBox( SvxPathControl_Impl * pParent )
1406 : : : SvTabListBox( pParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
1407 : 0 : mbFirstPaint( true )
1408 : : {
1409 : 0 : Size aBoxSize( pParent->GetOutputSizePixel() );
1410 : :
1411 : 0 : mpHeaderBar = new HeaderBar( pParent, /*WB_BUTTONSTYLE | */ WB_BOTTOMBORDER );
1412 : 0 : mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize.Width(), 16 ) );
1413 : 0 : mpHeaderBar->SetEndDragHdl( LINK( this, XMLFilterListBox, HeaderEndDrag_Impl ) );
1414 : :
1415 : 0 : String aStr1( RESID( STR_COLUMN_HEADER_NAME ) );
1416 : 0 : String aStr2( RESID( STR_COLUMN_HEADER_TYPE ) );
1417 : :
1418 : 0 : long nTabSize = aBoxSize.Width() / 2;
1419 : :
1420 : : mpHeaderBar->InsertItem( ITEMID_NAME, aStr1, nTabSize,
1421 : 0 : HIB_LEFT | HIB_VCENTER );
1422 : : mpHeaderBar->InsertItem( ITEMID_TYPE, aStr2, nTabSize,
1423 : 0 : HIB_LEFT | HIB_VCENTER );
1424 : :
1425 : 0 : static long nTabs[] = {3, 0, nTabSize, 2*nTabSize };
1426 : 0 : Size aHeadSize( mpHeaderBar->GetSizePixel() );
1427 : :
1428 : 0 : pParent->SetFocusControl( this );
1429 : : // SetDoubleClickHdl( aLink );
1430 : : // SetSelectHdl( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
1431 : 0 : SetSelectionMode( MULTIPLE_SELECTION );
1432 : 0 : SetPosSizePixel( Point( 0, aHeadSize.Height() ), Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
1433 : 0 : SetTabs( &nTabs[0], MAP_PIXEL );
1434 : 0 : SetScrolledHdl( LINK( this, XMLFilterListBox, TabBoxScrollHdl_Impl ) );
1435 : 0 : SetHighlightRange();
1436 : : // SetHelpId( HID_OPTPATH_CTL_PATH );
1437 : : // mpHeaderBar->SetHelpId( HID_OPTPATH_HEADERBAR );
1438 : 0 : Show();
1439 : 0 : mpHeaderBar->Show();
1440 : 0 : }
1441 : :
1442 : : // -----------------------------------------------------------------------
1443 : :
1444 : 0 : XMLFilterListBox::~XMLFilterListBox()
1445 : : {
1446 : 0 : delete mpHeaderBar;
1447 : 0 : }
1448 : :
1449 : : // -----------------------------------------------------------------------
1450 : :
1451 : 0 : void XMLFilterListBox::Reset()
1452 : : {
1453 : 0 : Size aBoxSize( Window::GetParent()->GetOutputSizePixel() );
1454 : 0 : long nTabSize = aBoxSize.Width() / 2;
1455 : 0 : static long nTabs[] = {3, 0, nTabSize, 2*nTabSize };
1456 : 0 : SetTabs( &nTabs[0], MAP_PIXEL );
1457 : 0 : mpHeaderBar->SetItemSize( ITEMID_NAME, nTabSize );
1458 : 0 : mpHeaderBar->SetItemSize( ITEMID_TYPE, nTabSize );
1459 : 0 : }
1460 : :
1461 : : // -----------------------------------------------------------------------
1462 : :
1463 : 0 : void XMLFilterListBox::Paint( const Rectangle& rRect )
1464 : : {
1465 : 0 : if( mbFirstPaint )
1466 : : {
1467 : 0 : mbFirstPaint = false;
1468 : 0 : RepaintScrollBars();
1469 : : }
1470 : :
1471 : 0 : SvTabListBox::Paint( rRect );
1472 : 0 : }
1473 : :
1474 : 0 : IMPL_LINK( XMLFilterListBox, TabBoxScrollHdl_Impl, SvTabListBox*, /* pList */ )
1475 : : {
1476 : 0 : mpHeaderBar->SetOffset( -GetXOffset() );
1477 : 0 : return 0;
1478 : : }
1479 : :
1480 : : // -----------------------------------------------------------------------
1481 : :
1482 : 0 : IMPL_LINK( XMLFilterListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
1483 : : {
1484 : 0 : if ( pBar && !pBar->GetCurItemId() )
1485 : 0 : return 0;
1486 : :
1487 : 0 : if ( !mpHeaderBar->IsItemMode() )
1488 : : {
1489 : 0 : Size aSz;
1490 : 0 : sal_uInt16 nTabs = mpHeaderBar->GetItemCount();
1491 : 0 : long nTmpSz = 0;
1492 : 0 : long nWidth = mpHeaderBar->GetItemSize(ITEMID_NAME);
1493 : 0 : long nBarWidth = mpHeaderBar->GetSizePixel().Width();
1494 : :
1495 : 0 : if(nWidth < 30)
1496 : 0 : mpHeaderBar->SetItemSize( ITEMID_TYPE, 30);
1497 : 0 : else if ( ( nBarWidth - nWidth ) < 30 )
1498 : 0 : mpHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - 30 );
1499 : :
1500 : 0 : for ( sal_uInt16 i = 1; i <= nTabs; ++i )
1501 : : {
1502 : 0 : long nW = mpHeaderBar->GetItemSize(i);
1503 : 0 : aSz.Width() = nW + nTmpSz;
1504 : 0 : nTmpSz += nW;
1505 : 0 : SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
1506 : : }
1507 : : }
1508 : 0 : return 1;
1509 : : }
1510 : :
1511 : : // -----------------------------------------------------------------------
1512 : :
1513 : : /** adds a new filter info entry to the ui filter list */
1514 : 0 : void XMLFilterListBox::addFilterEntry( const filter_info_impl* pInfo )
1515 : : {
1516 : 0 : const XubString aEntryStr( getEntryString( pInfo ) );
1517 : 0 : InsertEntryToColumn( aEntryStr, LIST_APPEND, 0xffff, (void*)pInfo );
1518 : 0 : }
1519 : :
1520 : : // -----------------------------------------------------------------------
1521 : :
1522 : 0 : void XMLFilterListBox::changeEntry( const filter_info_impl* pInfo )
1523 : : {
1524 : 0 : const sal_uLong nCount = GetEntryCount();
1525 : : sal_uLong nPos;
1526 : 0 : for( nPos = 0; nPos < nCount; nPos++ )
1527 : : {
1528 : 0 : SvLBoxEntry* pEntry = GetEntry( nPos );
1529 : 0 : if( (filter_info_impl*)pEntry->GetUserData() == pInfo )
1530 : : {
1531 : 0 : XubString aEntryText( getEntryString( pInfo ) );
1532 : 0 : SetEntryText( aEntryText, pEntry );
1533 : 0 : break;
1534 : : }
1535 : : }
1536 : 0 : }
1537 : :
1538 : : // -----------------------------------------------------------------------
1539 : :
1540 : 0 : String XMLFilterListBox::getEntryString( const filter_info_impl* pInfo ) const
1541 : : {
1542 : 0 : String aEntryStr( pInfo->maFilterName );
1543 : 0 : aEntryStr += '\t';
1544 : : // aEntryStr += String( getApplicationUIName( pInfo->maDocumentService ) );
1545 : 0 : if ( !pInfo->maExportService.isEmpty() )
1546 : 0 : aEntryStr += String( getApplicationUIName( pInfo->maExportService ) );
1547 : : else
1548 : 0 : aEntryStr += String( getApplicationUIName( pInfo->maImportService ) );
1549 : 0 : aEntryStr += ' ';
1550 : 0 : aEntryStr += '-';
1551 : 0 : aEntryStr += ' ';
1552 : :
1553 : 0 : if( pInfo->maFlags & 1 )
1554 : : {
1555 : 0 : if( pInfo->maFlags & 2 )
1556 : : {
1557 : 0 : aEntryStr += String( RESID( STR_IMPORT_EXPORT ) );
1558 : : }
1559 : : else
1560 : : {
1561 : 0 : aEntryStr += String( RESID( STR_IMPORT_ONLY ) );
1562 : : }
1563 : : }
1564 : 0 : else if( pInfo->maFlags & 2 )
1565 : : {
1566 : 0 : aEntryStr += String( RESID( STR_EXPORT_ONLY ) );
1567 : : }
1568 : : else
1569 : : {
1570 : 0 : aEntryStr += String( RESID( STR_UNDEFINED_FILTER ) );
1571 : : }
1572 : :
1573 : 0 : return aEntryStr;
1574 : : }
1575 : :
1576 : : // -----------------------------------------------------------------------
1577 : :
1578 : : // -----------------------------------------------------------------------
1579 : :
1580 : 0 : filter_info_impl::filter_info_impl()
1581 : : : maFlags(0x00080040),
1582 : : maFileFormatVersion(0),
1583 : : mnDocumentIconID(0),
1584 : 0 : mbReadonly(sal_False)
1585 : : {
1586 : 0 : }
1587 : :
1588 : : // -----------------------------------------------------------------------
1589 : :
1590 : 0 : filter_info_impl::filter_info_impl( const filter_info_impl& rInfo ) :
1591 : : maFilterName( rInfo.maFilterName ),
1592 : : maType( rInfo.maType ),
1593 : : maDocumentService( rInfo.maDocumentService ),
1594 : : maFilterService( rInfo.maFilterService ),
1595 : : maInterfaceName( rInfo.maInterfaceName ),
1596 : : maComment( rInfo.maComment ),
1597 : : maExtension( rInfo.maExtension ),
1598 : : maDTD( rInfo.maDTD ),
1599 : : maExportXSLT( rInfo.maExportXSLT ),
1600 : : maImportXSLT( rInfo.maImportXSLT ),
1601 : : maImportTemplate( rInfo.maImportTemplate ),
1602 : : maDocType( rInfo.maDocType ),
1603 : : maImportService( rInfo.maImportService ),
1604 : : maExportService( rInfo.maExportService ),
1605 : : maFlags( rInfo.maFlags ),
1606 : : maFileFormatVersion( rInfo.maFileFormatVersion ),
1607 : : mnDocumentIconID( rInfo.mnDocumentIconID ),
1608 : : mbReadonly( rInfo.mbReadonly ),
1609 : 0 : maXSLTTransformerImpl( rInfo.maXSLTTransformerImpl )
1610 : : {
1611 : 0 : }
1612 : :
1613 : : // -----------------------------------------------------------------------
1614 : :
1615 : 0 : int filter_info_impl::operator==( const filter_info_impl& r ) const
1616 : : {
1617 : 0 : if( maFilterName != r.maFilterName ||
1618 : 0 : maType != r.maType ||
1619 : 0 : maDocumentService != r.maDocumentService ||
1620 : 0 : maFilterService != r.maFilterService ||
1621 : 0 : maInterfaceName != r.maInterfaceName ||
1622 : 0 : maComment != r.maComment ||
1623 : 0 : maExtension != r.maExtension ||
1624 : 0 : maDocType != r.maDocType ||
1625 : 0 : maDTD != r.maDTD ||
1626 : 0 : maExportXSLT != r.maExportXSLT ||
1627 : 0 : maImportXSLT != r.maImportXSLT ||
1628 : 0 : maExportService != r.maExportService ||
1629 : 0 : maImportService != r.maImportService ||
1630 : 0 : maImportTemplate != r.maImportTemplate ||
1631 : : maFlags != r.maFlags ||
1632 : : maFileFormatVersion != r.maFileFormatVersion ||
1633 : 0 : maXSLTTransformerImpl != r.maXSLTTransformerImpl
1634 : : )
1635 : 0 : return false;
1636 : :
1637 : 0 : return true;
1638 : : }
1639 : :
1640 : : // -----------------------------------------------------------------------
1641 : :
1642 : 0 : Sequence< OUString > filter_info_impl::getFilterUserData() const
1643 : : {
1644 : 0 : Sequence< OUString > aUserData(8);
1645 : :
1646 : 0 : aUserData[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.documentconversion.XSLTFilter" ) );
1647 : 0 : aUserData[1] = maXSLTTransformerImpl;
1648 : 0 : aUserData[2] = maImportService;
1649 : 0 : aUserData[3] = maExportService;
1650 : 0 : aUserData[4] = maImportXSLT;
1651 : 0 : aUserData[5] = maExportXSLT;
1652 : 0 : aUserData[6] = maDTD;
1653 : 0 : aUserData[7] = maComment;
1654 : :
1655 : 0 : return aUserData;
1656 : : }
1657 : :
1658 : :
1659 : : // -----------------------------------------------------------------------
1660 : :
1661 : 0 : OUString string_encode( const OUString & rText )
1662 : : {
1663 : :
1664 : : static sal_Bool const aCharClass[]
1665 : : = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* UricNoSlash */
1666 : : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1667 : : 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, /* !"#$%&'()*+,-./*/
1668 : : 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /*0123456789:;<=>?*/
1669 : : 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*@ABCDEFGHIJKLMNO*/
1670 : : 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /*PQRSTUVWXYZ[\]^_*/
1671 : : 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*`abcdefghijklmno*/
1672 : : 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 /*pqrstuvwxyz{|}~ */
1673 : : };
1674 : :
1675 : :
1676 : 0 : return Uri::encode( rText, aCharClass, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 );
1677 : : }
1678 : :
1679 : : // -----------------------------------------------------------------------
1680 : :
1681 : 0 : OUString string_decode( const OUString & rText )
1682 : : {
1683 : 0 : return Uri::decode( rText, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
1684 : : }
1685 : :
1686 : : // -----------------------------------------------------------------------
1687 : :
1688 : 0 : bool isFileURL( const ::rtl::OUString & rURL )
1689 : : {
1690 : 0 : return rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("file:") ) == 0;
1691 : : }
1692 : :
1693 : : // -----------------------------------------------------------------------
1694 : :
1695 : 0 : bool copyStreams( Reference< XInputStream > xIS, Reference< XOutputStream > xOS )
1696 : : {
1697 : : try
1698 : : {
1699 : 0 : sal_Int32 nBufferSize = 512;
1700 : 0 : Sequence< sal_Int8 > aDataBuffer(nBufferSize);
1701 : :
1702 : : sal_Int32 nRead;
1703 : 0 : do
1704 : : {
1705 : 0 : nRead = xIS->readBytes( aDataBuffer, nBufferSize );
1706 : :
1707 : 0 : if( nRead )
1708 : : {
1709 : 0 : if( nRead < nBufferSize )
1710 : : {
1711 : 0 : nBufferSize = nRead;
1712 : 0 : aDataBuffer.realloc(nRead);
1713 : : }
1714 : :
1715 : 0 : xOS->writeBytes( aDataBuffer );
1716 : : }
1717 : : }
1718 : : while( nRead );
1719 : :
1720 : 0 : xOS->flush();
1721 : :
1722 : 0 : return true;
1723 : : }
1724 : 0 : catch(const Exception&)
1725 : : {
1726 : : OSL_FAIL( "copyStreams() exception catched!" );
1727 : : }
1728 : :
1729 : 0 : return false;
1730 : : }
1731 : :
1732 : : // -----------------------------------------------------------------------
1733 : :
1734 : 0 : bool createDirectory( OUString& rURL )
1735 : : {
1736 : 0 : sal_Int32 nLastIndex = sizeof( "file:///" ) - 2;
1737 : 0 : while( nLastIndex != -1 )
1738 : : {
1739 : 0 : nLastIndex = rURL.indexOf( sal_Unicode('/'), nLastIndex + 1);
1740 : 0 : if( nLastIndex != -1 )
1741 : : {
1742 : 0 : OUString aDirURL( rURL.copy( 0, nLastIndex ) );
1743 : 0 : Directory aDir( aDirURL );
1744 : 0 : Directory::RC rc = aDir.open();
1745 : 0 : if( rc == Directory::E_NOENT )
1746 : 0 : rc = osl::Directory::create( aDirURL );
1747 : :
1748 : 0 : if( rc != Directory::E_None )
1749 : : {
1750 : 0 : return false;
1751 : 0 : }
1752 : : }
1753 : : }
1754 : :
1755 : 0 : return true;
1756 : : }
1757 : :
1758 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|