diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2010-09-29 10:24:13 +0200 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2010-09-29 10:24:13 +0200 |
commit | 3db3d0728c6ba9f3277b32d3fefa900ecbcaf5f5 (patch) | |
tree | 1bac27ee52551a6f35856fcc282460dbf47f5312 /xmlreader/inc | |
parent | CWS-TOOLING: integrate CWS tl82 (diff) | |
parent | sb129: merged in DEV300_m88 (diff) | |
download | core-3db3d0728c6ba9f3277b32d3fefa900ecbcaf5f5.tar.gz core-3db3d0728c6ba9f3277b32d3fefa900ecbcaf5f5.zip |
CWS-TOOLING: integrate CWS sb129
Diffstat (limited to 'xmlreader/inc')
-rw-r--r-- | xmlreader/inc/makefile.mk | 40 | ||||
-rw-r--r-- | xmlreader/inc/pch/precompiled_xmlreader.cxx | 28 | ||||
-rw-r--r-- | xmlreader/inc/pch/precompiled_xmlreader.hxx | 32 | ||||
-rw-r--r-- | xmlreader/inc/xmlreader/detail/xmlreaderdllapi.hxx | 41 | ||||
-rw-r--r-- | xmlreader/inc/xmlreader/pad.hxx | 59 | ||||
-rw-r--r-- | xmlreader/inc/xmlreader/span.hxx | 69 | ||||
-rw-r--r-- | xmlreader/inc/xmlreader/xmlreader.hxx | 199 |
7 files changed, 468 insertions, 0 deletions
diff --git a/xmlreader/inc/makefile.mk b/xmlreader/inc/makefile.mk new file mode 100644 index 000000000000..9f84434701ac --- /dev/null +++ b/xmlreader/inc/makefile.mk @@ -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. +# +#***********************************************************************/ + +PRJ = .. +PRJNAME = xmlreader +TARGET = inc + +ENABLE_EXCEPTIONS = TRUE +VISIBILITY_HIDDEN = TRUE + +.INCLUDE: settings.mk +.INCLUDE: target.mk + +.IF "$(ENABLE_PCH)" != "" +ALLTAR: $(SLO)/precompiled.pch $(SLO)/precompiled_ex.pch +.ENDIF diff --git a/xmlreader/inc/pch/precompiled_xmlreader.cxx b/xmlreader/inc/pch/precompiled_xmlreader.cxx new file mode 100644 index 000000000000..e5d584855eb8 --- /dev/null +++ b/xmlreader/inc/pch/precompiled_xmlreader.cxx @@ -0,0 +1,28 @@ +/************************************************************************* +* +* 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. +* +************************************************************************/ + +#include "precompiled_xmlreader.hxx" diff --git a/xmlreader/inc/pch/precompiled_xmlreader.hxx b/xmlreader/inc/pch/precompiled_xmlreader.hxx new file mode 100644 index 000000000000..7561fe89f7c4 --- /dev/null +++ b/xmlreader/inc/pch/precompiled_xmlreader.hxx @@ -0,0 +1,32 @@ +/************************************************************************* +* +* 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. +* +************************************************************************/ + +#if defined PRECOMPILED_HEADERS + +#include "sal/config.h" + +#endif diff --git a/xmlreader/inc/xmlreader/detail/xmlreaderdllapi.hxx b/xmlreader/inc/xmlreader/detail/xmlreaderdllapi.hxx new file mode 100644 index 000000000000..238661a2426f --- /dev/null +++ b/xmlreader/inc/xmlreader/detail/xmlreaderdllapi.hxx @@ -0,0 +1,41 @@ +/************************************************************************* +* +* 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_XMLREADER_DETAIL_XMLREADERDLLAPI_HXX +#define INCLUDED_XMLREADER_DETAIL_XMLREADERDLLAPI_HXX + +#include "sal/config.h" + +#include "sal/types.h" + +#if defined OOO_DLLIMPLEMENTATION_XMLREADER +#define OOO_DLLPUBLIC_XMLREADER SAL_DLLPUBLIC_EXPORT +#else +#define OOO_DLLPUBLIC_XMLREADER SAL_DLLPUBLIC_IMPORT +#endif + +#endif diff --git a/xmlreader/inc/xmlreader/pad.hxx b/xmlreader/inc/xmlreader/pad.hxx new file mode 100644 index 000000000000..d01574147665 --- /dev/null +++ b/xmlreader/inc/xmlreader/pad.hxx @@ -0,0 +1,59 @@ +/************************************************************************* +* +* 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_XMLREADER_PAD_HXX +#define INCLUDED_XMLREADER_PAD_HXX + +#include "sal/config.h" + +#include "rtl/strbuf.hxx" +#include "sal/types.h" +#include "xmlreader/detail/xmlreaderdllapi.hxx" +#include "xmlreader/span.hxx" + +namespace xmlreader { + +class OOO_DLLPUBLIC_XMLREADER Pad { +public: + void add(char const * begin, sal_Int32 length); + + void addEphemeral(char const * begin, sal_Int32 length); + + void clear(); + + Span get() const; + +private: + SAL_DLLPRIVATE void flushSpan(); + + Span span_; + rtl::OStringBuffer buffer_; +}; + +} + +#endif diff --git a/xmlreader/inc/xmlreader/span.hxx b/xmlreader/inc/xmlreader/span.hxx new file mode 100644 index 000000000000..4ec8b574f940 --- /dev/null +++ b/xmlreader/inc/xmlreader/span.hxx @@ -0,0 +1,69 @@ +/************************************************************************* +* +* 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_XMLREADER_SPAN_HXX +#define INCLUDED_XMLREADER_SPAN_HXX + +#include "sal/config.h" + +#include "rtl/string.h" +#include "sal/types.h" +#include "xmlreader/detail/xmlreaderdllapi.hxx" + +namespace rtl { class OUString; } + +namespace xmlreader { + +struct OOO_DLLPUBLIC_XMLREADER Span { + char const * begin; + sal_Int32 length; + + inline Span(): begin(0), length(0) {} + // init length to avoid compiler warnings + + inline Span(char const * theBegin, sal_Int32 theLength): + begin(theBegin), length(theLength) {} + + inline void clear() throw() { begin = 0; } + + inline bool is() const { return begin != 0; } + + inline bool equals(Span const & text) const { + return rtl_str_compare_WithLength( + begin, length, text.begin, text.length) == 0; + } + + inline bool equals(char const * textBegin, sal_Int32 textLength) const { + return equals(Span(textBegin, textLength)); + } + + rtl::OUString convertFromUtf8() const; +}; + +} + +#endif diff --git a/xmlreader/inc/xmlreader/xmlreader.hxx b/xmlreader/inc/xmlreader/xmlreader.hxx new file mode 100644 index 000000000000..242af58c7306 --- /dev/null +++ b/xmlreader/inc/xmlreader/xmlreader.hxx @@ -0,0 +1,199 @@ +/************************************************************************* +* +* 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_XMLREADER_XMLREADER_HXX +#define INCLUDED_XMLREADER_XMLREADER_HXX + +#include "sal/config.h" + +#include <stack> +#include <vector> + +#include "boost/noncopyable.hpp" +#include "com/sun/star/container/NoSuchElementException.hpp" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "osl/file.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "xmlreader/detail/xmlreaderdllapi.hxx" +#include "xmlreader/pad.hxx" +#include "xmlreader/span.hxx" + +namespace xmlreader { + +class OOO_DLLPUBLIC_XMLREADER XmlReader: private boost::noncopyable { +public: + explicit XmlReader(rtl::OUString const & fileUrl) + SAL_THROW(( + com::sun::star::container::NoSuchElementException, + com::sun::star::uno::RuntimeException)); + + ~XmlReader(); + + enum { NAMESPACE_NONE = -2, NAMESPACE_UNKNOWN = -1, NAMESPACE_XML = 0 }; + + enum Text { TEXT_NONE, TEXT_RAW, TEXT_NORMALIZED }; + + enum Result { RESULT_BEGIN, RESULT_END, RESULT_TEXT, RESULT_DONE }; + + int registerNamespaceIri(Span const & iri); + + // RESULT_BEGIN: data = localName, ns = ns + // RESULT_END: data, ns unused + // RESULT_TEXT: data = text, ns unused + Result nextItem(Text reportText, Span * data, int * nsId); + + bool nextAttribute(int * nsId, Span * localName); + + // the span returned by getAttributeValue is only valid until the next call + // to nextItem or getAttributeValue + Span getAttributeValue(bool fullyNormalize); + + int getNamespaceId(Span const & prefix) const; + + rtl::OUString getUrl() const; + +private: + typedef std::vector< Span > NamespaceIris; + + // If NamespaceData (and similarly ElementData and AttributeData) is made + // SAL_DLLPRIVATE, at least gcc 4.2.3 erroneously warns about + // "'xmlreader::XmlReader' declared with greater visibility than the type of + // its field 'xmlreader::XmlReader::namespaces_'" (and similarly for + // elements_ and attributes_): + + struct NamespaceData { + Span prefix; + int nsId; + + NamespaceData() {} + + NamespaceData(Span const & thePrefix, int theNsId): + prefix(thePrefix), nsId(theNsId) {} + }; + + typedef std::vector< NamespaceData > NamespaceList; + + struct ElementData { + Span name; + NamespaceList::size_type inheritedNamespaces; + int defaultNamespaceId; + + ElementData( + Span const & theName, + NamespaceList::size_type theInheritedNamespaces, + int theDefaultNamespaceId): + name(theName), inheritedNamespaces(theInheritedNamespaces), + defaultNamespaceId(theDefaultNamespaceId) + {} + }; + + typedef std::stack< ElementData > ElementStack; + + struct AttributeData { + char const * nameBegin; + char const * nameEnd; + char const * nameColon; + char const * valueBegin; + char const * valueEnd; + + AttributeData( + char const * theNameBegin, char const * theNameEnd, + char const * theNameColon, char const * theValueBegin, + char const * theValueEnd): + nameBegin(theNameBegin), nameEnd(theNameEnd), + nameColon(theNameColon), valueBegin(theValueBegin), + valueEnd(theValueEnd) + {} + }; + + typedef std::vector< AttributeData > Attributes; + + enum State { + STATE_CONTENT, STATE_START_TAG, STATE_END_TAG, STATE_EMPTY_ELEMENT_TAG, + STATE_DONE }; + + SAL_DLLPRIVATE inline char read() { return pos_ == end_ ? '\0' : *pos_++; } + + SAL_DLLPRIVATE inline char peek() { return pos_ == end_ ? '\0' : *pos_; } + + SAL_DLLPRIVATE void normalizeLineEnds(Span const & text); + + SAL_DLLPRIVATE void skipSpace(); + + SAL_DLLPRIVATE bool skipComment(); + + SAL_DLLPRIVATE void skipProcessingInstruction(); + + SAL_DLLPRIVATE void skipDocumentTypeDeclaration(); + + SAL_DLLPRIVATE Span scanCdataSection(); + + SAL_DLLPRIVATE bool scanName(char const ** nameColon); + + SAL_DLLPRIVATE int scanNamespaceIri( + char const * begin, char const * end); + + SAL_DLLPRIVATE char const * handleReference( + char const * position, char const * end); + + SAL_DLLPRIVATE Span handleAttributeValue( + char const * begin, char const * end, bool fullyNormalize); + + SAL_DLLPRIVATE Result handleStartTag(int * nsId, Span * localName); + + SAL_DLLPRIVATE Result handleEndTag(); + + SAL_DLLPRIVATE void handleElementEnd(); + + SAL_DLLPRIVATE Result handleSkippedText(Span * data, int * nsId); + + SAL_DLLPRIVATE Result handleRawText(Span * text); + + SAL_DLLPRIVATE Result handleNormalizedText(Span * text); + + SAL_DLLPRIVATE int toNamespaceId(NamespaceIris::size_type pos); + + rtl::OUString fileUrl_; + oslFileHandle fileHandle_; + sal_uInt64 fileSize_; + void * fileAddress_; + NamespaceIris namespaceIris_; + NamespaceList namespaces_; + ElementStack elements_; + char const * pos_; + char const * end_; + State state_; + Attributes attributes_; + Attributes::iterator currentAttribute_; + bool firstAttribute_; + Pad pad_; +}; + +} + +#endif |