android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / misc / defaultobjectnamecheck.cxx
blob960219223051f3203099d41db15a9c467de1f3eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <core_resource.hxx>
21 #include <defaultobjectnamecheck.hxx>
23 #include <strings.hrc>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <com/sun/star/sdb/CommandType.hpp>
27 #include <com/sun/star/sdbc/SQLException.hpp>
29 #include <connectivity/dbexception.hxx>
30 #include <connectivity/dbmetadata.hxx>
32 #include <rtl/ustrbuf.hxx>
34 #include <comphelper/diagnose_ex.hxx>
35 #include <cppuhelper/exc_hlp.hxx>
37 #include <memory>
38 #include <string_view>
40 namespace dbaui
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::lang::IllegalArgumentException;
45 using ::com::sun::star::container::XHierarchicalNameAccess;
46 using ::com::sun::star::sdbc::SQLException;
47 using ::com::sun::star::uno::Exception;
48 using ::com::sun::star::sdbc::XConnection;
49 using ::com::sun::star::sdb::tools::XConnectionTools;
50 using ::com::sun::star::uno::UNO_QUERY;
52 using namespace dbtools;
54 namespace CommandType = ::com::sun::star::sdb::CommandType;
56 // helper
57 namespace
59 void lcl_fillNameExistsError( std::u16string_view _rObjectName, SQLExceptionInfo& _out_rErrorToDisplay )
61 SQLException aError;
62 OUString sErrorMessage = DBA_RES(STR_NAMED_OBJECT_ALREADY_EXISTS);
63 aError.Message = sErrorMessage.replaceAll("$#$", _rObjectName);
64 _out_rErrorToDisplay = aError;
69 // HierarchicalNameCheck
70 HierarchicalNameCheck::HierarchicalNameCheck( const Reference< XHierarchicalNameAccess >& _rxNames, const OUString& _rRelativeRoot )
72 mxHierarchicalNames = _rxNames;
73 msRelativeRoot = _rRelativeRoot;
75 if ( !mxHierarchicalNames.is() )
76 throw IllegalArgumentException();
79 HierarchicalNameCheck::~HierarchicalNameCheck()
83 bool HierarchicalNameCheck::isNameValid( const OUString& _rObjectName, SQLExceptionInfo& _out_rErrorToDisplay ) const
85 try
87 OUStringBuffer aCompleteName;
88 if ( !msRelativeRoot.isEmpty() )
90 aCompleteName.append( msRelativeRoot + "/" );
92 aCompleteName.append( _rObjectName );
94 OUString sCompleteName( aCompleteName.makeStringAndClear() );
95 if ( !mxHierarchicalNames->hasByHierarchicalName( sCompleteName ) )
96 return true;
98 catch( const Exception& )
100 DBG_UNHANDLED_EXCEPTION("dbaccess");
103 lcl_fillNameExistsError( _rObjectName, _out_rErrorToDisplay );
104 return false;
107 // DynamicTableOrQueryNameCheck
108 DynamicTableOrQueryNameCheck::DynamicTableOrQueryNameCheck( const Reference< XConnection >& _rxSdbLevelConnection, sal_Int32 _nCommandType )
110 Reference< XConnectionTools > xConnTools( _rxSdbLevelConnection, UNO_QUERY );
111 if ( xConnTools.is() )
112 mxObjectNames.set( xConnTools->getObjectNames() );
113 if ( !mxObjectNames.is() )
114 throw IllegalArgumentException();
116 if ( ( _nCommandType != CommandType::QUERY ) && ( _nCommandType != CommandType::TABLE ) )
117 throw IllegalArgumentException();
118 mnCommandType = _nCommandType;
121 DynamicTableOrQueryNameCheck::~DynamicTableOrQueryNameCheck()
125 bool DynamicTableOrQueryNameCheck::isNameValid( const OUString& _rObjectName, ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay ) const
129 mxObjectNames->checkNameForCreate( mnCommandType, _rObjectName );
130 return true;
132 catch( const SQLException& )
134 _out_rErrorToDisplay = ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() );
136 return false;
139 } // namespace dbaui
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */