diff options
Diffstat (limited to 'writerfilter/inc')
23 files changed, 4306 insertions, 0 deletions
diff --git a/writerfilter/inc/WriterFilterDllApi.hxx b/writerfilter/inc/WriterFilterDllApi.hxx new file mode 100644 index 000000000000..dff806017c8a --- /dev/null +++ b/writerfilter/inc/WriterFilterDllApi.hxx @@ -0,0 +1,40 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_WRITERFILTERDLLAPI_H +#define INCLUDED_WRITERFILTERDLLAPI_H + +#include "sal/types.h" + +#if defined(WRITERFILTER_DLLIMPLEMENTATION) +#define WRITERFILTER_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define WRITERFILTER_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define WRITERFILTER_DLLPRIVATE SAL_DLLPRIVATE + +#endif /* INCLUDED_WRITERFILTERDLLAPI_H */ diff --git a/writerfilter/inc/dmapper/DomainMapper.hxx b/writerfilter/inc/dmapper/DomainMapper.hxx new file mode 100644 index 000000000000..d7f6c005a5c4 --- /dev/null +++ b/writerfilter/inc/dmapper/DomainMapper.hxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_DOMAINMAPPER_HXX +#define INCLUDED_DOMAINMAPPER_HXX + +#include <WriterFilterDllApi.hxx> +#include <resourcemodel/LoggedResources.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/text/FontEmphasis.hpp> +#include <com/sun/star/style/TabAlign.hpp> + +#include <map> +#include <vector> + +namespace com{ namespace sun {namespace star{ + namespace beans{ + struct PropertyValue; + } + namespace io{ + class XInputStream; + } + namespace uno{ + class XComponentContext; + } + namespace lang{ + class XMultiServiceFactory; + } + namespace text{ + class XTextRange; + } +}}} + +typedef std::vector< com::sun::star::beans::PropertyValue > PropertyValueVector_t; + +namespace writerfilter { +namespace dmapper +{ + +class PropertyMap; +class DomainMapper_Impl; +class ListsManager; +class StyleSheetTable; + +// different context types require different sprm handling (e.g. names) +enum SprmType +{ + SPRM_DEFAULT, + SPRM_LIST +}; +enum SourceDocumentType +{ + DOCUMENT_DOC, + DOCUMENT_OOXML, + DOCUMENT_RTF +}; +class WRITERFILTER_DLLPUBLIC DomainMapper : public LoggedProperties, public LoggedTable, + public BinaryObj, public LoggedStream +{ + DomainMapper_Impl *m_pImpl; + +public: + DomainMapper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext, + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xModel, + SourceDocumentType eDocumentType ); + virtual ~DomainMapper(); + + // Stream + virtual void markLastParagraphInSection(); + + // BinaryObj + virtual void data(const sal_uInt8* buf, size_t len, + writerfilter::Reference<Properties>::Pointer_t ref); + + void sprmWithProps( Sprm& sprm, ::boost::shared_ptr<PropertyMap> pContext, SprmType = SPRM_DEFAULT ); + + void PushStyleSheetProperties( ::boost::shared_ptr<PropertyMap> pStyleProperties, bool bAffectTableMngr = false ); + void PopStyleSheetProperties( bool bAffectTableMngr = false ); + + void PushListProperties( ::boost::shared_ptr<PropertyMap> pListProperties ); + void PopListProperties(); + + bool IsOOXMLImport() const; + ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > GetTextFactory() const; + void AddListIDToLFOTable( sal_Int32 nAbstractNumId ); + ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > GetCurrentTextRange(); + + ::rtl::OUString getOrCreateCharStyle( PropertyValueVector_t& rCharProperties ); + boost::shared_ptr< ListsManager > GetListTable( ); + boost::shared_ptr< StyleSheetTable > GetStyleSheetTable( ); + +private: + // Stream + virtual void lcl_startSectionGroup(); + virtual void lcl_endSectionGroup(); + virtual void lcl_startParagraphGroup(); + virtual void lcl_endParagraphGroup(); + virtual void lcl_startCharacterGroup(); + virtual void lcl_endCharacterGroup(); + virtual void lcl_startShape( ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape ); + virtual void lcl_endShape( ); + + virtual void lcl_text(const sal_uInt8 * data, size_t len); + virtual void lcl_utext(const sal_uInt8 * data, size_t len); + virtual void lcl_props(writerfilter::Reference<Properties>::Pointer_t ref); + virtual void lcl_table(Id name, + writerfilter::Reference<Table>::Pointer_t ref); + virtual void lcl_substream(Id name, + ::writerfilter::Reference<Stream>::Pointer_t ref); + virtual void lcl_info(const string & info); + + // Properties + virtual void lcl_attribute(Id Name, Value & val); + virtual void lcl_sprm(Sprm & sprm); + + // Table + virtual void lcl_entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref); + + void handleUnderlineType(const sal_Int32 nIntValue, const ::boost::shared_ptr<PropertyMap> pContext); + void handleParaJustification(const sal_Int32 nIntValue, const ::boost::shared_ptr<PropertyMap> pContext, const bool bExchangeLeftRight); + bool getColorFromIndex(const sal_Int32 nIndex, sal_Int32 &nColor); + sal_Int16 getEmphasisValue(const sal_Int32 nIntValue); + rtl::OUString getBracketStringFromEnum(const sal_Int32 nIntValue, const bool bIsPrefix = true); + com::sun::star::style::TabAlign getTabAlignFromValue(const sal_Int32 nIntValue); + sal_Unicode getFillCharFromValue(const sal_Int32 nIntValue); + sal_Int32 mnBackgroundColor; + bool mbIsHighlightSet; +}; + +} // namespace dmapper +} // namespace writerfilter +#endif // diff --git a/writerfilter/inc/doctok/WW8Document.hxx b/writerfilter/inc/doctok/WW8Document.hxx new file mode 100644 index 000000000000..e3915c628761 --- /dev/null +++ b/writerfilter/inc/doctok/WW8Document.hxx @@ -0,0 +1,448 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_WW8_DOCUMENT_HXX +#define INCLUDED_WW8_DOCUMENT_HXX + +#include <boost/shared_ptr.hpp> +#include <sal/types.h> +#include <com/sun/star/uno/Reference.hxx> +#include <resourcemodel/SubSequence.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEX_HPP_ +#include <com/sun/star/uno/XComponentContext.hpp> +#endif + +#ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX +#include <resourcemodel/WW8ResourceModel.hxx> +#endif +#include <resourcemodel/OutputWithDepth.hxx> + +#include <WriterFilterDllApi.hxx> + +namespace writerfilter { +namespace doctok { + +using namespace ::com::sun::star; + +/** + A stream containing a WW8 document. + + The content of the stream is a sequence of unsigned bytes. The + stream consists of substreams that are identified by string + identifiers. +*/ +class WRITERFILTER_DLLPUBLIC WW8Stream +{ +public: + /** + Pointer to a WW8Stream. + */ + typedef boost::shared_ptr<WW8Stream> Pointer_t; + + /** + Type for the content of the stream + */ + typedef SubSequence<sal_uInt8> Sequence; + + virtual ~WW8Stream(); + + /** + Returns pointer to a substream. + + @param rSid identifier of substream to return + + @return the substream + */ + virtual Pointer_t getSubStream(const ::rtl::OUString & rSid) = 0; + + /** + Return a continious part of the stream. + + @param nOffset offset in the stream where the part starts + @param nCount length of the part (number of bytes) + + @return sequence of unsigned bytes + */ + virtual Sequence get(sal_uInt32 nOffset, sal_uInt32 nCount) + const = 0; + + // Returns the names of substreams contained in the stream + virtual string getSubStreamNames() const = 0; + + virtual uno::Sequence<rtl::OUString> getSubStreamUNames() const = 0; + + /** + Dumps content of stream to output. + + @param o the target output + */ + virtual void dump(OutputWithDepth<string> & o) const = 0; + + //virtual bool put(sal_uInt32 nOffset, const Sequence & rSeq) = 0; +}; + +/** + A property. + +*/ +class WRITERFILTER_DLLPUBLIC WW8Property +{ +public: + /** + Ponter to a property. + */ + typedef boost::shared_ptr<WW8Property> Pointer_t; + + virtual ~WW8Property(); + + virtual sal_uInt32 getId() const = 0; + virtual sal_uInt32 getParam() const = 0; + virtual WW8Stream::Sequence getParams() const = 0; + + virtual string toString() const = 0; + + /** + Dumps this object to an output. + + */ + virtual void dump(OutputWithDepth<string> & o) const = 0; +}; + +/** + An iterator for traversal of a set of properties. + + Sample code for use of iterator: + + \code + Return_t function(WW8PropertySet::tPointer pSet) + { + do_something; + + WW8PropertySetIterator::tPointer pIt = pSet->begin(); + WW8PropertySetIterator::tPointer pItEnd = pSet->end(); + + while ((*pIt) != (*pItEnd)) + { + do_something(); + + ++(*pIt); + } + + do_something; + } + \endcode +*/ +class WRITERFILTER_DLLPUBLIC WW8PropertySetIterator +{ +public: + typedef boost::shared_ptr<WW8PropertySetIterator> Pointer_t; + + virtual ~WW8PropertySetIterator(); + + /** + Advance iterator to the next property. + */ + virtual WW8PropertySetIterator & operator++() = 0; + + /** + Returns a pointer to the property the iterator references. + */ + virtual WW8Property::Pointer_t get() const = 0; + + /** + Checks if the iterator is equal to another one. + */ + virtual bool equal(const WW8PropertySetIterator & rIt) const = 0; + + /** + Returns string representation of iterator. + */ + virtual string toString() const = 0; +}; + +/** + Checks if two property set iterators are not equal. +*/ +bool operator != (const WW8PropertySetIterator & rA, + const WW8PropertySetIterator & rB); + +/** + A set of properties. +*/ +class WRITERFILTER_DLLPUBLIC WW8PropertySet +{ +public: + typedef boost::shared_ptr<WW8PropertySet> Pointer_t; + + virtual ~WW8PropertySet(); + + /** + Returns iterator to the start of the set. + */ + virtual WW8PropertySetIterator::Pointer_t begin() = 0; + + /** + Returns iterator to the end of the set. + */ + virtual WW8PropertySetIterator::Pointer_t end() = 0; + + /** + Dumps property set to output stream. + + @param o output stream to dump property set to + */ + virtual void dump(OutputWithDepth<string> & o) const = 0; + + /** + Iterate through property set and for each element dump a dot + output stream. + + @param o output stream to dump dots to + */ + virtual void dots(ostream & o) = 0; + + virtual bool isPap() const = 0; + virtual sal_uInt32 get_istd() const = 0; + + /** + Insert another property set into this property set. + + @param pSet the set to insert + */ + virtual void insert(const WW8PropertySet::Pointer_t pSet) = 0; +}; + +enum PropertyType { + /** Auxiliary type for character positions defined in piece table */ + PROP_DOC, + + /** properties are section properies */ + PROP_SEC, + + /** properties are paragraph properties */ + PROP_PAP, + + /** properties are character properties */ + PROP_CHP, + + /** a footnote reference */ + PROP_FOOTNOTE, + + /** an endnote reference */ + PROP_ENDNOTE, + + /** an annotaion reference */ + PROP_ANNOTATION, + + /** the start of a bookmark */ + PROP_BOOKMARKSTART, + + /** the end of a bookmark */ + PROP_BOOKMARKEND, + + /** a field character (start, separator or end) */ + PROP_FLD, + + /** a shape character */ + PROP_SHP, + + /** a break character */ + PROP_BRK +}; + +/** + An iterator for traversal of the character positions of a Word + document. + + The use of the iterator is analogous to WW8PropertySetIterator. +*/ +class WRITERFILTER_DLLPUBLIC WW8DocumentIterator +{ +public: + typedef boost::shared_ptr<WW8DocumentIterator> Pointer_t; + + virtual ~WW8DocumentIterator(); + + /** + Advance iterator to next character position of the document. + */ + virtual WW8DocumentIterator & operator++() = 0; + + /** + Recedes iterator to previous character postion of the document. + */ + virtual WW8DocumentIterator & operator--() = 0; + + /** + Returns properties set at the character position the iterator + points to. + + @return pointer to set of properties + */ + virtual writerfilter::Reference<Properties>::Pointer_t getProperties() + const = 0; + + virtual writerfilter::Reference<Stream>::Pointer_t getSubDocument() + const = 0; + + /** + Returns text run at the character position the iterator points + to. + */ + virtual WW8Stream::Sequence getText() = 0; + + /** + Return pointer to the shape at character position the iterator + is pointing to. + */ + virtual writerfilter::Reference<Properties>::Pointer_t getShape() const = 0; + + /** + Checks if the characters of the entity the iterator points to + are complex. + + Complex characters in a Word document are byte size + characters. Non-complex characters are word size characters. + + @retval true The characters are complex. + @retval false The characters are non-complex. + */ + virtual bool isComplex() const = 0; + + /** + Returns the property type of the entity the iterator points to. + */ + virtual PropertyType getPropertyType() const = 0; + + /** + Checks is the iterator is equal to another one. + + @param rIt iterator to check against + + @retval true the iterators are equal + @retval false else + */ + virtual bool equal(const WW8DocumentIterator & rIt) const = 0; + + /** + Returns string representation of the iterator. + */ + virtual string toString() const = 0; + + /** + Dumps the iterator to an output stream. + + @param o the output stream to dump the iterator to + */ + virtual void dump(ostream & o) const = 0; +}; + +/** + Checks if two document iterators are equal. + + @param rA first iterator + @param rB second iterator + + @retval true the document iterators are equal + @retval false else + */ +bool operator == (const WW8DocumentIterator & rA, + const WW8DocumentIterator & rB); + +class WRITERFILTER_DLLPUBLIC SubDocumentId +{ +public: + enum eType { FOOTNOTES, HEADERS, FOOTERS }; + +private: + eType mnType; + sal_uInt8 mnIndex; + +public: + SubDocumentId(eType nType, sal_uInt8 nIndex) + : mnType(nType), mnIndex(nIndex) + { + } + + eType getType() const { return mnType; } + sal_uInt8 getIndex() const { return mnIndex; } +}; + +/** + A Word 8 document. +*/ +class WRITERFILTER_DLLPUBLIC WW8Document : + public writerfilter::Reference<Stream> +{ +public: + typedef boost::shared_ptr<WW8Document> Pointer_t; + + virtual ~WW8Document(); + + /** + Get a subdocument. + + A subdocument can be + + - a header + - a footer + - a footnode + + @param nId identifier of the subdocumen + */ + virtual Pointer_t getSubDocument(SubDocumentId nId) = 0; + + /** + Returns iterator to beginning of document. + */ + virtual WW8DocumentIterator::Pointer_t begin() = 0; + + /** + Returns iterator to end of document. + */ + virtual WW8DocumentIterator::Pointer_t end() = 0; +}; + +class WRITERFILTER_DLLPUBLIC WW8DocumentFactory +{ +public: + static WW8Stream::Pointer_t + createStream(uno::Reference<uno::XComponentContext> rContext, + uno::Reference<io::XInputStream> rStream); + + static WW8Document * + createDocument(WW8Stream::Pointer_t rpStream); +}; + +void sprmidsToXML(::std::iostream & out); + +void doctokidsToXML(::std::iostream & out); + +}} + +#endif // INCLUDED_WW8_DOCUMENT_HXX diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx new file mode 100644 index 000000000000..cb5991c00929 --- /dev/null +++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_OOXML_DOCUMENT_HXX +#define INCLUDED_OOXML_DOCUMENT_HXX + +#include <sal/types.h> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEX_HPP_ +#include <com/sun/star/uno/XComponentContext.hpp> +#endif +#ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX +#include <resourcemodel/WW8ResourceModel.hxx> +#endif +#ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HOO_ +#include <com/sun/star/xml/sax/XParser.hpp> +#endif +#include <com/sun/star/xml/sax/XFastParser.hpp> +#include <com/sun/star/xml/sax/XFastTokenHandler.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> + +/** + @file OOXMLDocument.hxx + + <h1>Import of OOXML WordprocessingML Documents</h1> + + The following picture shows the classes involved in importing OOXML + WordprocessingML documents. + + @image html ooxmlimportchain.png + + The DOCX consists of parts. Each part is an XML document. The + OOXMLDocument opens the DOCX and creates a SAX parser for the part + containing the main document content. The OOXMLDocument creates a + SAX handler, too. This handler is set as the handler for the events + created by the parser. Finally the OOXMLDocument initiates the + parsing process. + + The SAX handler hosts a stack of contexts. Each context is an + instance of a class derived from OOXMLContext. There is a context + class for each <define> in the model.xml. + + For a detailed information about how the contexts are handled see + the documentation for OOXMLContext. + + The contexts know how to convert an element in OOXML to the + intermediate format that the domain mapper understands. They + enumerate the according entity in OOXML by sending the according + events to the domain mapper. + + The domain mapper knows how to convert the intermediate format to + API calls. It takes the events sent by the contexts and uses the + core API to insert the according elements to the core. + */ + +namespace writerfilter { +namespace ooxml +{ + +using namespace com::sun::star; + +class WRITERFILTER_DLLPUBLIC OOXMLStream +{ +public: + enum StreamType_t { UNKNOWN, DOCUMENT, STYLES, FONTTABLE, NUMBERING, + FOOTNOTES, ENDNOTES, COMMENTS, THEME, SETTINGS }; + typedef boost::shared_ptr<OOXMLStream> Pointer_t; + + virtual ~OOXMLStream() {} + + /** + Returns parser for this stream. + */ + virtual uno::Reference<xml::sax::XParser> getParser() = 0; + + /** + Returns fast parser for this stream. + */ + virtual uno::Reference<xml::sax::XFastParser> getFastParser() = 0; + + virtual uno::Reference<io::XInputStream> getDocumentStream() = 0; + + virtual uno::Reference<io::XInputStream> getStorageStream() = 0; + + /** + Returns component context for this stream. + */ + virtual uno::Reference<uno::XComponentContext> getContext() = 0; + + /** + Returns target URL from relationships for a given id. + + @param rId the id to look for + + @return the URL found or an empty string + */ + virtual ::rtl::OUString getTargetForId(const ::rtl::OUString & rId) = 0; + + virtual const ::rtl::OUString & getTarget() const = 0; + + virtual uno::Reference<xml::sax::XFastTokenHandler> + getFastTokenHandler(uno::Reference<uno::XComponentContext> rContext) = 0; + +}; + +class WRITERFILTER_DLLPUBLIC OOXMLDocument : public writerfilter::Reference<Stream> +{ +public: + /** + Pointer to this stream. + */ + typedef boost::shared_ptr<OOXMLDocument> Pointer_t; + + virtual ~OOXMLDocument() {} + + /** + Resolves this document to a stream handler. + + @param rStream stream handler to resolve this document to + */ + virtual void resolve(Stream & rStream) = 0; + + /** + Returns string representation of the type of this reference. + + DEBUGGING PURPOSE ONLY. + */ + virtual string getType() const = 0; + + /** + Resolves a footnote to a stream handler. + + A footnote is resolved if either the note type or + note id matches. + + @param rStream stream handler to resolve to + @param rNoteType type of footnote to resolve + @param rNoteId id of the footnote to resolve + */ + virtual void resolveFootnote(Stream & rStream, + const Id & rNoteType, + const rtl::OUString & rNoteId) = 0; + /** + Resolves an endnote to a stream handler. + + An endnote is resolved if either the note type or + note id matches. + + @param rStream stream handler to resolve to + @param rNoteType type of footnote to resolve + @param rNoteId id of the endnote to resolve + */ + virtual void resolveEndnote(Stream & rStream, + const Id & rNoteType, + const rtl::OUString & rNoteId) = 0; + + /** + Resolves a comment to a stream handler. + + @param rStream stream handler to resolve to + @param rComment id of the comment to resolve + */ + virtual void resolveComment(Stream & rStream, + const rtl::OUString & rCommentId) = 0; + + /** + Resolves a picture to a stream handler. + + @param rStream stream handler to resolve to + @param rPictureId id of the picture to resolve + */ + virtual void resolvePicture(Stream & rStream, + const rtl::OUString & rPictureId) = 0; + + /** + Resolves a header to a stream handler. + + @param rStream stream handler to resolve to + @param type type of header to resolve: + NS_ooxml::LN_Value_ST_HrdFtr_even header on even page + NS_ooxml::LN_Value_ST_HrdFtr_default header on right page + NS_ooxml::LN_Value_ST_HrdFtr_first header on first page + + @param rId id of the header + */ + virtual void resolveHeader(Stream & rStream, + const sal_Int32 type, + const rtl::OUString & rId) = 0; + + /** + Resolves a footer to a stream handler. + + @param rStream stream handler to resolve to + @param type type of footer to resolve: + NS_ooxml::LN_Value_ST_HrdFtr_even header on even page + NS_ooxml::LN_Value_ST_HrdFtr_default header on right page + NS_ooxml::LN_Value_ST_HrdFtr_first header on first page + + @param rId id of the header + */ + virtual void resolveFooter(Stream & rStream, + const sal_Int32 type, + const rtl::OUString & rId) = 0; + + + /** + Returns target URL from relationships for a given id. + + @param rId the id to look for + + @return the URL found or an empty string + */ + virtual ::rtl::OUString getTargetForId(const ::rtl::OUString & rId) = 0; + + virtual void setModel(uno::Reference<frame::XModel> xModel) = 0; + virtual uno::Reference<frame::XModel> getModel() = 0; + virtual void setDrawPage(uno::Reference<drawing::XDrawPage> xDrawPage) = 0; + virtual uno::Reference<drawing::XDrawPage> getDrawPage() = 0; + virtual uno::Reference<io::XInputStream> getInputStream() = 0; + virtual uno::Reference<io::XInputStream> getStorageStream() = 0; + virtual uno::Reference<io::XInputStream> getInputStreamForId + (const ::rtl::OUString & rId) = 0; + virtual void setXNoteId(const rtl::OUString & rId) = 0; + virtual const ::rtl::OUString & getXNoteId() const = 0; + virtual void setXNoteType(const Id & nId) = 0; + virtual const Id & getXNoteType() const = 0; + virtual const ::rtl::OUString & getTarget() const = 0; +}; + + +class WRITERFILTER_DLLPUBLIC OOXMLDocumentFactory +{ +public: + static OOXMLStream::Pointer_t + createStream(uno::Reference<uno::XComponentContext> rContext, + uno::Reference<io::XInputStream> rStream, + OOXMLStream::StreamType_t nStreamType = OOXMLStream::DOCUMENT); + + static OOXMLStream::Pointer_t + createStream(OOXMLStream::Pointer_t pStream, + OOXMLStream::StreamType_t nStreamType = OOXMLStream::DOCUMENT); + + static OOXMLStream::Pointer_t + createStream(OOXMLStream::Pointer_t pStream, const rtl::OUString & rId); + + static OOXMLDocument * + createDocument(OOXMLStream::Pointer_t pStream); + +}; + +void ooxmlidsToXML(::std::iostream & out); + +}} +#endif // INCLUDED_OOXML_DOCUMENT_HXX diff --git a/writerfilter/inc/resourcemodel/Fraction.hxx b/writerfilter/inc/resourcemodel/Fraction.hxx new file mode 100644 index 000000000000..a038d25c98f1 --- /dev/null +++ b/writerfilter/inc/resourcemodel/Fraction.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_FRACTION_HXX +#define INCLUDED_FRACTION_HXX + +#include <sal/types.h> + +namespace writerfilter { +namespace resourcemodel { + +class Fraction +{ +public: + explicit Fraction(sal_Int32 nNumerator, sal_Int32 nDenominator = 1); + explicit Fraction(const Fraction & a, const Fraction & b); + virtual ~Fraction(); + + void init(sal_Int32 nNumerator, sal_Int32 nDenominator); + void assign(const Fraction & rFraction); + + Fraction inverse() const; + + Fraction operator=(const Fraction & rFraction); + Fraction operator+(const Fraction & rFraction) const; + Fraction operator-(const Fraction & rFraction) const; + Fraction operator*(const Fraction & rFraction) const; + Fraction operator/(const Fraction & rFraction) const; + operator sal_Int32() const; + operator float() const; + +private: + sal_Int32 mnNumerator; + sal_Int32 mnDenominator; +}; +}} +#endif // INCLUDED_FRACTION_HXX diff --git a/writerfilter/inc/resourcemodel/LoggedResources.hxx b/writerfilter/inc/resourcemodel/LoggedResources.hxx new file mode 100644 index 000000000000..be30c32fd85e --- /dev/null +++ b/writerfilter/inc/resourcemodel/LoggedResources.hxx @@ -0,0 +1,128 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_LOGGED_RESOURCES_HXX +#define INCLUDED_LOGGED_RESOURCES_HXX + +#include "WW8ResourceModel.hxx" +#include "TagLogger.hxx" + +namespace writerfilter +{ + +class LoggedResourcesHelper +{ +public: + explicit LoggedResourcesHelper(TagLogger::Pointer_t pLogger, const string & sPrefix); + virtual ~LoggedResourcesHelper(); + + void startElement(const string & sElement); + void endElement(const string & sElement); + void chars(const ::rtl::OUString & rChars); + void chars(const string & rChars); + void attribute(const string & rName, const string & rValue); + void attribute(const string & rName, sal_uInt32 nValue); + + void setPrefix(const string & rPrefix); + +private: + TagLogger::Pointer_t mpLogger; + string msPrefix; +}; + +class LoggedStream : public Stream +{ +public: + explicit LoggedStream(TagLogger::Pointer_t pLogger, const string & sPrefix); + virtual ~LoggedStream(); + + void startSectionGroup(); + void endSectionGroup(); + void startParagraphGroup(); + void endParagraphGroup(); + void startCharacterGroup(); + void endCharacterGroup(); + void startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ); + void endShape(); + void text(const sal_uInt8 * data, size_t len); + void utext(const sal_uInt8 * data, size_t len); + void props(writerfilter::Reference<Properties>::Pointer_t ref); + void table(Id name, writerfilter::Reference<Table>::Pointer_t ref); + void substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref); + void info(const string & info); + +protected: + virtual void lcl_startSectionGroup() = 0; + virtual void lcl_endSectionGroup() = 0; + virtual void lcl_startParagraphGroup() = 0; + virtual void lcl_endParagraphGroup() = 0; + virtual void lcl_startCharacterGroup() = 0; + virtual void lcl_endCharacterGroup() = 0; + virtual void lcl_startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ) = 0; + virtual void lcl_endShape() = 0; + virtual void lcl_text(const sal_uInt8 * data, size_t len) = 0; + virtual void lcl_utext(const sal_uInt8 * data, size_t len) = 0; + virtual void lcl_props(writerfilter::Reference<Properties>::Pointer_t ref) = 0; + virtual void lcl_table(Id name, writerfilter::Reference<Table>::Pointer_t ref) = 0; + virtual void lcl_substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref) = 0; + virtual void lcl_info(const string & info) = 0; + + LoggedResourcesHelper mHelper; +}; + +class LoggedProperties : public Properties +{ +public: + explicit LoggedProperties(TagLogger::Pointer_t pLogger, const string & sPrefix); + virtual ~LoggedProperties(); + + void attribute(Id name, Value & val); + void sprm(Sprm & sprm); + +protected: + virtual void lcl_attribute(Id name, Value & val) = 0; + virtual void lcl_sprm(Sprm & sprm) = 0; + + LoggedResourcesHelper mHelper; +}; + +class LoggedTable : public Table +{ +public: + explicit LoggedTable(TagLogger::Pointer_t pLogger, const string & sPrefix); + virtual ~LoggedTable(); + + void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref); + +protected: + virtual void lcl_entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref) = 0; + + LoggedResourcesHelper mHelper; +}; + +} +#endif // INCLUDED_LOGGED_RESOURCES_HXX diff --git a/writerfilter/inc/resourcemodel/OutputWithDepth.hxx b/writerfilter/inc/resourcemodel/OutputWithDepth.hxx new file mode 100644 index 000000000000..b6c4d511ab7c --- /dev/null +++ b/writerfilter/inc/resourcemodel/OutputWithDepth.hxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_OUTPUT_WITH_DEPTH +#define INCLUDED_OUTPUT_WITH_DEPTH + +#include <vector> +#include <iostream> + +namespace writerfilter +{ + +using namespace ::std; + +template <typename T> +class OutputWithDepth +{ + typedef ::std::vector<T> Group_t; + Group_t mGroup; + + unsigned int mnCurrentDepth; + unsigned int mnGroupDepth; + + T mOpenTag; + T mCloseTag; + +protected: + virtual void output(const T & aItem) const = 0; + void outputGroup(); + void finalize(); + +public: + OutputWithDepth(const T & aOpenTag, const T & aCloseTag); + virtual ~OutputWithDepth(); + + void openGroup(); + void closeGroup(); + void addItem(const T & aItem); + void setDepth(unsigned int nDepth); +}; + +template <typename T> +OutputWithDepth<T>::OutputWithDepth(const T & aOpenTag, const T & aEndTag) +: mOpenTag(aOpenTag), mCloseTag(aEndTag) +{ +} + +template <typename T> +OutputWithDepth<T>::~OutputWithDepth() +{ +} + +template <typename T> +void OutputWithDepth<T>::finalize() +{ + outputGroup(); +} + +template <typename T> +void OutputWithDepth<T>::openGroup() +{ + outputGroup(); + mnGroupDepth = 0; +} + +template <typename T> +void OutputWithDepth<T>::closeGroup() +{ + if (mnGroupDepth > mnCurrentDepth) + for (unsigned int i = 0; i < mnGroupDepth - mnCurrentDepth; ++i) + output(mOpenTag); + else if (mnGroupDepth < mnCurrentDepth) + for (unsigned int i = 0; i < mnCurrentDepth - mnGroupDepth; ++i) + output(mCloseTag); + + outputGroup(); + + mnCurrentDepth = mnGroupDepth; +} + +template <typename T> +void OutputWithDepth<T>::addItem(const T & aItem) +{ + mGroup.push_back(aItem); +} + +template <typename T> +void OutputWithDepth<T>::setDepth(unsigned int nDepth) +{ + mnGroupDepth = nDepth; +} + +template <typename T> +void OutputWithDepth<T>::outputGroup() +{ + typename Group_t::iterator aItEnd = mGroup.end(); + + for (typename Group_t::iterator aIt = mGroup.begin(); aIt != aItEnd; aIt++) + { + output(*aIt); + } + + mGroup.clear(); +} +} +#endif // INCLUDED_OUTPUT_WITH_DEPTH diff --git a/writerfilter/inc/resourcemodel/Protocol.hxx b/writerfilter/inc/resourcemodel/Protocol.hxx new file mode 100644 index 000000000000..2f4c9f6261ba --- /dev/null +++ b/writerfilter/inc/resourcemodel/Protocol.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: $ + * $Revision: $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDE_WRITERFILTER_PROTOCOL_HXX +#define INCLUDE_WRITERFILTER_PROTOCOL_HXX + +#ifdef DEBUG + +#include <boost/shared_ptr.hpp> +#include "WW8ResourceModel.hxx" +#include "TagLogger.hxx" +namespace writerfilter +{ + +class StreamProtocol : public Stream +{ + Stream * m_pStream; + TagLogger::Pointer_t m_pTagLogger; + +public: + typedef boost::shared_ptr<StreamProtocol> Pointer_t; + + StreamProtocol(Stream * pStream, TagLogger::Pointer_t pTagLogger); + virtual ~StreamProtocol(); + + virtual void startSectionGroup(); + virtual void endSectionGroup(); + virtual void startParagraphGroup(); + virtual void endParagraphGroup(); + virtual void startCharacterGroup(); + virtual void endCharacterGroup(); + virtual void text(const sal_uInt8 * data, size_t len); + virtual void utext(const sal_uInt8 * data, size_t len); + virtual void props(writerfilter::Reference<Properties>::Pointer_t ref); + virtual void table(Id name, + writerfilter::Reference<Table>::Pointer_t ref); + virtual void substream(Id name, + writerfilter::Reference<Stream>::Pointer_t ref); + virtual void info(const string & rInfo); + virtual void startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ); + virtual void endShape(); +}; + +class PropertiesProtocol : public Properties +{ + Properties * m_pProperties; + TagLogger::Pointer_t m_pTagLogger; + +public: + typedef boost::shared_ptr<PropertiesProtocol> Pointer_t; + + PropertiesProtocol(Properties * pProperties, TagLogger::Pointer_t pTagLogger); + virtual ~PropertiesProtocol(); + + virtual void attribute(Id name, Value & val); + virtual void sprm(Sprm & sprm); +}; + +class TableProtocol : public Table +{ + Table * m_pTable; + TagLogger::Pointer_t m_pTagLogger; + +public: + typedef boost::shared_ptr<TableProtocol> Pointer_t; + + TableProtocol(Table * pTable, TagLogger::Pointer_t pTagLogger); + virtual ~TableProtocol(); + + virtual void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref); +}; + +} + +#endif // DEBUG +#endif // INCLUDE_WRITERFILTER_PROTOCOL_HXX diff --git a/writerfilter/inc/resourcemodel/QNameToString.hxx b/writerfilter/inc/resourcemodel/QNameToString.hxx new file mode 100644 index 000000000000..2c562b74762d --- /dev/null +++ b/writerfilter/inc/resourcemodel/QNameToString.hxx @@ -0,0 +1,88 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_QNAME_TO_STRING_HXX +#define INCLUDED_QNAME_TO_STRING_HXX + +#include <boost/shared_ptr.hpp> +#include <map> +#include <string> +#include <iostream> +#include <resourcemodel/WW8ResourceModel.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> + +namespace writerfilter +{ +using namespace ::std; + +class WRITERFILTER_DLLPUBLIC QNameToString +{ + typedef boost::shared_ptr<QNameToString> Pointer_t; + typedef map < Id, string > Map; + + static Pointer_t pInstance; + + void init_doctok(); + void init_ooxml(); + + Map mMap; + +protected: + /** + Generated. + */ + QNameToString(); + +public: + static Pointer_t Instance(); + + string operator()(Id qName); +}; + +class WRITERFILTER_DLLPUBLIC SprmIdToString +{ + typedef boost::shared_ptr<SprmIdToString> Pointer_t; + + static Pointer_t pInstance; + + map<sal_uInt32, string> mMap; + +protected: + /** + Generated automatically. + */ + SprmIdToString(); + +public: + static Pointer_t Instance(); + string operator()(sal_uInt32 nId); +}; + + + +} + +#endif // INCLUDED_QNAME_TO_STRING_HXX diff --git a/writerfilter/inc/resourcemodel/ResourceModelHelper.hxx b/writerfilter/inc/resourcemodel/ResourceModelHelper.hxx new file mode 100644 index 000000000000..c1c500545055 --- /dev/null +++ b/writerfilter/inc/resourcemodel/ResourceModelHelper.hxx @@ -0,0 +1,40 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_RESOURCE_MODEL_HELPER_HXX +#define INCLUDED_RESOURCE_MODEL_HELPER_HXX + +#include <resourcemodel/WW8ResourceModel.hxx> + +namespace writerfilter { +namespace resourcemodel { + +void WRITERFILTER_DLLPUBLIC resolveSprmProps(Properties & rHandler, Sprm & rSprm); +void WRITERFILTER_DLLPUBLIC resolveAttributeProperties(Properties & rHandler, Value & rValue); + +}} + +#endif // INCLUDED_RESOURCE_MODEL_HELPER_HXX diff --git a/writerfilter/inc/resourcemodel/SubSequence.hxx b/writerfilter/inc/resourcemodel/SubSequence.hxx new file mode 100644 index 000000000000..5f03d6ba94bf --- /dev/null +++ b/writerfilter/inc/resourcemodel/SubSequence.hxx @@ -0,0 +1,351 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_SUB_SEQUENCE_HXX +#define INCLUDED_SUB_SEQUENCE_HXX + +#include <com/sun/star/uno/Sequence.hxx> + +#include <boost/shared_ptr.hpp> +#include <iostream> +#include <stdio.h> +#include <ctype.h> +#include "exceptions.hxx" +#include <WriterFilterDllApi.hxx> +#include <resourcemodel/OutputWithDepth.hxx> + +namespace writerfilter { +using namespace ::std; + +template <class T> +class SubSequence; + +template <typename T> +void dumpLine(OutputWithDepth<string> & o, SubSequence<T> & rSeq, + sal_uInt32 nOffset, sal_uInt32 nStep); + +template <class T> +class WRITERFILTER_DLLPUBLIC SubSequence +{ + typedef boost::shared_ptr<com::sun::star::uno::Sequence<T> > + SequencePointer; + + SequencePointer mpSequence; + sal_uInt32 mnOffset; + sal_uInt32 mnCount; + +public: + typedef boost::shared_ptr<SubSequence> Pointer_t; + + SubSequence() : mpSequence(new ::com::sun::star::uno::Sequence<T>()), + mnOffset(0), mnCount(0) + { + } + + SubSequence(SequencePointer pSequence, sal_uInt32 nOffset_, + sal_uInt32 nCount_) + : mpSequence(pSequence), mnOffset(nOffset_), mnCount(nCount_) + { + } + + SubSequence(SequencePointer pSequence) + : mpSequence(pSequence), mnOffset(0), mnCount(pSequence->getLength()) + { + } + + SubSequence(const SubSequence & rSubSequence, sal_uInt32 nOffset_, + sal_uInt32 nCount_) + : mpSequence(rSubSequence.mpSequence), + mnOffset(rSubSequence.mnOffset + nOffset_), + mnCount(nCount_) + { + } + + SubSequence(const T * pStart, sal_uInt32 nCount_) + : mpSequence(new com::sun::star::uno::Sequence<T>(pStart, nCount_)), + mnOffset(0), mnCount(nCount_) + { + } + + SubSequence(sal_Int32 nCount_) + : mpSequence(new com::sun::star::uno::Sequence<T>(nCount_)), mnOffset(0), + mnCount(nCount_) + { + } + + ::com::sun::star::uno::Sequence<T> & getSequence() + { + return *mpSequence; + } + + const ::com::sun::star::uno::Sequence<T> & getSequence() const + { + return *mpSequence; + } + + void reset() { + mnOffset = 0; + mnCount = mpSequence->getLength(); + } + + sal_uInt32 getOffset() const { return mnOffset; } + sal_uInt32 getCount() const { return mnCount; } + + const T & operator[] (sal_uInt32 nIndex) const + { + if (mnOffset + nIndex >= + sal::static_int_cast<sal_uInt32>(mpSequence->getLength())) + throw ExceptionOutOfBounds("SubSequence::operator[]"); + + return (*mpSequence)[mnOffset + nIndex]; + } + + void dump(ostream & o) const + { + { + char sBuffer[256]; + + snprintf(sBuffer, sizeof(sBuffer), + "<sequence id='%p' offset='%lx' count='%lx'>", + mpSequence.get(), mnOffset, mnCount); + o << sBuffer << endl; + } + + sal_uInt32 n = 0; + sal_uInt32 nStep = 16; + + while (n < getCount()) + { + char sBuffer[256]; + + o << "<line>"; + + snprintf(sBuffer, 255, "%08lx: ", n); + + o << sBuffer; + + for (sal_uInt32 i = 0; i < nStep; i++) + { + if (n + i < getCount()) + { + snprintf(sBuffer, 255, "%02x ", operator[](n + i)); + o << sBuffer; + } + else + o << " "; + + if (i % 8 == 7) + o << " "; + } + + { + for (sal_uInt32 i = 0; i < nStep; i++) + { + if (n + i < getCount()) + { + unsigned char c = + static_cast<unsigned char>(operator[](n + i)); + + if (c=='&') + o << "&"; + else if (c=='<') + o << "<"; + else if (c=='>') + o << ">"; + else if (c < 128 && isprint(c)) + o << c; + else + o << "."; + } + + } + } + + o << "</line>" << endl; + + n += nStep; + } + + o << "</sequence>" << endl; + } + + void dump(OutputWithDepth<string> & o) + { + { + char sBuffer[256]; + + snprintf(sBuffer, sizeof(sBuffer), + "<sequence id='%p' offset='%" SAL_PRIxUINT32 "' count='%" SAL_PRIxUINT32 "'>", + mpSequence.get(), mnOffset, mnCount); + o.addItem(sBuffer); + } + + sal_uInt32 n = 0; + sal_uInt32 nStep = 16; + + try + { + sal_uInt32 nCount = getCount(); + while (n < nCount) + { + sal_uInt32 nBytes = nCount - n; + + if (nBytes > nStep) + nBytes = nStep; + + SubSequence<T> aSeq(*this, n, nBytes); + dumpLine(o, aSeq, n, nStep); + + n += nBytes; + } + } + catch (...) + { + o.addItem("<exception/>"); + } + + o.addItem("</sequence>"); + } + + string toString() const + { + sal_uInt32 n = 0; + sal_uInt32 nStep = 16; + + string sResult; + + while (n < getCount()) + { + char sBuffer[256]; + + snprintf(sBuffer, 255, "<line>%08" SAL_PRIxUINT32 ": ", n); + + sResult += sBuffer; + + for (sal_uInt32 i = 0; i < nStep; i++) + { + if (n + i < getCount()) + { + snprintf(sBuffer, 255, "%02x ", operator[](n + i)); + sResult += sBuffer; + } + else + sResult += " "; + + if (i % 8 == 7) + sResult += " "; + } + + { + for (sal_uInt32 i = 0; i < nStep; i++) + { + if (n + i < getCount()) + { + unsigned char c = + static_cast<unsigned char>(operator[](n + i)); + + if (c=='&') + sResult += "&"; + else if (c=='<') + sResult += "<"; + else if (c=='>') + sResult += ">"; + else if (c < 128 && isprint(c)) + sResult += c; + else + sResult += "."; + } + } + } + + sResult += "</line>\n"; + + n += nStep; + } + + return sResult; + } +}; + +template <typename T> +void dumpLine(OutputWithDepth<string> & o, SubSequence<T> & rSeq, + sal_uInt32 nOffset, sal_uInt32 nStep) +{ + sal_uInt32 nCount = rSeq.getCount(); + char sBuffer[256]; + + string tmpStr = "<line>"; + + snprintf(sBuffer, 255, "%08" SAL_PRIxUINT32 ": ", nOffset); + + tmpStr += sBuffer; + + for (sal_uInt32 i = 0; i < nStep; i++) + { + if (i < nCount) + { + snprintf(sBuffer, 255, "%02x ", rSeq[i]); + tmpStr += sBuffer; + } + else + tmpStr += " "; + + if (i % 8 == 7) + tmpStr += " "; + } + + { + for (sal_uInt32 i = 0; i < nStep; i++) + { + if (i < nCount) + { + unsigned char c = + static_cast<unsigned char>(rSeq[i]); + + if (c=='&') + tmpStr += "&"; + else if (c=='<') + tmpStr += "<"; + else if (c=='>') + tmpStr += ">"; + else if (c < 128 && isprint(c)) + tmpStr += c; + else + tmpStr += "."; + } + + } + } + + tmpStr += "</line>"; + + o.addItem(tmpStr); +} + +} + +#endif // INCLUDED_SUB_SEQUENCE_HXX diff --git a/writerfilter/inc/resourcemodel/TableData.hxx b/writerfilter/inc/resourcemodel/TableData.hxx new file mode 100644 index 000000000000..aca4fce71064 --- /dev/null +++ b/writerfilter/inc/resourcemodel/TableData.hxx @@ -0,0 +1,426 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_TABLE_DATA +#define INCLUDED_TABLE_DATA + +#ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX +#include <resourcemodel/WW8ResourceModel.hxx> +#endif + +#include <vector> +#include <boost/shared_ptr.hpp> + +namespace writerfilter +{ + +template <typename T, typename PropertiesPointer> +/** + Class containing the data to describe a table cell. + */ +class WRITERFILTER_DLLPUBLIC CellData +{ + /** + Handle to start of cell. + */ + T mStart; + + /** + Handle to end of cell. + */ + T mEnd; + + /** + Pointer to properties of cell. + */ + PropertiesPointer mpProps; + + bool mbOpen; + +public: + typedef boost::shared_ptr<CellData> Pointer_t; + + CellData(T start, PropertiesPointer pProps) + : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true) + { + } + + virtual ~CellData() {} + + /** + Set the start handle of the cell. + + @param start the start handle of the cell + */ + void setStart(T start) { mStart = start; } + + /** + Set the end handle of a cell. + + @param end the end handle of the cell + */ + void setEnd(T end) { mEnd = end; mbOpen = false; } + + /** + Set the properties of the cell. + + @param pProps the properties of the cell + */ + void setProperties(PropertiesPointer pProps) { mpProps = pProps; } + + /** + Adds properties to the cell. + + @param pProps the properties to add + */ + void insertProperties(PropertiesPointer pProps) + { + if( mpProps.get() ) + mpProps->insert(pProps); + else + mpProps = pProps; + } + + /** + Return start handle of the cell. + */ + const T & getStart() { return mStart; } + + /** + Return end handle of the cell. + */ + const T & getEnd() { return mEnd; } + + /** + Return properties of the cell. + */ + PropertiesPointer getProperties() { return mpProps; } + + bool isOpen() const { return mbOpen; } +}; + +template <typename T, typename PropertiesPointer> +/** + Class to handle data of a table row. + */ +class WRITERFILTER_DLLPUBLIC RowData +{ + typedef typename CellData<T, PropertiesPointer>::Pointer_t + CellDataPointer_t; + typedef ::std::vector<CellDataPointer_t> Cells; + + /** + the cell data of the row + */ + Cells mCells; + + /** + the properties of the row + */ + mutable PropertiesPointer mpProperties; + +public: + typedef boost::shared_ptr<RowData <T, PropertiesPointer> > Pointer_t; + + RowData() {} + + RowData(const RowData<T, PropertiesPointer> & rRowData) + : mCells(rRowData.mCells), mpProperties(rRowData.mpProperties) + { + } + + virtual ~RowData() {} + + /** + Add a cell to the row. + + @param start the start handle of the cell + @param end the end handle of the cell + @param pProps the properties of the cell + */ + void addCell(const T & start, PropertiesPointer pProps) + { + CellDataPointer_t pCellData + (new CellData<T, PropertiesPointer>(start, pProps)); + mCells.push_back(pCellData); + } + + void endCell(const T & end) + { + if (mCells.size() > 0) + mCells.back()->setEnd(end); + } + + bool isCellOpen() const + { + return mCells.size() > 0 && mCells.back()->isOpen(); + } + + /** + Add properties to the row. + + @param pProperties the properties to set + */ + void insertProperties(PropertiesPointer pProperties) + { + if( pProperties.get() ) + { + if( !mpProperties.get() ) + mpProperties = pProperties; + else + mpProperties->insert( pProperties ); + } + } + + /** + Add properties to a cell of the row. + + @param i index of the cell + @param pProps the properties to add + */ + void insertCellProperties(unsigned int i, PropertiesPointer pProps) + { + mCells[i]->insertProperties(pProps); + } + + /** + Add properties to the last cell of the row. + */ + void insertCellProperties(PropertiesPointer pProps) + { + if (! mCells.empty()) + mCells.back()->insertProperties(pProps); + } + + /** + Return number of cells in the row. + */ + unsigned int getCellCount() + { + return mCells.size(); + } + + /** + Return start handle of a cell in the row. + + @param i index of the cell + */ + const T & getCellStart(unsigned int i) const + { + return mCells[i]->getStart(); + } + + /** + Return end handle of a cell in the row. + + @param i index of the cell + */ + const T & getCellEnd(unsigned int i) const + { + return mCells[i]->getEnd(); + } + + /** + Return the properties of a cell in the row. + + @param i index of the cell + */ + PropertiesPointer getCellProperties(unsigned int i) const + { + return mCells[i]->getProperties(); + } + + /** + Return properties of the row. + */ + PropertiesPointer getProperties() + { + return mpProperties; + } + + /** + Clear the row data. + */ + void clear() + { + mCells.clear(); + mpProperties.reset(); + } +}; + +template <typename T, typename PropertiesPointer> +/** + Class that holds the data of a table. + */ +class WRITERFILTER_DLLPUBLIC TableData +{ + typedef typename RowData<T, PropertiesPointer>::Pointer_t RowPointer_t; + typedef ::std::vector<RowPointer_t> Rows; + + /** + the table properties + */ + PropertiesPointer mpTableProps; + + /** + the data of the rows of the table + */ + Rows mRows; + + /** + pointer to the data of the current row (while building up the table data). + */ + RowPointer_t mpRow; + + /** + depth of the current table in a hierarchy of tables + */ + unsigned int mnDepth; + + /** + initialize mpRow + */ + void newRow() { mpRow = RowPointer_t(new RowData<T, PropertiesPointer>()); } + +public: + typedef boost::shared_ptr<TableData <T, PropertiesPointer> > Pointer_t; + + TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); } + ~TableData() {} + + /** + End the current row. + + Sets properties of the current row and pushes the row to the + back of the rows currently contained in the table. + + @param pProperties properties of the row to be ended + */ + void endRow(PropertiesPointer pProperties) + { + mpRow->insertProperties(pProperties); + mRows.push_back(mpRow); + newRow(); + } + + /** + Add a cell to the current row. + + @param start start handle of the cell + @param end end handle of the cell + @param pProps properties of the cell + */ + void addCell(const T & start, PropertiesPointer pProps) + { + mpRow->addCell(start, pProps); + } + + /** + End the current cell of the current row. + + @parm end end handle of the cell + */ + void endCell(const T & end) + { + mpRow->endCell(end); + } + + /** + Return if the current cell of the current row is open. + */ + bool isCellOpen() const + { + return mpRow->isCellOpen(); + } + + /** + Insert properties to the current cell of the current row. + + @param pProps the properties to add + */ + void insertCellProperties(PropertiesPointer pProps) + { + mpRow->insertCellProperties(pProps); + } + + /** + Add properties to a cell of the current row. + + @param i index of the cell + @param pProps properties to add + */ + void insertCellProperties(unsigned int i, PropertiesPointer pProps) + { + mpRow->insertCellProperties(i, pProps); + } + + void insertTableProperties( PropertiesPointer pProps ) + { + if ( mpTableProps.get( ) ) + mpTableProps->insert( pProps ); + else + mpTableProps = pProps; + } + + /** + Return the table properties. + */ + PropertiesPointer getTableProperties( ) + { + return mpTableProps; + } + + /** + Return number of rows in the table. + */ + unsigned int getRowCount() + { + return mRows.size(); + } + + /** + Return depth of table in surrounding table hierarchy. + */ + unsigned int getDepth() + { + return mnDepth; + } + + /** + Return row data of a certain row. + + @param i index of the row + */ + const RowPointer_t getRow(unsigned int i) const + { + return mRows[i]; + } +}; + +} + +#endif // INCLUDED_TABLE_DATA diff --git a/writerfilter/inc/resourcemodel/TableManager.hxx b/writerfilter/inc/resourcemodel/TableManager.hxx new file mode 100644 index 000000000000..fe43694d25d2 --- /dev/null +++ b/writerfilter/inc/resourcemodel/TableManager.hxx @@ -0,0 +1,1099 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_TABLE_MANAGER_HXX +#define INCLUDED_TABLE_MANAGER_HXX + +#ifndef INCLUDED_TABLE_DATA_HXX +#include <resourcemodel/TableData.hxx> +#endif + +#ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX +#include <resourcemodel/WW8ResourceModel.hxx> +#endif + +#ifndef INCLUDED_SPRMIDS_HXX +#include <doctok/sprmids.hxx> +#endif + +#include <boost/shared_ptr.hpp> +#include <stack> +#include "util.hxx" +#include "TagLogger.hxx" + +namespace writerfilter +{ + +using namespace ::std; + +template <typename T, typename PropertiesPointer> +/** + Class to handle events generated by TableManager::resolveCurrentTable + */ +class WRITERFILTER_DLLPUBLIC TableDataHandler +{ +public: + typedef boost::shared_ptr<TableDataHandler> Pointer_t; + + /** + Handle start of table. + + @param nRows number of rows in the table + @param nDepth depth of the table in surrounding table hierarchy + @param pProps properties of the table + */ + virtual void startTable(unsigned int nRows, unsigned int nDepth, + PropertiesPointer pProps) = 0; + + /** + Handle end of table. + */ + virtual void endTable() = 0; + + /** + Handle start of row. + + @param nCols number of columns in the table + @param pProps properties of the row + */ + virtual void startRow(unsigned int nCols, + PropertiesPointer pProps) = 0; + + /** + Handle end of row. + */ + virtual void endRow() = 0; + + /** + Handle start of cell. + + @param rT start handle of the cell + @param pProps properties of the cell + */ + virtual void startCell(const T & rT, PropertiesPointer pProps) = 0; + + /** + Handle end of cell. + + @param rT end handle of cell + */ + virtual void endCell(const T & rT) = 0; +}; + +template <typename T, typename PropertiesPointer> +/** + The table manager. + + This class gets forwarded events from the tokenizer. It gathers the + table data and after ending the table generates events for the + table structure. The events have to be handles by a TableDataHandler. + + */ +class TableManager +{ +#ifdef DEBUG_TABLE + TagLogger::Pointer_t mpTableLogger; +#endif + + class TableManagerState + { + /** + properties at the current point in document + */ + PropertiesPointer mpProps; + + /** + properties of the current cell + */ + PropertiesPointer mpCellProps; + + /** + properties of the current row + */ + PropertiesPointer mpRowProps; + + /** + properties of the current table + */ + stack<PropertiesPointer> mTableProps; + + /** + true if at the end of a row + */ + bool mbRowEnd; + + /** + true when in a cell + */ + bool mbInCell; + + /** + true when at the end of a cell + */ + bool mbCellEnd; + + public: + /** + Constructor + */ + TableManagerState() + : mbRowEnd(false), mbInCell(false), mbCellEnd(false) + { + } + + virtual ~TableManagerState() + { + } + + void startLevel() + { + PropertiesPointer pProps; + mTableProps.push(pProps); + } + + void endLevel() + { + mTableProps.pop(); + } + + /** + Reset to initial state at beginning of row. + */ + void resetCellSpecifics() + { + mbRowEnd = false; + mbInCell = false; + mbCellEnd = false; + } + + void resetProps() + { + mpProps.reset(); + } + + void setProps(PropertiesPointer pProps) + { + mpProps = pProps; + } + + PropertiesPointer getProps() + { + return mpProps; + } + + void resetCellProps() + { + mpCellProps.reset(); + } + + void setCellProps(PropertiesPointer pProps) + { + mpCellProps = pProps; + } + + PropertiesPointer getCellProps() + { + return mpCellProps; + } + + void resetRowProps() + { + mpCellProps.reset(); + } + + void setRowProps(PropertiesPointer pProps) + { + mpRowProps = pProps; + } + + PropertiesPointer getRowProps() + { + return mpRowProps; + } + + void resetTableProps() + { + if (mTableProps.size() > 0) + mTableProps.top().reset(); + } + + void setTableProps(PropertiesPointer pProps) + { + if (mTableProps.size() > 0) + mTableProps.top() = pProps; + } + + PropertiesPointer getTableProps() + { + PropertiesPointer pResult; + + if (mTableProps.size() > 0) + pResult = mTableProps.top(); + + return pResult; + } + + void setInCell(bool bInCell) + { + mbInCell = bInCell; + } + + bool isInCell() const + { + return mbInCell; + } + + void setCellEnd(bool bCellEnd) + { + mbCellEnd = bCellEnd; + } + + bool isCellEnd() const + { + return mbCellEnd; + } + + void setRowEnd(bool bRowEnd) + { + mbRowEnd = bRowEnd; + } + + bool isRowEnd() const + { + return mbRowEnd; + } + }; + + /** + handle for the current position in document + */ + T mCurHandle; + + TableManagerState mState; + +protected: + PropertiesPointer getProps() + { + return mState.getProps(); + } + + void setProps(PropertiesPointer pProps) + { + mState.setProps(pProps); + } + + void resetProps() + { + mState.resetProps(); + } + + PropertiesPointer getCellProps() + { + return mState.getCellProps(); + } + + void setCellProps(PropertiesPointer pProps) + { + mState.setCellProps(pProps); + } + + void resetCellProps() + { + mState.resetCellProps(); + } + + PropertiesPointer getRowProps() + { + return mState.getRowProps(); + } + + void setRowProps(PropertiesPointer pProps) + { + mState.setRowProps(pProps); + } + + void resetRowProps() + { + mState.resetRowProps(); + } + + void setInCell(bool bInCell) + { + mState.setInCell(bInCell); + } + + bool isInCell() const + { + return mState.isInCell(); + } + + void setCellEnd(bool bCellEnd) + { + mState.setCellEnd(bCellEnd); + } + + bool isCellEnd() const + { + return mState.isCellEnd(); + } + + void setRowEnd(bool bRowEnd) + { + mState.setRowEnd(bRowEnd); + } + + bool isRowEnd() const + { + return mState.isRowEnd(); + } + + PropertiesPointer getTableProps() + { + return mState.getTableProps(); + } + + void setTableProps(PropertiesPointer pProps) + { + mState.setTableProps(pProps); + } + + void resetTableProps() + { + mState.resetTableProps(); + } + + T getHandle() + { + return mCurHandle; + } + + void setHandle(const T & rHandle) + { + mCurHandle = rHandle; + } + +private: + typedef boost::shared_ptr<T> T_p; + + /** + depth of the current cell + */ + sal_uInt32 mnTableDepthNew; + + /** + depth of the previous cell + */ + sal_uInt32 mnTableDepth; + + /** + stack of table data + + for each level of nested tables there is one frame in the stack + */ + stack<typename TableData<T, PropertiesPointer>::Pointer_t > mTableDataStack; + + typedef typename TableDataHandler<T, PropertiesPointer>::Pointer_t TableDataHandlerPointer_t; + + /** + handler for resolveCurrentTable + */ + TableDataHandlerPointer_t mpTableDataHandler; + + /** + Set flag which indicates the current handle is in a cell. + */ + void inCell(); + + /** + Set flag which indicate the current handle is at the end of a cell. + */ + void endCell(); + + /** + Set the table depth of the current cell. + + @param nDepth the cell depth + */ + void cellDepth(sal_uInt32 nDepth); + + /** + Set flag indication the current handle is at the end of a row. + */ + void endRow(); + + /** + Resolve the current table to the TableDataHandler. + */ + void resolveCurrentTable(); + + /** + Open a cell at current level. + */ + + void openCell(const T & handle, PropertiesPointer pProps); + + /** + Close a cell at current level. + */ + void closeCell(const T & handle); + + /** + Ensure a cell is open at the current level. + */ + void ensureOpenCell(PropertiesPointer pProps); + +protected: + + /** + Return current table depth. + */ + sal_uInt32 getTableDepthNew() { return mnTableDepthNew; } + + /** + Action to be carried out at the end of the last paragraph of a + cell. + */ + virtual void endOfCellAction(); + + /** + Action to be carried out at the end of the "table row" + paragraph. + */ + virtual void endOfRowAction(); + /** let the derived class clear their table related data + */ + virtual void clearData(); + + +public: + TableManager(); + virtual ~TableManager(){} + + /** + Set handler for resolveCurrentTable. + + @param pTableDataHandler the handler + */ + void setHandler(TableDataHandlerPointer_t pTableDataHandler); + + /** + Set the current handle. + + @param rHandle the handle + */ + virtual void handle(const T & rHandle); + + /** + Start a new table level. + + A new context is pushed onto the table data stack, + */ + virtual void startLevel(); + + /** + End a table level. + + The current table is resolved and the context is popped from + the stack. + */ + virtual void endLevel(); + + /** + Handle the start of a paragraph group. + */ + virtual void startParagraphGroup(); + + /** + Handle the end of a paragraph group. + */ + virtual void endParagraphGroup(); + + /** + Handle an SPRM at curent handle. + + @param rSprm the SPRM + */ + virtual bool sprm(Sprm & rSprm); + + /** + Handle properties at current handle. + + @param pProps the properites + */ + virtual void props(PropertiesPointer pProps); + + /** + Handle occurance of character 0x7. + */ + virtual void handle0x7(); + + /** + Handle 8 bit text at current handle. + + @param data array of characters + @param len number of characters to handle + */ + virtual void text(const sal_uInt8 * data, size_t len); + + /** + Handle 16 bit text at current handle. + + @param data array of characters + @param len number of characters to handle + */ + virtual void utext(const sal_uInt8 * data, size_t len); + + /** + Handle properties of the current cell. + + @param pProps the properties + */ + virtual void cellProps(PropertiesPointer pProps); + + /** + Handle properties of a certain cell in the current row. + + @paran i index of the cell in the current row + @param pProps the properties + */ + virtual void cellPropsByCell(unsigned int i, PropertiesPointer pProps); + + /** + Handle properties of the current row. + + @param pProps the properties + */ + virtual void insertRowProps(PropertiesPointer pProps); + + /** + Handle properties of the current table. + + @param pProps the properties + */ + virtual void insertTableProps(PropertiesPointer pProps); + + /** + Return if table manager has detected paragraph to ignore. + + If this function returns true the current paragraph contains + only control information, e.g. end of row. + */ + virtual bool isIgnore() const; + + +#ifdef DEBUG_TABLE + void setTagLogger(TagLogger::Pointer_t _tagLogger) + { + mpTableLogger = _tagLogger; + } +#endif +}; + +template <typename T, typename PropertiesPointer> +TableManager<T, PropertiesPointer>::TableManager() +: mnTableDepthNew(0), mnTableDepth(0) +{ + setRowEnd(false); + setInCell(false); + setCellEnd(false); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth) +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + { + mpTableLogger->startElement("tablemanager.cellDepth"); + mpTableLogger->attribute("depth", nDepth); + mpTableLogger->endElement("tablemanager.cellDepth"); + } +#endif + + mnTableDepthNew = nDepth; +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::inCell() +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->element("tablemanager.inCell"); +#endif + setInCell(true); + + if (mnTableDepthNew < 1) + mnTableDepthNew = 1; +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::endCell() +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->element("tablemanager.endCell"); +#endif + + setCellEnd(true); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::endRow() +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->element("tablemanager.endRow"); +#endif + + setRowEnd(true); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::setHandler +(typename TableDataHandler<T, PropertiesPointer>::Pointer_t pTableDataHandler) +{ + mpTableDataHandler = pTableDataHandler; +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::handle(const T & rHandle) +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get()) + { + mpTableLogger->startElement("tablemanager.handle"); + mpTableLogger->chars(toString(rHandle)); + mpTableLogger->endElement("tablemanager.handle"); + } +#endif + + setHandle(rHandle); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::startLevel() +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + { + typename TableData<T, PropertiesPointer>::Pointer_t pTableData; + + if (mTableDataStack.size() > 0) + pTableData = mTableDataStack.top(); + + mpTableLogger->startElement("tablemanager.startLevel"); + mpTableLogger->attribute("level", mTableDataStack.size()); + + if (pTableData.get() != NULL) + mpTableLogger->attribute("openCell", + pTableData->isCellOpen() ? "yes" : "no"); + + mpTableLogger->endElement("tablemanager.startLevel"); + } +#endif + + typename TableData<T, PropertiesPointer>::Pointer_t pTableData + (new TableData<T, PropertiesPointer>(mTableDataStack.size())); + + mTableDataStack.push(pTableData); + mState.startLevel(); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::endLevel() +{ + if (mpTableDataHandler.get() != NULL) + resolveCurrentTable(); + + mState.endLevel(); + mTableDataStack.pop(); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + { + typename TableData<T, PropertiesPointer>::Pointer_t pTableData; + + if (mTableDataStack.size() > 0) + pTableData = mTableDataStack.top(); + + mpTableLogger->startElement("tablemanager.endLevel"); + mpTableLogger->attribute("level", mTableDataStack.size()); + + if (pTableData.get() != NULL) + mpTableLogger->attribute("openCell", + pTableData->isCellOpen() ? "yes" : "no"); + + mpTableLogger->endElement("tablemanager.endLevel"); + } +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::startParagraphGroup() +{ + mState.resetCellSpecifics(); + mnTableDepthNew = 0; +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::endParagraphGroup() +{ + sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth; + + PropertiesPointer pEmptyProps; + + while (nTableDepthDifference > 0) + { + ensureOpenCell(pEmptyProps); + startLevel(); + + --nTableDepthDifference; + } + while (nTableDepthDifference < 0) + { + endLevel(); + + ++nTableDepthDifference; + } + + mnTableDepth = mnTableDepthNew; + + if (mnTableDepth > 0) + { + typename TableData<T, PropertiesPointer>::Pointer_t pTableData = + mTableDataStack.top(); + + if (isRowEnd()) + { + endOfRowAction(); + pTableData->endRow(getRowProps()); + resetRowProps(); + } + + else if (isInCell()) + { + ensureOpenCell(getCellProps()); + + if (isCellEnd()) + { + endOfCellAction(); + closeCell(getHandle()); + } + } + resetCellProps(); + } +} + +template <typename T, typename PropertiesPointer> +bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm) +{ + bool bRet = true; + switch (rSprm.getId()) + { + case NS_sprm::LN_PTableDepth: + { + Value::Pointer_t pValue = rSprm.getValue(); + + cellDepth(pValue->getInt()); + } + break; + case NS_sprm::LN_PFInTable: + inCell(); + break; + case NS_sprm::LN_PCell: + endCell(); + break; + case NS_sprm::LN_PFTtp: + case NS_sprm::LN_PRow: + endRow(); + break; + default: + bRet = false; + } + return bRet; +} +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::props(PropertiesPointer pProps) +{ + setProps(pProps); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::handle0x7() +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->startElement("tablemanager.handle0x7"); +#endif + + if (mnTableDepthNew < 1) + mnTableDepthNew = 1; + + if (isInCell()) + endCell(); + else + endRow(); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->endElement("tablemanager.handle0x7"); +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len) +{ + // optimization: cell/row end characters are the last characters in a run + if (len > 0) + { + if (data[len - 1] == 0x7) + handle0x7(); + } +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t len) +{ + // optimization: cell/row end characters are the last characters in a run + + if (len > 0) + { + sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8); + if (nChar == 0x7) + handle0x7(); + } +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps) +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->startElement("tablemanager.cellProps"); +#endif + + if(getCellProps().get()) + getCellProps()->insert( pProps ); + else + setCellProps(pProps); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->endElement("tablemanager.cellProps"); +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::cellPropsByCell +(unsigned int i, PropertiesPointer pProps) +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->startElement("tablemanager.cellPropsByCell"); +#endif + + mTableDataStack.top()->insertCellProperties(i, pProps); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->endElement("tablemanager.cellPropsByCell"); +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps) +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->startElement("tablemanager.insertRowProps"); +#endif + + if( getRowProps().get() ) + getRowProps()->insert( pProps ); + else + setRowProps(pProps); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->endElement("tablemanager.insertRowProps"); +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pProps) +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->startElement("tablemanager.insertTableProps"); +#endif + + if( getTableProps().get() ) + getTableProps()->insert( pProps ); + else + setTableProps(pProps); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->endElement("tablemanager.insertTableProps"); +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::resolveCurrentTable() +{ +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->startElement("tablemanager.resolveCurrentTable"); +#endif + + if (mpTableDataHandler.get() != NULL) + { + typename TableData<T, PropertiesPointer>::Pointer_t + pTableData = mTableDataStack.top(); + + unsigned int nRows = pTableData->getRowCount(); + + mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps()); + + for (unsigned int nRow = 0; nRow < nRows; ++nRow) + { + typename RowData<T, PropertiesPointer>::Pointer_t pRowData = pTableData->getRow(nRow); + + unsigned int nCells = pRowData->getCellCount(); + + mpTableDataHandler->startRow(nCells, pRowData->getProperties()); + + for (unsigned int nCell = 0; nCell < nCells; ++nCell) + { + mpTableDataHandler->startCell + (pRowData->getCellStart(nCell), + pRowData->getCellProperties(nCell)); + + mpTableDataHandler->endCell(pRowData->getCellEnd(nCell)); + } + + mpTableDataHandler->endRow(); + } + + mpTableDataHandler->endTable(); + } + resetTableProps(); + clearData(); + +#ifdef DEBUG_TABLE + if (mpTableLogger.get() != NULL) + mpTableLogger->endElement("tablemanager.resolveCurrentTable"); +#endif +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::endOfCellAction() +{ +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::endOfRowAction() +{ +} + +template <typename T, typename PropertiesPointer> +bool TableManager<T, PropertiesPointer>::isIgnore() const +{ + return isRowEnd(); +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::clearData() +{ +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::openCell +(const T & rHandle, PropertiesPointer pProps) +{ +#ifdef DEBUG_TABLE + mpTableLogger->startElement("tablemanager.openCell"); + mpTableLogger->chars(toString(rHandle)); + mpTableLogger->endElement("tablemanager.openCell"); +#endif + + if (mTableDataStack.size() > 0) + { + typename TableData<T, PropertiesPointer>::Pointer_t + pTableData = mTableDataStack.top(); + + pTableData->addCell(rHandle, pProps); + } +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::closeCell +(const T & rHandle) +{ +#ifdef DEBUG_TABLE + mpTableLogger->startElement("tablemanager.closeCell"); + mpTableLogger->chars(toString(rHandle)); + mpTableLogger->endElement("tablemanager.closeCell"); +#endif + + if (mTableDataStack.size() > 0) + { + typename TableData<T, PropertiesPointer>::Pointer_t + pTableData = mTableDataStack.top(); + + pTableData->endCell(rHandle); + } +} + +template <typename T, typename PropertiesPointer> +void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProps) +{ +#ifdef DEBUG_TABLE + mpTableLogger->startElement("tablemanager.ensureOpenCell"); +#endif + + if (mTableDataStack.size() > 0) + { + typename TableData<T, PropertiesPointer>::Pointer_t + pTableData = mTableDataStack.top(); + + if (pTableData.get() != NULL) + { + if (!pTableData->isCellOpen()) + openCell(getHandle(), pProps); + else + pTableData->insertCellProperties(pProps); + } + } +#ifdef DEBUG_TABLE + mpTableLogger->endElement("tablemanager.ensureOpenCell"); +#endif +} + +} + +#endif // INCLUDED_TABLE_MANAGER_HXX diff --git a/writerfilter/inc/resourcemodel/TagLogger.hxx b/writerfilter/inc/resourcemodel/TagLogger.hxx new file mode 100644 index 000000000000..a2c8290e0c4b --- /dev/null +++ b/writerfilter/inc/resourcemodel/TagLogger.hxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_TAG_LOGGER_HXX +#define INCLUDED_TAG_LOGGER_HXX + +#include <rtl/ustring.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <WriterFilterDllApi.hxx> +#include <resourcemodel/WW8ResourceModel.hxx> +#include <string> +#include <vector> +#include <stack> +#include <hash_map> +#include <boost/shared_ptr.hpp> +#include <iostream> + +namespace writerfilter +{ + using namespace::std; + + struct XMLAttribute + { + string mName; + string mValue; + public: + XMLAttribute(string sName, string sValue) + : mName(sName), mValue(sValue) + { + } + }; + + class WRITERFILTER_DLLPUBLIC XMLTag + { + public: + enum eMode { START, END, COMPLETE }; + typedef boost::shared_ptr<XMLTag> Pointer_t; + static Pointer_t NIL; + + private: + string mTag; + string mChars; + + typedef vector<XMLAttribute> XMLAttributes_t; + XMLAttributes_t mAttrs; + typedef vector<XMLTag::Pointer_t> XMLTags_t; + XMLTags_t mTags; + eMode mMode; + + public: + XMLTag(string sTag, eMode mode = COMPLETE) : mTag(sTag), mMode(mode) {} + + void addAttr(string name, string value); + void addAttr(string name, const ::rtl::OUString & value); + void addAttr(string name, sal_uInt32 nValue); + void addAttr(string name, uno::Any rAny); + void addTag(Pointer_t pTag); + void chars(const string & rChars); + void chars(const ::rtl::OUString & rChars); + const string & getTag() const; + string toString() const; + + ostream & output(ostream & o, const string & sIndent = "") const; + }; + + class WRITERFILTER_DLLPUBLIC TagLogger + { + public: + typedef boost::shared_ptr<TagLogger> Pointer_t; + + private: + stack<XMLTag::Pointer_t> mTags; + XMLTag::Pointer_t currentTag() const; + XMLTag::Pointer_t mpRoot; + string mFileName; + + TagLogger(); + + public: + ~TagLogger(); + + static Pointer_t getInstance(const char * name); + + void setFileName(const string & rName); + + void startDocument(); + void element(const string & name); + void startElement(const string & name); + void attribute(const string & name, const string & value); + void attribute(const string & name, const ::rtl::OUString & value); + void attribute(const string & name, sal_uInt32 value); + void attribute(const string & name, const uno::Any aAny); + void addTag(XMLTag::Pointer_t pTag); + void chars(const string & chars); + void chars(const ::rtl::OUString & chars); + void endElement(const string & name); + void endDocument(); + + ostream & output(ostream & o) const; + static void dump(const char * name); + }; + + class IdToString + { + public: + typedef boost::shared_ptr<IdToString> Pointer_t; + virtual string toString(const Id & id) const = 0; + }; + + class WRITERFILTER_DLLPUBLIC PropertySetToTagHandler : public Properties + { + XMLTag::Pointer_t mpTag; + IdToString::Pointer_t mpIdToString; + + public: + PropertySetToTagHandler(IdToString::Pointer_t pIdToString); + virtual ~PropertySetToTagHandler(); + + XMLTag::Pointer_t getTag() const { return mpTag; } + + void resolve(XMLTag & rTag, + writerfilter::Reference<Properties>::Pointer_t props); + + virtual void attribute(Id name, Value & val); + virtual void sprm(Sprm & sprm); + }; + +WRITERFILTER_DLLPUBLIC XMLTag::Pointer_t unoPropertySetToTag(uno::Reference<beans::XPropertySet> rPropSet); +} + +#endif // INCLUDED_TAG_LOGGER_HXX diff --git a/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx b/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx new file mode 100644 index 000000000000..1e6d46554c0c --- /dev/null +++ b/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx @@ -0,0 +1,401 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_WW8_EVENT_HANDLER_HXX +#define INCLUDED_WW8_EVENT_HANDLER_HXX + +#include <string> +#include <memory> +#include <boost/shared_ptr.hpp> +#include <sal/types.h> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <WriterFilterDllApi.hxx> +#include <resourcemodel/OutputWithDepth.hxx> +/** + @file WW8ResourceModel.hxx + + The classes in this file define the interfaces for the resource + model of the DocTokenizer: + + @image html doctok.png + + A resource is a set of events that describe an object. A resource + is only an abstract concept. It is not instanciated to a class. + + A reference to a resource represents the object that the resource + describes. The reference can be resolved thereby generating the + events of the resource. + + A handler receives the events generated by resolving a + reference. There are several types of handlers each accepting their + specific set of events. + + References always have a parameter determining the kind of handler + they send the events they generate to. The set of events generated + by resolving the reference is a subset of the events received by + the handler. +*/ + + +typedef sal_uInt32 Id; + +namespace writerfilter { +using namespace ::com::sun::star; +using namespace ::std; + +/** + Reference to an resource that generates events and sends them to a + handler. + + The reference can be resolved, i.e. the resource generates its + events. The events must be suitable for the handler type given by + the template parameter. + + @attention The parameter of the template does not determine the + type of the reference's target. It determines the type of the handler! + + Example: + + A Word document can be represented as a stream of events. Event + types in a Word document are text, properties, tables, starts and + ends of groups. These can be handled by a stream handler (@see + Stream). Thus a reference to a Word document is resolved by + sending these events to a stream handler. +*/ + +template <class T> +class WRITERFILTER_DLLPUBLIC Reference +{ +public: + /** + Pointer to reference + + @attention The ownership of a reference is transfered when + the reference is passed. + */ + typedef boost::shared_ptr< Reference<T> > Pointer_t; + + virtual ~Reference() {} + + /** + Resolves the reference. + + The events of the references target resource are generated and + send to a handler. + + @param rHandler handler which receives the events + */ + virtual void resolve(T & rHandler) = 0; + + /** + Returns the type of the reference aka the name of the access class. + */ + virtual string getType() const = 0; +}; + +class Value; +class Sprm; + +/** + Handler for properties. + */ +class WRITERFILTER_DLLPUBLIC Properties +{ +public: + /** + Receives an attribute. + + @param name name of the attribute + @param val value of the attribute + */ + virtual void attribute(Id name, Value & val) = 0; + + /** + Receives a SPRM. + + @param sprm the SPRM received + */ + virtual void sprm(Sprm & sprm) = 0; + +}; + +/** + Handler for tables. + */ +class WRITERFILTER_DLLPUBLIC Table +{ +public: + typedef boost::shared_ptr<Table> Pointer_t; + /** + Receives an entry of the table. + + @param pos position of the entry in the table + @param ref reference to properties of the entry + */ + virtual void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref) = 0; +}; + +/** + Handler for binary objects. + */ +class WRITERFILTER_DLLPUBLIC BinaryObj +{ +public: + /** + Receives binary data of the object. + + @param buf pointer to buffer containing the data + @param len size of buffer + @param ref reference to properties of binary object + */ + virtual void data(const sal_uInt8* buf, size_t len, + writerfilter::Reference<Properties>::Pointer_t ref) = 0; +}; + +/** + Handler for a stream. + */ +class WRITERFILTER_DLLPUBLIC Stream +{ +public: + /** + Pointer to this stream. + */ + typedef boost::shared_ptr<Stream> Pointer_t; + + /** + Receives start mark for group with the same section properties. + */ + virtual void startSectionGroup() = 0; + + /** + Receives end mark for group with the same section properties. + */ + virtual void endSectionGroup() = 0; + + /** + Receives start mark for group with the same paragraph properties. + */ + virtual void startParagraphGroup() = 0; + + /** + Receives end mark for group with the same paragraph properties. + */ + virtual void endParagraphGroup() = 0; + + virtual void markLastParagraphInSection( ) { }; + + /** + Receives start mark for group with the same character properties. + */ + virtual void startCharacterGroup() = 0; + + /** + Receives end mark for group with the same character properties. + */ + virtual void endCharacterGroup() = 0; + + /** + Receives a shape. + */ + virtual void startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ) = 0; + + virtual void endShape( ) = 0; + + /** + Receives 8-bit per character text. + + @param data buffer containing the text + @param len number of characters in the text + */ + virtual void text(const sal_uInt8 * data, size_t len) = 0; + + /** + Receives 16-bit per character text. + + @param data buffer containing the text + @param len number of characters in the text. + */ + virtual void utext(const sal_uInt8 * data, size_t len) = 0; + + /** + Receives properties of the current run of text. + + @param ref reference to the properties + */ + virtual void props(writerfilter::Reference<Properties>::Pointer_t ref) = 0; + + /** + Receives table. + + @param name name of the table + @param ref referecne to the table + */ + virtual void table(Id name, + writerfilter::Reference<Table>::Pointer_t ref) = 0; + + /** + Receives a substream. + + @param name name of the substream + @param ref reference to the substream + */ + virtual void substream(Id name, + writerfilter::Reference<Stream>::Pointer_t ref) = 0; + + + /** + Debugging: Receives information about current point in stream. + + @param info the information + */ + virtual void info(const string & info) = 0; +}; + +/** + A value. + + The methods of this class may throw exceptions if a certain aspect + makes no sense for a certain value, e.g. the integer value of a + string. + */ +class WRITERFILTER_DLLPUBLIC Value +{ +public: + /** + Pointer to a value. + */ + typedef auto_ptr<Value> Pointer_t; + + /** + Returns integer representation of the value. + */ + virtual int getInt() const = 0; + + /** + Returns string representation of the value. + */ + virtual ::rtl::OUString getString() const = 0; + + /** + Returns representation of the value as uno::Any. + */ + virtual uno::Any getAny() const = 0; + + /** + Returns properties of this value. + */ + virtual writerfilter::Reference<Properties>::Pointer_t getProperties() = 0; + + /** + Returns stream of this value. + */ + virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0; + + /** + Returns binary object of this value. + */ + virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0; + + /** + Returns string representation of this value. + */ + virtual string toString() const = 0; +}; + +/** + An SPRM. + + */ +class WRITERFILTER_DLLPUBLIC Sprm +{ +public: + typedef auto_ptr<Sprm> Pointer_t; + enum Kind { UNKNOWN, CHARACTER, PARAGRAPH, TABLE }; + /** + Returns id of the SPRM. + */ + virtual sal_uInt32 getId() const = 0; + + /** + Returns value of the SPRM. + */ + virtual Value::Pointer_t getValue() = 0; + + /** + Returns reference to binary object contained in the SPRM. + */ + virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0; + + /** + Returns reference to stream associated with the SPRM. + */ + virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0; + + /** + Returns reference to properties contained in the SPRM. + + */ + virtual writerfilter::Reference<Properties>::Pointer_t getProps() = 0; + + /** + Returns the kind of this SPRM. + */ + virtual Kind getKind() = 0; + + /** + Returns name of sprm. + */ + virtual string getName() const = 0; + + /** + Returns string repesentation of sprm. + */ + virtual string toString() const = 0; +}; + +/** + Creates handler for a stream. +*/ +Stream::Pointer_t WRITERFILTER_DLLPUBLIC createStreamHandler(); + + void WRITERFILTER_DLLPUBLIC analyzerIds(); + Stream::Pointer_t WRITERFILTER_DLLPUBLIC createAnalyzer(); + + void WRITERFILTER_DLLPUBLIC logger(string prefix, string message); + + void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & o, const char * name, writerfilter::Reference<Properties>::Pointer_t props); + void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & o, const char * name, sal_uInt32 n); + void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & /*o*/, const char * /*name*/, + const rtl::OUString & /*str*/); + void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & o, const char * name, writerfilter::Reference<BinaryObj>::Pointer_t binary); + +} + + +#endif // INCLUDED_WW8_EVENT_HANDLER_HXX diff --git a/writerfilter/inc/resourcemodel/XPathLogger.hxx b/writerfilter/inc/resourcemodel/XPathLogger.hxx new file mode 100644 index 000000000000..22e50fc15bb9 --- /dev/null +++ b/writerfilter/inc/resourcemodel/XPathLogger.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_XPATH_LOGGER_HXX +#define INCLUDED_XPATH_LOGGER_HXX + +#include <hash_map> +#include <stack> +#include <string> +#include <vector> +#include <boost/shared_ptr.hpp> +#include <WriterFilterDllApi.hxx> + +namespace writerfilter +{ +using ::std::hash_map; +using ::std::stack; +using ::std::string; +using ::std::vector; + +class WRITERFILTER_DLLPUBLIC XPathLogger +{ + typedef hash_map<string, unsigned int> TokenMap_t; + typedef boost::shared_ptr<TokenMap_t> TokenMapPointer_t; + + TokenMapPointer_t mp_tokenMap; + stack<TokenMapPointer_t> m_tokenMapStack; + vector<string> m_path; + string m_currentPath; + + void updateCurrentPath(); + +public: + explicit XPathLogger(); + virtual ~XPathLogger(); + + string getXPath() const; + void startElement(string _token); + void endElement(); +}; +} +#endif // INCLUDED_XPATH_LOGGER_HXX diff --git a/writerfilter/inc/resourcemodel/exceptions.hxx b/writerfilter/inc/resourcemodel/exceptions.hxx new file mode 100644 index 000000000000..708355bff880 --- /dev/null +++ b/writerfilter/inc/resourcemodel/exceptions.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DOCTOK_EXCEPTIONS_HXX +#define _DOCTOK_EXCEPTIONS_HXX + +#include <string> +#include <WriterFilterDllApi.hxx> + +namespace writerfilter { +using namespace ::std; + +class WRITERFILTER_DLLPUBLIC Exception +{ + string mText; + +public: + Exception(string text) : mText(text) {} + + const string & getText() const { return mText; } +}; + +class WRITERFILTER_DLLPUBLIC ExceptionNotFound : public Exception +{ +public: + ExceptionNotFound(string text) : Exception(text) {} +}; + +class WRITERFILTER_DLLPUBLIC ExceptionOutOfBounds : public Exception +{ +public: + ExceptionOutOfBounds(string text) : Exception(text) {} +}; +} + +#endif // _DOCTOK_EXCEPTIONS_HXX diff --git a/writerfilter/inc/resourcemodel/util.hxx b/writerfilter/inc/resourcemodel/util.hxx new file mode 100644 index 000000000000..0a700513576a --- /dev/null +++ b/writerfilter/inc/resourcemodel/util.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RESOURCEMODEL_UTIL_HXX +#define INCLUDED_RESOURCEMODEL_UTIL_HXX +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <WriterFilterDllApi.hxx> +#include <string> + +namespace writerfilter +{ + using namespace ::std; + using namespace ::com::sun::star; + + string WRITERFILTER_DLLPUBLIC xmlify(const string & str); + +#ifdef DEBUG + string WRITERFILTER_DLLPUBLIC propertysetToString + (uno::Reference<beans::XPropertySet> const & rProps); + + string toString(uno::Reference< text::XTextRange > textRange); + string toString(const string & rString); +#endif +} +#endif // INCLUDED_RESOURCEMODEL_UTIL_HXX diff --git a/writerfilter/inc/rtftok/RTFInputSource.hxx b/writerfilter/inc/rtftok/RTFInputSource.hxx new file mode 100644 index 000000000000..7eb191431206 --- /dev/null +++ b/writerfilter/inc/rtftok/RTFInputSource.hxx @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RTFINPUTSOURCE_HXX +#define INCLUDED_RTFINPUTSOURCE_HXX + +namespace writerfilter { namespace rtftok { + +class RTFInputSource +{ +public: + virtual int read(void *buffer, int maxLen) = 0; +}; + +} } /* end namespace writerfilter::rtftok */ + + +#endif /* INCLUDED_RTFINPUTSOURCE_HXX */ diff --git a/writerfilter/inc/rtftok/RTFParseException.hxx b/writerfilter/inc/rtftok/RTFParseException.hxx new file mode 100644 index 000000000000..558ecdc45cf3 --- /dev/null +++ b/writerfilter/inc/rtftok/RTFParseException.hxx @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RTFPARSEEXCEPTION_HXX +#define INCLUDED_RTFPARSEEXCEPTION_HXX + +namespace writerfilter { namespace rtftok { + +class RTFParseException +{ +public: + RTFParseException(char *message); +}; + +} } /* end namespace writerfilter::rtftok */ + + +#endif /* INCLUDED_RTFPARSEEXCEPTION_HXX */ diff --git a/writerfilter/inc/rtftok/RTFScanner.hxx b/writerfilter/inc/rtftok/RTFScanner.hxx new file mode 100644 index 000000000000..56372dc27bb5 --- /dev/null +++ b/writerfilter/inc/rtftok/RTFScanner.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RTFSCANNER_HXX +#define INCLUDED_RTFSCANNER_HXX + +#include <WriterFilterDllApi.hxx> +#include <vector> +#include <rtftok/RTFInputSource.hxx> +#include <rtftok/RTFScannerHandler.hxx> + +namespace writerfilter { namespace rtftok { + +class WRITERFILTER_DLLPUBLIC RTFScanner { +public: + RTFScanner(RTFScannerHandler &eventHandler_) : eventHandler(eventHandler_) {}; + virtual ~RTFScanner() { } + + const char* YYText() { return yytext; } + int YYLeng() { return yyleng; } + + virtual int yylex() = 0; + + int lineno() const { return yylineno; } + +protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" + RTFScannerHandler &eventHandler; + + +public: + static writerfilter::rtftok::RTFScanner* createRTFScanner(writerfilter::rtftok::RTFInputSource& inputSource, writerfilter::rtftok::RTFScannerHandler &eventHandler); +}; + +} } /* end namespace writerfilter::rtftok */ + + +#endif /* INCLUDED_RTFSCANNER_HXX */ diff --git a/writerfilter/inc/rtftok/RTFScannerHandler.hxx b/writerfilter/inc/rtftok/RTFScannerHandler.hxx new file mode 100644 index 000000000000..c8e61903055c --- /dev/null +++ b/writerfilter/inc/rtftok/RTFScannerHandler.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RTFSCANNERHANDLER_HXX +#define INCLUDED_RTFSCANNERHANDLER_HXX + +namespace writerfilter { namespace rtftok { + +class RTFScannerHandler +{ +public: + virtual void dest(char*token, char*value)=0; + virtual void ctrl(char*token, char*value)=0; + virtual void lbrace(void)=0; + virtual void rbrace(void)=0; + virtual void addSpaces(int count)=0; + virtual void addBinData(unsigned char data)=0; + virtual void addChar(char ch) =0; + virtual void addCharU(sal_Unicode ch) =0; + virtual void addHexChar(char* hexch) =0; + +}; + +} } /* end namespace writerfilter::rtftok */ + +#endif /* INCLUDED_RTFSCANNERHANDLER_HXX */ diff --git a/writerfilter/inc/writerfilter.mk b/writerfilter/inc/writerfilter.mk new file mode 100644 index 000000000000..f8ea735a4ec5 --- /dev/null +++ b/writerfilter/inc/writerfilter.mk @@ -0,0 +1,29 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +CDEFS+=-DWRITERFILTER_DLLIMPLEMENTATION + |