1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: queries.h,v $
10 * $Revision: 1.7.80.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_QUERIES_H_
32 #define __FRAMEWORK_QUERIES_H_
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
38 #include <filterflags.h>
41 //_________________________________________________________________________________________________________________
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <rtl/ustring.hxx>
46 #include <rtl/ustrbuf.hxx>
48 //_________________________________________________________________________________________________________________
50 //_________________________________________________________________________________________________________________
54 //_________________________________________________________________________________________________________________
56 //_________________________________________________________________________________________________________________
58 /*-************************************************************************************************************//**
59 @short These values describe our supported queries for type, filter ... properties.
60 They are used by our FilterFactory or ouer TypeDetection to return
61 subsets of our cached configuration.
62 *//*-*************************************************************************************************************/
63 #define BASE_QUERY_ALL DECLARE_ASCII("_query_all" )
64 #define BASE_QUERY_WRITER DECLARE_ASCII("_query_Writer" )
65 #define BASE_QUERY_WEB DECLARE_ASCII("_query_web" )
66 #define BASE_QUERY_GLOBAL DECLARE_ASCII("_query_global" )
67 #define BASE_QUERY_CHART DECLARE_ASCII("_query_chart" )
68 #define BASE_QUERY_CALC DECLARE_ASCII("_query_calc" )
69 #define BASE_QUERY_IMPRESS DECLARE_ASCII("_query_impress" )
70 #define BASE_QUERY_DRAW DECLARE_ASCII("_query_draw" )
71 #define BASE_QUERY_MATH DECLARE_ASCII("_query_math" )
72 #define BASE_QUERY_GRAPHICS DECLARE_ASCII("_query_graphics")
74 /*-************************************************************************************************************//**
75 @short These parameters can be used in combination with BASE_QUERY_... defines to
77 use follow syntax to do so: "<query>[:<param>[=<value>]]"
78 e.g.: "_query_writer:default_first:use_order:sort_prop=uiname"
80 argument description default
81 -----------------------------------------------------------------------------------------------
82 iflags=<mask> include filters by given mask 0
83 eflags=<mask> exclude filters by given mask 0
84 sort_prop=<[name,uiname]> sort by internal name or uiname name
85 descending sort descending false
86 use_order use order flag of filters for sorting false
87 default_first set default filter on top of return list false
88 case_sensitive compare "sort_prop" case sensitive false
89 *//*-*************************************************************************************************************/
90 #define SEPERATOR_QUERYPARAM ((sal_Unicode)':')
91 #define SEPERATOR_QUERYPARAMVALUE ((sal_Unicode)'=')
93 #define QUERYPARAM_IFLAGS DECLARE_ASCII("iflags" )
94 #define QUERYPARAM_EFLAGS DECLARE_ASCII("eflags" )
95 #define QUERYPARAM_SORT_PROP DECLARE_ASCII("sort_prop" )
97 #define QUERYPARAM_DESCENDING DECLARE_ASCII("descending" )
98 #define QUERYPARAM_USE_ORDER DECLARE_ASCII("use_order" )
99 #define QUERYPARAM_DEFAULT_FIRST DECLARE_ASCII("default_first" )
100 #define QUERYPARAM_CASE_SENSITIVE DECLARE_ASCII("case_sensitive" )
102 #define QUERYPARAMVALUE_SORT_PROP_NAME DECLARE_ASCII("name" )
103 #define QUERYPARAMVALUE_SORT_PROP_UINAME DECLARE_ASCII("uiname" )
105 /*-************************************************************************************************************//**
106 @short Helper class to support easy building of a query statements.
107 *//*-*************************************************************************************************************/
111 //---------------------------------------------------------------------------------------------------------
112 // start with empty query
113 //---------------------------------------------------------------------------------------------------------
119 //---------------------------------------------------------------------------------------------------------
120 // returns full query as copy of internal set values
121 //---------------------------------------------------------------------------------------------------------
122 ::rtl::OUString
getQuery()
124 ::rtl::OUStringBuffer
sCopy( m_sParams
);
125 sCopy
.insert( 0, m_sBase
);
126 return sCopy
.makeStringAndClear();
129 //---------------------------------------------------------------------------------------------------------
130 // set new or change existing base query part
131 //---------------------------------------------------------------------------------------------------------
132 void setBase( const ::rtl::OUString
& sBase
)
137 //---------------------------------------------------------------------------------------------------------
138 // add new parameter (with optional value) to param list
139 //---------------------------------------------------------------------------------------------------------
140 void addParam( const ::rtl::OUString
& sParam
, const ::rtl::OUString
& sValue
= ::rtl::OUString() )
142 m_sParams
.append( SEPERATOR_QUERYPARAM
);
143 m_sParams
.append( sParam
);
144 if( sValue
.getLength() > 0 )
146 m_sParams
.append( SEPERATOR_QUERYPARAMVALUE
);
147 m_sParams
.append( sValue
);
151 //---------------------------------------------------------------------------------------------------------
152 // forget all setted params and start with empty ones
153 // Attention: base of query isn't changed!
154 //---------------------------------------------------------------------------------------------------------
157 m_sParams
.makeStringAndClear();
158 m_sParams
.ensureCapacity( 256 );
161 //---------------------------------------------------------------------------------------------------------
162 // start with new empty query
163 //---------------------------------------------------------------------------------------------------------
166 m_sBase
= ::rtl::OUString();
171 ::rtl::OUString m_sBase
;
172 ::rtl::OUStringBuffer m_sParams
;
174 }; // class QueryBuilder
176 /*-************************************************************************************************************//**
177 @short Helper class to analyze queries and split into his different parts (base, params and values).
178 *//*-*************************************************************************************************************/
183 //---------------------------------------------------------------------------------------------------------
184 // it's will not perform to compare strings as query type ...
185 // so we convert it into these enum values.
187 //---------------------------------------------------------------------------------------------------------
202 //---------------------------------------------------------------------------------------------------------
203 // these are valid values for param "sort_prop".
204 // other ones are not supported!
206 //---------------------------------------------------------------------------------------------------------
213 //---------------------------------------------------------------------------------------------------------
214 // analyze given query and split it into his different parts; <base>:<param1>:<param2=value>...
215 //---------------------------------------------------------------------------------------------------------
216 QueryAnalyzer( const ::rtl::OUString
& sQuery
)
217 // Don't forget to set default values for non given params!
218 : m_eQuery ( E_ALL
) // return ALL filter ...
219 , m_nIFlags ( 0 ) // which has set ANY flag ... (we remove all entries which match with these mask .. => 0!)
220 , m_nEFlags ( 0 ) // (only used, if nIFlags==0 and himself!=0!)
221 , m_eSortProp ( E_NAME
) // sort it by internal name ...
222 , m_bDescending ( sal_False
) // in ascending order ...
223 , m_bCaseSensitive( sal_False
) // ignore case ...
224 , m_bUseOrder ( sal_False
) // don't use order flag ...
225 , m_bDefaultFirst ( sal_False
) // and don't handle default entries in special case!
227 // Translate old query format to new one first!
228 ::rtl::OUString
sNewQuery( sQuery
);
229 if( sQuery
== DECLARE_ASCII("_filterquery_textdocument_withdefault") )
230 sNewQuery
=DECLARE_ASCII("_query_writer:default_first:use_order:sort_prop=uiname");
232 if( sQuery
== DECLARE_ASCII("_filterquery_webdocument_withdefault") )
233 sNewQuery
=DECLARE_ASCII("_query_web:default_first:use_order:sort_prop=uiname");
235 if( sQuery
== DECLARE_ASCII("_filterquery_globaldocument_withdefault") )
236 sNewQuery
=DECLARE_ASCII("_query_global:default_first:use_order:sort_prop=uiname");
238 if( sQuery
== DECLARE_ASCII("_filterquery_chartdocument_withdefault") )
239 sNewQuery
=DECLARE_ASCII("_query_chart:default_first:use_order:sort_prop=uiname");
241 if( sQuery
== DECLARE_ASCII("_filterquery_spreadsheetdocument_withdefault") )
242 sNewQuery
=DECLARE_ASCII("_query_calc:default_first:use_order:sort_prop=uiname");
244 if( sQuery
== DECLARE_ASCII("_filterquery_presentationdocument_withdefault") )
245 sNewQuery
=DECLARE_ASCII("_query_impress:default_first:use_order:sort_prop=uiname");
247 if( sQuery
== DECLARE_ASCII("_filterquery_drawingdocument_withdefault") )
248 sNewQuery
=DECLARE_ASCII("_query_draw:default_first:use_order:sort_prop=uiname");
250 if( sQuery
== DECLARE_ASCII("_filterquery_formulaproperties_withdefault") )
251 sNewQuery
=DECLARE_ASCII("_query_math:default_first:use_order:sort_prop=uiname");
253 if( sQuery
== DECLARE_ASCII("_filterquery_textdocument") )
254 sNewQuery
=DECLARE_ASCII("_query_writer:use_order:sort_prop=uiname");
256 if( sQuery
== DECLARE_ASCII("_filterquery_webdocument") )
257 sNewQuery
=DECLARE_ASCII("_query_web:use_order:sort_prop=uiname");
259 if( sQuery
== DECLARE_ASCII("_filterquery_globaldocument") )
260 sNewQuery
=DECLARE_ASCII("_query_global:use_order:sort_prop=uiname");
262 if( sQuery
== DECLARE_ASCII("_filterquery_chartdocument") )
263 sNewQuery
=DECLARE_ASCII("_query_chart:use_order:sort_prop=uiname");
265 if( sQuery
== DECLARE_ASCII("_filterquery_spreadsheetdocument") )
266 sNewQuery
=DECLARE_ASCII("_query_calc:use_order:sort_prop=uiname");
268 if( sQuery
== DECLARE_ASCII("_filterquery_presentationdocument") )
269 sNewQuery
=DECLARE_ASCII("_query_impress:use_order:sort_prop=uiname");
271 if( sQuery
== DECLARE_ASCII("_filterquery_drawingdocument") )
272 sNewQuery
=DECLARE_ASCII("_query_draw:use_order:sort_prop=uiname");
274 if( sQuery
== DECLARE_ASCII("_filterquery_formulaproperties") )
275 sNewQuery
=DECLARE_ASCII("_query_math:use_order:sort_prop=uiname");
278 // Try to find base of it and safe it for faster access as enum value!
279 sal_Int32 nToken
= 0;
280 ::rtl::OUString sParam
;
281 ::rtl::OUString sBase
= sNewQuery
.getToken( 0, SEPERATOR_QUERYPARAM
, nToken
);
283 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_ALL
) == sal_True
) m_eQuery
= E_ALL
; else
284 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_WRITER
) == sal_True
) m_eQuery
= E_WRITER
; else
285 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_WEB
) == sal_True
) m_eQuery
= E_WEB
; else
286 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_GLOBAL
) == sal_True
) m_eQuery
= E_GLOBAL
; else
287 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_CHART
) == sal_True
) m_eQuery
= E_CHART
; else
288 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_CALC
) == sal_True
) m_eQuery
= E_CALC
; else
289 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_IMPRESS
) == sal_True
) m_eQuery
= E_IMPRESS
; else
290 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_DRAW
) == sal_True
) m_eQuery
= E_DRAW
; else
291 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_MATH
) == sal_True
) m_eQuery
= E_MATH
; else
292 if( sBase
.equalsIgnoreAsciiCase( BASE_QUERY_GRAPHICS
) == sal_True
) m_eQuery
= E_GRAPHICS
;
294 // Try to get additional parameters ...
297 sParam
= sNewQuery
.getToken( 0, SEPERATOR_QUERYPARAM
, nToken
);
299 if( sParam
.compareTo( QUERYPARAM_DEFAULT_FIRST
, QUERYPARAM_DEFAULT_FIRST
.getLength() ) == 0 )
301 m_bDefaultFirst
= sal_True
;
305 if( sParam
.compareTo( QUERYPARAM_USE_ORDER
, QUERYPARAM_USE_ORDER
.getLength() ) == 0 )
307 m_bUseOrder
= sal_True
;
311 if( sParam
.compareTo( QUERYPARAM_DESCENDING
, QUERYPARAM_DESCENDING
.getLength() ) == 0 )
313 m_bDescending
= sal_True
;
317 if( sParam
.compareTo( QUERYPARAM_CASE_SENSITIVE
, QUERYPARAM_CASE_SENSITIVE
.getLength() ) == 0 )
319 m_bCaseSensitive
= sal_True
;
323 if( sParam
.compareTo( QUERYPARAM_IFLAGS
, QUERYPARAM_IFLAGS
.getLength() ) == 0 )
325 sal_Int32 nSubToken
= 0;
326 ::rtl::OUString sParamName
= sParam
.getToken( 0, SEPERATOR_QUERYPARAMVALUE
, nSubToken
);
329 m_nIFlags
= sParam
.getToken( 0, SEPERATOR_QUERYPARAMVALUE
, nSubToken
).toInt32();
334 if( sParam
.compareTo( QUERYPARAM_EFLAGS
, QUERYPARAM_EFLAGS
.getLength() ) == 0 )
336 sal_Int32 nSubToken
= 0;
337 ::rtl::OUString sParamName
= sParam
.getToken( 0, SEPERATOR_QUERYPARAMVALUE
, nSubToken
);
340 m_nEFlags
= sParam
.getToken( 0, SEPERATOR_QUERYPARAMVALUE
, nSubToken
).toInt32();
344 // "sort_prop=<[name,uiname]>"
345 if( sParam
.compareTo( QUERYPARAM_SORT_PROP
, QUERYPARAM_SORT_PROP
.getLength() ) == 0 )
347 sal_Int32 nSubToken
= 0;
348 ::rtl::OUString sParamName
= sParam
.getToken( 0, SEPERATOR_QUERYPARAMVALUE
, nSubToken
);
351 ::rtl::OUString sParamValue
= sParam
.getToken( 0, SEPERATOR_QUERYPARAMVALUE
, nSubToken
);
352 if( sParamValue
.compareTo( QUERYPARAMVALUE_SORT_PROP_NAME
, QUERYPARAMVALUE_SORT_PROP_NAME
.getLength() ) == 0 )
353 m_eSortProp
= E_NAME
;
355 if( sParamValue
.compareTo( QUERYPARAMVALUE_SORT_PROP_UINAME
, QUERYPARAMVALUE_SORT_PROP_UINAME
.getLength() ) == 0 )
356 m_eSortProp
= E_UINAME
;
362 //---------------------------------------------------------------------------------------------------------
363 // return type of query. User can decide then, which action should be started.
364 // For faster work we converted query string into corresponding enum value!
365 //---------------------------------------------------------------------------------------------------------
366 EQuery
getQueryType() const { return m_eQuery
; }
368 //---------------------------------------------------------------------------------------------------------
369 // access to additional parameter values
370 // Methods return default of realy set values!
371 //---------------------------------------------------------------------------------------------------------
372 sal_uInt32
getIFlags () const { return m_nIFlags
; }
373 sal_uInt32
getEFlags () const { return m_nEFlags
; }
374 ESortProp
getSortProp () const { return m_eSortProp
; }
375 sal_Bool
getDescending () const { return m_bDescending
; }
376 sal_Bool
getCaseSensitive() const { return m_bCaseSensitive
; }
377 sal_Bool
getUseOrder () const { return m_bUseOrder
; }
378 sal_Bool
getDefaultFirst () const { return m_bDefaultFirst
; }
380 //---------------------------------------------------------------------------------------------------------
381 // this method checks if given string match any supported query.
382 // (ignore additional parameters!)
383 //---------------------------------------------------------------------------------------------------------
384 static sal_Bool
isQuery( const ::rtl::OUString
& sQuery
)
387 ( sQuery
.compareToAscii( "_query_" , 7 ) == 0 ) || // new style
388 ( sQuery
.compareToAscii( "_filterquery_", 13 ) == 0 ) // old style!
394 sal_uInt32 m_nIFlags
;
395 sal_uInt32 m_nEFlags
;
396 ESortProp m_eSortProp
;
397 sal_Bool m_bDescending
;
398 sal_Bool m_bCaseSensitive
;
399 sal_Bool m_bUseOrder
;
400 sal_Bool m_bDefaultFirst
;
402 }; // class QueryAnalyzer
404 } // namespace framework
406 #endif // #ifndef __FRAMEWORK_QUERIES_H_