Update ooo320-m1
[ooovba.git] / sw / source / core / swg / SwXMLBlockListContext.cxx
blobba23ea6e587c46d5a78927ec7eac5c173293acc1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXMLBlockListContext.cxx,v $
10 * $Revision: 1.14 $
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 #include <SwXMLBlockListContext.hxx>
34 #include <SwXMLBlockImport.hxx>
35 #include <SwXMLTextBlocks.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmlnmspe.hxx>
38 #include <unotools/charclass.hxx>
39 #include <swtypes.hxx>
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star;
43 using namespace ::xmloff::token;
44 using ::rtl::OUString;
46 SwXMLBlockListContext::SwXMLBlockListContext(
47 SwXMLBlockListImport& rImport,
48 sal_uInt16 nPrefix,
49 const OUString& rLocalName,
50 const uno::Reference<
51 xml::sax::XAttributeList > & xAttrList ) :
52 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
53 rLocalRef (rImport)
55 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
56 for (sal_Int16 i=0; i < nAttrCount; i++)
58 const OUString& rAttrName = xAttrList->getNameByIndex( i );
59 OUString aLocalName;
60 sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
61 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
62 if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
64 if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
66 rImport.getBlockList().SetName(rAttrValue);
67 break;
73 SwXMLBlockListContext::~SwXMLBlockListContext ( void )
77 SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
78 sal_uInt16 nPrefix,
79 const OUString& rLocalName,
80 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
82 SvXMLImportContext *pContext = 0;
83 if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
84 IsXMLToken ( rLocalName, XML_BLOCK ) )
85 pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
86 else
87 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
88 return pContext;
91 SwXMLBlockContext::SwXMLBlockContext(
92 SwXMLBlockListImport& rImport,
93 sal_uInt16 nPrefix,
94 const OUString& rLocalName,
95 const uno::Reference<
96 xml::sax::XAttributeList > & xAttrList ) :
97 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
98 rLocalRef(rImport)
100 static const CharClass & rCC = GetAppCharClass();
101 String aShort, aLong, aPackageName;
102 BOOL bTextOnly = FALSE;
104 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
105 for (sal_Int16 i=0; i < nAttrCount; i++)
107 const OUString& rAttrName = xAttrList->getNameByIndex( i );
108 OUString aLocalName;
109 sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
110 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
111 if (XML_NAMESPACE_BLOCKLIST == nPrefx)
113 if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
115 aShort = rCC.upper(rAttrValue);
117 else if ( IsXMLToken ( aLocalName, XML_NAME ) )
119 aLong = rAttrValue;
121 else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
123 aPackageName = rAttrValue;
125 else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
127 if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
128 bTextOnly = TRUE;
132 if (!aShort.Len() || !aLong.Len() || !aPackageName.Len())
133 return;
134 rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
137 SwXMLBlockContext::~SwXMLBlockContext ( void )
141 SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
142 SwXMLTextBlockImport& rImport,
143 sal_uInt16 nPrefix,
144 const OUString& rLocalName,
145 const uno::Reference<
146 xml::sax::XAttributeList > & ) :
147 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
148 rLocalRef(rImport)
152 SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
153 sal_uInt16 nPrefix,
154 const OUString& rLocalName,
155 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
157 SvXMLImportContext *pContext = 0;
158 if (nPrefix == XML_NAMESPACE_OFFICE &&
159 IsXMLToken ( rLocalName, XML_BODY ) )
160 pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
161 else
162 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
163 return pContext;
165 SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
170 SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
171 SwXMLTextBlockImport& rImport,
172 sal_uInt16 nPrefix,
173 const OUString& rLocalName,
174 const uno::Reference<
175 xml::sax::XAttributeList > & ) :
176 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
177 rLocalRef(rImport)
181 SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext(
182 sal_uInt16 nPrefix,
183 const OUString& rLocalName,
184 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
186 SvXMLImportContext *pContext = 0;
187 if (nPrefix == XML_NAMESPACE_TEXT &&
188 IsXMLToken ( rLocalName, XML_P ) )
189 pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
190 else
191 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
192 return pContext;
194 SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
199 SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
200 SwXMLTextBlockImport& rImport,
201 sal_uInt16 nPrefix,
202 const OUString& rLocalName,
203 const uno::Reference<
204 xml::sax::XAttributeList > & ) :
205 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
206 rLocalRef(rImport)
210 SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
211 sal_uInt16 nPrefix,
212 const OUString& rLocalName,
213 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
215 SvXMLImportContext *pContext = 0;
216 if (nPrefix == XML_NAMESPACE_OFFICE &&
217 IsXMLToken ( rLocalName, XML_TEXT ) )
218 pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
219 else if (nPrefix == XML_NAMESPACE_TEXT &&
220 IsXMLToken ( rLocalName, XML_P ) )
221 pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
222 else
223 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
224 return pContext;
226 SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
229 SwXMLTextBlockParContext::SwXMLTextBlockParContext(
230 SwXMLTextBlockImport& rImport,
231 sal_uInt16 nPrefix,
232 const OUString& rLocalName,
233 const uno::Reference<
234 xml::sax::XAttributeList > & ) :
235 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
236 rLocalRef(rImport)
240 void SwXMLTextBlockParContext::Characters( const ::rtl::OUString& rChars )
242 rLocalRef.m_rText.Append ( rChars.getStr());
244 SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
246 if (rLocalRef.bTextOnly)
247 rLocalRef.m_rText.AppendAscii( "\015" );
248 else
250 if (rLocalRef.m_rText.GetChar ( rLocalRef.m_rText.Len()) != ' ' )
251 rLocalRef.m_rText.AppendAscii( " " );