LibreOffice Module svx (master) 1
ParseContext.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
21#include <sal/macros.h>
22#include <svx/ParseContext.hxx>
23#include <svx/strings.hrc>
24
25#include <svx/dialmgr.hxx>
26
29#include <vcl/svapp.hxx>
30#include <osl/diagnose.h>
31#include <fmstring.hrc>
32#include <mutex>
33
34using namespace svxform;
35using namespace ::connectivity;
36
37OSystemParseContext::OSystemParseContext()
38 : IParseContext()
39{
40 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_RSC_SQL_INTERNATIONAL); ++i)
41 m_aLocalizedKeywords.push_back(SvxResId(RID_RSC_SQL_INTERNATIONAL[i]));
42}
43
45{
46}
47
49{
51}
52
54{
55 OUString aMsg;
56 SolarMutexGuard aGuard;
57 switch (_eCode)
58 {
59 case ErrorCode::General: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_ERROR); break;
60 case ErrorCode::ValueNoLike: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break;
61 case ErrorCode::FieldNoLike: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break;
62 case ErrorCode::InvalidCompare: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break;
63 case ErrorCode::InvalidIntCompare: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break;
64 case ErrorCode::InvalidDateCompare: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break;
65 case ErrorCode::InvalidRealCompare: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break;
66 case ErrorCode::InvalidTableNosuch: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_TABLE); break;
67 case ErrorCode::InvalidTableOrQuery: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break;
68 case ErrorCode::InvalidColumn: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_COLUMN); break;
69 case ErrorCode::InvalidTableExist: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break;
70 case ErrorCode::InvalidQueryExist: aMsg = SvxResId(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break;
71 default: break;
72 }
73 return aMsg;
74}
75
77{
78 size_t nIndex = 0;
79 switch ( _eKey )
80 {
81 case InternationalKeyCode::Like: nIndex = 0; break;
82 case InternationalKeyCode::Not: nIndex = 1; break;
83 case InternationalKeyCode::Null: nIndex = 2; break;
84 case InternationalKeyCode::True: nIndex = 3; break;
85 case InternationalKeyCode::False: nIndex = 4; break;
86 case InternationalKeyCode::Is: nIndex = 5; break;
88 case InternationalKeyCode::Or: nIndex = 7; break;
89 case InternationalKeyCode::And: nIndex = 8; break;
90 case InternationalKeyCode::Avg: nIndex = 9; break;
91 case InternationalKeyCode::Count: nIndex = 10; break;
92 case InternationalKeyCode::Max: nIndex = 11; break;
93 case InternationalKeyCode::Min: nIndex = 12; break;
94 case InternationalKeyCode::Sum: nIndex = 13; break;
95 case InternationalKeyCode::Every: nIndex = 14; break;
96 case InternationalKeyCode::Any: nIndex = 15; break;
97 case InternationalKeyCode::Some: nIndex = 16; break;
100 case InternationalKeyCode::VarSamp: nIndex = 19; break;
101 case InternationalKeyCode::VarPop: nIndex = 20; break;
102 case InternationalKeyCode::Collect: nIndex = 21; break;
103 case InternationalKeyCode::Fusion: nIndex = 22; break;
106 OSL_FAIL( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
107 break;
108 }
109
110 OSL_ENSURE( nIndex < m_aLocalizedKeywords.size(), "OSystemParseContext::getIntlKeywordAscii: invalid index!" );
111
112 OString sKeyword;
113 if ( nIndex < m_aLocalizedKeywords.size() )
114 sKeyword = OUStringToOString(m_aLocalizedKeywords[nIndex], RTL_TEXTENCODING_UTF8);
115 return sKeyword;
116}
117
118
119IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const OString& rToken) const
120{
121 static const IParseContext::InternationalKeyCode Intl_TokenID[] =
122 {
130 };
131
132 sal_uInt32 const nCount = SAL_N_ELEMENTS(Intl_TokenID);
133 for (sal_uInt32 i = 0; i < nCount; i++)
134 {
135 OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
136 if (rToken.equalsIgnoreAsciiCase(aKey))
137 return Intl_TokenID[i];
138 }
139
141}
142
143
144namespace
145{
146
147 std::mutex& getSafetyMutex()
148 {
149 static ::std::mutex s_aSafety;
150 return s_aSafety;
151 }
152
153 int s_nCounter;
154
155 OSystemParseContext* getSharedContext(OSystemParseContext* _pContext, bool _bSet)
156 {
157 static OSystemParseContext* s_pSharedContext = nullptr;
158 if ( _pContext && !s_pSharedContext )
159 {
160 s_pSharedContext = _pContext;
161 return s_pSharedContext;
162 }
163 if ( _bSet )
164 {
165 OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext;
166 s_pSharedContext = _pContext;
167 return pReturn;
168 }
169 return s_pSharedContext;
170 }
171
172}
173
175{
176 std::scoped_lock aGuard( getSafetyMutex() );
177 ++s_nCounter;
178 if ( 1 == s_nCounter )
179 { // first instance
180 getSharedContext( new OSystemParseContext, false );
181 }
182}
183
184
186{
187 std::scoped_lock aGuard( getSafetyMutex() );
188 --s_nCounter;
189 if ( 0 == s_nCounter )
190 delete getSharedContext(nullptr,true);
191}
192
194{
195 return getSharedContext(nullptr, false);
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
const LanguageTag & GetLanguageTag() const
const OSystemParseContext * getParseContext() const
::std::vector< OUString > m_aLocalizedKeywords
virtual OString getIntlKeywordAscii(InternationalKeyCode _eKey) const override
virtual SVXCORE_DLLPUBLIC css::lang::Locale getPreferredLocale() const override
gets a locale instance which should be used when parsing in the context specified by this instance
virtual OUString getErrorMessage(ErrorCode _eCodes) const override
virtual InternationalKeyCode getIntlKeyCode(const OString &rToken) const override
virtual SVXCORE_DLLPUBLIC ~OSystemParseContext()
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int32 nIndex
#define SAL_N_ELEMENTS(arr)
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
class FmSearchEngine - Impl class for FmSearchDialog