Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <SwXMLSectionList.hxx>
21 : #include <xmloff/nmspmap.hxx>
22 : #include <xmloff/xmlnmspe.hxx>
23 : #include <vector>
24 :
25 : using namespace ::com::sun::star;
26 : using namespace ::xmloff::token;
27 :
28 : // TODO: verify if these should match the same-name constants
29 : // in xmloff/source/core/xmlimp.cxx ("_office" and "_office")
30 : sal_Char const sXML_np__office[] = "_ooffice";
31 : sal_Char const sXML_np__text[] = "_otext";
32 :
33 : // #110680#
34 0 : SwXMLSectionList::SwXMLSectionList(
35 : const uno::Reference< uno::XComponentContext > xContext,
36 : std::vector<OUString*> &rNewSectionList)
37 : : SvXMLImport( xContext, "" ),
38 0 : rSectionList ( rNewSectionList )
39 : {
40 0 : GetNamespaceMap().Add( OUString( sXML_np__office ),
41 0 : GetXMLToken(XML_N_OFFICE_OOO),
42 0 : XML_NAMESPACE_OFFICE );
43 0 : GetNamespaceMap().Add( OUString( sXML_np__text ),
44 0 : GetXMLToken(XML_N_TEXT_OOO),
45 0 : XML_NAMESPACE_TEXT );
46 0 : }
47 :
48 0 : SwXMLSectionList::~SwXMLSectionList ( void )
49 0 : throw()
50 : {
51 0 : }
52 :
53 0 : SvXMLImportContext *SwXMLSectionList::CreateContext(
54 : sal_uInt16 nPrefix,
55 : const OUString& rLocalName,
56 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
57 : {
58 0 : SvXMLImportContext *pContext = 0;
59 :
60 0 : if(( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken ( rLocalName, XML_BODY )) ||
61 0 : ( nPrefix == XML_NAMESPACE_TEXT &&
62 0 : (IsXMLToken ( rLocalName, XML_P ) ||
63 0 : IsXMLToken ( rLocalName, XML_H ) ||
64 0 : IsXMLToken ( rLocalName, XML_A ) ||
65 0 : IsXMLToken ( rLocalName, XML_SPAN ) ||
66 0 : IsXMLToken ( rLocalName, XML_SECTION ) ||
67 0 : IsXMLToken ( rLocalName, XML_INDEX_BODY ) ||
68 0 : IsXMLToken ( rLocalName, XML_INDEX_TITLE )||
69 0 : IsXMLToken ( rLocalName, XML_INSERTION ) ||
70 0 : IsXMLToken ( rLocalName, XML_DELETION ) )
71 : )
72 : )
73 : {
74 0 : pContext = new SvXMLSectionListContext (*this, nPrefix, rLocalName, xAttrList);
75 : }
76 : else
77 0 : pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
78 0 : return pContext;
79 : }
80 :
81 0 : SvXMLSectionListContext::SvXMLSectionListContext(
82 : SwXMLSectionList& rImport,
83 : sal_uInt16 nPrefix,
84 : const OUString& rLocalName,
85 : const uno::Reference< xml::sax::XAttributeList > & ) :
86 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
87 0 : rLocalRef(rImport)
88 : {
89 0 : }
90 :
91 0 : SvXMLImportContext *SvXMLSectionListContext::CreateChildContext(
92 : sal_uInt16 nPrefix,
93 : const OUString& rLocalName,
94 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
95 : {
96 0 : SvXMLImportContext *pContext = 0;
97 :
98 0 : if (nPrefix == XML_NAMESPACE_TEXT && ( IsXMLToken ( rLocalName, XML_SECTION ) ||
99 0 : IsXMLToken ( rLocalName, XML_BOOKMARK) ) )
100 : {
101 0 : OUString sName;
102 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
103 :
104 0 : for (sal_Int16 i=0; i < nAttrCount; i++)
105 : {
106 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
107 0 : OUString aLocalName;
108 0 : sal_uInt16 nPrefx = rLocalRef.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
109 0 : if (XML_NAMESPACE_TEXT == nPrefx && IsXMLToken ( aLocalName, XML_NAME ) )
110 0 : sName = xAttrList->getValueByIndex( i );
111 0 : }
112 0 : if ( !sName.isEmpty() )
113 0 : rLocalRef.rSectionList.push_back( new OUString(sName) );
114 : }
115 :
116 0 : pContext = new SvXMLSectionListContext (rLocalRef, nPrefix, rLocalName, xAttrList);
117 0 : return pContext;
118 : }
119 0 : SvXMLSectionListContext::~SvXMLSectionListContext ( void )
120 : {
121 0 : }
122 :
123 0 : SvXMLIgnoreSectionListContext::SvXMLIgnoreSectionListContext(
124 : SwXMLSectionList& rImport,
125 : sal_uInt16 nPrefix,
126 : const OUString& rLocalName,
127 : const uno::Reference< xml::sax::XAttributeList > & ) :
128 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
129 0 : rLocalRef(rImport)
130 : {
131 0 : }
132 :
133 0 : SvXMLIgnoreSectionListContext::~SvXMLIgnoreSectionListContext ( void )
134 : {
135 0 : }
136 0 : SvXMLImportContext *SvXMLIgnoreSectionListContext::CreateChildContext(
137 : sal_uInt16 nPrefix,
138 : const OUString& rLocalName,
139 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
140 : {
141 0 : return new SvXMLIgnoreSectionListContext (rLocalRef, nPrefix, rLocalName, xAttrList);
142 : }
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|