merge the formfield patch from ooo-build
[ooovba.git] / filter / source / xsltdialog / xmlfiltertabpagexslt.cxx
blob2d038de67b2f52aa3812fc3cbfaa954128fbe64c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfiltertabpagexslt.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
33 #include <com/sun/star/frame/XConfigManager.hpp>
35 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
36 #include <sfx2/filedlghelper.hxx>
37 #include <unotools/localfilehelper.hxx>
38 #include <osl/file.hxx>
39 #include <svtools/urihelper.hxx>
41 #include "xmlfiltertabpagexslt.hxx"
42 #include "xmlfiltertabpagexslt.hrc"
43 #include "xmlfiltersettingsdialog.hxx"
44 #include "xmlfilterhelpids.hrc"
46 using namespace ::rtl;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::frame;
49 using namespace ::com::sun::star::lang;
51 XMLFilterTabPageXSLT::XMLFilterTabPageXSLT( Window* pParent, ResMgr& rResMgr, const Reference< XMultiServiceFactory >& rxMSF ) :
52 TabPage( pParent, ResId( RID_XML_FILTER_TABPAGE_XSLT, rResMgr ) ),
54 maFTDocType( this, ResId( FT_XML_DOCTYPE, rResMgr ) ),
55 maEDDocType( this, ResId( ED_XML_DOCTYPE, rResMgr ) ),
57 maFTDTDSchema( this, ResId( FT_XML_DTD_SCHEMA, rResMgr ) ),
58 maEDDTDSchema( this, ResId( ED_XML_DTD_SCHEMA, rResMgr ), INET_PROT_FILE ),
59 maPBDTDSchemaBrowse( this, ResId( ED_XML_DTD_SCHEMA_BROWSE, rResMgr ) ),
61 maFTExportXSLT( this, ResId( FT_XML_EXPORT_XSLT, rResMgr ) ),
62 maEDExportXSLT( this, ResId( ED_XML_EXPORT_XSLT, rResMgr ), INET_PROT_FILE ),
63 maPBExprotXSLT( this, ResId( PB_XML_EXPORT_XSLT_BROWSE, rResMgr ) ),
65 maFTImportXSLT( this, ResId( FT_XML_IMPORT_XSLT, rResMgr ) ),
66 maEDImportXSLT( this, ResId( ED_XML_IMPORT_XSLT, rResMgr ), INET_PROT_FILE ),
67 maPBImportXSLT( this, ResId( PB_XML_IMPORT_XSLT_BROWSE, rResMgr ) ),
69 maFTImportTemplate( this, ResId( FT_XML_IMPORT_TEMPLATE, rResMgr ) ),
70 maEDImportTemplate( this, ResId( ED_XML_IMPORT_TEMPLATE, rResMgr ), INET_PROT_FILE ),
71 maPBImportTemplate( this, ResId( PB_XML_IMPORT_TEMPLATE_BROWSE, rResMgr ) ),
73 sHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ),
74 sSHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ),
75 sFILESchema( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ),
76 sFTPSchema( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ),
77 sInstPath( RTL_CONSTASCII_USTRINGPARAM( "$(prog)/" ) )
79 FreeResource();
81 try
83 Reference< XConfigManager > xCfgMgr( rxMSF->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY );
84 if( xCfgMgr.is() )
85 sInstPath = xCfgMgr->substituteVariables( sInstPath );
87 catch(Exception&)
89 DBG_ERROR( "XMLFilterTabPageXSLT::XMLFilterTabPageXSLT exception catched!" );
92 maPBDTDSchemaBrowse.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
93 maPBExprotXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
94 maPBImportXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
95 maPBImportTemplate.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
97 maEDDTDSchema.SetHelpId( HID_XML_FILTER_DTD );
98 maEDExportXSLT.SetHelpId( HID_XML_FILTER_EXPORT_XSLT );
99 maEDImportXSLT.SetHelpId( HID_XML_FILTER_IMPORT_XSLT );
100 maEDImportTemplate.SetHelpId( HID_XML_FILTER_IMPORT_TEMPLATE );
103 XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT()
107 bool XMLFilterTabPageXSLT::FillInfo( filter_info_impl* pInfo )
109 if( pInfo )
111 pInfo->maDocType = maEDDocType.GetText();
112 pInfo->maDTD = GetURL( maEDDTDSchema );
113 pInfo->maExportXSLT = GetURL( maEDExportXSLT );
114 pInfo->maImportXSLT = GetURL( maEDImportXSLT );
115 pInfo->maImportTemplate = GetURL( maEDImportTemplate );
118 return true;
121 void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl* pInfo)
123 if( pInfo )
125 maEDDocType.SetText( pInfo->maDocType );
127 SetURL( maEDDTDSchema, pInfo->maDTD );
128 SetURL( maEDExportXSLT, pInfo->maExportXSLT );
129 SetURL( maEDImportXSLT, pInfo->maImportXSLT );
130 SetURL( maEDImportTemplate, pInfo->maImportTemplate );
134 void XMLFilterTabPageXSLT::SetURL( SvtURLBox& rURLBox, const OUString& rURL )
136 OUString aPath;
138 if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ) ) )
140 osl::FileBase::getSystemPathFromFileURL( rURL, aPath );
142 rURLBox.SetBaseURL( rURL );
143 rURLBox.SetText( aPath );
145 else if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) ||
146 rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) ||
147 rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) )
149 rURLBox.SetBaseURL( rURL );
150 rURLBox.SetText( rURL );
152 else if( rURL.getLength() )
154 rtl::OUString aURL( rURL );
155 aURL = URIHelper::SmartRel2Abs( sInstPath, aURL, Link(), false );
156 osl::FileBase::getSystemPathFromFileURL( aURL, aPath );
158 rURLBox.SetBaseURL( aURL );
159 rURLBox.SetText( aPath );
161 else
163 rURLBox.SetBaseURL( sInstPath );
164 String aEmpty;
165 rURLBox.SetText( aEmpty );
169 OUString XMLFilterTabPageXSLT::GetURL( SvtURLBox& rURLBox )
171 OUString aURL;
172 OUString aStrPath ( rURLBox.GetText() );
173 if( aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) ||
174 aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) ||
175 aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) )
177 return aStrPath;
179 else
181 const String aBaseURL ( rURLBox.GetBaseURL() );
182 osl::FileBase::getFileURLFromSystemPath( aStrPath, aURL );
185 return aURL;
188 IMPL_LINK ( XMLFilterTabPageXSLT, ClickBrowseHdl_Impl, PushButton *, pButton )
190 SvtURLBox* pURLBox;
192 if( pButton == &maPBDTDSchemaBrowse )
194 pURLBox = &maEDDTDSchema;
196 else if( pButton == &maPBExprotXSLT )
198 pURLBox = &maEDExportXSLT;
200 else if( pButton == &maPBImportXSLT )
202 pURLBox = &maEDImportXSLT;
204 else
206 pURLBox = &maEDImportTemplate;
209 // Open Fileopen-Dialog
210 ::sfx2::FileDialogHelper aDlg(
211 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
213 aDlg.SetDisplayDirectory( GetURL( *pURLBox ) );
215 if ( aDlg.Execute() == ERRCODE_NONE )
217 OUString aURL( aDlg.GetPath() );
219 SetURL( *pURLBox, aURL );
222 return( 0L );