Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/frame/XConfigManager.hpp>
21 :
22 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
23 : #include <sfx2/filedlghelper.hxx>
24 : #include <unotools/localfilehelper.hxx>
25 : #include <unotools/pathoptions.hxx>
26 : #include <osl/file.hxx>
27 : #include <svl/urihelper.hxx>
28 :
29 : #include "xmlfiltertabpagexslt.hxx"
30 : #include "xmlfiltertabpagexslt.hrc"
31 : #include "xmlfiltersettingsdialog.hxx"
32 : #include "xmlfilterhelpids.hrc"
33 :
34 : using namespace ::rtl;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::frame;
37 : using namespace ::com::sun::star::lang;
38 :
39 0 : XMLFilterTabPageXSLT::XMLFilterTabPageXSLT( Window* pParent, ResMgr& rResMgr ) :
40 : TabPage( pParent, ResId( RID_XML_FILTER_TABPAGE_XSLT, rResMgr ) ),
41 :
42 : maFTDocType( this, ResId( FT_XML_DOCTYPE, rResMgr ) ),
43 : maEDDocType( this, ResId( ED_XML_DOCTYPE, rResMgr ) ),
44 :
45 : maFTExportXSLT( this, ResId( FT_XML_EXPORT_XSLT, rResMgr ) ),
46 : maEDExportXSLT( this, ResId( ED_XML_EXPORT_XSLT, rResMgr ), INET_PROT_FILE ),
47 : maPBExprotXSLT( this, ResId( PB_XML_EXPORT_XSLT_BROWSE, rResMgr ) ),
48 :
49 : maFTImportXSLT( this, ResId( FT_XML_IMPORT_XSLT, rResMgr ) ),
50 : maEDImportXSLT( this, ResId( ED_XML_IMPORT_XSLT, rResMgr ), INET_PROT_FILE ),
51 : maPBImportXSLT( this, ResId( PB_XML_IMPORT_XSLT_BROWSE, rResMgr ) ),
52 :
53 : maFTImportTemplate( this, ResId( FT_XML_IMPORT_TEMPLATE, rResMgr ) ),
54 : maEDImportTemplate( this, ResId( ED_XML_IMPORT_TEMPLATE, rResMgr ), INET_PROT_FILE ),
55 : maPBImportTemplate( this, ResId( PB_XML_IMPORT_TEMPLATE_BROWSE, rResMgr ) ),
56 :
57 : maFTNeedsXSLT2( this, ResId (FT_XML_NEEDS_XSLT2, rResMgr ) ),
58 : maCBNeedsXSLT2( this, ResId (CB_XML_NEEDS_XSLT2, rResMgr ) ),
59 :
60 : sHTTPSchema( "http://" ),
61 : sSHTTPSchema( "https://" ),
62 : sFILESchema( "file://" ),
63 : sFTPSchema( "ftp://" ),
64 0 : sInstPath( "$(prog)/" )
65 : {
66 0 : FreeResource();
67 :
68 0 : SvtPathOptions aOptions;
69 0 : sInstPath = aOptions.SubstituteVariable( sInstPath );
70 :
71 0 : maPBExprotXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
72 0 : maPBImportXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
73 0 : maPBImportTemplate.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
74 :
75 0 : maEDExportXSLT.SetHelpId( HID_XML_FILTER_EXPORT_XSLT );
76 0 : maEDImportXSLT.SetHelpId( HID_XML_FILTER_IMPORT_XSLT );
77 0 : maEDImportTemplate.SetHelpId( HID_XML_FILTER_IMPORT_TEMPLATE );
78 0 : maCBNeedsXSLT2.SetHelpId( HID_XML_FILTER_NEEDS_XSLT2 );
79 0 : }
80 :
81 0 : XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT()
82 : {
83 0 : }
84 :
85 0 : bool XMLFilterTabPageXSLT::FillInfo( filter_info_impl* pInfo )
86 : {
87 0 : if( pInfo )
88 : {
89 0 : pInfo->maDocType = maEDDocType.GetText();
90 0 : pInfo->maExportXSLT = GetURL( maEDExportXSLT );
91 0 : pInfo->maImportXSLT = GetURL( maEDImportXSLT );
92 0 : pInfo->maImportTemplate = GetURL( maEDImportTemplate );
93 0 : pInfo->mbNeedsXSLT2 = maCBNeedsXSLT2.IsChecked();
94 : }
95 :
96 0 : return true;
97 : }
98 :
99 0 : void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl* pInfo)
100 : {
101 0 : if( pInfo )
102 : {
103 0 : maEDDocType.SetText( pInfo->maDocType );
104 :
105 0 : SetURL( maEDExportXSLT, pInfo->maExportXSLT );
106 0 : SetURL( maEDImportXSLT, pInfo->maImportXSLT );
107 0 : SetURL( maEDImportTemplate, pInfo->maImportTemplate );
108 0 : maCBNeedsXSLT2.Check( pInfo->mbNeedsXSLT2 );
109 : }
110 0 : }
111 :
112 0 : void XMLFilterTabPageXSLT::SetURL( SvtURLBox& rURLBox, const OUString& rURL )
113 : {
114 0 : OUString aPath;
115 :
116 0 : if( rURL.matchIgnoreAsciiCase( "file://" ) )
117 : {
118 0 : osl::FileBase::getSystemPathFromFileURL( rURL, aPath );
119 :
120 0 : rURLBox.SetBaseURL( rURL );
121 0 : rURLBox.SetText( aPath );
122 : }
123 0 : else if( rURL.matchIgnoreAsciiCase( "http://" ) ||
124 0 : rURL.matchIgnoreAsciiCase( "https://" ) ||
125 0 : rURL.matchIgnoreAsciiCase( "ftp://" ) )
126 : {
127 0 : rURLBox.SetBaseURL( rURL );
128 0 : rURLBox.SetText( rURL );
129 : }
130 0 : else if( !rURL.isEmpty() )
131 : {
132 0 : OUString aURL( rURL );
133 0 : aURL = URIHelper::SmartRel2Abs( sInstPath, aURL, Link(), false );
134 0 : osl::FileBase::getSystemPathFromFileURL( aURL, aPath );
135 :
136 0 : rURLBox.SetBaseURL( aURL );
137 0 : rURLBox.SetText( aPath );
138 : }
139 : else
140 : {
141 0 : rURLBox.SetBaseURL( sInstPath );
142 0 : OUString aEmpty;
143 0 : rURLBox.SetText( aEmpty );
144 0 : }
145 0 : }
146 :
147 0 : OUString XMLFilterTabPageXSLT::GetURL( SvtURLBox& rURLBox )
148 : {
149 0 : OUString aURL;
150 0 : OUString aStrPath ( rURLBox.GetText() );
151 0 : if( aStrPath.matchIgnoreAsciiCase( "http://" ) ||
152 0 : aStrPath.matchIgnoreAsciiCase( "https://" ) ||
153 0 : aStrPath.matchIgnoreAsciiCase( "ftp://" ) )
154 : {
155 0 : return aStrPath;
156 : }
157 : else
158 : {
159 0 : osl::FileBase::getFileURLFromSystemPath( aStrPath, aURL );
160 : }
161 :
162 0 : return aURL;
163 : }
164 :
165 0 : IMPL_LINK ( XMLFilterTabPageXSLT, ClickBrowseHdl_Impl, PushButton *, pButton )
166 : {
167 : SvtURLBox* pURLBox;
168 :
169 0 : if( pButton == &maPBExprotXSLT )
170 : {
171 0 : pURLBox = &maEDExportXSLT;
172 : }
173 0 : else if( pButton == &maPBImportXSLT )
174 : {
175 0 : pURLBox = &maEDImportXSLT;
176 : }
177 : else
178 : {
179 0 : pURLBox = &maEDImportTemplate;
180 : }
181 :
182 : // Open Fileopen-Dialog
183 : ::sfx2::FileDialogHelper aDlg(
184 0 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
185 :
186 0 : aDlg.SetDisplayDirectory( GetURL( *pURLBox ) );
187 :
188 0 : if ( aDlg.Execute() == ERRCODE_NONE )
189 : {
190 0 : OUString aURL( aDlg.GetPath() );
191 :
192 0 : SetURL( *pURLBox, aURL );
193 : }
194 :
195 0 : return( 0L );
196 0 : }
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|