LibreOffice Module filter (master) 1
xmlfiltertabdialog.cxx
Go to the documentation of this file.
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/container/XNameAccess.hpp>
21#include <com/sun/star/beans/PropertyValue.hpp>
22#include <com/sun/star/uno/XComponentContext.hpp>
25#include <vcl/svapp.hxx>
26#include <vcl/weld.hxx>
27#include <osl/file.hxx>
28
29#include <strings.hrc>
33#include "xmlfiltercommon.hxx"
34
35using namespace com::sun::star::uno;
36using namespace com::sun::star::container;
37using namespace com::sun::star::beans;
38using namespace com::sun::star::lang;
39
41 const Reference< XComponentContext >& rxContext, const filter_info_impl* pInfo)
42 : GenericDialogController(pParent, "filter/ui/xsltfilterdialog.ui", "XSLTFilterDialog")
43 , mxContext(rxContext)
44 , m_xTabCtrl(m_xBuilder->weld_notebook("tabcontrol"))
45 , m_xOKBtn(m_xBuilder->weld_button("ok"))
46 , mpBasicPage(new XMLFilterTabPageBasic(m_xTabCtrl->get_page("general")))
47 , mpXSLTPage(new XMLFilterTabPageXSLT(m_xTabCtrl->get_page("transformation"), m_xDialog.get()))
48{
49 mpOldInfo = pInfo;
50 mpNewInfo.reset( new filter_info_impl( *mpOldInfo ) );
51
52 OUString aTitle(m_xDialog->get_title());
53 aTitle = aTitle.replaceAll("%s", mpNewInfo->maFilterName);
54 m_xDialog->set_title(aTitle);
55
56 m_xOKBtn->connect_clicked( LINK( this, XMLFilterTabDialog, OkHdl ) );
57
58 mpBasicPage->SetInfo( mpNewInfo.get() );
59 mpXSLTPage->SetInfo( mpNewInfo.get() );
60}
61
63{
64}
65
67{
68 mpXSLTPage->FillInfo( mpNewInfo.get() );
69 mpBasicPage->FillInfo( mpNewInfo.get() );
70
71 OUString sErrorPage;
72 TranslateId pErrorId;
73 weld::Widget* pFocusWindow = nullptr;
74 OUString aReplace1;
75 OUString aReplace2;
76
77 // 1. see if the filter name is ok
78 if( (mpNewInfo->maFilterName.isEmpty()) || (mpNewInfo->maFilterName != mpOldInfo->maFilterName) )
79 {
80 // if the user deleted the filter name, we reset the original filter name
81 if( mpNewInfo->maFilterName.isEmpty() )
82 {
83 mpNewInfo->maFilterName = mpOldInfo->maFilterName;
84 }
85 else
86 {
87 try
88 {
89 Reference< XNameAccess > xFilterContainer( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext ), UNO_QUERY );
90 if( xFilterContainer.is() )
91 {
92 if( xFilterContainer->hasByName( mpNewInfo->maFilterName ) )
93 {
94 sErrorPage = "general";
95 pErrorId = STR_ERROR_FILTER_NAME_EXISTS;
96 pFocusWindow = mpBasicPage->m_xEDFilterName.get();
97 aReplace1 = mpNewInfo->maFilterName;
98 }
99
100 }
101 }
102 catch( const Exception& )
103 {
104 TOOLS_WARN_EXCEPTION("filter.xslt", "");
105 }
106 }
107 }
108
109 // 2. see if the interface name is ok
110 if( (mpNewInfo->maInterfaceName.isEmpty()) || (mpNewInfo->maInterfaceName != mpOldInfo->maInterfaceName) )
111 {
112 // if the user deleted the interface name, we reset the original filter name
113 if( mpNewInfo->maInterfaceName.isEmpty() )
114 {
115 mpNewInfo->maInterfaceName = mpOldInfo->maInterfaceName;
116 }
117 else
118 {
119 try
120 {
121 Reference< XNameAccess > xFilterContainer( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext ), UNO_QUERY );
122 if( xFilterContainer.is() )
123 {
124 Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
125 OUString* pFilterName = aFilterNames.getArray();
126
127 const sal_Int32 nCount = aFilterNames.getLength();
128 sal_Int32 nFilter;
129
131 for( nFilter = 0; (nFilter < nCount) && !pErrorId; nFilter++, pFilterName++ )
132 {
133 Any aAny( xFilterContainer->getByName( *pFilterName ) );
134 if( !(aAny >>= aValues) )
135 continue;
136
137 const sal_Int32 nValueCount( aValues.getLength() );
138 PropertyValue* pValues = aValues.getArray();
139 sal_Int32 nValue;
140
141 for( nValue = 0; (nValue < nValueCount) && !pErrorId; nValue++, pValues++ )
142 {
143 if ( pValues->Name == "UIName" )
144 {
145 OUString aInterfaceName;
146 pValues->Value >>= aInterfaceName;
147 if( aInterfaceName == mpNewInfo->maInterfaceName )
148 {
149 sErrorPage = "general";
150 pErrorId = STR_ERROR_TYPE_NAME_EXISTS;
151 pFocusWindow = mpBasicPage->m_xEDInterfaceName.get();
152 aReplace1 = mpNewInfo->maInterfaceName;
153 aReplace2 = *pFilterName;
154 }
155 }
156 }
157 }
158 }
159 }
160 catch( const Exception& )
161 {
162 TOOLS_WARN_EXCEPTION("filter.xslt", "");
163 }
164 }
165 }
166
167 if (!pErrorId)
168 {
169 // 4. see if the export xslt is valid
170 if( (mpNewInfo->maExportXSLT != mpOldInfo->maExportXSLT) && comphelper::isFileUrl( mpNewInfo->maExportXSLT ) )
171 {
172 osl::File aFile( mpNewInfo->maExportXSLT );
173 osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
174 if( aRC != osl::File::E_None )
175 {
176 pErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
177 sErrorPage = "transformation";
178 pFocusWindow = mpXSLTPage->m_xEDExportXSLT->getWidget();
179 }
180 }
181 }
182
183 if (!pErrorId)
184 {
185 // 5. see if the import xslt is valid
186 if( (mpNewInfo->maImportXSLT != mpOldInfo->maImportXSLT) && comphelper::isFileUrl( mpNewInfo->maImportXSLT ) )
187 {
188 osl::File aFile( mpNewInfo->maImportXSLT );
189 osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
190 if( aRC != osl::File::E_None )
191 {
192 pErrorId = STR_ERROR_IMPORT_XSLT_NOT_FOUND;
193 sErrorPage = "transformation";
194 pFocusWindow = mpXSLTPage->m_xEDImportTemplate->getWidget();
195 }
196 }
197 }
198
199 // see if we have at least an import or an export xslt
200 if((mpNewInfo->maImportXSLT.isEmpty()) && (mpNewInfo->maExportXSLT.isEmpty()) )
201 {
202 pErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
203 sErrorPage = "transformation";
204 pFocusWindow = mpXSLTPage->m_xEDExportXSLT->getWidget();
205 }
206
207 if (!pErrorId)
208 {
209 // 6. see if the import template is valid
210 if( (mpNewInfo->maImportTemplate != mpOldInfo->maImportTemplate) && comphelper::isFileUrl( mpNewInfo->maImportTemplate ) )
211 {
212 osl::File aFile( mpNewInfo->maImportTemplate );
213 osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
214 if( aRC != osl::File::E_None )
215 {
216 pErrorId = STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND;
217 sErrorPage = "transformation";
218 pFocusWindow = mpXSLTPage->m_xEDImportTemplate->getWidget();
219 }
220 }
221 }
222
223 if (pErrorId)
224 {
225 m_xTabCtrl->set_current_page(sErrorPage);
226
227 OUString aMessage(FilterResId(pErrorId));
228
229 if( aReplace2.getLength() )
230 {
231 aMessage = aMessage.replaceAll( "%s1", aReplace1 );
232 aMessage = aMessage.replaceAll( "%s2", aReplace2 );
233 }
234 else if( aReplace1.getLength() )
235 {
236 aMessage = aMessage.replaceAll( "%s", aReplace1 );
237 }
238
239 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
240 VclMessageType::Warning, VclButtonsType::Ok,
241 aMessage));
242 xBox->run();
243
244 if( pFocusWindow )
245 pFocusWindow->grab_focus();
246
247 return false;
248 }
249 else
250 {
251 return true;
252 }
253}
254
256{
257 if( onOk() )
258 m_xDialog->response(RET_OK);
259}
260
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< XMLFilterTabPageXSLT > mpXSLTPage
virtual ~XMLFilterTabDialog() override
css::uno::Reference< css::uno::XComponentContext > mxContext
const filter_info_impl * mpOldInfo
std::unique_ptr< filter_info_impl > mpNewInfo
XMLFilterTabDialog(weld::Window *pParent, const css::uno::Reference< css::uno::XComponentContext > &rxContext, const filter_info_impl *pInfo)
std::unique_ptr< weld::Button > m_xOKBtn
std::unique_ptr< weld::Notebook > m_xTabCtrl
std::unique_ptr< XMLFilterTabPageBasic > mpBasicPage
std::shared_ptr< weld::Dialog > m_xDialog
virtual void grab_focus()=0
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
uno::Reference< uno::XComponentContext > mxContext
sal_Int16 nValue
@ Exception
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
RET_OK
IMPL_LINK_NOARG(XMLFilterTabDialog, OkHdl, weld::Button &, void)