xref: /trunk/main/sw/source/filter/ww8/tracer.cxx (revision efeef26f)
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_sw.hxx"
26 
27 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
28 #include <tools/urlobj.hxx>         //INetURLObject
29 #include <sfx2/docfile.hxx>         //SfxMedium
30 #include <filter/msfilter/msfiltertracer.hxx>   //MSFilterTracer
31 #include "tracer.hxx"               //sw::log::Tracer
32 
33 using rtl::OUString;
34 #define CAU(X) RTL_CONSTASCII_USTRINGPARAM(X)
35 #define C2O(X) OUString(CAU(X))
36 #define COMMENT(X) OUString()
37 
38 namespace sw
39 {
40     namespace log
41     {
Tracer(const SfxMedium & rMed)42         Tracer::Tracer(const SfxMedium &rMed)
43             : mpTrace(0)
44         {
45             using namespace ::com::sun::star::uno;
46             using namespace ::com::sun::star::beans;
47             Sequence<PropertyValue> aConfig(1);
48             PropertyValue aPropValue;
49             aPropValue.Value <<=
50                 OUString(rMed.GetURLObject().GetMainURL(
51                     INetURLObject::NO_DECODE));
52             aPropValue.Name = C2O("DocumentURL");
53             aConfig[0] = aPropValue;
54             OUString aTraceConfigPath(CAU("Office.Tracing/Import/Word"));
55             mpTrace = new MSFilterTracer(aTraceConfigPath, &aConfig);
56             if (mpTrace)
57                 mpTrace->StartTracing();
58         }
59 
~Tracer()60         Tracer::~Tracer()
61         {
62             if (mpTrace)
63             {
64                 mpTrace->EndTracing();
65                 delete mpTrace;
66             }
67         }
68 
Log(Problem eProblem)69         void Tracer::Log(Problem eProblem)
70         {
71             if (!mpTrace)
72                 return;
73 
74             OUString sID(CAU("sw"));
75             sID += rtl::OUString::valueOf(static_cast<sal_Int32>(eProblem));
76             switch (eProblem)
77             {
78                 case ePrinterMetrics:
79                     mpTrace->Trace(sID, COMMENT("PrinterMetrics"));
80                     break;
81                 case eExtraLeading:
82                     mpTrace->Trace(sID, COMMENT("Extra Leading"));
83                     break;
84                 case eTabStopDistance:
85                     mpTrace->Trace(sID, COMMENT("Minimum Tab Distance"));
86                     break;
87                 case eDontUseHTMLAutoSpacing:
88                     mpTrace->Trace(sID, COMMENT("HTML AutoSpacing"));
89                     break;
90                 case eAutoWidthFrame:
91                     mpTrace->Trace(sID, COMMENT("AutoWidth"));
92                     break;
93                 case eRowCanSplit:
94                     mpTrace->Trace(sID, COMMENT("Splitable Row"));
95                     break;
96                 case eSpacingBetweenCells:
97                     mpTrace->Trace(sID, COMMENT("Spacing Between Cells"));
98                     break;
99                 case eTabInNumbering:
100                     mpTrace->Trace(sID, COMMENT("Tab In Numbering"));
101                     break;
102                 case eNegativeVertPlacement:
103                     mpTrace->Trace(sID,
104                         COMMENT("Negative Vertical Placement"));
105                     break;
106                 case eAutoColorBg:
107                     mpTrace->Trace(sID,
108                         COMMENT("Bad Background for Autocolour"));
109                     break;
110                 case eTooWideAsChar:
111                     mpTrace->Trace(sID,
112                         COMMENT("Inline wider than TextArea"));
113                     break;
114                 case eAnimatedText:
115                     mpTrace->Trace(sID,
116                         COMMENT("Animated Text"));
117                     break;
118                 case eDontAddSpaceForEqualStyles:
119                     mpTrace->Trace(sID,
120                         COMMENT("Don't Add Space between Equal Style"));
121                     break;
122                 case eBorderDistOutside:
123                     mpTrace->Trace(sID,
124                         COMMENT("Word draws the border outside"));
125                     break;
126                 case eContainsVisualBasic:
127                     mpTrace->Trace(sID, COMMENT("Contains VBA"));
128                     break;
129                 case eContainsWordBasic:
130                     mpTrace->Trace(sID, COMMENT("Contains Word Basic"));
131                     break;
132                 default:
133                     mpTrace->Trace(sID, COMMENT("UNKNOWN"));
134                     break;
135             }
136         }
137 
GetContext(Environment eContext) const138         rtl::OUString Tracer::GetContext(Environment eContext) const
139         {
140             rtl::OUString sContext;
141             switch (eContext)
142             {
143                 case eMacros:
144                 case eDocumentProperties:
145                     sContext = C2O("Global");
146                     break;
147                 case eMainText:
148                     sContext = C2O("Text");
149                     break;
150                 case eSubDoc:
151                     sContext = C2O("Text");
152                     break;
153                 case eTable:
154                     sContext = C2O("Table");
155                     break;
156                 default:
157                     sContext = C2O("UNKNOWN");
158                     break;
159             }
160             return sContext;
161         }
162 
GetDetails(Environment eContext) const163         rtl::OUString Tracer::GetDetails(Environment eContext) const
164         {
165             rtl::OUString sDetails;
166             switch (eContext)
167             {
168                 case eDocumentProperties:
169                     sDetails = C2O("Document Properties");
170                     break;
171                 case eMacros:
172                     sDetails = C2O("Macros");
173                     break;
174                 case eMainText:
175                     sDetails = C2O("MainDocument");
176                     break;
177                 case eSubDoc:
178                     sDetails = C2O("Unknown Subdocument");
179                     break;
180                 default:
181                     sDetails = C2O("UNKNOWN");
182                     break;
183             }
184             return sDetails;
185         }
186 
EnterEnvironment(Environment eContext)187         void Tracer::EnterEnvironment(Environment eContext)
188         {
189             mpTrace->AddAttribute(GetContext(eContext), GetDetails(eContext));
190         }
191 
EnterEnvironment(Environment eContext,const rtl::OUString & rDetails)192         void Tracer::EnterEnvironment(Environment eContext,
193             const rtl::OUString &rDetails)
194         {
195             mpTrace->AddAttribute(GetContext(eContext), rDetails);
196         }
197 
LeaveEnvironment(Environment eContext)198         void Tracer::LeaveEnvironment(Environment eContext)
199         {
200             mpTrace->RemoveAttribute(GetContext(eContext));
201         }
202     }
203 }
204 
205 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
206