1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 #include "SchXMLImport.hxx"
32 #include "SchXMLTextListContext.hxx"
33 #include "SchXMLParagraphContext.hxx"
34 
35 #include "xmloff/xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/nmspmap.hxx>
38 
39 using ::rtl::OUString;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::uno::Reference;
42 using namespace com::sun::star;
43 using namespace ::xmloff::token;
44 
45 //-------------------------------------------------
46 class SchXMLListItemContext : public SvXMLImportContext
47 {
48 public:
49 	SchXMLListItemContext( SvXMLImport& rImport, const OUString& rLocalName, OUString& rText );
50 	virtual ~SchXMLListItemContext();
51 	virtual void StartElement( const Reference< xml::sax::XAttributeList >& xAttrList );
52 	virtual void EndElement();
53 
54 	virtual SvXMLImportContext* CreateChildContext(
55 		sal_uInt16 nPrefix,
56 		const ::rtl::OUString& rLocalName,
57 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
58 
59 private:
60     ::rtl::OUString& m_rText;
61 };
62 
63 SchXMLListItemContext::SchXMLListItemContext(
64         SvXMLImport& rImport
65         , const OUString& rLocalName
66 		, OUString& rText )
67         : SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName )
68         , m_rText( rText )
69 {
70 }
71 
72 SchXMLListItemContext::~SchXMLListItemContext()
73 {}
74 
75 void SchXMLListItemContext::StartElement( const Reference< xml::sax::XAttributeList >& /*xAttrList*/ )
76 {
77 }
78 
79 void SchXMLListItemContext::EndElement()
80 {
81 }
82 
83 SvXMLImportContext* SchXMLListItemContext::CreateChildContext(
84     sal_uInt16 nPrefix, const OUString& rLocalName,
85     const uno::Reference< xml::sax::XAttributeList >& )
86 {
87 	SvXMLImportContext* pContext = 0;
88 	if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_P ) )
89 		pContext = new SchXMLParagraphContext( GetImport(), rLocalName, m_rText );
90 	else
91 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
92 	return pContext;
93 }
94 
95 //-------------------------------------------------
96 
97 SchXMLTextListContext::SchXMLTextListContext(
98         SvXMLImport& rImport
99         , const OUString& rLocalName
100 		, Sequence< OUString>& rTextList )
101         : SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName )
102         , m_rTextList( rTextList )
103         , m_aTextVector()
104 {
105 }
106 
107 SchXMLTextListContext::~SchXMLTextListContext()
108 {
109 }
110 
111 void SchXMLTextListContext::StartElement( const Reference< xml::sax::XAttributeList >& /*xAttrList*/ )
112 {
113 }
114 
115 void SchXMLTextListContext::EndElement()
116 {
117     sal_Int32 nCount = m_aTextVector.size();
118     m_rTextList.realloc(nCount);
119     for( sal_Int32 nN=0; nN<nCount; nN++ )
120         m_rTextList[nN]=m_aTextVector[nN];
121 }
122 
123 SvXMLImportContext* SchXMLTextListContext::CreateChildContext(
124     sal_uInt16 nPrefix, const OUString& rLocalName,
125     const uno::Reference< xml::sax::XAttributeList >& )
126 {
127 	SvXMLImportContext* pContext = 0;
128 	if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_LIST_ITEM ) )
129     {
130         m_aTextVector.push_back( OUString() );
131     	pContext = new SchXMLListItemContext( GetImport(), rLocalName, m_aTextVector.back() );
132     }
133 	else
134 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
135 	return pContext;
136 }
137