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 "ConfigurationClassifier.hxx"
31 : :
32 : : #include "framework/FrameworkHelper.hxx"
33 : :
34 : : using namespace ::com::sun::star;
35 : : using namespace ::com::sun::star::uno;
36 : : using namespace ::com::sun::star::drawing::framework;
37 : : using ::rtl::OUString;
38 : :
39 : : namespace sd { namespace framework {
40 : :
41 : 653 : ConfigurationClassifier::ConfigurationClassifier (
42 : : const Reference<XConfiguration>& rxConfiguration1,
43 : : const Reference<XConfiguration>& rxConfiguration2)
44 : : : mxConfiguration1(rxConfiguration1),
45 : : mxConfiguration2(rxConfiguration2),
46 : : maC1minusC2(),
47 : : maC2minusC1(),
48 [ + - ][ + - ]: 653 : maC1andC2()
[ + - ]
49 : : {
50 : 653 : }
51 : :
52 : :
53 : :
54 : :
55 : 653 : bool ConfigurationClassifier::Partition (void)
56 : : {
57 : 653 : maC1minusC2.clear();
58 : 653 : maC2minusC1.clear();
59 : 653 : maC1andC2.clear();
60 : :
61 : : PartitionResources(
62 [ + - ]: 653 : mxConfiguration1->getResources(NULL, OUString(), AnchorBindingMode_DIRECT),
63 [ + - ][ + - ]: 1306 : mxConfiguration2->getResources(NULL, OUString(), AnchorBindingMode_DIRECT));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
64 : :
65 [ + + ][ + + ]: 653 : return !maC1minusC2.empty() || !maC2minusC1.empty();
66 : : }
67 : :
68 : :
69 : :
70 : :
71 : 542 : const ConfigurationClassifier::ResourceIdVector& ConfigurationClassifier::GetC1minusC2 (void) const
72 : : {
73 : 542 : return maC1minusC2;
74 : : }
75 : :
76 : :
77 : :
78 : :
79 : 542 : const ConfigurationClassifier::ResourceIdVector& ConfigurationClassifier::GetC2minusC1 (void) const
80 : : {
81 : 542 : return maC2minusC1;
82 : : }
83 : :
84 : :
85 : :
86 : 0 : const ConfigurationClassifier::ResourceIdVector& ConfigurationClassifier::GetC1andC2 (void) const
87 : : {
88 : 0 : return maC1andC2;
89 : : }
90 : :
91 : :
92 : 1559 : void ConfigurationClassifier::PartitionResources (
93 : : const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS1,
94 : : const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS2)
95 : : {
96 [ + - ]: 1559 : ResourceIdVector aC1minusC2;
97 [ + - ]: 1559 : ResourceIdVector aC2minusC1;
98 [ + - ]: 1559 : ResourceIdVector aC1andC2;
99 : :
100 : : // Classify the resources in the configurations that are not bound to
101 : : // other resources.
102 : : ClassifyResources(
103 : : rS1,
104 : : rS2,
105 : : aC1minusC2,
106 : : aC2minusC1,
107 [ + - ]: 1559 : aC1andC2);
108 : :
109 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying resource ids to C1-C2");
110 [ + - ]: 1559 : CopyResources(aC1minusC2, mxConfiguration1, maC1minusC2);
111 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying resource ids to C2-C1");
112 [ + - ]: 1559 : CopyResources(aC2minusC1, mxConfiguration2, maC2minusC1);
113 : :
114 : : // Process the unique resources that belong to both configurations.
115 : 1559 : ResourceIdVector::const_iterator iResource;
116 [ + - ][ + - ]: 2465 : for (iResource=aC1andC2.begin(); iResource!=aC1andC2.end(); ++iResource)
[ + + ]
117 : : {
118 [ + - ]: 906 : maC1andC2.push_back(*iResource);
119 : : PartitionResources(
120 [ + - ]: 1812 : mxConfiguration1->getResources(*iResource, OUString(), AnchorBindingMode_DIRECT),
121 [ + - ][ + - ]: 2718 : mxConfiguration2->getResources(*iResource, OUString(), AnchorBindingMode_DIRECT));
[ + - ][ + - ]
[ + - ][ + - ]
122 : 1559 : }
123 : 1559 : }
124 : :
125 : :
126 : :
127 : :
128 : 1559 : void ConfigurationClassifier::ClassifyResources (
129 : : const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS1,
130 : : const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS2,
131 : : ResourceIdVector& rS1minusS2,
132 : : ResourceIdVector& rS2minusS1,
133 : : ResourceIdVector& rS1andS2)
134 : : {
135 : : // Get arrays from the sequences for faster iteration.
136 : 1559 : const Reference<XResourceId>* aA1 = rS1.getConstArray();
137 : 1559 : const Reference<XResourceId>* aA2 = rS2.getConstArray();
138 : 1559 : sal_Int32 nL1 (rS1.getLength());
139 : 1559 : sal_Int32 nL2 (rS2.getLength());
140 : :
141 : : // Find all elements in rS1 and place them in rS1minusS2 or rS1andS2
142 : : // depending on whether they are in rS2 or not.
143 [ + + ]: 2929 : for (sal_Int32 i=0; i<nL1; ++i)
144 : : {
145 : 1370 : bool bFound (false);
146 [ + + ][ + + ]: 2675 : for (sal_Int32 j=0; j<nL2 && !bFound; ++j)
[ + + ]
147 [ + - ][ + - ]: 1305 : if (aA1[i]->getResourceURL().equals(aA2[j]->getResourceURL()))
[ + + ]
148 : 906 : bFound = true;
149 : :
150 [ + + ]: 1370 : if (bFound)
151 : 906 : rS1andS2.push_back(aA1[i]);
152 : : else
153 : 464 : rS1minusS2.push_back(aA1[i]);
154 : : }
155 : :
156 : : // Find all elements in rS2 that are not in rS1. The elements that are
157 : : // in both rS1 and rS2 have been handled above and are therefore ignored
158 : : // here.
159 [ + + ]: 3043 : for (sal_Int32 j=0; j<nL2; ++j)
160 : : {
161 : 1484 : bool bFound (false);
162 [ + + ][ + + ]: 2789 : for (sal_Int32 i=0; i<nL1 && !bFound; ++i)
[ + + ]
163 [ + - ][ + - ]: 1305 : if (aA2[j]->getResourceURL().equals(aA1[i]->getResourceURL()))
[ + + ]
164 : 906 : bFound = true;
165 : :
166 [ + + ]: 1484 : if ( ! bFound)
167 : 578 : rS2minusS1.push_back(aA2[j]);
168 : : }
169 : 1559 : }
170 : :
171 : :
172 : :
173 : :
174 : 3118 : void ConfigurationClassifier::CopyResources (
175 : : const ResourceIdVector& rSource,
176 : : const Reference<XConfiguration>& rxConfiguration,
177 : : ResourceIdVector& rTarget)
178 : : {
179 : : // Copy all resources bound to the ones in aC1minusC2Unique to rC1minusC2.
180 : 3118 : ResourceIdVector::const_iterator iResource (rSource.begin());
181 : 3118 : ResourceIdVector::const_iterator iEnd(rSource.end());
182 [ + - ][ + + ]: 4160 : for ( ; iResource!=iEnd; ++iResource)
183 : : {
184 : : const Sequence<Reference<XResourceId> > aBoundResources (
185 [ + - ]: 1042 : rxConfiguration->getResources(
186 : 1042 : *iResource,
187 : : OUString(),
188 [ + - ]: 2084 : AnchorBindingMode_INDIRECT));
189 : 1042 : const sal_Int32 nL (aBoundResources.getLength());
190 : :
191 [ + - ]: 1042 : rTarget.reserve(rTarget.size() + 1 + nL);
192 [ + - ]: 1042 : rTarget.push_back(*iResource);
193 : :
194 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying " <<
195 : : OUStringToOString(FrameworkHelper::ResourceIdToString(*iResource),
196 : : RTL_TEXTENCODING_UTF8).getStr());
197 : :
198 : 1042 : const Reference<XResourceId>* aA = aBoundResources.getConstArray();
199 [ + + ]: 2166 : for (sal_Int32 i=0; i<nL; ++i)
200 : : {
201 [ + - ]: 1124 : rTarget.push_back(aA[i]);
202 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying " <<
203 : : OUStringToOString(FrameworkHelper::ResourceIdToString(aA[i]),
204 : : RTL_TEXTENCODING_UTF8).getStr());
205 : : }
206 [ + - ]: 1042 : }
207 : 3118 : }
208 : :
209 : :
210 : 0 : void ConfigurationClassifier::TraceResourceIdVector (
211 : : const sal_Char* pMessage,
212 : : const ResourceIdVector& rResources) const
213 : : {
214 : :
215 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " << pMessage);
216 : 0 : ResourceIdVector::const_iterator iResource;
217 [ # # ][ # # ]: 0 : for (iResource=rResources.begin(); iResource!=rResources.end(); ++iResource)
218 : : {
219 [ # # ]: 0 : OUString sResource (FrameworkHelper::ResourceIdToString(*iResource));
220 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " <<
221 : : OUStringToOString(sResource, RTL_TEXTENCODING_UTF8).getStr());
222 : 0 : }
223 : 0 : }
224 : :
225 : :
226 : : } } // end of namespace sd::framework
227 : :
228 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|