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 
28 #include <unotools/syslocale.hxx>
29 #include <vcl/svapp.hxx>
30 #include <osl/diagnose.h>
31 #include <osl/mutex.hxx>
32 #include <fmstring.hrc>
33 
34 using namespace svxform;
35 using namespace ::connectivity;
36 
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 
48 css::lang::Locale OSystemParseContext::getPreferredLocale( ) const
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;
87  case InternationalKeyCode::Between: nIndex = 6; 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;
98  case InternationalKeyCode::StdDevPop: nIndex = 17; break;
99  case InternationalKeyCode::StdDevSamp: nIndex = 18; 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;
104  case InternationalKeyCode::Intersection: nIndex = 23; 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 
119 IParseContext::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 
144 namespace
145 {
146 
147  ::osl::Mutex& getSafteyMutex()
148  {
149  static ::osl::Mutex s_aSafety;
150  return s_aSafety;
151  }
152 
153  oslInterlockedCount& getCounter()
154  {
155  static oslInterlockedCount s_nCounter;
156  return s_nCounter;
157  }
158 
159  OSystemParseContext* getSharedContext(OSystemParseContext* _pContext, bool _bSet)
160  {
161  static OSystemParseContext* s_pSharedContext = nullptr;
162  if ( _pContext && !s_pSharedContext )
163  {
164  s_pSharedContext = _pContext;
165  return s_pSharedContext;
166  }
167  if ( _bSet )
168  {
169  OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext;
170  s_pSharedContext = _pContext;
171  return pReturn;
172  }
173  return s_pSharedContext;
174  }
175 
176 }
177 
179 {
180  ::osl::MutexGuard aGuard( getSafteyMutex() );
181  if ( 1 == osl_atomic_increment( &getCounter() ) )
182  { // first instance
183  getSharedContext( new OSystemParseContext, false );
184  }
185 }
186 
187 
189 {
190  ::osl::MutexGuard aGuard( getSafteyMutex() );
191  if ( 0 == osl_atomic_decrement( &getCounter() ) )
192  delete getSharedContext(nullptr,true);
193 }
194 
196 {
197  return getSharedContext(nullptr, false);
198 }
199 
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
virtual OUString getErrorMessage(ErrorCode _eCodes) const override
::std::vector< OUString > m_aLocalizedKeywords
const OSystemParseContext * getParseContext() const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
int nCount
#define SAL_N_ELEMENTS(arr)
virtual OString getIntlKeywordAscii(InternationalKeyCode _eKey) const override
int i
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
virtual InternationalKeyCode getIntlKeyCode(const OString &rToken) const override
const LanguageTag & GetLanguageTag() const
virtual css::lang::Locale getPreferredLocale() const override
gets a locale instance which should be used when parsing in the context specified by this instance ...
class FmSearchEngine - Impl class for FmSearchDialog