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 <tools/string.hxx>
21 : #include <SwXMLSectionList.hxx>
22 : #include <xmloff/nmspmap.hxx>
23 : #include <xmloff/xmlnmspe.hxx>
24 : #include <vector>
25 :
26 : using namespace ::com::sun::star;
27 : using namespace ::xmloff::token;
28 :
29 : sal_Char const sXML_np__office[] = "_ooffice";
30 : sal_Char const sXML_np__text[] = "_otext";
31 :
32 : // #110680#
33 0 : SwXMLSectionList::SwXMLSectionList(
34 : const uno::Reference< uno::XComponentContext > xContext,
35 : std::vector<String*> &rNewSectionList)
36 : : SvXMLImport( xContext ),
37 0 : rSectionList ( rNewSectionList )
38 : {
39 0 : GetNamespaceMap().Add( OUString( sXML_np__office ),
40 0 : GetXMLToken(XML_N_OFFICE_OOO),
41 0 : XML_NAMESPACE_OFFICE );
42 0 : GetNamespaceMap().Add( OUString( sXML_np__text ),
43 0 : GetXMLToken(XML_N_TEXT_OOO),
44 0 : XML_NAMESPACE_TEXT );
45 0 : }
46 :
47 0 : SwXMLSectionList::~SwXMLSectionList ( void )
48 0 : throw()
49 : {
50 0 : }
51 :
52 0 : SvXMLImportContext *SwXMLSectionList::CreateContext(
53 : sal_uInt16 nPrefix,
54 : const OUString& rLocalName,
55 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
56 : {
57 0 : SvXMLImportContext *pContext = 0;
58 :
59 0 : if(( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken ( rLocalName, XML_BODY )) ||
60 0 : ( nPrefix == XML_NAMESPACE_TEXT &&
61 0 : (IsXMLToken ( rLocalName, XML_P ) ||
62 0 : IsXMLToken ( rLocalName, XML_H ) ||
63 0 : IsXMLToken ( rLocalName, XML_A ) ||
64 0 : IsXMLToken ( rLocalName, XML_SPAN ) ||
65 0 : IsXMLToken ( rLocalName, XML_SECTION ) ||
66 0 : IsXMLToken ( rLocalName, XML_INDEX_BODY ) ||
67 0 : IsXMLToken ( rLocalName, XML_INDEX_TITLE )||
68 0 : IsXMLToken ( rLocalName, XML_INSERTION ) ||
69 0 : IsXMLToken ( rLocalName, XML_DELETION ) )
70 : )
71 : )
72 : {
73 0 : pContext = new SvXMLSectionListContext (*this, nPrefix, rLocalName, xAttrList);
74 : }
75 : else
76 0 : pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
77 0 : return pContext;
78 : }
79 :
80 0 : SvXMLSectionListContext::SvXMLSectionListContext(
81 : SwXMLSectionList& rImport,
82 : sal_uInt16 nPrefix,
83 : const OUString& rLocalName,
84 : const uno::Reference< xml::sax::XAttributeList > & ) :
85 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
86 0 : rLocalRef(rImport)
87 : {
88 0 : }
89 :
90 0 : SvXMLImportContext *SvXMLSectionListContext::CreateChildContext(
91 : sal_uInt16 nPrefix,
92 : const OUString& rLocalName,
93 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
94 : {
95 0 : SvXMLImportContext *pContext = 0;
96 0 : String sName;
97 :
98 0 : if (nPrefix == XML_NAMESPACE_TEXT && ( IsXMLToken ( rLocalName, XML_SECTION ) ||
99 0 : IsXMLToken ( rLocalName, XML_BOOKMARK) ) )
100 : {
101 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
102 :
103 0 : for (sal_Int16 i=0; i < nAttrCount; i++)
104 : {
105 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
106 0 : OUString aLocalName;
107 0 : sal_uInt16 nPrefx = rLocalRef.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
108 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
109 0 : if (XML_NAMESPACE_TEXT == nPrefx && IsXMLToken ( aLocalName, XML_NAME ) )
110 0 : sName = rAttrValue;
111 0 : }
112 0 : if ( sName.Len() )
113 0 : rLocalRef.rSectionList.push_back( new String(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: */
|