1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_QUERIES_H_ 25 #define __FRAMEWORK_QUERIES_H_ 26 27 //_________________________________________________________________________________________________________________ 28 // own includes 29 //_________________________________________________________________________________________________________________ 30 31 #include <general.h> 32 33 //_________________________________________________________________________________________________________________ 34 // other includes 35 //_________________________________________________________________________________________________________________ 36 #include <com/sun/star/uno/Sequence.hxx> 37 #include <rtl/ustring.hxx> 38 #include <rtl/ustrbuf.hxx> 39 40 //_________________________________________________________________________________________________________________ 41 // namespace 42 //_________________________________________________________________________________________________________________ 43 44 namespace framework{ 45 46 //_________________________________________________________________________________________________________________ 47 // const 48 //_________________________________________________________________________________________________________________ 49 50 /*-************************************************************************************************************//** 51 @short These values describe our supported queries for type, filter ... properties. 52 They are used by our FilterFactory or ouer TypeDetection to return 53 subsets of our cached configuration. 54 *//*-*************************************************************************************************************/ 55 #define BASE_QUERY_ALL DECLARE_ASCII("_query_all" ) 56 #define BASE_QUERY_WRITER DECLARE_ASCII("_query_Writer" ) 57 #define BASE_QUERY_WEB DECLARE_ASCII("_query_web" ) 58 #define BASE_QUERY_GLOBAL DECLARE_ASCII("_query_global" ) 59 #define BASE_QUERY_CHART DECLARE_ASCII("_query_chart" ) 60 #define BASE_QUERY_CALC DECLARE_ASCII("_query_calc" ) 61 #define BASE_QUERY_IMPRESS DECLARE_ASCII("_query_impress" ) 62 #define BASE_QUERY_DRAW DECLARE_ASCII("_query_draw" ) 63 #define BASE_QUERY_MATH DECLARE_ASCII("_query_math" ) 64 #define BASE_QUERY_GRAPHICS DECLARE_ASCII("_query_graphics") 65 66 /*-************************************************************************************************************//** 67 @short These parameters can be used in combination with BASE_QUERY_... defines to 68 specialize it. 69 use follow syntax to do so: "<query>[:<param>[=<value>]]" 70 e.g.: "_query_writer:default_first:use_order:sort_prop=uiname" 71 72 argument description default 73 ----------------------------------------------------------------------------------------------- 74 iflags=<mask> include filters by given mask 0 75 eflags=<mask> exclude filters by given mask 0 76 sort_prop=<[name,uiname]> sort by internal name or uiname name 77 descending sort descending false 78 use_order use order flag of filters for sorting false 79 default_first set default filter on top of return list false 80 case_sensitive compare "sort_prop" case sensitive false 81 *//*-*************************************************************************************************************/ 82 #define SEPERATOR_QUERYPARAM ((sal_Unicode)':') 83 #define SEPERATOR_QUERYPARAMVALUE ((sal_Unicode)'=') 84 85 #define QUERYPARAM_IFLAGS DECLARE_ASCII("iflags" ) 86 #define QUERYPARAM_EFLAGS DECLARE_ASCII("eflags" ) 87 #define QUERYPARAM_SORT_PROP DECLARE_ASCII("sort_prop" ) 88 89 #define QUERYPARAM_DESCENDING DECLARE_ASCII("descending" ) 90 #define QUERYPARAM_USE_ORDER DECLARE_ASCII("use_order" ) 91 #define QUERYPARAM_DEFAULT_FIRST DECLARE_ASCII("default_first" ) 92 #define QUERYPARAM_CASE_SENSITIVE DECLARE_ASCII("case_sensitive" ) 93 94 #define QUERYPARAMVALUE_SORT_PROP_NAME DECLARE_ASCII("name" ) 95 #define QUERYPARAMVALUE_SORT_PROP_UINAME DECLARE_ASCII("uiname" ) 96 97 /*-************************************************************************************************************//** 98 @short Helper class to support easy building of a query statements. 99 *//*-*************************************************************************************************************/ 100 class QueryBuilder 101 { 102 public: 103 //--------------------------------------------------------------------------------------------------------- 104 // start with empty query 105 //--------------------------------------------------------------------------------------------------------- 106 QueryBuilder() 107 { 108 resetAll(); 109 } 110 111 //--------------------------------------------------------------------------------------------------------- 112 // returns full query as copy of internal set values 113 //--------------------------------------------------------------------------------------------------------- 114 ::rtl::OUString getQuery() 115 { 116 ::rtl::OUStringBuffer sCopy( m_sParams ); 117 sCopy.insert( 0, m_sBase ); 118 return sCopy.makeStringAndClear(); 119 } 120 121 //--------------------------------------------------------------------------------------------------------- 122 // set new or change existing base query part 123 //--------------------------------------------------------------------------------------------------------- 124 void setBase( const ::rtl::OUString& sBase ) 125 { 126 m_sBase = sBase; 127 } 128 129 //--------------------------------------------------------------------------------------------------------- 130 // add new parameter (with optional value) to param list 131 //--------------------------------------------------------------------------------------------------------- 132 void addParam( const ::rtl::OUString& sParam, const ::rtl::OUString& sValue = ::rtl::OUString() ) 133 { 134 m_sParams.append( SEPERATOR_QUERYPARAM ); 135 m_sParams.append( sParam ); 136 if( sValue.getLength() > 0 ) 137 { 138 m_sParams.append( SEPERATOR_QUERYPARAMVALUE ); 139 m_sParams.append( sValue ); 140 } 141 } 142 143 //--------------------------------------------------------------------------------------------------------- 144 // forget all set params and start with empty ones 145 // Attention: base of query isn't changed! 146 //--------------------------------------------------------------------------------------------------------- 147 void resetParams() 148 { 149 m_sParams.makeStringAndClear(); 150 m_sParams.ensureCapacity( 256 ); 151 } 152 153 //--------------------------------------------------------------------------------------------------------- 154 // start with new empty query 155 //--------------------------------------------------------------------------------------------------------- 156 void resetAll() 157 { 158 m_sBase = ::rtl::OUString(); 159 resetParams(); 160 } 161 162 private: 163 ::rtl::OUString m_sBase ; 164 ::rtl::OUStringBuffer m_sParams ; 165 166 }; // class QueryBuilder 167 168 /*-************************************************************************************************************//** 169 @short Helper class to analyze queries and split into his different parts (base, params and values). 170 *//*-*************************************************************************************************************/ 171 class QueryAnalyzer 172 { 173 public: 174 175 //--------------------------------------------------------------------------------------------------------- 176 // it's will not perform to compare strings as query type ... 177 // so we convert it into these enum values. 178 // default = E_ALL! 179 //--------------------------------------------------------------------------------------------------------- 180 enum EQuery 181 { 182 E_ALL , 183 E_WRITER , 184 E_WEB , 185 E_GLOBAL , 186 E_CHART , 187 E_CALC , 188 E_IMPRESS , 189 E_DRAW , 190 E_MATH , 191 E_GRAPHICS 192 }; 193 194 //--------------------------------------------------------------------------------------------------------- 195 // these are valid values for param "sort_prop". 196 // other ones are not supported! 197 // default = E_NAME 198 //--------------------------------------------------------------------------------------------------------- 199 enum ESortProp 200 { 201 E_NAME , 202 E_UINAME 203 }; 204 205 //--------------------------------------------------------------------------------------------------------- 206 // analyze given query and split it into his different parts; <base>:<param1>:<param2=value>... 207 //--------------------------------------------------------------------------------------------------------- 208 QueryAnalyzer( const ::rtl::OUString& sQuery ) 209 // Don't forget to set default values for non given params! 210 : m_eQuery ( E_ALL ) // return ALL filter ... 211 , m_nIFlags ( 0 ) // which has set ANY flag ... (we remove all entries which match with these mask .. => 0!) 212 , m_nEFlags ( 0 ) // (only used, if nIFlags==0 and himself!=0!) 213 , m_eSortProp ( E_NAME ) // sort it by internal name ... 214 , m_bDescending ( sal_False ) // in ascending order ... 215 , m_bCaseSensitive( sal_False ) // ignore case ... 216 , m_bUseOrder ( sal_False ) // don't use order flag ... 217 , m_bDefaultFirst ( sal_False ) // and don't handle default entries in special case! 218 { 219 // Translate old query format to new one first! 220 ::rtl::OUString sNewQuery( sQuery ); 221 if( sQuery == DECLARE_ASCII("_filterquery_textdocument_withdefault") ) 222 sNewQuery=DECLARE_ASCII("_query_writer:default_first:use_order:sort_prop=uiname"); 223 else 224 if( sQuery == DECLARE_ASCII("_filterquery_webdocument_withdefault") ) 225 sNewQuery=DECLARE_ASCII("_query_web:default_first:use_order:sort_prop=uiname"); 226 else 227 if( sQuery == DECLARE_ASCII("_filterquery_globaldocument_withdefault") ) 228 sNewQuery=DECLARE_ASCII("_query_global:default_first:use_order:sort_prop=uiname"); 229 else 230 if( sQuery == DECLARE_ASCII("_filterquery_chartdocument_withdefault") ) 231 sNewQuery=DECLARE_ASCII("_query_chart:default_first:use_order:sort_prop=uiname"); 232 else 233 if( sQuery == DECLARE_ASCII("_filterquery_spreadsheetdocument_withdefault") ) 234 sNewQuery=DECLARE_ASCII("_query_calc:default_first:use_order:sort_prop=uiname"); 235 else 236 if( sQuery == DECLARE_ASCII("_filterquery_presentationdocument_withdefault") ) 237 sNewQuery=DECLARE_ASCII("_query_impress:default_first:use_order:sort_prop=uiname"); 238 else 239 if( sQuery == DECLARE_ASCII("_filterquery_drawingdocument_withdefault") ) 240 sNewQuery=DECLARE_ASCII("_query_draw:default_first:use_order:sort_prop=uiname"); 241 else 242 if( sQuery == DECLARE_ASCII("_filterquery_formulaproperties_withdefault") ) 243 sNewQuery=DECLARE_ASCII("_query_math:default_first:use_order:sort_prop=uiname"); 244 else 245 if( sQuery == DECLARE_ASCII("_filterquery_textdocument") ) 246 sNewQuery=DECLARE_ASCII("_query_writer:use_order:sort_prop=uiname"); 247 else 248 if( sQuery == DECLARE_ASCII("_filterquery_webdocument") ) 249 sNewQuery=DECLARE_ASCII("_query_web:use_order:sort_prop=uiname"); 250 else 251 if( sQuery == DECLARE_ASCII("_filterquery_globaldocument") ) 252 sNewQuery=DECLARE_ASCII("_query_global:use_order:sort_prop=uiname"); 253 else 254 if( sQuery == DECLARE_ASCII("_filterquery_chartdocument") ) 255 sNewQuery=DECLARE_ASCII("_query_chart:use_order:sort_prop=uiname"); 256 else 257 if( sQuery == DECLARE_ASCII("_filterquery_spreadsheetdocument") ) 258 sNewQuery=DECLARE_ASCII("_query_calc:use_order:sort_prop=uiname"); 259 else 260 if( sQuery == DECLARE_ASCII("_filterquery_presentationdocument") ) 261 sNewQuery=DECLARE_ASCII("_query_impress:use_order:sort_prop=uiname"); 262 else 263 if( sQuery == DECLARE_ASCII("_filterquery_drawingdocument") ) 264 sNewQuery=DECLARE_ASCII("_query_draw:use_order:sort_prop=uiname"); 265 else 266 if( sQuery == DECLARE_ASCII("_filterquery_formulaproperties") ) 267 sNewQuery=DECLARE_ASCII("_query_math:use_order:sort_prop=uiname"); 268 269 // Analyze query ... 270 // Try to find base of it and safe it for faster access as enum value! 271 sal_Int32 nToken = 0; 272 ::rtl::OUString sParam ; 273 ::rtl::OUString sBase = sNewQuery.getToken( 0, SEPERATOR_QUERYPARAM, nToken ); 274 275 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_ALL ) == sal_True ) m_eQuery = E_ALL ; else 276 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_WRITER ) == sal_True ) m_eQuery = E_WRITER ; else 277 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_WEB ) == sal_True ) m_eQuery = E_WEB ; else 278 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_GLOBAL ) == sal_True ) m_eQuery = E_GLOBAL ; else 279 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_CHART ) == sal_True ) m_eQuery = E_CHART ; else 280 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_CALC ) == sal_True ) m_eQuery = E_CALC ; else 281 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_IMPRESS ) == sal_True ) m_eQuery = E_IMPRESS ; else 282 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_DRAW ) == sal_True ) m_eQuery = E_DRAW ; else 283 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_MATH ) == sal_True ) m_eQuery = E_MATH ; else 284 if( sBase.equalsIgnoreAsciiCase( BASE_QUERY_GRAPHICS ) == sal_True ) m_eQuery = E_GRAPHICS ; 285 286 // Try to get additional parameters ... 287 while( nToken >= 0 ) 288 { 289 sParam = sNewQuery.getToken( 0, SEPERATOR_QUERYPARAM, nToken ); 290 // "default_first" 291 if( sParam.compareTo( QUERYPARAM_DEFAULT_FIRST, QUERYPARAM_DEFAULT_FIRST.getLength() ) == 0 ) 292 { 293 m_bDefaultFirst = sal_True; 294 } 295 else 296 // "use_order" 297 if( sParam.compareTo( QUERYPARAM_USE_ORDER, QUERYPARAM_USE_ORDER.getLength() ) == 0 ) 298 { 299 m_bUseOrder = sal_True; 300 } 301 else 302 // "descending" 303 if( sParam.compareTo( QUERYPARAM_DESCENDING, QUERYPARAM_DESCENDING.getLength() ) == 0 ) 304 { 305 m_bDescending = sal_True; 306 } 307 else 308 // "case_sensitive" 309 if( sParam.compareTo( QUERYPARAM_CASE_SENSITIVE, QUERYPARAM_CASE_SENSITIVE.getLength() ) == 0 ) 310 { 311 m_bCaseSensitive = sal_True; 312 } 313 else 314 // "iflags=<mask>" 315 if( sParam.compareTo( QUERYPARAM_IFLAGS, QUERYPARAM_IFLAGS.getLength() ) == 0 ) 316 { 317 sal_Int32 nSubToken = 0; 318 ::rtl::OUString sParamName = sParam.getToken( 0, SEPERATOR_QUERYPARAMVALUE, nSubToken ); 319 if( nSubToken > 0 ) 320 { 321 m_nIFlags = sParam.getToken( 0, SEPERATOR_QUERYPARAMVALUE, nSubToken ).toInt32(); 322 } 323 } 324 else 325 // "eflags=<mask>" 326 if( sParam.compareTo( QUERYPARAM_EFLAGS, QUERYPARAM_EFLAGS.getLength() ) == 0 ) 327 { 328 sal_Int32 nSubToken = 0; 329 ::rtl::OUString sParamName = sParam.getToken( 0, SEPERATOR_QUERYPARAMVALUE, nSubToken ); 330 if( nSubToken > 0 ) 331 { 332 m_nEFlags = sParam.getToken( 0, SEPERATOR_QUERYPARAMVALUE, nSubToken ).toInt32(); 333 } 334 } 335 else 336 // "sort_prop=<[name,uiname]>" 337 if( sParam.compareTo( QUERYPARAM_SORT_PROP, QUERYPARAM_SORT_PROP.getLength() ) == 0 ) 338 { 339 sal_Int32 nSubToken = 0; 340 ::rtl::OUString sParamName = sParam.getToken( 0, SEPERATOR_QUERYPARAMVALUE, nSubToken ); 341 if( nSubToken > 0 ) 342 { 343 ::rtl::OUString sParamValue = sParam.getToken( 0, SEPERATOR_QUERYPARAMVALUE, nSubToken ); 344 if( sParamValue.compareTo( QUERYPARAMVALUE_SORT_PROP_NAME, QUERYPARAMVALUE_SORT_PROP_NAME.getLength() ) == 0 ) 345 m_eSortProp = E_NAME; 346 else 347 if( sParamValue.compareTo( QUERYPARAMVALUE_SORT_PROP_UINAME, QUERYPARAMVALUE_SORT_PROP_UINAME.getLength() ) == 0 ) 348 m_eSortProp = E_UINAME; 349 } 350 } 351 } 352 } 353 354 //--------------------------------------------------------------------------------------------------------- 355 // return type of query. User can decide then, which action should be started. 356 // For faster work we converted query string into corresponding enum value! 357 //--------------------------------------------------------------------------------------------------------- 358 EQuery getQueryType() const { return m_eQuery; } 359 360 //--------------------------------------------------------------------------------------------------------- 361 // access to additional parameter values 362 // Methods return default of really set values! 363 //--------------------------------------------------------------------------------------------------------- 364 sal_uInt32 getIFlags () const { return m_nIFlags ; } 365 sal_uInt32 getEFlags () const { return m_nEFlags ; } 366 ESortProp getSortProp () const { return m_eSortProp ; } 367 sal_Bool getDescending () const { return m_bDescending ; } 368 sal_Bool getCaseSensitive() const { return m_bCaseSensitive; } 369 sal_Bool getUseOrder () const { return m_bUseOrder ; } 370 sal_Bool getDefaultFirst () const { return m_bDefaultFirst ; } 371 372 //--------------------------------------------------------------------------------------------------------- 373 // this method checks if given string match any supported query. 374 // (ignore additional parameters!) 375 //--------------------------------------------------------------------------------------------------------- 376 static sal_Bool isQuery( const ::rtl::OUString& sQuery ) 377 { 378 return( 379 ( sQuery.compareToAscii( "_query_" , 7 ) == 0 ) || // new style 380 ( sQuery.compareToAscii( "_filterquery_", 13 ) == 0 ) // old style! 381 ); 382 } 383 384 private: 385 EQuery m_eQuery ; 386 sal_uInt32 m_nIFlags ; 387 sal_uInt32 m_nEFlags ; 388 ESortProp m_eSortProp ; 389 sal_Bool m_bDescending ; 390 sal_Bool m_bCaseSensitive ; 391 sal_Bool m_bUseOrder ; 392 sal_Bool m_bDefaultFirst ; 393 394 }; // class QueryAnalyzer 395 396 } // namespace framework 397 398 #endif // #ifndef __FRAMEWORK_QUERIES_H_ 399