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