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 : :
31 : : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
32 : : #include <sfx2/filedlghelper.hxx>
33 : : #include <unotools/localfilehelper.hxx>
34 : : #include <osl/file.hxx>
35 : : #include <svl/urihelper.hxx>
36 : :
37 : : #include "xmlfiltertabpagexslt.hxx"
38 : : #include "xmlfiltertabpagexslt.hrc"
39 : : #include "xmlfiltersettingsdialog.hxx"
40 : : #include "xmlfilterhelpids.hrc"
41 : :
42 : : using namespace ::rtl;
43 : : using namespace ::com::sun::star::uno;
44 : : using namespace ::com::sun::star::frame;
45 : : using namespace ::com::sun::star::lang;
46 : :
47 : : namespace css = com::sun::star;
48 : :
49 : 0 : XMLFilterTabPageXSLT::XMLFilterTabPageXSLT( Window* pParent, ResMgr& rResMgr, const css::uno::Reference< XMultiServiceFactory >& rxMSF ) :
50 : : TabPage( pParent, ResId( RID_XML_FILTER_TABPAGE_XSLT, rResMgr ) ),
51 : :
52 : : maFTDocType( this, ResId( FT_XML_DOCTYPE, rResMgr ) ),
53 : : maEDDocType( this, ResId( ED_XML_DOCTYPE, rResMgr ) ),
54 : :
55 : : maFTDTDSchema( this, ResId( FT_XML_DTD_SCHEMA, rResMgr ) ),
56 : : maEDDTDSchema( this, ResId( ED_XML_DTD_SCHEMA, rResMgr ), INET_PROT_FILE ),
57 : : maPBDTDSchemaBrowse( this, ResId( ED_XML_DTD_SCHEMA_BROWSE, rResMgr ) ),
58 : :
59 : : maFTExportXSLT( this, ResId( FT_XML_EXPORT_XSLT, rResMgr ) ),
60 : : maEDExportXSLT( this, ResId( ED_XML_EXPORT_XSLT, rResMgr ), INET_PROT_FILE ),
61 : : maPBExprotXSLT( this, ResId( PB_XML_EXPORT_XSLT_BROWSE, rResMgr ) ),
62 : :
63 : : maFTImportXSLT( this, ResId( FT_XML_IMPORT_XSLT, rResMgr ) ),
64 : : maEDImportXSLT( this, ResId( ED_XML_IMPORT_XSLT, rResMgr ), INET_PROT_FILE ),
65 : : maPBImportXSLT( this, ResId( PB_XML_IMPORT_XSLT_BROWSE, rResMgr ) ),
66 : :
67 : : maFTImportTemplate( this, ResId( FT_XML_IMPORT_TEMPLATE, rResMgr ) ),
68 : : maEDImportTemplate( this, ResId( ED_XML_IMPORT_TEMPLATE, rResMgr ), INET_PROT_FILE ),
69 : : maPBImportTemplate( this, ResId( PB_XML_IMPORT_TEMPLATE_BROWSE, rResMgr ) ),
70 : :
71 : : maFTTransformationService( this, ResId (FT_XML_TRANSFORM_SERVICE, rResMgr ) ),
72 : : maRBTransformationServiceLibXSLT( this, ResId (RB_XML_TRANSFORM_SERVICE_LIBXSLT, rResMgr ) ),
73 : : maRBTransformationServiceSaxonJ( this, ResId (RB_XML_TRANSFORM_SERVICE_SAXON_J, rResMgr ) ),
74 : :
75 : : sHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ),
76 : : sSHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ),
77 : : sFILESchema( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ),
78 : : sFTPSchema( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ),
79 : 0 : sInstPath( RTL_CONSTASCII_USTRINGPARAM( "$(prog)/" ) )
80 : : {
81 : 0 : FreeResource();
82 : :
83 : : try
84 : : {
85 : 0 : css::uno::Reference< XConfigManager > xCfgMgr( rxMSF->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.config.SpecialConfigManager" ))), UNO_QUERY );
86 : 0 : if( xCfgMgr.is() )
87 : 0 : sInstPath = xCfgMgr->substituteVariables( sInstPath );
88 : : }
89 : 0 : catch(const Exception&)
90 : : {
91 : : OSL_FAIL( "XMLFilterTabPageXSLT::XMLFilterTabPageXSLT exception catched!" );
92 : : }
93 : :
94 : 0 : maPBDTDSchemaBrowse.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
95 : 0 : maPBExprotXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
96 : 0 : maPBImportXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
97 : 0 : maPBImportTemplate.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
98 : :
99 : 0 : maEDDTDSchema.SetHelpId( HID_XML_FILTER_DTD );
100 : 0 : maEDExportXSLT.SetHelpId( HID_XML_FILTER_EXPORT_XSLT );
101 : 0 : maEDImportXSLT.SetHelpId( HID_XML_FILTER_IMPORT_XSLT );
102 : 0 : maEDImportTemplate.SetHelpId( HID_XML_FILTER_IMPORT_TEMPLATE );
103 : 0 : maRBTransformationServiceLibXSLT.SetHelpId( HID_XML_FILTER_TRANSFORM_SERVICE_LIBXSLT );
104 : 0 : maRBTransformationServiceSaxonJ.SetHelpId( HID_XML_FILTER_TRANSFORM_SERVICE_SAXON_J );
105 : 0 : }
106 : :
107 : 0 : XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT()
108 : : {
109 : 0 : }
110 : :
111 : 0 : bool XMLFilterTabPageXSLT::FillInfo( filter_info_impl* pInfo )
112 : : {
113 : 0 : if( pInfo )
114 : : {
115 : 0 : pInfo->maDocType = maEDDocType.GetText();
116 : 0 : pInfo->maDTD = GetURL( maEDDTDSchema );
117 : 0 : pInfo->maExportXSLT = GetURL( maEDExportXSLT );
118 : 0 : pInfo->maImportXSLT = GetURL( maEDImportXSLT );
119 : 0 : pInfo->maImportTemplate = GetURL( maEDImportTemplate );
120 : : pInfo->maXSLTTransformerImpl
121 : 0 : = maRBTransformationServiceSaxonJ.IsChecked() ? OUString(
122 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.JAXTHelper" ))
123 : 0 : : OUString(RTL_CONSTASCII_USTRINGPARAM( "" ));
124 : : }
125 : :
126 : 0 : return true;
127 : : }
128 : :
129 : 0 : void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl* pInfo)
130 : : {
131 : 0 : if( pInfo )
132 : : {
133 : 0 : maEDDocType.SetText( pInfo->maDocType );
134 : :
135 : 0 : SetURL( maEDDTDSchema, pInfo->maDTD );
136 : 0 : SetURL( maEDExportXSLT, pInfo->maExportXSLT );
137 : 0 : SetURL( maEDImportXSLT, pInfo->maImportXSLT );
138 : 0 : SetURL( maEDImportTemplate, pInfo->maImportTemplate );
139 : 0 : if (pInfo->maXSLTTransformerImpl.equals(OUString(
140 : 0 : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.JAXTHelper" )))) {
141 : 0 : maRBTransformationServiceSaxonJ.Check();
142 : : } else {
143 : 0 : maRBTransformationServiceLibXSLT.Check();
144 : : }
145 : : }
146 : 0 : }
147 : :
148 : 0 : void XMLFilterTabPageXSLT::SetURL( SvtURLBox& rURLBox, const OUString& rURL )
149 : : {
150 : 0 : OUString aPath;
151 : :
152 : 0 : if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ) ) )
153 : : {
154 : 0 : osl::FileBase::getSystemPathFromFileURL( rURL, aPath );
155 : :
156 : 0 : rURLBox.SetBaseURL( rURL );
157 : 0 : rURLBox.SetText( aPath );
158 : : }
159 : 0 : else if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) ||
160 : 0 : rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) ||
161 : 0 : rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) )
162 : : {
163 : 0 : rURLBox.SetBaseURL( rURL );
164 : 0 : rURLBox.SetText( rURL );
165 : : }
166 : 0 : else if( !rURL.isEmpty() )
167 : : {
168 : 0 : rtl::OUString aURL( rURL );
169 : 0 : aURL = URIHelper::SmartRel2Abs( sInstPath, aURL, Link(), false );
170 : 0 : osl::FileBase::getSystemPathFromFileURL( aURL, aPath );
171 : :
172 : 0 : rURLBox.SetBaseURL( aURL );
173 : 0 : rURLBox.SetText( aPath );
174 : : }
175 : : else
176 : : {
177 : 0 : rURLBox.SetBaseURL( sInstPath );
178 : 0 : String aEmpty;
179 : 0 : rURLBox.SetText( aEmpty );
180 : 0 : }
181 : 0 : }
182 : :
183 : 0 : OUString XMLFilterTabPageXSLT::GetURL( SvtURLBox& rURLBox )
184 : : {
185 : 0 : OUString aURL;
186 : 0 : OUString aStrPath ( rURLBox.GetText() );
187 : 0 : if( aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) ||
188 : 0 : aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) ||
189 : 0 : aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) )
190 : : {
191 : 0 : return aStrPath;
192 : : }
193 : : else
194 : : {
195 : 0 : const String aBaseURL ( rURLBox.GetBaseURL() );
196 : 0 : osl::FileBase::getFileURLFromSystemPath( aStrPath, aURL );
197 : : }
198 : :
199 : 0 : return aURL;
200 : : }
201 : :
202 : 0 : IMPL_LINK ( XMLFilterTabPageXSLT, ClickBrowseHdl_Impl, PushButton *, pButton )
203 : : {
204 : : SvtURLBox* pURLBox;
205 : :
206 : 0 : if( pButton == &maPBDTDSchemaBrowse )
207 : : {
208 : 0 : pURLBox = &maEDDTDSchema;
209 : : }
210 : 0 : else if( pButton == &maPBExprotXSLT )
211 : : {
212 : 0 : pURLBox = &maEDExportXSLT;
213 : : }
214 : 0 : else if( pButton == &maPBImportXSLT )
215 : : {
216 : 0 : pURLBox = &maEDImportXSLT;
217 : : }
218 : : else
219 : : {
220 : 0 : pURLBox = &maEDImportTemplate;
221 : : }
222 : :
223 : : // Open Fileopen-Dialog
224 : : ::sfx2::FileDialogHelper aDlg(
225 : 0 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
226 : :
227 : 0 : aDlg.SetDisplayDirectory( GetURL( *pURLBox ) );
228 : :
229 : 0 : if ( aDlg.Execute() == ERRCODE_NONE )
230 : : {
231 : 0 : OUString aURL( aDlg.GetPath() );
232 : :
233 : 0 : SetURL( *pURLBox, aURL );
234 : : }
235 : :
236 : 0 : return( 0L );
237 : : }
238 : :
239 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|