1b4a4f18cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b4a4f18cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b4a4f18cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b4a4f18cSAndrew Rist  * distributed with this work for additional information
6b4a4f18cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b4a4f18cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b4a4f18cSAndrew Rist  * "License"); you may not use this file except in compliance
9b4a4f18cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10b4a4f18cSAndrew Rist  *
11b4a4f18cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b4a4f18cSAndrew Rist  *
13b4a4f18cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b4a4f18cSAndrew Rist  * software distributed under the License is distributed on an
15b4a4f18cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b4a4f18cSAndrew Rist  * KIND, either express or implied.  See the License for the
17b4a4f18cSAndrew Rist  * specific language governing permissions and limitations
18b4a4f18cSAndrew Rist  * under the License.
19b4a4f18cSAndrew Rist  *
20b4a4f18cSAndrew Rist  *************************************************************/
21b4a4f18cSAndrew Rist 
22b4a4f18cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir #include <resourcemodel/WW8ResourceModel.hxx>
26cdf0e10cSrcweir #include <resourcemodel/TableManager.hxx>
27cdf0e10cSrcweir #include <resourcemodel/QNameToString.hxx>
28cdf0e10cSrcweir #include <resourcemodel/exceptions.hxx>
29cdf0e10cSrcweir #include <resourcemodel/SubSequence.hxx>
30cdf0e10cSrcweir #include <resourcemodel/util.hxx>
31cdf0e10cSrcweir #include <resourcemodel.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace writerfilter {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class ResourceModelOutputWithDepth : public OutputWithDepth<string>
36cdf0e10cSrcweir {
37cdf0e10cSrcweir public:
ResourceModelOutputWithDepth()38cdf0e10cSrcweir     ResourceModelOutputWithDepth()
39cdf0e10cSrcweir     : OutputWithDepth<string>("<tablegroup>", "</tablegroup>") {}
40cdf0e10cSrcweir 
~ResourceModelOutputWithDepth()41cdf0e10cSrcweir     ~ResourceModelOutputWithDepth() {outputGroup();}
42cdf0e10cSrcweir 
output(const string & str) const43cdf0e10cSrcweir     void output(const string & str) const { cout << str << endl; }
44cdf0e10cSrcweir };
45cdf0e10cSrcweir 
46cdf0e10cSrcweir ResourceModelOutputWithDepth output;
47cdf0e10cSrcweir 
createStreamHandler()48cdf0e10cSrcweir Stream::Pointer_t createStreamHandler()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     return Stream::Pointer_t(new WW8StreamHandler());
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
dump(OutputWithDepth<string> &,const char *,writerfilter::Reference<Properties>::Pointer_t)53cdf0e10cSrcweir void dump(OutputWithDepth<string> & /*o*/, const char * /*name*/,
54cdf0e10cSrcweir           writerfilter::Reference<Properties>::Pointer_t /*props*/)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
dump(OutputWithDepth<string> & o,const char * name,sal_uInt32 n)58cdf0e10cSrcweir void dump(OutputWithDepth<string> & o, const char * name, sal_uInt32 n)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     char sBuffer[256];
61cdf0e10cSrcweir     snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, n);
62cdf0e10cSrcweir     string tmpStr = name;
63cdf0e10cSrcweir     tmpStr += "=";
64cdf0e10cSrcweir     tmpStr += sBuffer;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     o.addItem(tmpStr);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
dump(OutputWithDepth<string> &,const char *,const rtl::OUString &)69cdf0e10cSrcweir void dump(OutputWithDepth<string> & /*o*/, const char * /*name*/,
70cdf0e10cSrcweir           const rtl::OUString & /*str*/)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
dump(OutputWithDepth<string> &,const char *,writerfilter::Reference<BinaryObj>::Pointer_t)74cdf0e10cSrcweir void dump(OutputWithDepth<string> & /*o*/, const char * /*name*/,
75cdf0e10cSrcweir           writerfilter::Reference<BinaryObj>::Pointer_t /*binary*/)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir string gInfo = "";
80cdf0e10cSrcweir // ------- WW8TableDataHandler ---------
81cdf0e10cSrcweir 
82cdf0e10cSrcweir class TablePropsRef : public writerfilter::Reference<Properties>
83cdf0e10cSrcweir {
84cdf0e10cSrcweir public:
85cdf0e10cSrcweir     typedef boost::shared_ptr<TablePropsRef> Pointer_t;
86cdf0e10cSrcweir 
TablePropsRef()87cdf0e10cSrcweir     TablePropsRef() {}
~TablePropsRef()88cdf0e10cSrcweir     virtual ~TablePropsRef() {}
89cdf0e10cSrcweir 
resolve(Properties &)90cdf0e10cSrcweir     virtual void resolve(Properties & /*rHandler*/) {}
91cdf0e10cSrcweir 
getType() const92cdf0e10cSrcweir     virtual string getType() const { return "TableProps"; }
reset()93cdf0e10cSrcweir     void reset() {}
insert(Pointer_t)94cdf0e10cSrcweir     void insert(Pointer_t /* pTablePropsRef */) {}
95cdf0e10cSrcweir };
96cdf0e10cSrcweir 
97cdf0e10cSrcweir typedef TablePropsRef::Pointer_t TablePropsRef_t;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir class WW8TableDataHandler : public TableDataHandler<string,
100cdf0e10cSrcweir                             TablePropsRef_t>
101cdf0e10cSrcweir {
102cdf0e10cSrcweir public:
103cdf0e10cSrcweir     typedef boost::shared_ptr<WW8TableDataHandler> Pointer_t;
104cdf0e10cSrcweir     virtual void startTable(unsigned int nRows, unsigned int nDepth,
105cdf0e10cSrcweir                             TablePropsRef_t pProps);
106*14ac695dSOliver-Rainer Wittmann     virtual void endTable(
107*14ac695dSOliver-Rainer Wittmann         const unsigned int nDepth );
108cdf0e10cSrcweir     virtual void startRow(unsigned int nCols,
109cdf0e10cSrcweir                           TablePropsRef_t pProps);
110cdf0e10cSrcweir     virtual void endRow();
111cdf0e10cSrcweir     virtual void startCell(const string & start, TablePropsRef_t pProps);
112cdf0e10cSrcweir     virtual void endCell(const string & end);
113cdf0e10cSrcweir };
114cdf0e10cSrcweir 
startTable(unsigned int nRows,unsigned int nDepth,TablePropsRef_t)115cdf0e10cSrcweir void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth,
116cdf0e10cSrcweir                                      TablePropsRef_t /*pProps*/)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     char sBuffer[256];
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     string tmpStr = "<tabledata.table rows=\"";
121cdf0e10cSrcweir     snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
122cdf0e10cSrcweir     tmpStr += sBuffer;
123cdf0e10cSrcweir     tmpStr += "\" depth=\"";
124cdf0e10cSrcweir     snprintf(sBuffer, sizeof(sBuffer), "%d", nDepth);
125cdf0e10cSrcweir     tmpStr += sBuffer;
126cdf0e10cSrcweir     tmpStr += "\">";
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     output.addItem(tmpStr);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
endTable(const unsigned int)131*14ac695dSOliver-Rainer Wittmann void WW8TableDataHandler::endTable(
132*14ac695dSOliver-Rainer Wittmann     const unsigned int /*nDepth*/ )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     output.addItem("</tabledata.table>");
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
startRow(unsigned int nCols,TablePropsRef_t)137cdf0e10cSrcweir void WW8TableDataHandler::startRow
138cdf0e10cSrcweir (unsigned int nCols, TablePropsRef_t /*pProps*/)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     char sBuffer[256];
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     snprintf(sBuffer, sizeof(sBuffer), "%d", nCols);
143cdf0e10cSrcweir     string tmpStr = "<tabledata.row cells=\"";
144cdf0e10cSrcweir     tmpStr += sBuffer;
145cdf0e10cSrcweir     tmpStr += "\">";
146cdf0e10cSrcweir     output.addItem(tmpStr);
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
endRow()149cdf0e10cSrcweir void WW8TableDataHandler::endRow()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     output.addItem("</tabledata.row>");
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
startCell(const string & start,TablePropsRef_t)154cdf0e10cSrcweir void WW8TableDataHandler::startCell(const string & start,
155cdf0e10cSrcweir                                     TablePropsRef_t /*pProps*/)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     output.addItem("<tabledata.cell>");
158cdf0e10cSrcweir     output.addItem(start);
159cdf0e10cSrcweir     output.addItem(", ");
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
endCell(const string & end)162cdf0e10cSrcweir void WW8TableDataHandler::endCell(const string & end)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     output.addItem(end);
165cdf0e10cSrcweir     output.addItem("</tabledata.cell>");
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir // ----- WW8TableDataManager -------------------------------
169cdf0e10cSrcweir 
170cdf0e10cSrcweir class WW8TableManager :
171cdf0e10cSrcweir     public TableManager<string, TablePropsRef_t>
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     typedef TableDataHandler<string, TablePropsRef_t>
174cdf0e10cSrcweir     TableDataHandlerPointer_t;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir public:
177cdf0e10cSrcweir     WW8TableManager();
~WW8TableManager()178cdf0e10cSrcweir     virtual ~WW8TableManager() {}
179cdf0e10cSrcweir     virtual void endParagraphGroup();
180cdf0e10cSrcweir     virtual bool sprm(Sprm & rSprm);
181cdf0e10cSrcweir };
182cdf0e10cSrcweir 
WW8TableManager()183cdf0e10cSrcweir WW8TableManager::WW8TableManager()
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     TableDataHandler<string, TablePropsRef_t>::Pointer_t pHandler(new WW8TableDataHandler());
186cdf0e10cSrcweir     setHandler(pHandler);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
sprm(Sprm & rSprm)189cdf0e10cSrcweir bool WW8TableManager::sprm(Sprm & rSprm)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     TableManager<string, TablePropsRef_t>::sprm(rSprm);
192cdf0e10cSrcweir     output.setDepth(getTableDepthNew());
193cdf0e10cSrcweir     return true;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
endParagraphGroup()196cdf0e10cSrcweir void WW8TableManager::endParagraphGroup()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     string tmpStr = "<tabledepth depth=\"";
199cdf0e10cSrcweir     char sBuffer[256];
200cdf0e10cSrcweir     snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, getTableDepthNew());
201cdf0e10cSrcweir     tmpStr += sBuffer;
202cdf0e10cSrcweir     tmpStr += "\"/>";
203cdf0e10cSrcweir     output.addItem(tmpStr);
204cdf0e10cSrcweir     TableManager<string, TablePropsRef_t>::endParagraphGroup();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir WW8TableManager gTableManager;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir /* WW8StreamHandler */
210cdf0e10cSrcweir 
WW8StreamHandler()211cdf0e10cSrcweir WW8StreamHandler::WW8StreamHandler()
212cdf0e10cSrcweir : mnUTextCount(0)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     output.closeGroup();
215cdf0e10cSrcweir     output.addItem("<stream>");
216cdf0e10cSrcweir     gTableManager.startLevel();
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
~WW8StreamHandler()219cdf0e10cSrcweir WW8StreamHandler::~WW8StreamHandler()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     gTableManager.endLevel();
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     output.closeGroup();
224cdf0e10cSrcweir     output.addItem("</stream>");
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
startSectionGroup()227cdf0e10cSrcweir void WW8StreamHandler::startSectionGroup()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     output.addItem("<section-group>");
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
endSectionGroup()232cdf0e10cSrcweir void WW8StreamHandler::endSectionGroup()
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     output.addItem("</section-group>");
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
startParagraphGroup()237cdf0e10cSrcweir void WW8StreamHandler::startParagraphGroup()
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     output.openGroup();
240cdf0e10cSrcweir     output.addItem("<paragraph-group>");
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     gTableManager.startParagraphGroup();
243cdf0e10cSrcweir     gTableManager.handle(gInfo);
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
endParagraphGroup()246cdf0e10cSrcweir void WW8StreamHandler::endParagraphGroup()
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     gTableManager.endParagraphGroup();
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     output.addItem("</paragraph-group>");
251cdf0e10cSrcweir     output.closeGroup();
252cdf0e10cSrcweir 
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
startCharacterGroup()255cdf0e10cSrcweir void WW8StreamHandler::startCharacterGroup()
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     output.addItem("<character-group>");
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
endCharacterGroup()260cdf0e10cSrcweir void WW8StreamHandler::endCharacterGroup()
261cdf0e10cSrcweir {
262cdf0e10cSrcweir     output.addItem("</character-group>");
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
startShape(::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape>)265cdf0e10cSrcweir void WW8StreamHandler::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > /*xShape*/ )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir     output.addItem("<shape>");
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
endShape()270cdf0e10cSrcweir void WW8StreamHandler::endShape( )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     output.addItem( "</shape>" );
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
text(const sal_uInt8 * data,size_t len)275cdf0e10cSrcweir void WW8StreamHandler::text(const sal_uInt8 * data, size_t len)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir     string tmpStr = "<text>";
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     for (unsigned int n = 0; n < len; ++n)
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         switch (static_cast<unsigned char>(data[n]))
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir         case '<':
284cdf0e10cSrcweir             tmpStr += "&lt;";
285cdf0e10cSrcweir 
286cdf0e10cSrcweir             break;
287cdf0e10cSrcweir         case '>':
288cdf0e10cSrcweir             tmpStr += "&gt;";
289cdf0e10cSrcweir 
290cdf0e10cSrcweir             break;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         case '&':
293cdf0e10cSrcweir             tmpStr += "&amp;";
294cdf0e10cSrcweir 
295cdf0e10cSrcweir             break;
296cdf0e10cSrcweir         default:
297cdf0e10cSrcweir             if (isprint(data[n]))
298cdf0e10cSrcweir                 tmpStr += static_cast<char>(data[n]);
299cdf0e10cSrcweir             else
300cdf0e10cSrcweir             {
301cdf0e10cSrcweir                 char sBuffer[256];
302cdf0e10cSrcweir 
303cdf0e10cSrcweir                 snprintf(sBuffer, sizeof(sBuffer), "\\0x%02x", data[n]);
304cdf0e10cSrcweir 
305cdf0e10cSrcweir                 tmpStr += sBuffer;
306cdf0e10cSrcweir             }
307cdf0e10cSrcweir         }
308cdf0e10cSrcweir     }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     tmpStr += "</text>";
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     output.addItem(tmpStr);
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     gTableManager.text(data, len);
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
utext(const sal_uInt8 * data,size_t len)317cdf0e10cSrcweir void WW8StreamHandler::utext(const sal_uInt8 * data, size_t len)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir 	static char sBuffer[256];
320cdf0e10cSrcweir 	snprintf(sBuffer, sizeof(sBuffer), "<utext count=\"%d\">", mnUTextCount);
321cdf0e10cSrcweir     string tmpStr(sBuffer);
322cdf0e10cSrcweir 
323cdf0e10cSrcweir     for (unsigned int n = 0; n < len; ++n)
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         sal_Unicode nChar = data[n * 2] + (data[n * 2 + 1] << 8);
326cdf0e10cSrcweir         if (nChar < 0xff && isprint(nChar))
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             switch (nChar)
329cdf0e10cSrcweir             {
330cdf0e10cSrcweir             case '&':
331cdf0e10cSrcweir                 tmpStr += "&amp;";
332cdf0e10cSrcweir                 break;
333cdf0e10cSrcweir             case '<':
334cdf0e10cSrcweir                 tmpStr += "&lt;";
335cdf0e10cSrcweir                 break;
336cdf0e10cSrcweir             case '>':
337cdf0e10cSrcweir                 tmpStr += "&gt;";
338cdf0e10cSrcweir                 break;
339cdf0e10cSrcweir             default:
340cdf0e10cSrcweir                 tmpStr += static_cast<char>(nChar);
341cdf0e10cSrcweir             }
342cdf0e10cSrcweir         }
343cdf0e10cSrcweir         else
344cdf0e10cSrcweir         {
345cdf0e10cSrcweir             snprintf(sBuffer, sizeof(sBuffer), "\\0x%04x", nChar);
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             tmpStr += sBuffer;
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     tmpStr += "</utext>";
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     output.addItem(tmpStr);
354cdf0e10cSrcweir 
355cdf0e10cSrcweir     gTableManager.utext(data, len);
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	mnUTextCount++;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
props(writerfilter::Reference<Properties>::Pointer_t ref)360cdf0e10cSrcweir void WW8StreamHandler::props(writerfilter::Reference<Properties>::Pointer_t ref)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir     WW8PropertiesHandler aHandler;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     output.addItem("<properties type=\"" + ref->getType() + "\">");
365cdf0e10cSrcweir     ref->resolve(aHandler);
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     //gTableManager.props(ref);
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     output.addItem("</properties>");
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
table(Id name,writerfilter::Reference<Table>::Pointer_t ref)372cdf0e10cSrcweir void WW8StreamHandler::table(Id name, writerfilter::Reference<Table>::Pointer_t ref)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir     WW8TableHandler aHandler;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     output.addItem("<table id=\"" + (*QNameToString::Instance())(name)
377cdf0e10cSrcweir                    + "\">");
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     try
380cdf0e10cSrcweir     {
381cdf0e10cSrcweir         ref->resolve(aHandler);
382cdf0e10cSrcweir     }
383cdf0e10cSrcweir     catch (Exception e)
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         output.addItem("<exception>" + e.getText() + "</exception>");
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     output.addItem("</table>");
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
substream(Id name,writerfilter::Reference<Stream>::Pointer_t ref)391cdf0e10cSrcweir void WW8StreamHandler::substream(Id name,
392cdf0e10cSrcweir                                  writerfilter::Reference<Stream>::Pointer_t ref)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir     output.addItem("<substream name=\"" + (*QNameToString::Instance())(name)
395cdf0e10cSrcweir                    + "\">");
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     gTableManager.startLevel();
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     ref->resolve(*this);
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     gTableManager.endLevel();
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     output.addItem("</substream>");
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
info(const string & info_)406cdf0e10cSrcweir void WW8StreamHandler::info(const string & info_)
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     gInfo = info_;
409cdf0e10cSrcweir     output.addItem("<info>" + info_ + "</info>");
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
attribute(Id name,Value & val)412cdf0e10cSrcweir void WW8PropertiesHandler::attribute(Id name, Value & val)
413cdf0e10cSrcweir {
414cdf0e10cSrcweir     boost::shared_ptr<rtl::OString> pStr(new ::rtl::OString());
415cdf0e10cSrcweir     ::rtl::OUString aStr = val.getString();
416cdf0e10cSrcweir     aStr.convertToString(pStr.get(), RTL_TEXTENCODING_ASCII_US,
417cdf0e10cSrcweir                          OUSTRING_TO_OSTRING_CVTFLAGS);
418cdf0e10cSrcweir     string sXMLValue = xmlify(pStr->getStr());
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     char sBuffer[256];
421cdf0e10cSrcweir     snprintf(sBuffer, sizeof(sBuffer), "0x%x", val.getInt());
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     output.addItem("<attribute name=\"" +
424cdf0e10cSrcweir                    (*QNameToString::Instance())(name) +
425cdf0e10cSrcweir                    "\" value=\"" +
426cdf0e10cSrcweir                    sXMLValue +
427cdf0e10cSrcweir                    + "\" hexvalue=\""
428cdf0e10cSrcweir                    + sBuffer + "\">");
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     writerfilter::Reference<Properties>::Pointer_t pProps = val.getProperties();
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     if (pProps.get() != NULL)
433cdf0e10cSrcweir     {
434cdf0e10cSrcweir         output.addItem("<properties name=\"" +
435cdf0e10cSrcweir                        (*QNameToString::Instance())(name)
436cdf0e10cSrcweir                        + "\" type=\"" + pProps->getType() + "\">");
437cdf0e10cSrcweir 
438cdf0e10cSrcweir         try
439cdf0e10cSrcweir         {
440cdf0e10cSrcweir             pProps->resolve(*this);
441cdf0e10cSrcweir         }
442cdf0e10cSrcweir         catch (ExceptionOutOfBounds e)
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir         }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir         output.addItem("</properties>");
447cdf0e10cSrcweir     }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     writerfilter::Reference<Stream>::Pointer_t pStream = val.getStream();
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     if (pStream.get() != NULL)
452cdf0e10cSrcweir     {
453cdf0e10cSrcweir         try
454cdf0e10cSrcweir         {
455cdf0e10cSrcweir             WW8StreamHandler aHandler;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir             pStream->resolve(aHandler);
458cdf0e10cSrcweir         }
459cdf0e10cSrcweir         catch (ExceptionOutOfBounds e)
460cdf0e10cSrcweir         {
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir     }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     writerfilter::Reference<BinaryObj>::Pointer_t pBinObj = val.getBinary();
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     if (pBinObj.get() != NULL)
467cdf0e10cSrcweir     {
468cdf0e10cSrcweir         try
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             WW8BinaryObjHandler aHandler;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir             pBinObj->resolve(aHandler);
473cdf0e10cSrcweir         }
474cdf0e10cSrcweir         catch (ExceptionOutOfBounds e)
475cdf0e10cSrcweir         {
476cdf0e10cSrcweir         }
477cdf0e10cSrcweir     }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     output.addItem("</attribute>");
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
sprm(Sprm & sprm_)482cdf0e10cSrcweir void WW8PropertiesHandler::sprm(Sprm & sprm_)
483cdf0e10cSrcweir {
484cdf0e10cSrcweir     string tmpStr = "<sprm id=\"";
485cdf0e10cSrcweir     char buffer[256];
486cdf0e10cSrcweir     snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, sprm_.getId());
487cdf0e10cSrcweir     tmpStr += buffer;
488cdf0e10cSrcweir     tmpStr += "\" name=\"";
489cdf0e10cSrcweir     tmpStr += sprm_.getName();
490cdf0e10cSrcweir     tmpStr += "\">";
491cdf0e10cSrcweir     output.addItem(tmpStr);
492cdf0e10cSrcweir     output.addItem(sprm_.toString());
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     writerfilter::Reference<Properties>::Pointer_t pProps = sprm_.getProps();
495cdf0e10cSrcweir 
496cdf0e10cSrcweir     if (pProps.get() != NULL)
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         output.addItem("<properties type=\"" + pProps->getType() + "\">");
499cdf0e10cSrcweir         pProps->resolve(*this);
500cdf0e10cSrcweir         output.addItem("</properties>");
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     writerfilter::Reference<BinaryObj>::Pointer_t pBinObj = sprm_.getBinary();
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     if (pBinObj.get() != NULL)
506cdf0e10cSrcweir     {
507cdf0e10cSrcweir         output.addItem("<binary>");
508cdf0e10cSrcweir         WW8BinaryObjHandler aHandler;
509cdf0e10cSrcweir         pBinObj->resolve(aHandler);
510cdf0e10cSrcweir         output.addItem("</binary>");
511cdf0e10cSrcweir     }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     writerfilter::Reference<Stream>::Pointer_t pStream = sprm_.getStream();
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     if (pStream.get() != NULL)
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         output.addItem("<stream>");
518cdf0e10cSrcweir         WW8StreamHandler aHandler;
519cdf0e10cSrcweir         pStream->resolve(aHandler);
520cdf0e10cSrcweir         output.addItem("</stream>");
521cdf0e10cSrcweir     }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     gTableManager.sprm(sprm_);
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     output.addItem("</sprm>");
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
entry(int,writerfilter::Reference<Properties>::Pointer_t ref)528cdf0e10cSrcweir void WW8TableHandler::entry(int /*pos*/,
529cdf0e10cSrcweir                             writerfilter::Reference<Properties>::Pointer_t ref)
530cdf0e10cSrcweir {
531cdf0e10cSrcweir     output.addItem("<tableentry>");
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     WW8PropertiesHandler aHandler;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     try
536cdf0e10cSrcweir     {
537cdf0e10cSrcweir         ref->resolve(aHandler);
538cdf0e10cSrcweir     }
539cdf0e10cSrcweir     catch (Exception e)
540cdf0e10cSrcweir     {
541cdf0e10cSrcweir         output.addItem("<exception>" + e.getText() + "</exception>");
542cdf0e10cSrcweir         output.addItem("</tableentry>");
543cdf0e10cSrcweir 
544cdf0e10cSrcweir         throw e;
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     output.addItem("</tableentry>");
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
data(const sal_uInt8 * buf,size_t length,writerfilter::Reference<Properties>::Pointer_t)550cdf0e10cSrcweir void WW8BinaryObjHandler::data
551cdf0e10cSrcweir (const sal_uInt8 * buf, size_t length,
552cdf0e10cSrcweir  writerfilter::Reference<Properties>::Pointer_t /*pRef*/)
553cdf0e10cSrcweir {
554cdf0e10cSrcweir #if 1
555cdf0e10cSrcweir     SubSequence<sal_uInt8> aSeq(buf, length);
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     aSeq.dump(output);
558cdf0e10cSrcweir #endif
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir }
562