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 ::rtl::OUString;
28 : using namespace ::xmloff::token;
29 :
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< lang::XMultiServiceFactory > xServiceFactory,
36 : std::vector<String*> &rNewSectionList)
37 : : SvXMLImport( xServiceFactory ),
38 0 : rSectionList ( rNewSectionList )
39 : {
40 0 : GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ),
41 0 : GetXMLToken(XML_N_OFFICE_OOO),
42 0 : XML_NAMESPACE_OFFICE );
43 0 : GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( 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 : ( 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 0 : String sName;
98 :
99 0 : if (nPrefix == XML_NAMESPACE_TEXT && ( IsXMLToken ( rLocalName, XML_SECTION ) ||
100 0 : IsXMLToken ( rLocalName, XML_BOOKMARK) ) )
101 : {
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 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
110 0 : if (XML_NAMESPACE_TEXT == nPrefx && IsXMLToken ( aLocalName, XML_NAME ) )
111 0 : sName = rAttrValue;
112 0 : }
113 0 : if ( sName.Len() )
114 0 : rLocalRef.rSectionList.push_back( new String(sName) );
115 : }
116 :
117 0 : pContext = new SvXMLSectionListContext (rLocalRef, nPrefix, rLocalName, xAttrList);
118 0 : return pContext;
119 : }
120 0 : SvXMLSectionListContext::~SvXMLSectionListContext ( void )
121 : {
122 0 : }
123 :
124 0 : SvXMLIgnoreSectionListContext::SvXMLIgnoreSectionListContext(
125 : SwXMLSectionList& rImport,
126 : sal_uInt16 nPrefix,
127 : const OUString& rLocalName,
128 : const uno::Reference< xml::sax::XAttributeList > & ) :
129 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
130 0 : rLocalRef(rImport)
131 : {
132 0 : }
133 :
134 0 : SvXMLIgnoreSectionListContext::~SvXMLIgnoreSectionListContext ( void )
135 : {
136 0 : }
137 0 : SvXMLImportContext *SvXMLIgnoreSectionListContext::CreateChildContext(
138 : sal_uInt16 nPrefix,
139 : const OUString& rLocalName,
140 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
141 : {
142 0 : return new SvXMLIgnoreSectionListContext (rLocalRef, nPrefix, rLocalName, xAttrList);
143 : }
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|