Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <SwXMLBlockListContext.hxx>
30 : : #include <SwXMLBlockImport.hxx>
31 : : #include <SwXMLTextBlocks.hxx>
32 : : #include <xmloff/nmspmap.hxx>
33 : : #include <xmloff/xmlnmspe.hxx>
34 : : #include <unotools/charclass.hxx>
35 : : #include <swtypes.hxx>
36 : :
37 : : using namespace ::com::sun::star::uno;
38 : : using namespace ::com::sun::star;
39 : : using namespace ::xmloff::token;
40 : : using ::rtl::OUString;
41 : :
42 : 114 : SwXMLBlockListContext::SwXMLBlockListContext(
43 : : SwXMLBlockListImport& rImport,
44 : : sal_uInt16 nPrefix,
45 : : const OUString& rLocalName,
46 : : const uno::Reference<
47 : : xml::sax::XAttributeList > & xAttrList ) :
48 : : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
49 : 114 : rLocalRef (rImport)
50 : : {
51 [ + - ][ + - ]: 114 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
52 [ + - ]: 342 : for (sal_Int16 i=0; i < nAttrCount; i++)
53 : : {
54 [ + - ][ + - ]: 228 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
55 : 228 : OUString aLocalName;
56 [ + - ]: 228 : sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
57 [ + - ][ + - ]: 228 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
58 [ + + ]: 228 : if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
59 : : {
60 [ + - ][ + - ]: 114 : if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
61 : : {
62 [ + - ][ + - ]: 228 : rImport.getBlockList().SetName(rAttrValue);
[ + - ]
63 : : break;
64 : : }
65 : : }
66 [ + + ][ + + ]: 228 : }
[ + + ]
67 : 114 : }
68 : :
69 : 114 : SwXMLBlockListContext::~SwXMLBlockListContext ( void )
70 : : {
71 [ - + ]: 228 : }
72 : :
73 : 68 : SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
74 : : sal_uInt16 nPrefix,
75 : : const OUString& rLocalName,
76 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
77 : : {
78 : 68 : SvXMLImportContext *pContext = 0;
79 [ + - + - ]: 136 : if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
[ + - ]
80 : 68 : IsXMLToken ( rLocalName, XML_BLOCK ) )
81 [ + - ]: 68 : pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
82 : : else
83 [ # # ]: 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
84 : 68 : return pContext;
85 : : }
86 : :
87 : 68 : SwXMLBlockContext::SwXMLBlockContext(
88 : : SwXMLBlockListImport& rImport,
89 : : sal_uInt16 nPrefix,
90 : : const OUString& rLocalName,
91 : : const uno::Reference<
92 : : xml::sax::XAttributeList > & xAttrList ) :
93 : : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
94 : 68 : rLocalRef(rImport)
95 : : {
96 [ + - ][ + - ]: 68 : static const CharClass & rCC = GetAppCharClass();
[ # # ][ + + ]
97 [ + - ][ + - ]: 68 : String aShort, aLong, aPackageName;
[ + - ]
98 : 68 : sal_Bool bTextOnly = sal_False;
99 : :
100 [ + - ][ + - ]: 68 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
101 [ + + ]: 340 : for (sal_Int16 i=0; i < nAttrCount; i++)
102 : : {
103 [ + - ][ + - ]: 272 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
104 : 272 : OUString aLocalName;
105 [ + - ]: 272 : sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
106 [ + - ][ + - ]: 272 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
107 [ + - ]: 272 : if (XML_NAMESPACE_BLOCKLIST == nPrefx)
108 : : {
109 [ + - ][ + + ]: 272 : if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
110 : : {
111 [ + - ][ + - ]: 68 : aShort = rCC.uppercase(rAttrValue);
112 : : }
113 [ + - ][ + + ]: 204 : else if ( IsXMLToken ( aLocalName, XML_NAME ) )
114 : : {
115 [ + - ]: 68 : aLong = rAttrValue;
116 : : }
117 [ + - ][ + + ]: 136 : else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
118 : : {
119 [ + - ]: 68 : aPackageName = rAttrValue;
120 : : }
121 [ + - ][ + - ]: 68 : else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
122 : : {
123 [ + - ][ + - ]: 68 : if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
124 : 68 : bTextOnly = sal_True;
125 : : }
126 : : }
127 : 272 : }
128 [ + - ][ + - ]: 68 : if (!aShort.Len() || !aLong.Len() || !aPackageName.Len())
[ - + ][ - + ]
129 : 68 : return;
130 [ + - ][ + - ]: 68 : rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
[ - + ][ + - ]
[ - + ][ + - ]
[ + - ]
131 : : }
132 : :
133 : 68 : SwXMLBlockContext::~SwXMLBlockContext ( void )
134 : : {
135 [ - + ]: 136 : }
136 : :
137 : 8 : SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
138 : : SwXMLTextBlockImport& rImport,
139 : : sal_uInt16 nPrefix,
140 : : const OUString& rLocalName,
141 : : const uno::Reference<
142 : : xml::sax::XAttributeList > & ) :
143 : : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
144 : 8 : rLocalRef(rImport)
145 : : {
146 : 8 : }
147 : :
148 : 8 : SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
149 : : sal_uInt16 nPrefix,
150 : : const OUString& rLocalName,
151 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
152 : : {
153 : 8 : SvXMLImportContext *pContext = 0;
154 [ + - + - ]: 16 : if (nPrefix == XML_NAMESPACE_OFFICE &&
[ + - ]
155 : 8 : IsXMLToken ( rLocalName, XML_BODY ) )
156 [ + - ]: 8 : pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
157 : : else
158 [ # # ]: 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
159 : 8 : return pContext;
160 : : }
161 : 8 : SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
162 : : {
163 [ - + ]: 16 : }
164 : :
165 : :
166 : 0 : SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
167 : : SwXMLTextBlockImport& rImport,
168 : : sal_uInt16 nPrefix,
169 : : const OUString& rLocalName,
170 : : const uno::Reference<
171 : : xml::sax::XAttributeList > & ) :
172 : : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
173 : 0 : rLocalRef(rImport)
174 : : {
175 : 0 : }
176 : :
177 : 0 : SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext(
178 : : sal_uInt16 nPrefix,
179 : : const OUString& rLocalName,
180 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
181 : : {
182 : 0 : SvXMLImportContext *pContext = 0;
183 [ # # # # ]: 0 : if (nPrefix == XML_NAMESPACE_TEXT &&
[ # # ]
184 : 0 : IsXMLToken ( rLocalName, XML_P ) )
185 [ # # ]: 0 : pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
186 : : else
187 [ # # ]: 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
188 : 0 : return pContext;
189 : : }
190 : 0 : SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
191 : : {
192 [ # # ]: 0 : }
193 : :
194 : :
195 : 8 : SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
196 : : SwXMLTextBlockImport& rImport,
197 : : sal_uInt16 nPrefix,
198 : : const OUString& rLocalName,
199 : : const uno::Reference<
200 : : xml::sax::XAttributeList > & ) :
201 : : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
202 : 8 : rLocalRef(rImport)
203 : : {
204 : 8 : }
205 : :
206 : 12 : SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
207 : : sal_uInt16 nPrefix,
208 : : const OUString& rLocalName,
209 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
210 : : {
211 : 12 : SvXMLImportContext *pContext = 0;
212 [ - + # # ]: 12 : if (nPrefix == XML_NAMESPACE_OFFICE &&
[ - + ]
213 : 0 : IsXMLToken ( rLocalName, XML_TEXT ) )
214 [ # # ]: 0 : pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
215 [ + - + - ]: 24 : else if (nPrefix == XML_NAMESPACE_TEXT &&
[ + - ]
216 : 12 : IsXMLToken ( rLocalName, XML_P ) )
217 [ + - ]: 12 : pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
218 : : else
219 [ # # ]: 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
220 : 12 : return pContext;
221 : : }
222 : 8 : SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
223 : : {
224 [ - + ]: 16 : }
225 : 12 : SwXMLTextBlockParContext::SwXMLTextBlockParContext(
226 : : SwXMLTextBlockImport& rImport,
227 : : sal_uInt16 nPrefix,
228 : : const OUString& rLocalName,
229 : : const uno::Reference<
230 : : xml::sax::XAttributeList > & ) :
231 : : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
232 : 12 : rLocalRef(rImport)
233 : : {
234 : 12 : }
235 : :
236 : 12 : void SwXMLTextBlockParContext::Characters( const ::rtl::OUString& rChars )
237 : : {
238 : 12 : rLocalRef.m_rText.Append ( rChars.getStr());
239 : 12 : }
240 : 12 : SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
241 : : {
242 [ + - ]: 12 : if (rLocalRef.bTextOnly)
243 [ + - ]: 12 : rLocalRef.m_rText.AppendAscii( "\015" );
244 : : else
245 : : {
246 [ # # ]: 0 : if (rLocalRef.m_rText.GetChar ( rLocalRef.m_rText.Len()) != ' ' )
247 [ # # ]: 0 : rLocalRef.m_rText.AppendAscii( " " );
248 : : }
249 [ - + ]: 24 : }
250 : :
251 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|