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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scfilt.hxx"
26
27 // ============================================================================
28 #include "xltracer.hxx"
29 #include <filter/msfilter/msfiltertracer.hxx>
30 #include "address.hxx"
31
32 using ::rtl::OUString;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::beans::PropertyValue;
35
36 // ============================================================================
37
38 // Trace Table details are grouped by functionality using the context entry.
39 // Each separate context starts at the next 1000 interval. New entries should
40 // be added to their appropriate context. New contexts should be added onto
41 // the end. Any gaps in the 1000 sequence or within the 1000 are the result
42 // of trace events no longer present.
43 static const XclTracerDetails pTracerDetails[] =
44 {
45 { eUnKnown, 0, "UNKNOWN", "UNKNOWN", "Unknown trace property." },
46 { eRowLimitExceeded, 1000, "Limits", "Sheet", "Row limit exceeded." },
47 { eTabLimitExceeded, 1001, "Limits", "Sheet", "Sheet limit exceeded." },
48 { ePassword, 2000, "Protection", "Password", "Document is password protected." },
49 { ePrintRange, 3000, "Print", "Print Range", "Print Range present." },
50 { eShortDate, 4000, "CellFormatting", "Short Dates", "Possible Date format issue." },
51 { eBorderLineStyle, 4004, "CellFormatting", "Border", "Line style not supported.", },
52 { eFillPattern, 4005, "CellFormatting", "Pattern", "Fill Pattern not supported.", },
53 { eInvisibleGrid, 5000, "Properties", "Grid Invisible", "Grid invisible on first sheet." },
54 { eFormattedNote, 6000, "Notes", "Formatting", "Text may be formatted." },
55 { eFormulaExtName, 7000, "Formula", "External Name", "External names not supported." },
56 { eFormulaMissingArg, 7001, "Formula", "Missing Argument","Parameter missing." },
57 { ePivotDataSource, 8000, "Chart", "Pivot", "External data source not supported."},
58 { ePivotChartExists, 8001, "Chart", "Pivot", "Pivot Chart not supported."},
59 { eChartUnKnownType, 8002, "Chart", "Type", "Chart Type not supported."},
60 { eChartTrendLines, 8003, "Chart", "Type", "Chart trendlines not supported."},
61 { eChartOnlySheet, 8004, "Chart", "Type", "Chart only sheet not supported."},
62 { eChartRange, 8005, "Chart", "Source Data", "Chart source ranges too complex."},
63 { eChartDSName, 8006, "Chart", "Source Data", "Series titles not linked to cells."},
64 { eChartDataTable, 8007, "Chart", "Legend", "Data table not supported."},
65 { eChartLegendPosition, 8008, "Chart", "Legend", "Position not guaranteed."},
66 { eChartTextFormatting, 8009, "Chart", "Formatting", "Text formatting present."},
67 { eChartEmbeddedObj, 8010, "Chart", "Area", "Object inside chart."},
68 { eChartAxisAuto, 8012, "Chart", "Axis", "Axis interval is automatic."},
69 { eChartInvalidXY, 8013, "Chart", "Scatter", "Unsupported or invalid data range for XY chart."},
70 { eChartErrorBars, 8014, "Chart", "Type", "Chart error bars not supported."},
71 { eChartAxisManual, 8015, "Chart", "Axis", "Manual axis crossing point adjusted."},
72 { eUnsupportedObject, 9000, "Object", "Type", "Limited Object support."},
73 { eObjectNotPrintable, 9001, "Object", "Print", "Object not printable."},
74 { eDVType, 10000, "DataValidation", "Type", "Custom type present."}
75 };
76
XclTracer(const String & rDocUrl,const OUString & rConfigPath)77 XclTracer::XclTracer( const String& rDocUrl, const OUString& rConfigPath ) :
78 maFirstTimes(eTraceLength,true)
79 {
80 Sequence< PropertyValue > aConfigData( 1 );
81 aConfigData[ 0 ].Name = CREATE_OUSTRING( "DocumentURL" );
82 aConfigData[ 0 ].Value <<= OUString( rDocUrl );
83 mpTracer.reset( new MSFilterTracer( rConfigPath, &aConfigData ) );
84 mpTracer->StartTracing();
85 mbEnabled = mpTracer->IsEnabled();
86 }
87
~XclTracer()88 XclTracer::~XclTracer()
89 {
90 mpTracer->EndTracing();
91 }
92
AddAttribute(const OUString & rName,const OUString & rValue)93 void XclTracer::AddAttribute( const OUString& rName, const OUString& rValue )
94 {
95 if( mbEnabled )
96 mpTracer->AddAttribute( rName, rValue );
97 }
98
Trace(const OUString & rElementID,const OUString & rMessage)99 void XclTracer::Trace( const OUString& rElementID, const OUString& rMessage )
100 {
101 if( mbEnabled )
102 {
103 mpTracer->Trace( rElementID, rMessage );
104 mpTracer->ClearAttributes();
105 }
106 }
107
TraceLog(XclTracerId eProblem,sal_Int32 nValue)108 void XclTracer::TraceLog( XclTracerId eProblem, sal_Int32 nValue )
109 {
110 if( mbEnabled )
111 {
112 OUString sID( CREATE_STRING( "SC" ) );
113 sID += OUString::valueOf( static_cast< sal_Int32 >( pTracerDetails[ eProblem ].mnID ) );
114 OUString sProblem = OUString::createFromAscii( pTracerDetails[ eProblem ].mpProblem );
115
116 switch (eProblem)
117 {
118 case eRowLimitExceeded:
119 Context(eProblem,static_cast<SCTAB>(nValue));
120 break;
121 case eTabLimitExceeded:
122 Context(eProblem,static_cast<SCTAB>(nValue));
123 break;
124 default:
125 Context(eProblem);
126 break;
127 }
128 Trace(sID, sProblem);
129 }
130 }
131
Context(XclTracerId eProblem,SCTAB nTab)132 void XclTracer::Context( XclTracerId eProblem, SCTAB nTab )
133 {
134 OUString sContext = OUString::createFromAscii( pTracerDetails[ eProblem ].mpContext );
135 OUString sDetail = OUString::createFromAscii( pTracerDetails[ eProblem ].mpDetail );
136
137 switch (eProblem)
138 {
139 case eRowLimitExceeded:
140 case eTabLimitExceeded:
141 sDetail += OUString::valueOf( static_cast< sal_Int32 >( nTab + 1 ) );
142 break;
143 default:
144 break;
145 }
146 AddAttribute(sContext, sDetail);
147 }
148
ProcessTraceOnce(XclTracerId eProblem,SCTAB nTab)149 void XclTracer::ProcessTraceOnce(XclTracerId eProblem, SCTAB nTab)
150 {
151 if( mbEnabled && maFirstTimes[eProblem])
152 {
153 TraceLog(pTracerDetails[eProblem].meProblemId, nTab);
154 maFirstTimes[eProblem] = false;
155 }
156 }
157
TraceInvalidAddress(const ScAddress & rPos,const ScAddress & rMaxPos)158 void XclTracer::TraceInvalidAddress( const ScAddress& rPos, const ScAddress& rMaxPos )
159 {
160 TraceInvalidRow(rPos.Tab(), rPos.Row(), rMaxPos.Row());
161 TraceInvalidTab(rPos.Tab(), rMaxPos.Tab());
162 }
163
TraceInvalidRow(SCTAB nTab,sal_uInt32 nRow,sal_uInt32 nMaxRow)164 void XclTracer::TraceInvalidRow( SCTAB nTab, sal_uInt32 nRow, sal_uInt32 nMaxRow )
165 {
166 if(nRow > nMaxRow)
167 ProcessTraceOnce(eRowLimitExceeded, nTab);
168 }
169
TraceInvalidTab(SCTAB nTab,SCTAB nMaxTab)170 void XclTracer::TraceInvalidTab( SCTAB nTab, SCTAB nMaxTab )
171 {
172 if(nTab > nMaxTab)
173 ProcessTraceOnce(eTabLimitExceeded, nTab);
174 }
175
TracePrintRange()176 void XclTracer::TracePrintRange()
177 {
178 ProcessTraceOnce( ePrintRange);
179 }
180
TraceDates(sal_uInt16 nNumFmt)181 void XclTracer::TraceDates( sal_uInt16 nNumFmt)
182 {
183 // Short Date = 14 and Short Date+Time = 22
184 if(nNumFmt == 14 || nNumFmt == 22)
185 ProcessTraceOnce(eShortDate);
186 }
187
TraceBorderLineStyle(bool bBorderLineStyle)188 void XclTracer::TraceBorderLineStyle( bool bBorderLineStyle)
189 {
190 if(bBorderLineStyle)
191 ProcessTraceOnce(eBorderLineStyle);
192 }
193
TraceFillPattern(bool bFillPattern)194 void XclTracer::TraceFillPattern( bool bFillPattern)
195 {
196 if(bFillPattern)
197 ProcessTraceOnce(eFillPattern);
198 }
199
TraceFormulaMissingArg()200 void XclTracer::TraceFormulaMissingArg()
201 {
202 // missing parameter in Formula record
203 ProcessTraceOnce(eFormulaMissingArg);
204 }
205
TracePivotDataSource(bool bExternal)206 void XclTracer::TracePivotDataSource( bool bExternal)
207 {
208 if(bExternal)
209 ProcessTraceOnce(ePivotDataSource);
210 }
211
TracePivotChartExists()212 void XclTracer::TracePivotChartExists()
213 {
214 // Pivot Charts not currently displayed.
215 ProcessTraceOnce(ePivotChartExists);
216 }
217
TraceChartUnKnownType()218 void XclTracer::TraceChartUnKnownType()
219 {
220 ProcessTraceOnce(eChartUnKnownType);
221 }
222
TraceChartOnlySheet()223 void XclTracer::TraceChartOnlySheet()
224 {
225 ProcessTraceOnce(eChartOnlySheet);
226 }
227
TraceChartDataTable()228 void XclTracer::TraceChartDataTable()
229 {
230 // Data table is not supported.
231 ProcessTraceOnce(eChartDataTable);
232 }
233
TraceChartLegendPosition()234 void XclTracer::TraceChartLegendPosition()
235 {
236 // If position is set to "not docked or inside the plot area" then
237 // we cannot guarantee the legend position.
238 ProcessTraceOnce(eChartLegendPosition);
239 }
240
TraceChartEmbeddedObj()241 void XclTracer::TraceChartEmbeddedObj()
242 {
243 // drawing objects e.g. text boxes etc not supported inside charts
244 ProcessTraceOnce(eChartEmbeddedObj);
245 }
246
TraceUnsupportedObjects()247 void XclTracer::TraceUnsupportedObjects()
248 {
249 // Called from Excel 5.0 - limited Graphical object support.
250 ProcessTraceOnce(eUnsupportedObject);
251 }
252
TraceObjectNotPrintable()253 void XclTracer::TraceObjectNotPrintable()
254 {
255 ProcessTraceOnce(eObjectNotPrintable);
256 }
257
TraceDVType(bool bType)258 void XclTracer::TraceDVType( bool bType)
259 {
260 // Custom types work if 'Data->validity dialog' is not OKed.
261 if(bType)
262 ProcessTraceOnce(eDVType);
263 }
264
265 // ============================================================================
266
267