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 #include <WW8Analyzer.hxx>
25 #include <doctok/resourceids.hxx>
26 #include <resourcemodel/QNameToString.hxx>
27
28 namespace writerfilter
29 {
operator ()(sal_uInt32 n1,sal_uInt32 n2) const30 bool eqSalUInt32::operator () (sal_uInt32 n1, sal_uInt32 n2) const
31 {
32 return n1 == n2;
33 }
34
WW8Analyzer()35 WW8Analyzer::WW8Analyzer()
36 {
37 }
38
~WW8Analyzer()39 WW8Analyzer::~WW8Analyzer()
40 {
41 dumpStats(cout);
42 }
43
attribute(Id name,Value & val)44 void WW8Analyzer::attribute(Id name, Value & val)
45 {
46 string aAttrName = (*QNameToString::Instance())(name);
47 string aStr;
48
49 if (aAttrName.length() > 6)
50 aStr = aAttrName.substr(4, 2);
51 else
52 logger("DEBUG", "WW8Analyzer::attribute:" + aAttrName);
53
54 bool bAdd = false;
55 if (aStr.compare("LC") == 0 || aStr.compare("FC") == 0)
56 {
57 if (val.getInt() != 0)
58 {
59 bAdd = true;
60 }
61 }
62 else
63 {
64 bAdd = true;
65 }
66
67 if (bAdd)
68 {
69 if (mAttributeMap.count(name) > 0)
70 {
71 sal_uInt32 nCount = mAttributeMap[name] + 1;
72 mAttributeMap[name] = nCount;
73 }
74 else
75 mAttributeMap[name] = 1;
76
77 mAttributeIdSet.insert(name);
78 }
79 }
80
sprm(Sprm & sprm_)81 void WW8Analyzer::sprm(Sprm & sprm_)
82 {
83 if (mSprmMap.count(sprm_.getId()) > 0)
84 {
85 sal_uInt32 nCount = mSprmMap[sprm_.getId()] + 1;
86 mSprmMap[sprm_.getId()] = nCount;
87 }
88 else
89 mSprmMap[sprm_.getId()] = 1;
90
91 mSprmIdSet.insert(sprm_.getId());
92
93 writerfilter::Reference<Properties>::Pointer_t pProps = sprm_.getProps();
94
95 if (pProps.get() != NULL)
96 {
97 pProps->resolve(*this);
98 }
99
100 }
101
entry(int,::writerfilter::Reference<Properties>::Pointer_t ref)102 void WW8Analyzer::entry(int /*pos*/, ::writerfilter::Reference<Properties>::Pointer_t ref)
103 {
104 ref->resolve(*this);
105 }
106
data(const sal_uInt8 *,size_t,::writerfilter::Reference<Properties>::Pointer_t)107 void WW8Analyzer::data(const sal_uInt8 * /*buf*/, size_t /*len*/,
108 ::writerfilter::Reference<Properties>::Pointer_t /*ref*/)
109 {
110 }
111
startSectionGroup()112 void WW8Analyzer::startSectionGroup()
113 {
114 }
115
endSectionGroup()116 void WW8Analyzer::endSectionGroup()
117 {
118 }
119
startParagraphGroup()120 void WW8Analyzer::startParagraphGroup()
121 {
122 }
123
endParagraphGroup()124 void WW8Analyzer::endParagraphGroup()
125 {
126 }
127
startCharacterGroup()128 void WW8Analyzer::startCharacterGroup()
129 {
130 }
131
endCharacterGroup()132 void WW8Analyzer::endCharacterGroup()
133 {
134 }
135
text(const sal_uInt8 *,size_t)136 void WW8Analyzer::text(const sal_uInt8 * /*data*/, size_t /*len*/)
137 {
138 }
139
utext(const sal_uInt8 *,size_t)140 void WW8Analyzer::utext(const sal_uInt8 * /*data*/, size_t /*len*/)
141 {
142 }
143
props(writerfilter::Reference<Properties>::Pointer_t ref)144 void WW8Analyzer::props(writerfilter::Reference<Properties>::Pointer_t ref)
145 {
146 ref->resolve(*this);
147 }
148
table(Id,writerfilter::Reference<Table>::Pointer_t ref)149 void WW8Analyzer::table(Id /*id*/, writerfilter::Reference<Table>::Pointer_t ref)
150 {
151 ref->resolve(*this);
152 }
153
substream(Id,writerfilter::Reference<Stream>::Pointer_t ref)154 void WW8Analyzer::substream(Id /*name*/,
155 writerfilter::Reference<Stream>::Pointer_t ref)
156 {
157 ref->resolve(*this);
158 }
159
info(const string &)160 void WW8Analyzer::info(const string & /*info*/)
161 {
162 }
163
startShape(::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape>)164 void WW8Analyzer::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > /*xShape*/ )
165 {
166 }
167
endShape()168 void WW8Analyzer::endShape( )
169 {
170 }
171
dumpStats(ostream & o) const172 void WW8Analyzer::dumpStats(ostream & o) const
173 {
174 {
175 for (IdSet::const_iterator aIt = mSprmIdSet.begin();
176 aIt != mSprmIdSet.end(); aIt++)
177 {
178 sal_uInt32 aId = *aIt;
179
180 o << "<sprm>" << endl
181 << "<id>" << hex << aId << "</id>" << endl
182 << "<name>" << (*SprmIdToString::Instance())(aId)
183 << "</name>" << endl
184 << "<count>" << dec << mSprmMap[aId] << "</count>"
185 << endl
186 << "</sprm>" << endl;
187 }
188 }
189
190 {
191 for (IdSet::const_iterator aIt = mAttributeIdSet.begin();
192 aIt != mAttributeIdSet.end(); aIt++)
193 {
194 sal_uInt32 aId = *aIt;
195
196 o << "<attribute>" << endl
197 << "<name>" << (*QNameToString::Instance())(aId) << "</name>"
198 << endl
199 << "<count>" << dec << mAttributeMap[aId] << "</count>"
200 << endl
201 << "</attribute>" << endl;
202 }
203 }
204
205 }
206
createAnalyzer()207 Stream::Pointer_t createAnalyzer()
208 {
209 return Stream::Pointer_t(new WW8Analyzer());
210 }
211
212 }
213