Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <SwXMLBlockListContext.hxx>
21 : #include <SwXMLBlockImport.hxx>
22 : #include <SwXMLTextBlocks.hxx>
23 : #include <xmloff/nmspmap.hxx>
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <unotools/charclass.hxx>
26 : #include <swtypes.hxx>
27 :
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star;
30 : using namespace ::xmloff::token;
31 :
32 114 : SwXMLBlockListContext::SwXMLBlockListContext(
33 : SwXMLBlockListImport& rImport,
34 : sal_uInt16 nPrefix,
35 : const OUString& rLocalName,
36 : const uno::Reference<
37 : xml::sax::XAttributeList > & xAttrList ) :
38 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
39 114 : rLocalRef (rImport)
40 : {
41 114 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
42 228 : for (sal_Int16 i=0; i < nAttrCount; i++)
43 : {
44 228 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
45 342 : OUString aLocalName;
46 228 : sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
47 342 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
48 228 : if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
49 : {
50 114 : if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
51 : {
52 114 : rImport.getBlockList().SetName(rAttrValue);
53 114 : break;
54 : }
55 : }
56 114 : }
57 114 : }
58 :
59 228 : SwXMLBlockListContext::~SwXMLBlockListContext ( void )
60 : {
61 228 : }
62 :
63 68 : SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
64 : sal_uInt16 nPrefix,
65 : const OUString& rLocalName,
66 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
67 : {
68 68 : SvXMLImportContext *pContext = 0;
69 136 : if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
70 68 : IsXMLToken ( rLocalName, XML_BLOCK ) )
71 68 : pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
72 : else
73 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
74 68 : return pContext;
75 : }
76 :
77 68 : SwXMLBlockContext::SwXMLBlockContext(
78 : SwXMLBlockListImport& rImport,
79 : sal_uInt16 nPrefix,
80 : const OUString& rLocalName,
81 : const uno::Reference<
82 : xml::sax::XAttributeList > & xAttrList ) :
83 68 : SvXMLImportContext ( rImport, nPrefix, rLocalName )
84 : {
85 68 : static const CharClass & rCC = GetAppCharClass();
86 68 : OUString aShort;
87 136 : OUString aLong;
88 136 : OUString aPackageName;
89 68 : bool bTextOnly = false;
90 :
91 68 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
92 340 : for (sal_Int16 i=0; i < nAttrCount; i++)
93 : {
94 272 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
95 544 : OUString aLocalName;
96 272 : sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
97 544 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
98 272 : if (XML_NAMESPACE_BLOCKLIST == nPrefx)
99 : {
100 272 : if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
101 : {
102 68 : aShort = rCC.uppercase(rAttrValue);
103 : }
104 204 : else if ( IsXMLToken ( aLocalName, XML_NAME ) )
105 : {
106 68 : aLong = rAttrValue;
107 : }
108 136 : else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
109 : {
110 68 : aPackageName = rAttrValue;
111 : }
112 68 : else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
113 : {
114 68 : if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
115 68 : bTextOnly = true;
116 : }
117 : }
118 272 : }
119 68 : if (aShort.isEmpty() || aLong.isEmpty() || aPackageName.isEmpty())
120 68 : return;
121 136 : rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
122 : }
123 :
124 136 : SwXMLBlockContext::~SwXMLBlockContext ( void )
125 : {
126 136 : }
127 :
128 8 : SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
129 : SwXMLTextBlockImport& rImport,
130 : sal_uInt16 nPrefix,
131 : const OUString& rLocalName,
132 : const uno::Reference<
133 : xml::sax::XAttributeList > & ) :
134 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
135 8 : rLocalRef(rImport)
136 : {
137 8 : }
138 :
139 8 : SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
140 : sal_uInt16 nPrefix,
141 : const OUString& rLocalName,
142 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
143 : {
144 8 : SvXMLImportContext *pContext = 0;
145 16 : if (nPrefix == XML_NAMESPACE_OFFICE &&
146 8 : IsXMLToken ( rLocalName, XML_BODY ) )
147 8 : pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
148 : else
149 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
150 8 : return pContext;
151 : }
152 16 : SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
153 : {
154 16 : }
155 :
156 0 : SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
157 : SwXMLTextBlockImport& rImport,
158 : sal_uInt16 nPrefix,
159 : const OUString& rLocalName,
160 : const uno::Reference<
161 : xml::sax::XAttributeList > & ) :
162 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
163 0 : rLocalRef(rImport)
164 : {
165 0 : }
166 :
167 0 : SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext(
168 : sal_uInt16 nPrefix,
169 : const OUString& rLocalName,
170 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
171 : {
172 0 : SvXMLImportContext *pContext = 0;
173 0 : if (nPrefix == XML_NAMESPACE_TEXT &&
174 0 : IsXMLToken ( rLocalName, XML_P ) )
175 0 : pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
176 : else
177 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
178 0 : return pContext;
179 : }
180 0 : SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
181 : {
182 0 : }
183 :
184 8 : SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
185 : SwXMLTextBlockImport& rImport,
186 : sal_uInt16 nPrefix,
187 : const OUString& rLocalName,
188 : const uno::Reference<
189 : xml::sax::XAttributeList > & ) :
190 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
191 8 : rLocalRef(rImport)
192 : {
193 8 : }
194 :
195 12 : SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
196 : sal_uInt16 nPrefix,
197 : const OUString& rLocalName,
198 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
199 : {
200 12 : SvXMLImportContext *pContext = 0;
201 12 : if (nPrefix == XML_NAMESPACE_OFFICE &&
202 0 : IsXMLToken ( rLocalName, XML_TEXT ) )
203 0 : pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
204 24 : else if (nPrefix == XML_NAMESPACE_TEXT &&
205 12 : IsXMLToken ( rLocalName, XML_P ) )
206 12 : pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
207 : else
208 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
209 12 : return pContext;
210 : }
211 16 : SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
212 : {
213 16 : }
214 12 : SwXMLTextBlockParContext::SwXMLTextBlockParContext(
215 : SwXMLTextBlockImport& rImport,
216 : sal_uInt16 nPrefix,
217 : const OUString& rLocalName,
218 : const uno::Reference<
219 : xml::sax::XAttributeList > & ) :
220 : SvXMLImportContext ( rImport, nPrefix, rLocalName ),
221 12 : rLocalRef(rImport)
222 : {
223 12 : }
224 :
225 12 : void SwXMLTextBlockParContext::Characters( const OUString& rChars )
226 : {
227 12 : rLocalRef.m_rText += rChars;
228 12 : }
229 36 : SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
230 : {
231 12 : if (rLocalRef.bTextOnly)
232 12 : rLocalRef.m_rText += "\015";
233 : else
234 : {
235 0 : if (!rLocalRef.m_rText.endsWith( " " ))
236 0 : rLocalRef.m_rText += " ";
237 : }
238 294 : }
239 :
240 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|