1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26 #include <com/sun/star/frame/XConfigManager.hpp>
27
28 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
29 #include <sfx2/filedlghelper.hxx>
30 #include <unotools/localfilehelper.hxx>
31 #include <osl/file.hxx>
32 #include <svl/urihelper.hxx>
33
34 #include "xmlfiltertabpagexslt.hxx"
35 #include "xmlfiltertabpagexslt.hrc"
36 #include "xmlfiltersettingsdialog.hxx"
37 #include "xmlfilterhelpids.hrc"
38
39 using namespace ::rtl;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::frame;
42 using namespace ::com::sun::star::lang;
43
XMLFilterTabPageXSLT(Window * pParent,ResMgr & rResMgr,const Reference<XMultiServiceFactory> & rxMSF)44 XMLFilterTabPageXSLT::XMLFilterTabPageXSLT( Window* pParent, ResMgr& rResMgr, const Reference< XMultiServiceFactory >& rxMSF ) :
45 TabPage( pParent, ResId( RID_XML_FILTER_TABPAGE_XSLT, rResMgr ) ),
46
47 maFTDocType( this, ResId( FT_XML_DOCTYPE, rResMgr ) ),
48 maEDDocType( this, ResId( ED_XML_DOCTYPE, rResMgr ) ),
49
50 maFTDTDSchema( this, ResId( FT_XML_DTD_SCHEMA, rResMgr ) ),
51 maEDDTDSchema( this, ResId( ED_XML_DTD_SCHEMA, rResMgr ), INET_PROT_FILE ),
52 maPBDTDSchemaBrowse( this, ResId( ED_XML_DTD_SCHEMA_BROWSE, rResMgr ) ),
53
54 maFTExportXSLT( this, ResId( FT_XML_EXPORT_XSLT, rResMgr ) ),
55 maEDExportXSLT( this, ResId( ED_XML_EXPORT_XSLT, rResMgr ), INET_PROT_FILE ),
56 maPBExprotXSLT( this, ResId( PB_XML_EXPORT_XSLT_BROWSE, rResMgr ) ),
57
58 maFTImportXSLT( this, ResId( FT_XML_IMPORT_XSLT, rResMgr ) ),
59 maEDImportXSLT( this, ResId( ED_XML_IMPORT_XSLT, rResMgr ), INET_PROT_FILE ),
60 maPBImportXSLT( this, ResId( PB_XML_IMPORT_XSLT_BROWSE, rResMgr ) ),
61
62 maFTImportTemplate( this, ResId( FT_XML_IMPORT_TEMPLATE, rResMgr ) ),
63 maEDImportTemplate( this, ResId( ED_XML_IMPORT_TEMPLATE, rResMgr ), INET_PROT_FILE ),
64 maPBImportTemplate( this, ResId( PB_XML_IMPORT_TEMPLATE_BROWSE, rResMgr ) ),
65
66 sHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ),
67 sSHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ),
68 sFILESchema( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ),
69 sFTPSchema( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ),
70 sInstPath( RTL_CONSTASCII_USTRINGPARAM( "$(prog)/" ) )
71 {
72 FreeResource();
73
74 try
75 {
76 Reference< XConfigManager > xCfgMgr( rxMSF->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY );
77 if( xCfgMgr.is() )
78 sInstPath = xCfgMgr->substituteVariables( sInstPath );
79 }
80 catch(Exception&)
81 {
82 DBG_ERROR( "XMLFilterTabPageXSLT::XMLFilterTabPageXSLT exception caught!" );
83 }
84
85 maPBDTDSchemaBrowse.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
86 maPBExprotXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
87 maPBImportXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
88 maPBImportTemplate.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
89
90 maEDDTDSchema.SetHelpId( HID_XML_FILTER_DTD );
91 maEDExportXSLT.SetHelpId( HID_XML_FILTER_EXPORT_XSLT );
92 maEDImportXSLT.SetHelpId( HID_XML_FILTER_IMPORT_XSLT );
93 maEDImportTemplate.SetHelpId( HID_XML_FILTER_IMPORT_TEMPLATE );
94 }
95
~XMLFilterTabPageXSLT()96 XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT()
97 {
98 }
99
FillInfo(filter_info_impl * pInfo)100 bool XMLFilterTabPageXSLT::FillInfo( filter_info_impl* pInfo )
101 {
102 if( pInfo )
103 {
104 pInfo->maDocType = maEDDocType.GetText();
105 pInfo->maDTD = GetURL( maEDDTDSchema );
106 pInfo->maExportXSLT = GetURL( maEDExportXSLT );
107 pInfo->maImportXSLT = GetURL( maEDImportXSLT );
108 pInfo->maImportTemplate = GetURL( maEDImportTemplate );
109 }
110
111 return true;
112 }
113
SetInfo(const filter_info_impl * pInfo)114 void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl* pInfo)
115 {
116 if( pInfo )
117 {
118 maEDDocType.SetText( pInfo->maDocType );
119
120 SetURL( maEDDTDSchema, pInfo->maDTD );
121 SetURL( maEDExportXSLT, pInfo->maExportXSLT );
122 SetURL( maEDImportXSLT, pInfo->maImportXSLT );
123 SetURL( maEDImportTemplate, pInfo->maImportTemplate );
124 }
125 }
126
SetURL(SvtURLBox & rURLBox,const OUString & rURL)127 void XMLFilterTabPageXSLT::SetURL( SvtURLBox& rURLBox, const OUString& rURL )
128 {
129 OUString aPath;
130
131 if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ) ) )
132 {
133 osl::FileBase::getSystemPathFromFileURL( rURL, aPath );
134
135 rURLBox.SetBaseURL( rURL );
136 rURLBox.SetText( aPath );
137 }
138 else if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) ||
139 rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) ||
140 rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) )
141 {
142 rURLBox.SetBaseURL( rURL );
143 rURLBox.SetText( rURL );
144 }
145 else if( rURL.getLength() )
146 {
147 rtl::OUString aURL( rURL );
148 aURL = URIHelper::SmartRel2Abs( sInstPath, aURL, Link(), false );
149 osl::FileBase::getSystemPathFromFileURL( aURL, aPath );
150
151 rURLBox.SetBaseURL( aURL );
152 rURLBox.SetText( aPath );
153 }
154 else
155 {
156 rURLBox.SetBaseURL( sInstPath );
157 String aEmpty;
158 rURLBox.SetText( aEmpty );
159 }
160 }
161
GetURL(SvtURLBox & rURLBox)162 OUString XMLFilterTabPageXSLT::GetURL( SvtURLBox& rURLBox )
163 {
164 OUString aURL;
165 OUString aStrPath ( rURLBox.GetText() );
166 if( aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) ||
167 aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) ||
168 aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) )
169 {
170 return aStrPath;
171 }
172 else
173 {
174 const String aBaseURL ( rURLBox.GetBaseURL() );
175 osl::FileBase::getFileURLFromSystemPath( aStrPath, aURL );
176 }
177
178 return aURL;
179 }
180
IMPL_LINK(XMLFilterTabPageXSLT,ClickBrowseHdl_Impl,PushButton *,pButton)181 IMPL_LINK ( XMLFilterTabPageXSLT, ClickBrowseHdl_Impl, PushButton *, pButton )
182 {
183 SvtURLBox* pURLBox;
184
185 if( pButton == &maPBDTDSchemaBrowse )
186 {
187 pURLBox = &maEDDTDSchema;
188 }
189 else if( pButton == &maPBExprotXSLT )
190 {
191 pURLBox = &maEDExportXSLT;
192 }
193 else if( pButton == &maPBImportXSLT )
194 {
195 pURLBox = &maEDImportXSLT;
196 }
197 else
198 {
199 pURLBox = &maEDImportTemplate;
200 }
201
202 // Open Fileopen-Dialog
203 ::sfx2::FileDialogHelper aDlg(
204 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
205
206 aDlg.SetDisplayDirectory( GetURL( *pURLBox ) );
207
208 if ( aDlg.Execute() == ERRCODE_NONE )
209 {
210 OUString aURL( aDlg.GetPath() );
211
212 SetURL( *pURLBox, aURL );
213 }
214
215 return( 0L );
216 }
217
218