Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <bibconfig.hxx>
31 : : #include <com/sun/star/uno/Sequence.hxx>
32 : : #include <com/sun/star/uno/Any.hxx>
33 : : #include <com/sun/star/beans/PropertyValue.hpp>
34 : : #include <com/sun/star/container/XNameAccess.hpp>
35 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 : : #include <comphelper/processfactory.hxx>
37 : :
38 : : using namespace ::com::sun::star::uno;
39 : : using namespace ::com::sun::star::beans;
40 : : using namespace ::com::sun::star::container;
41 : : using namespace ::com::sun::star::lang;
42 : :
43 : : using ::rtl::OUString;
44 : :
45 : : #define C2U(cChar) OUString::createFromAscii(cChar)
46 : :
47 : : const char* cDataSourceHistory = "DataSourceHistory";
48 : :
49 : 0 : Sequence<OUString> BibConfig::GetPropertyNames()
50 : : {
51 [ # # ][ # # ]: 0 : static Sequence<OUString> aNames;
[ # # ][ # # ]
52 [ # # ]: 0 : if(!aNames.getLength())
53 : : {
54 : 0 : aNames.realloc(8);
55 : 0 : OUString* pNames = aNames.getArray();
56 : 0 : pNames[0] = C2U("CurrentDataSource/DataSourceName");
57 : 0 : pNames[1] = C2U("CurrentDataSource/Command");
58 : 0 : pNames[2] = C2U("CurrentDataSource/CommandType");
59 : 0 : pNames[3] = C2U("BeamerHeight");
60 : 0 : pNames[4] = C2U("ViewHeight");
61 : 0 : pNames[5] = C2U("QueryText");
62 : 0 : pNames[6] = C2U("QueryField");
63 : 0 : pNames[7] = C2U("ShowColumnAssignmentWarning");
64 : : }
65 : 0 : return aNames;
66 : : }
67 : :
68 : 0 : BibConfig::BibConfig() :
69 : : ConfigItem(C2U("Office.DataAccess/Bibliography"), CONFIG_MODE_DELAYED_UPDATE),
70 [ # # ]: 0 : pMappingsArr(new MappingArray),
71 : : nBeamerSize(0),
72 : : nViewSize(0),
73 [ # # ][ # # ]: 0 : bShowColumnAssignmentWarning(sal_False)
[ # # ]
74 : : {
75 : : //Names of the default columns
76 : 0 : aColumnDefaults[0] = C2U("Identifier");
77 : 0 : aColumnDefaults[1] = C2U("BibliographyType");
78 : 0 : aColumnDefaults[2] = C2U("Author");
79 : 0 : aColumnDefaults[3] = C2U("Title");
80 : 0 : aColumnDefaults[4] = C2U("Year");
81 : 0 : aColumnDefaults[5] = C2U("ISBN");
82 : 0 : aColumnDefaults[6] = C2U("Booktitle");
83 : 0 : aColumnDefaults[7] = C2U("Chapter");
84 : 0 : aColumnDefaults[8] = C2U("Edition");
85 : 0 : aColumnDefaults[9] = C2U("Editor");
86 : 0 : aColumnDefaults[10] = C2U("Howpublished");
87 : 0 : aColumnDefaults[11] = C2U("Institution");
88 : 0 : aColumnDefaults[12] = C2U("Journal");
89 : 0 : aColumnDefaults[13] = C2U("Month");
90 : 0 : aColumnDefaults[14] = C2U("Note");
91 : 0 : aColumnDefaults[15] = C2U("Annote");
92 : 0 : aColumnDefaults[16] = C2U("Number");
93 : 0 : aColumnDefaults[17] = C2U("Organizations");
94 : 0 : aColumnDefaults[18] = C2U("Pages");
95 : 0 : aColumnDefaults[19] = C2U("Publisher");
96 : 0 : aColumnDefaults[20] = C2U("Address");
97 : 0 : aColumnDefaults[21] = C2U("School");
98 : 0 : aColumnDefaults[22] = C2U("Series");
99 : 0 : aColumnDefaults[23] = C2U("ReportType");
100 : 0 : aColumnDefaults[24] = C2U("Volume");
101 : 0 : aColumnDefaults[25] = C2U("URL");
102 : 0 : aColumnDefaults[26] = C2U("Custom1");
103 : 0 : aColumnDefaults[27] = C2U("Custom2");
104 : 0 : aColumnDefaults[28] = C2U("Custom3");
105 : 0 : aColumnDefaults[29] = C2U("Custom4");
106 : 0 : aColumnDefaults[30] = C2U("Custom5");
107 : :
108 : :
109 [ # # ]: 0 : const Sequence< OUString > aPropertyNames = GetPropertyNames();
110 [ # # ]: 0 : const Sequence<Any> aPropertyValues = GetProperties( aPropertyNames );
111 : 0 : const Any* pValues = aPropertyValues.getConstArray();
112 [ # # ]: 0 : if(aPropertyValues.getLength() == aPropertyNames.getLength())
113 : : {
114 [ # # ]: 0 : for(int nProp = 0; nProp < aPropertyNames.getLength(); nProp++)
115 : : {
116 [ # # ]: 0 : if(pValues[nProp].hasValue())
117 : : {
118 [ # # # # : 0 : switch(nProp)
# # # #
# ]
119 : : {
120 : 0 : case 0: pValues[nProp] >>= sDataSource; break;
121 : 0 : case 1: pValues[nProp] >>= sTableOrQuery; break;
122 : 0 : case 2: pValues[nProp] >>= nTblOrQuery; break;
123 : 0 : case 3: pValues[nProp] >>= nBeamerSize; break;
124 : 0 : case 4: pValues[nProp] >>= nViewSize ; break;
125 : 0 : case 5: pValues[nProp] >>= sQueryText ; break;
126 : 0 : case 6: pValues[nProp] >>= sQueryField; break;
127 : : case 7:
128 : 0 : bShowColumnAssignmentWarning = *(sal_Bool*)pValues[nProp].getValue();
129 : 0 : break;
130 : : }
131 : : }
132 : : }
133 : : }
134 : 0 : OUString sName(C2U("DataSourceName"));
135 : 0 : OUString sTable(C2U("Command"));
136 : 0 : OUString sCommandType(C2U("CommandType"));
137 [ # # ]: 0 : Sequence< OUString > aNodeNames = GetNodeNames(C2U(cDataSourceHistory));
138 : 0 : const OUString* pNodeNames = aNodeNames.getConstArray();
139 [ # # ]: 0 : for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength(); nNode++)
140 : : {
141 [ # # ]: 0 : Sequence<OUString> aHistoryNames(3);
142 [ # # ]: 0 : OUString* pHistoryNames = aHistoryNames.getArray();
143 : :
144 : 0 : OUString sPrefix(C2U(cDataSourceHistory));
145 : 0 : sPrefix += C2U("/");
146 : 0 : sPrefix += pNodeNames[nNode];
147 : 0 : sPrefix += C2U("/");
148 : 0 : pHistoryNames[0] = sPrefix;
149 : 0 : pHistoryNames[0] += sName;
150 : 0 : pHistoryNames[1] = sPrefix;
151 : 0 : pHistoryNames[1] += sTable;
152 : 0 : pHistoryNames[2] = sPrefix;
153 : 0 : pHistoryNames[2] += sCommandType;
154 : :
155 [ # # ]: 0 : Sequence<Any> aHistoryValues = GetProperties( aHistoryNames );
156 : 0 : const Any* pHistoryValues = aHistoryValues.getConstArray();
157 : :
158 [ # # ]: 0 : if(aHistoryValues.getLength() == aHistoryNames.getLength())
159 : : {
160 [ # # ]: 0 : Mapping* pMapping = new Mapping;
161 : 0 : pHistoryValues[0] >>= pMapping->sURL;
162 : 0 : pHistoryValues[1] >>= pMapping->sTableName;
163 : 0 : pHistoryValues[2] >>= pMapping->nCommandType;
164 : : //field assignment is contained in another set
165 : 0 : sPrefix += C2U("Fields");
166 [ # # ]: 0 : Sequence< OUString > aAssignmentNodeNames = GetNodeNames(sPrefix);
167 : 0 : const OUString* pAssignmentNodeNames = aAssignmentNodeNames.getConstArray();
168 [ # # ]: 0 : Sequence<OUString> aAssignmentPropertyNames(aAssignmentNodeNames.getLength() * 2);
169 [ # # ]: 0 : OUString* pAssignmentPropertyNames = aAssignmentPropertyNames.getArray();
170 : 0 : sal_Int16 nFieldIdx = 0;
171 [ # # ]: 0 : for(sal_Int16 nField = 0; nField < aAssignmentNodeNames.getLength(); nField++)
172 : : {
173 : 0 : OUString sSubPrefix(sPrefix);
174 : 0 : sSubPrefix += C2U("/");
175 : 0 : sSubPrefix += pAssignmentNodeNames[nField];
176 : 0 : pAssignmentPropertyNames[nFieldIdx] = sSubPrefix;
177 : 0 : pAssignmentPropertyNames[nFieldIdx++] += C2U("/ProgrammaticFieldName");
178 : 0 : pAssignmentPropertyNames[nFieldIdx] = sSubPrefix;
179 : 0 : pAssignmentPropertyNames[nFieldIdx++] += C2U("/AssignedFieldName");
180 : 0 : }
181 [ # # ]: 0 : Sequence<Any> aAssignmentValues = GetProperties(aAssignmentPropertyNames);
182 : 0 : const Any* pAssignmentValues = aAssignmentValues.getConstArray();
183 : 0 : OUString sTempLogical;
184 : 0 : OUString sTempReal;
185 : 0 : sal_Int16 nSetMapping = 0;
186 : 0 : nFieldIdx = 0;
187 [ # # ]: 0 : for(sal_Int16 nFieldVal = 0; nFieldVal < aAssignmentValues.getLength() / 2; nFieldVal++)
188 : : {
189 : 0 : pAssignmentValues[nFieldIdx++] >>= sTempLogical;
190 : 0 : pAssignmentValues[nFieldIdx++] >>= sTempReal;
191 [ # # ][ # # ]: 0 : if(!(sTempLogical.isEmpty() || sTempReal.isEmpty()))
[ # # ]
192 : : {
193 : 0 : pMapping->aColumnPairs[nSetMapping].sLogicalColumnName = sTempLogical;
194 : 0 : pMapping->aColumnPairs[nSetMapping++].sRealColumnName = sTempReal;
195 : : }
196 : : }
197 [ # # ][ # # ]: 0 : pMappingsArr->push_back(pMapping);
[ # # ][ # # ]
198 : : }
199 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
200 [ # # # # ]: 0 : }
201 : :
202 : 0 : BibConfig::~BibConfig()
203 : : {
204 [ # # ][ # # ]: 0 : if(IsModified())
205 [ # # ]: 0 : Commit();
206 [ # # ][ # # ]: 0 : delete pMappingsArr;
207 [ # # ]: 0 : }
[ # # # # ]
[ # # # # ]
208 : :
209 : 0 : BibDBDescriptor BibConfig::GetBibliographyURL()
210 : : {
211 : 0 : BibDBDescriptor aRet;
212 : 0 : aRet.sDataSource = sDataSource;
213 : 0 : aRet.sTableOrQuery = sTableOrQuery;
214 : 0 : aRet.nCommandType = nTblOrQuery;
215 : 0 : return aRet;
216 : : };
217 : :
218 : 0 : void BibConfig::SetBibliographyURL(const BibDBDescriptor& rDesc)
219 : : {
220 : 0 : sDataSource = rDesc.sDataSource;
221 : 0 : sTableOrQuery = rDesc.sTableOrQuery;
222 : 0 : nTblOrQuery = rDesc.nCommandType;
223 : 0 : SetModified();
224 : 0 : };
225 : : //---------------------------------------------------------------------------
226 : 0 : void BibConfig::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& )
227 : : {
228 : 0 : }
229 : :
230 : 0 : void BibConfig::Commit()
231 : : {
232 [ # # ]: 0 : const Sequence<OUString> aPropertyNames = GetPropertyNames();
233 [ # # ]: 0 : Sequence<Any> aValues(aPropertyNames.getLength());
234 [ # # ]: 0 : Any* pValues = aValues.getArray();
235 : :
236 [ # # ]: 0 : for(int nProp = 0; nProp < aPropertyNames.getLength(); nProp++)
237 : : {
238 [ # # # # : 0 : switch(nProp)
# # # #
# ]
239 : : {
240 [ # # ]: 0 : case 0: pValues[nProp] <<= sDataSource; break;
241 [ # # ]: 0 : case 1: pValues[nProp] <<= sTableOrQuery; break;
242 [ # # ]: 0 : case 2: pValues[nProp] <<= nTblOrQuery; break;
243 [ # # ]: 0 : case 3: pValues[nProp] <<= nBeamerSize; break;
244 [ # # ]: 0 : case 4: pValues[nProp] <<= nViewSize; break;
245 [ # # ]: 0 : case 5: pValues[nProp] <<= sQueryText; break;
246 [ # # ]: 0 : case 6: pValues[nProp] <<= sQueryField; break;
247 : : case 7:
248 [ # # ]: 0 : pValues[nProp].setValue(&bShowColumnAssignmentWarning, ::getBooleanCppuType());
249 : 0 : break;
250 : : }
251 : : }
252 [ # # ]: 0 : PutProperties(aPropertyNames, aValues);
253 [ # # ]: 0 : ClearNodeSet( C2U(cDataSourceHistory));
254 [ # # ]: 0 : Sequence< PropertyValue > aNodeValues(pMappingsArr->size() * 3);
255 [ # # ]: 0 : PropertyValue* pNodeValues = aNodeValues.getArray();
256 : :
257 : 0 : sal_Int32 nIndex = 0;
258 : 0 : OUString sName(C2U("DataSourceName"));
259 : 0 : OUString sTable(C2U("Command"));
260 : 0 : OUString sCommandType(C2U("CommandType"));
261 [ # # ]: 0 : for(sal_Int32 i = 0; i < (sal_Int32)pMappingsArr->size(); i++)
262 : : {
263 [ # # ]: 0 : const Mapping* pMapping = &(*pMappingsArr)[i];
264 : 0 : OUString sPrefix(C2U(cDataSourceHistory));
265 : 0 : sPrefix += C2U("/_");
266 : 0 : sPrefix += OUString::valueOf(i);
267 : 0 : sPrefix += C2U("/");
268 : 0 : pNodeValues[nIndex].Name = sPrefix;
269 : 0 : pNodeValues[nIndex].Name += sName;
270 [ # # ]: 0 : pNodeValues[nIndex++].Value <<= pMapping->sURL;
271 : 0 : pNodeValues[nIndex].Name = sPrefix;
272 : 0 : pNodeValues[nIndex].Name += sTable;
273 [ # # ]: 0 : pNodeValues[nIndex++].Value <<= pMapping->sTableName;
274 : 0 : pNodeValues[nIndex].Name = sPrefix;
275 : 0 : pNodeValues[nIndex].Name += sCommandType;
276 [ # # ]: 0 : pNodeValues[nIndex++].Value <<= pMapping->nCommandType;
277 [ # # ][ # # ]: 0 : SetSetProperties( C2U(cDataSourceHistory), aNodeValues);
[ # # ]
278 : :
279 : 0 : sPrefix += C2U("Fields");
280 : 0 : sal_Int32 nFieldAssignment = 0;
281 : 0 : OUString sFieldName = C2U("/ProgrammaticFieldName");
282 : 0 : OUString sDatabaseFieldName = C2U("/AssignedFieldName");
283 [ # # ]: 0 : ClearNodeSet( sPrefix );
284 : :
285 [ # # # # ]: 0 : while(nFieldAssignment < COLUMN_COUNT &&
[ # # ]
286 : 0 : !pMapping->aColumnPairs[nFieldAssignment].sLogicalColumnName.isEmpty())
287 : : {
288 : 0 : OUString sSubPrefix(sPrefix);
289 : 0 : sSubPrefix += C2U("/_");
290 : 0 : sSubPrefix += OUString::valueOf(nFieldAssignment);
291 [ # # ]: 0 : Sequence< PropertyValue > aAssignmentValues(2);
292 [ # # ]: 0 : PropertyValue* pAssignmentValues = aAssignmentValues.getArray();
293 : 0 : pAssignmentValues[0].Name = sSubPrefix;
294 : 0 : pAssignmentValues[0].Name += sFieldName;
295 [ # # ]: 0 : pAssignmentValues[0].Value <<= pMapping->aColumnPairs[nFieldAssignment].sLogicalColumnName;
296 : 0 : pAssignmentValues[1].Name = sSubPrefix;
297 : 0 : pAssignmentValues[1].Name += sDatabaseFieldName;
298 [ # # ]: 0 : pAssignmentValues[1].Value <<= pMapping->aColumnPairs[nFieldAssignment].sRealColumnName;
299 [ # # ][ # # ]: 0 : SetSetProperties( sPrefix, aAssignmentValues );
[ # # ]
300 : 0 : nFieldAssignment++;
301 [ # # ]: 0 : }
302 [ # # ][ # # ]: 0 : }
[ # # ]
303 : 0 : }
304 : :
305 : 0 : const Mapping* BibConfig::GetMapping(const BibDBDescriptor& rDesc) const
306 : : {
307 [ # # ]: 0 : for(sal_uInt16 i = 0; i < pMappingsArr->size(); i++)
308 : : {
309 : 0 : Mapping& rMapping = (*pMappingsArr)[i];
310 : 0 : sal_Bool bURLEqual = rDesc.sDataSource.equals(rMapping.sURL);
311 [ # # ][ # # ]: 0 : if(rDesc.sTableOrQuery == rMapping.sTableName && bURLEqual)
[ # # ]
312 : 0 : return &rMapping;
313 : : }
314 : 0 : return 0;
315 : : }
316 : :
317 : 0 : void BibConfig::SetMapping(const BibDBDescriptor& rDesc, const Mapping* pSetMapping)
318 : : {
319 [ # # ]: 0 : for(sal_uInt16 i = 0; i < pMappingsArr->size(); i++)
320 : : {
321 : 0 : Mapping& rMapping = (*pMappingsArr)[i];
322 : 0 : sal_Bool bURLEqual = rDesc.sDataSource.equals(rMapping.sURL);
323 [ # # ][ # # ]: 0 : if(rDesc.sTableOrQuery == rMapping.sTableName && bURLEqual)
[ # # ]
324 : : {
325 : 0 : pMappingsArr->erase(pMappingsArr->begin()+i);
326 : 0 : break;
327 : : }
328 : : }
329 : 0 : Mapping* pNew = new Mapping(*pSetMapping);
330 : 0 : pMappingsArr->push_back(pNew);
331 : 0 : SetModified();
332 : 0 : }
333 : :
334 : 0 : DBChangeDialogConfig_Impl::DBChangeDialogConfig_Impl()
335 : : {
336 : 0 : }
337 : :
338 : 0 : DBChangeDialogConfig_Impl::~DBChangeDialogConfig_Impl()
339 : : {
340 : 0 : }
341 : :
342 : 0 : const Sequence<OUString>& DBChangeDialogConfig_Impl::GetDataSourceNames()
343 : : {
344 [ # # ]: 0 : if(!aSourceNames.getLength())
345 : : {
346 : 0 : Reference<XNameAccess> xDBContext;
347 [ # # ]: 0 : Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
348 [ # # ]: 0 : if( xMgr.is() )
349 : : {
350 [ # # ][ # # ]: 0 : Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" ));
351 [ # # ][ # # ]: 0 : xDBContext = Reference<XNameAccess>(xInstance, UNO_QUERY) ;
352 : : }
353 [ # # ]: 0 : if(xDBContext.is())
354 : : {
355 [ # # ][ # # ]: 0 : aSourceNames = xDBContext->getElementNames();
[ # # ][ # # ]
356 : 0 : }
357 : : }
358 : 0 : return aSourceNames;
359 : : }
360 : :
361 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|