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 57 : 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 57 : rLocalRef (rImport)
40 : {
41 57 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
42 114 : for (sal_Int16 i=0; i < nAttrCount; i++)
43 : {
44 114 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
45 171 : OUString aLocalName;
46 114 : sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
47 171 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
48 114 : if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
49 : {
50 57 : if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
51 : {
52 57 : rImport.getBlockList().SetName(rAttrValue);
53 57 : break;
54 : }
55 : }
56 57 : }
57 57 : }
58 :
59 114 : SwXMLBlockListContext::~SwXMLBlockListContext ( void )
60 : {
61 114 : }
62 :
63 34 : SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
64 : sal_uInt16 nPrefix,
65 : const OUString& rLocalName,
66 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
67 : {
68 34 : SvXMLImportContext *pContext = 0;
69 68 : if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
70 34 : IsXMLToken ( rLocalName, XML_BLOCK ) )
71 34 : pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
72 : else
73 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
74 34 : return pContext;
75 : }
76 :
77 34 : SwXMLBlockContext::SwXMLBlockContext(
78 : SwXMLBlockListImport& rImport,
79 : sal_uInt16 nPrefix,
80 : const OUString& rLocalName,
81 : const uno::Reference<
82 : xml::sax::XAttributeList > & xAttrList ) :
83 34 : SvXMLImportContext ( rImport, nPrefix, rLocalName )
84 : {
85 34 : static const CharClass & rCC = GetAppCharClass();
86 34 : OUString aShort;
87 68 : OUString aLong;
88 68 : OUString aPackageName;
89 34 : sal_Bool bTextOnly = sal_False;
90 :
91 34 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
92 170 : for (sal_Int16 i=0; i < nAttrCount; i++)
93 : {
94 136 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
95 272 : OUString aLocalName;
96 136 : sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
97 272 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
98 136 : if (XML_NAMESPACE_BLOCKLIST == nPrefx)
99 : {
100 136 : if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
101 : {
102 34 : aShort = rCC.uppercase(rAttrValue);
103 : }
104 102 : else if ( IsXMLToken ( aLocalName, XML_NAME ) )
105 : {
106 34 : aLong = rAttrValue;
107 : }
108 68 : else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
109 : {
110 34 : aPackageName = rAttrValue;
111 : }
112 34 : else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
113 : {
114 34 : if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
115 34 : bTextOnly = sal_True;
116 : }
117 : }
118 136 : }
119 34 : if (aShort.isEmpty() || aLong.isEmpty() || aPackageName.isEmpty())
120 34 : return;
121 68 : rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
122 : }
123 :
124 68 : SwXMLBlockContext::~SwXMLBlockContext ( void )
125 : {
126 68 : }
127 :
128 4 : 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 4 : rLocalRef(rImport)
136 : {
137 4 : }
138 :
139 4 : SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
140 : sal_uInt16 nPrefix,
141 : const OUString& rLocalName,
142 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
143 : {
144 4 : SvXMLImportContext *pContext = 0;
145 8 : if (nPrefix == XML_NAMESPACE_OFFICE &&
146 4 : IsXMLToken ( rLocalName, XML_BODY ) )
147 4 : pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
148 : else
149 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
150 4 : return pContext;
151 : }
152 8 : SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
153 : {
154 8 : }
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 4 : 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 4 : rLocalRef(rImport)
192 : {
193 4 : }
194 :
195 6 : SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
196 : sal_uInt16 nPrefix,
197 : const OUString& rLocalName,
198 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
199 : {
200 6 : SvXMLImportContext *pContext = 0;
201 6 : if (nPrefix == XML_NAMESPACE_OFFICE &&
202 0 : IsXMLToken ( rLocalName, XML_TEXT ) )
203 0 : pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
204 12 : else if (nPrefix == XML_NAMESPACE_TEXT &&
205 6 : IsXMLToken ( rLocalName, XML_P ) )
206 6 : pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
207 : else
208 0 : pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
209 6 : return pContext;
210 : }
211 8 : SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
212 : {
213 8 : }
214 6 : 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 6 : rLocalRef(rImport)
222 : {
223 6 : }
224 :
225 6 : void SwXMLTextBlockParContext::Characters( const OUString& rChars )
226 : {
227 6 : rLocalRef.m_rText += rChars;
228 6 : }
229 18 : SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
230 : {
231 6 : if (rLocalRef.bTextOnly)
232 6 : rLocalRef.m_rText += "\015";
233 : else
234 : {
235 0 : if (!rLocalRef.m_rText.endsWith( " " ))
236 0 : rLocalRef.m_rText += " ";
237 : }
238 12 : }
239 :
240 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|