/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ #include #include #include #include #include #include #include #include namespace writerfilter { class ResourceModelOutputWithDepth : public OutputWithDepth { public: ResourceModelOutputWithDepth() : OutputWithDepth("", "") {} ~ResourceModelOutputWithDepth() {outputGroup();} void output(const string & str) const { cout << str << endl; } }; ResourceModelOutputWithDepth output; Stream::Pointer_t createStreamHandler() { return Stream::Pointer_t(new WW8StreamHandler()); } void dump(OutputWithDepth & /*o*/, const char * /*name*/, writerfilter::Reference::Pointer_t /*props*/) { } void dump(OutputWithDepth & o, const char * name, sal_uInt32 n) { char sBuffer[256]; snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, n); string tmpStr = name; tmpStr += "="; tmpStr += sBuffer; o.addItem(tmpStr); } void dump(OutputWithDepth & /*o*/, const char * /*name*/, const rtl::OUString & /*str*/) { } void dump(OutputWithDepth & /*o*/, const char * /*name*/, writerfilter::Reference::Pointer_t /*binary*/) { } string gInfo = ""; // ------- WW8TableDataHandler --------- class TablePropsRef : public writerfilter::Reference { public: typedef boost::shared_ptr Pointer_t; TablePropsRef() {} virtual ~TablePropsRef() {} virtual void resolve(Properties & /*rHandler*/) {} virtual string getType() const { return "TableProps"; } void reset() {} void insert(Pointer_t /* pTablePropsRef */) {} }; typedef TablePropsRef::Pointer_t TablePropsRef_t; class WW8TableDataHandler : public TableDataHandler { public: typedef boost::shared_ptr Pointer_t; virtual void startTable(unsigned int nRows, unsigned int nDepth, TablePropsRef_t pProps); virtual void endTable( const unsigned int nDepth ); virtual void startRow(unsigned int nCols, TablePropsRef_t pProps); virtual void endRow(); virtual void startCell(const string & start, TablePropsRef_t pProps); virtual void endCell(const string & end); }; void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth, TablePropsRef_t /*pProps*/) { char sBuffer[256]; string tmpStr = ""; output.addItem(tmpStr); } void WW8TableDataHandler::endTable( const unsigned int /*nDepth*/ ) { output.addItem(""); } void WW8TableDataHandler::startRow (unsigned int nCols, TablePropsRef_t /*pProps*/) { char sBuffer[256]; snprintf(sBuffer, sizeof(sBuffer), "%d", nCols); string tmpStr = ""; output.addItem(tmpStr); } void WW8TableDataHandler::endRow() { output.addItem(""); } void WW8TableDataHandler::startCell(const string & start, TablePropsRef_t /*pProps*/) { output.addItem(""); output.addItem(start); output.addItem(", "); } void WW8TableDataHandler::endCell(const string & end) { output.addItem(end); output.addItem(""); } // ----- WW8TableDataManager ------------------------------- class WW8TableManager : public TableManager { typedef TableDataHandler TableDataHandlerPointer_t; public: WW8TableManager(); virtual ~WW8TableManager() {} virtual void endParagraphGroup(); virtual bool sprm(Sprm & rSprm); }; WW8TableManager::WW8TableManager() { TableDataHandler::Pointer_t pHandler(new WW8TableDataHandler()); setHandler(pHandler); } bool WW8TableManager::sprm(Sprm & rSprm) { TableManager::sprm(rSprm); output.setDepth(getTableDepthNew()); return true; } void WW8TableManager::endParagraphGroup() { string tmpStr = ""; output.addItem(tmpStr); TableManager::endParagraphGroup(); } WW8TableManager gTableManager; /* WW8StreamHandler */ WW8StreamHandler::WW8StreamHandler() : mnUTextCount(0) { output.closeGroup(); output.addItem(""); gTableManager.startLevel(); } WW8StreamHandler::~WW8StreamHandler() { gTableManager.endLevel(); output.closeGroup(); output.addItem(""); } void WW8StreamHandler::startSectionGroup() { output.addItem(""); } void WW8StreamHandler::endSectionGroup() { output.addItem(""); } void WW8StreamHandler::startParagraphGroup() { output.openGroup(); output.addItem(""); gTableManager.startParagraphGroup(); gTableManager.handle(gInfo); } void WW8StreamHandler::endParagraphGroup() { gTableManager.endParagraphGroup(); output.addItem(""); output.closeGroup(); } void WW8StreamHandler::startCharacterGroup() { output.addItem(""); } void WW8StreamHandler::endCharacterGroup() { output.addItem(""); } void WW8StreamHandler::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > /*xShape*/ ) { output.addItem(""); } void WW8StreamHandler::endShape( ) { output.addItem( "" ); } void WW8StreamHandler::text(const sal_uInt8 * data, size_t len) { string tmpStr = ""; for (unsigned int n = 0; n < len; ++n) { switch (static_cast(data[n])) { case '<': tmpStr += "<"; break; case '>': tmpStr += ">"; break; case '&': tmpStr += "&"; break; default: if (isprint(data[n])) tmpStr += static_cast(data[n]); else { char sBuffer[256]; snprintf(sBuffer, sizeof(sBuffer), "\\0x%02x", data[n]); tmpStr += sBuffer; } } } tmpStr += ""; output.addItem(tmpStr); gTableManager.text(data, len); } void WW8StreamHandler::utext(const sal_uInt8 * data, size_t len) { static char sBuffer[256]; snprintf(sBuffer, sizeof(sBuffer), "", mnUTextCount); string tmpStr(sBuffer); for (unsigned int n = 0; n < len; ++n) { sal_Unicode nChar = data[n * 2] + (data[n * 2 + 1] << 8); if (nChar < 0xff && isprint(nChar)) { switch (nChar) { case '&': tmpStr += "&"; break; case '<': tmpStr += "<"; break; case '>': tmpStr += ">"; break; default: tmpStr += static_cast(nChar); } } else { snprintf(sBuffer, sizeof(sBuffer), "\\0x%04x", nChar); tmpStr += sBuffer; } } tmpStr += ""; output.addItem(tmpStr); gTableManager.utext(data, len); mnUTextCount++; } void WW8StreamHandler::props(writerfilter::Reference::Pointer_t ref) { WW8PropertiesHandler aHandler; output.addItem("getType() + "\">"); ref->resolve(aHandler); //gTableManager.props(ref); output.addItem(""); } void WW8StreamHandler::table(Id name, writerfilter::Reference::Pointer_t ref) { WW8TableHandler aHandler; output.addItem("
"); try { ref->resolve(aHandler); } catch (Exception e) { output.addItem("" + e.getText() + ""); } output.addItem("
"); } void WW8StreamHandler::substream(Id name, writerfilter::Reference::Pointer_t ref) { output.addItem(""); gTableManager.startLevel(); ref->resolve(*this); gTableManager.endLevel(); output.addItem(""); } void WW8StreamHandler::info(const string & info_) { gInfo = info_; output.addItem("" + info_ + ""); } void WW8PropertiesHandler::attribute(Id name, Value & val) { boost::shared_ptr pStr(new ::rtl::OString()); ::rtl::OUString aStr = val.getString(); aStr.convertToString(pStr.get(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS); string sXMLValue = xmlify(pStr->getStr()); char sBuffer[256]; snprintf(sBuffer, sizeof(sBuffer), "0x%x", val.getInt()); output.addItem(""); writerfilter::Reference::Pointer_t pProps = val.getProperties(); if (pProps.get() != NULL) { output.addItem("getType() + "\">"); try { pProps->resolve(*this); } catch (ExceptionOutOfBounds e) { } output.addItem(""); } writerfilter::Reference::Pointer_t pStream = val.getStream(); if (pStream.get() != NULL) { try { WW8StreamHandler aHandler; pStream->resolve(aHandler); } catch (ExceptionOutOfBounds e) { } } writerfilter::Reference::Pointer_t pBinObj = val.getBinary(); if (pBinObj.get() != NULL) { try { WW8BinaryObjHandler aHandler; pBinObj->resolve(aHandler); } catch (ExceptionOutOfBounds e) { } } output.addItem(""); } void WW8PropertiesHandler::sprm(Sprm & sprm_) { string tmpStr = ""; output.addItem(tmpStr); output.addItem(sprm_.toString()); writerfilter::Reference::Pointer_t pProps = sprm_.getProps(); if (pProps.get() != NULL) { output.addItem("getType() + "\">"); pProps->resolve(*this); output.addItem(""); } writerfilter::Reference::Pointer_t pBinObj = sprm_.getBinary(); if (pBinObj.get() != NULL) { output.addItem(""); WW8BinaryObjHandler aHandler; pBinObj->resolve(aHandler); output.addItem(""); } writerfilter::Reference::Pointer_t pStream = sprm_.getStream(); if (pStream.get() != NULL) { output.addItem(""); WW8StreamHandler aHandler; pStream->resolve(aHandler); output.addItem(""); } gTableManager.sprm(sprm_); output.addItem(""); } void WW8TableHandler::entry(int /*pos*/, writerfilter::Reference::Pointer_t ref) { output.addItem(""); WW8PropertiesHandler aHandler; try { ref->resolve(aHandler); } catch (Exception e) { output.addItem("" + e.getText() + ""); output.addItem(""); throw e; } output.addItem(""); } void WW8BinaryObjHandler::data (const sal_uInt8 * buf, size_t length, writerfilter::Reference::Pointer_t /*pRef*/) { #if 1 SubSequence aSeq(buf, length); aSeq.dump(output); #endif } }