1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXMLSectionList.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #define _SVSTDARR_STRINGSDTOR
34 #define _SVSTDARR_STRINGS
35 #include <svtools/svstdarr.hxx>
36 #include <SwXMLSectionList.hxx>
37 #include <xmloff/nmspmap.hxx>
38 #include <xmloff/xmlnmspe.hxx>
40 using namespace ::com::sun::star
;
41 using ::rtl::OUString
;
42 using namespace ::xmloff::token
;
44 sal_Char __READONLY_DATA sXML_np__office
[] = "_ooffice";
45 sal_Char __READONLY_DATA sXML_np__text
[] = "_otext";
48 SwXMLSectionList::SwXMLSectionList(
49 const uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory
,
50 SvStrings
& rNewSectionList
)
51 : SvXMLImport( xServiceFactory
),
52 rSectionList ( rNewSectionList
)
54 GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office
) ),
55 GetXMLToken(XML_N_OFFICE_OOO
),
56 XML_NAMESPACE_OFFICE
);
57 GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__text
) ),
58 GetXMLToken(XML_N_TEXT_OOO
),
62 SwXMLSectionList::~SwXMLSectionList ( void )
67 SvXMLImportContext
*SwXMLSectionList::CreateContext(
69 const OUString
& rLocalName
,
70 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
72 SvXMLImportContext
*pContext
= 0;
74 if (nPrefix
== XML_NAMESPACE_OFFICE
&& IsXMLToken ( rLocalName
, XML_BODY
) ||
75 nPrefix
== XML_NAMESPACE_TEXT
&&
76 (IsXMLToken ( rLocalName
, XML_P
) ||
77 IsXMLToken ( rLocalName
, XML_H
) ||
78 IsXMLToken ( rLocalName
, XML_A
) ||
79 IsXMLToken ( rLocalName
, XML_SPAN
) ||
80 IsXMLToken ( rLocalName
, XML_SECTION
) ||
81 IsXMLToken ( rLocalName
, XML_INDEX_BODY
) ||
82 IsXMLToken ( rLocalName
, XML_INDEX_TITLE
)||
83 IsXMLToken ( rLocalName
, XML_INSERTION
) ||
84 IsXMLToken ( rLocalName
, XML_DELETION
) ) )
85 pContext
= new SvXMLSectionListContext (*this, nPrefix
, rLocalName
, xAttrList
);
87 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
91 SvXMLSectionListContext::SvXMLSectionListContext(
92 SwXMLSectionList
& rImport
,
94 const OUString
& rLocalName
,
95 const uno::Reference
< xml::sax::XAttributeList
> & ) :
96 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
101 SvXMLImportContext
*SvXMLSectionListContext::CreateChildContext(
103 const OUString
& rLocalName
,
104 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
106 SvXMLImportContext
*pContext
= 0;
109 if (nPrefix
== XML_NAMESPACE_TEXT
&& ( IsXMLToken ( rLocalName
, XML_SECTION
) ||
110 IsXMLToken ( rLocalName
, XML_BOOKMARK
) ) )
112 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
114 for (sal_Int16 i
=0; i
< nAttrCount
; i
++)
116 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
118 sal_uInt16 nPrefx
= rLocalRef
.GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
119 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
120 if (XML_NAMESPACE_TEXT
== nPrefx
&& IsXMLToken ( aLocalName
, XML_NAME
) )
124 rLocalRef
.rSectionList
.Insert ( new String(sName
), rLocalRef
.rSectionList
.Count() );
127 pContext
= new SvXMLSectionListContext (rLocalRef
, nPrefix
, rLocalName
, xAttrList
);
130 SvXMLSectionListContext::~SvXMLSectionListContext ( void )
134 SvXMLIgnoreSectionListContext::SvXMLIgnoreSectionListContext(
135 SwXMLSectionList
& rImport
,
137 const OUString
& rLocalName
,
138 const uno::Reference
< xml::sax::XAttributeList
> & ) :
139 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
144 SvXMLIgnoreSectionListContext::~SvXMLIgnoreSectionListContext ( void )
147 SvXMLImportContext
*SvXMLIgnoreSectionListContext::CreateChildContext(
149 const OUString
& rLocalName
,
150 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
152 return new SvXMLIgnoreSectionListContext (rLocalRef
, nPrefix
, rLocalName
, xAttrList
);