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: SwXMLBlockListContext.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 #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
,
49 const OUString
& rLocalName
,
51 xml::sax::XAttributeList
> & xAttrList
) :
52 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
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
);
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
);
73 SwXMLBlockListContext::~SwXMLBlockListContext ( void )
77 SvXMLImportContext
*SwXMLBlockListContext::CreateChildContext(
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
);
87 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
91 SwXMLBlockContext::SwXMLBlockContext(
92 SwXMLBlockListImport
& rImport
,
94 const OUString
& rLocalName
,
96 xml::sax::XAttributeList
> & xAttrList
) :
97 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
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
);
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
) )
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
) )
132 if (!aShort
.Len() || !aLong
.Len() || !aPackageName
.Len())
134 rImport
.getBlockList().AddName( aShort
, aLong
, aPackageName
, bTextOnly
);
137 SwXMLBlockContext::~SwXMLBlockContext ( void )
141 SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
142 SwXMLTextBlockImport
& rImport
,
144 const OUString
& rLocalName
,
145 const uno::Reference
<
146 xml::sax::XAttributeList
> & ) :
147 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
152 SvXMLImportContext
*SwXMLTextBlockDocumentContext::CreateChildContext(
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
);
162 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
165 SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
170 SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
171 SwXMLTextBlockImport
& rImport
,
173 const OUString
& rLocalName
,
174 const uno::Reference
<
175 xml::sax::XAttributeList
> & ) :
176 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
181 SvXMLImportContext
*SwXMLTextBlockTextContext::CreateChildContext(
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
);
191 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
194 SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
199 SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
200 SwXMLTextBlockImport
& rImport
,
202 const OUString
& rLocalName
,
203 const uno::Reference
<
204 xml::sax::XAttributeList
> & ) :
205 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
210 SvXMLImportContext
*SwXMLTextBlockBodyContext::CreateChildContext(
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
);
223 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
226 SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
229 SwXMLTextBlockParContext::SwXMLTextBlockParContext(
230 SwXMLTextBlockImport
& rImport
,
232 const OUString
& rLocalName
,
233 const uno::Reference
<
234 xml::sax::XAttributeList
> & ) :
235 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
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" );
250 if (rLocalRef
.m_rText
.GetChar ( rLocalRef
.m_rText
.Len()) != ' ' )
251 rLocalRef
.m_rText
.AppendAscii( " " );