1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #define _SVSTDARR_STRINGSDTOR
27 #define _SVSTDARR_STRINGS
28 #include <svl/svstdarr.hxx>
29 #include <SwXMLSectionList.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmlnmspe.hxx>
32
33 using namespace ::com::sun::star;
34 using ::rtl::OUString;
35 using namespace ::xmloff::token;
36
37 sal_Char __READONLY_DATA sXML_np__office[] = "_ooffice";
38 sal_Char __READONLY_DATA sXML_np__text[] = "_otext";
39
40 // #110680#
SwXMLSectionList(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,SvStrings & rNewSectionList)41 SwXMLSectionList::SwXMLSectionList(
42 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
43 SvStrings & rNewSectionList)
44 : SvXMLImport( xServiceFactory ),
45 rSectionList ( rNewSectionList )
46 {
47 GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ),
48 GetXMLToken(XML_N_OFFICE_OOO),
49 XML_NAMESPACE_OFFICE );
50 GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__text ) ),
51 GetXMLToken(XML_N_TEXT_OOO),
52 XML_NAMESPACE_TEXT );
53 }
54
~SwXMLSectionList(void)55 SwXMLSectionList::~SwXMLSectionList ( void )
56 throw()
57 {
58 }
59
CreateContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)60 SvXMLImportContext *SwXMLSectionList::CreateContext(
61 sal_uInt16 nPrefix,
62 const OUString& rLocalName,
63 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
64 {
65 SvXMLImportContext *pContext = 0;
66
67 if(( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken ( rLocalName, XML_BODY )) ||
68 ( nPrefix == XML_NAMESPACE_TEXT &&
69 (IsXMLToken ( rLocalName, XML_P ) ||
70 IsXMLToken ( rLocalName, XML_H ) ||
71 IsXMLToken ( rLocalName, XML_A ) ||
72 IsXMLToken ( rLocalName, XML_SPAN ) ||
73 IsXMLToken ( rLocalName, XML_SECTION ) ||
74 IsXMLToken ( rLocalName, XML_INDEX_BODY ) ||
75 IsXMLToken ( rLocalName, XML_INDEX_TITLE )||
76 IsXMLToken ( rLocalName, XML_INSERTION ) ||
77 IsXMLToken ( rLocalName, XML_DELETION ) )
78 )
79 )
80 {
81 pContext = new SvXMLSectionListContext (*this, nPrefix, rLocalName, xAttrList);
82 }
83 else
84 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
85 return pContext;
86 }
87
SvXMLSectionListContext(SwXMLSectionList & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)88 SvXMLSectionListContext::SvXMLSectionListContext(
89 SwXMLSectionList& rImport,
90 sal_uInt16 nPrefix,
91 const OUString& rLocalName,
92 const uno::Reference< xml::sax::XAttributeList > & ) :
93 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
94 rLocalRef(rImport)
95 {
96 }
97
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)98 SvXMLImportContext *SvXMLSectionListContext::CreateChildContext(
99 sal_uInt16 nPrefix,
100 const OUString& rLocalName,
101 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
102 {
103 SvXMLImportContext *pContext = 0;
104 String sName;
105
106 if (nPrefix == XML_NAMESPACE_TEXT && ( IsXMLToken ( rLocalName, XML_SECTION ) ||
107 IsXMLToken ( rLocalName, XML_BOOKMARK) ) )
108 {
109 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
110
111 for (sal_Int16 i=0; i < nAttrCount; i++)
112 {
113 const OUString& rAttrName = xAttrList->getNameByIndex( i );
114 OUString aLocalName;
115 sal_uInt16 nPrefx = rLocalRef.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
116 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
117 if (XML_NAMESPACE_TEXT == nPrefx && IsXMLToken ( aLocalName, XML_NAME ) )
118 sName = rAttrValue;
119 }
120 if ( sName.Len() )
121 rLocalRef.rSectionList.Insert ( new String(sName), rLocalRef.rSectionList.Count() );
122 }
123
124 pContext = new SvXMLSectionListContext (rLocalRef, nPrefix, rLocalName, xAttrList);
125 return pContext;
126 }
~SvXMLSectionListContext(void)127 SvXMLSectionListContext::~SvXMLSectionListContext ( void )
128 {
129 }
130
SvXMLIgnoreSectionListContext(SwXMLSectionList & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)131 SvXMLIgnoreSectionListContext::SvXMLIgnoreSectionListContext(
132 SwXMLSectionList& rImport,
133 sal_uInt16 nPrefix,
134 const OUString& rLocalName,
135 const uno::Reference< xml::sax::XAttributeList > & ) :
136 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
137 rLocalRef(rImport)
138 {
139 }
140
~SvXMLIgnoreSectionListContext(void)141 SvXMLIgnoreSectionListContext::~SvXMLIgnoreSectionListContext ( void )
142 {
143 }
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)144 SvXMLImportContext *SvXMLIgnoreSectionListContext::CreateChildContext(
145 sal_uInt16 nPrefix,
146 const OUString& rLocalName,
147 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
148 {
149 return new SvXMLIgnoreSectionListContext (rLocalRef, nPrefix, rLocalName, xAttrList);
150 }
151