1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #include <SwXMLBlockListContext.hxx>
27 #include <SwXMLBlockImport.hxx>
28 #include <SwXMLTextBlocks.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <unotools/charclass.hxx>
32 #include <swtypes.hxx>
33 
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star;
36 using namespace ::xmloff::token;
37 using ::rtl::OUString;
38 
SwXMLBlockListContext(SwXMLBlockListImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)39 SwXMLBlockListContext::SwXMLBlockListContext(
40    SwXMLBlockListImport& rImport,
41    sal_uInt16 nPrefix,
42    const OUString& rLocalName,
43    const uno::Reference<
44    xml::sax::XAttributeList > & xAttrList ) :
45 	SvXMLImportContext ( rImport, nPrefix, rLocalName ),
46 	rLocalRef (rImport)
47 {
48 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
49 	for (sal_Int16 i=0; i < nAttrCount; i++)
50 	{
51 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
52 		OUString aLocalName;
53 		sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
54 		const OUString& rAttrValue = xAttrList->getValueByIndex( i );
55 		if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
56 		{
57 			if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
58 			{
59 				rImport.getBlockList().SetName(rAttrValue);
60 				break;
61 			}
62 		}
63 	}
64 }
65 
~SwXMLBlockListContext(void)66 SwXMLBlockListContext::~SwXMLBlockListContext ( void )
67 {
68 }
69 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)70 SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
71 	sal_uInt16 nPrefix,
72 	const OUString& rLocalName,
73 	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
74 {
75 	SvXMLImportContext *pContext = 0;
76 	if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
77 		IsXMLToken ( rLocalName, XML_BLOCK ) )
78 		pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
79 	else
80 		pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
81 	return pContext;
82 }
83 
SwXMLBlockContext(SwXMLBlockListImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)84 SwXMLBlockContext::SwXMLBlockContext(
85    SwXMLBlockListImport& rImport,
86    sal_uInt16 nPrefix,
87    const OUString& rLocalName,
88    const uno::Reference<
89    xml::sax::XAttributeList > & xAttrList ) :
90 	SvXMLImportContext ( rImport, nPrefix, rLocalName ),
91     rLocalRef(rImport)
92 {
93 	static const CharClass & rCC = GetAppCharClass();
94 	String aShort, aLong, aPackageName;
95 	sal_Bool bTextOnly = sal_False;
96 
97 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
98 	for (sal_Int16 i=0; i < nAttrCount; i++)
99 	{
100 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
101 		OUString aLocalName;
102 		sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
103 		const OUString& rAttrValue = xAttrList->getValueByIndex( i );
104 		if (XML_NAMESPACE_BLOCKLIST == nPrefx)
105 		{
106 			if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
107 			{
108 				aShort = rCC.upper(rAttrValue);
109 			}
110 			else if ( IsXMLToken ( aLocalName, XML_NAME ) )
111 			{
112 				aLong = rAttrValue;
113 			}
114 			else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
115 			{
116 				aPackageName = rAttrValue;
117 			}
118 			else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
119 			{
120 				if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
121 					bTextOnly = sal_True;
122 			}
123 		}
124 	}
125 	if (!aShort.Len() || !aLong.Len() || !aPackageName.Len())
126 		return;
127 	rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
128 }
129 
~SwXMLBlockContext(void)130 SwXMLBlockContext::~SwXMLBlockContext ( void )
131 {
132 }
133 
SwXMLTextBlockDocumentContext(SwXMLTextBlockImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)134 SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
135    SwXMLTextBlockImport& rImport,
136    sal_uInt16 nPrefix,
137    const OUString& rLocalName,
138    const uno::Reference<
139    xml::sax::XAttributeList > & ) :
140 	SvXMLImportContext ( rImport, nPrefix, rLocalName ),
141 	rLocalRef(rImport)
142 {
143 }
144 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)145 SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
146 	sal_uInt16 nPrefix,
147 	const OUString& rLocalName,
148 	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
149 {
150 	SvXMLImportContext *pContext = 0;
151 	if (nPrefix == XML_NAMESPACE_OFFICE &&
152 		IsXMLToken ( rLocalName, XML_BODY ) )
153 		pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
154 	else
155 		pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
156 	return pContext;
157 }
~SwXMLTextBlockDocumentContext(void)158 SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
159 {
160 }
161 
162 
SwXMLTextBlockTextContext(SwXMLTextBlockImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)163 SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
164    SwXMLTextBlockImport& rImport,
165    sal_uInt16 nPrefix,
166    const OUString& rLocalName,
167    const uno::Reference<
168    xml::sax::XAttributeList > & ) :
169 	SvXMLImportContext ( rImport, nPrefix, rLocalName ),
170 	rLocalRef(rImport)
171 {
172 }
173 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)174 SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext(
175 	sal_uInt16 nPrefix,
176 	const OUString& rLocalName,
177 	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
178 {
179 	SvXMLImportContext *pContext = 0;
180 	if (nPrefix == XML_NAMESPACE_TEXT &&
181 		IsXMLToken ( rLocalName, XML_P ) )
182 		pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
183 	else
184 		pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
185 	return pContext;
186 }
~SwXMLTextBlockTextContext(void)187 SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
188 {
189 }
190 
191 
SwXMLTextBlockBodyContext(SwXMLTextBlockImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)192 SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
193    SwXMLTextBlockImport& rImport,
194    sal_uInt16 nPrefix,
195    const OUString& rLocalName,
196    const uno::Reference<
197    xml::sax::XAttributeList > & ) :
198 	SvXMLImportContext ( rImport, nPrefix, rLocalName ),
199 	rLocalRef(rImport)
200 {
201 }
202 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)203 SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
204 	sal_uInt16 nPrefix,
205 	const OUString& rLocalName,
206 	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
207 {
208 	SvXMLImportContext *pContext = 0;
209 	if (nPrefix == XML_NAMESPACE_OFFICE &&
210 		IsXMLToken ( rLocalName, XML_TEXT ) )
211 		pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
212 	else if (nPrefix == XML_NAMESPACE_TEXT &&
213 		IsXMLToken ( rLocalName, XML_P ) )
214 		pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
215 	else
216 		pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
217 	return pContext;
218 }
~SwXMLTextBlockBodyContext(void)219 SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
220 {
221 }
SwXMLTextBlockParContext(SwXMLTextBlockImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)222 SwXMLTextBlockParContext::SwXMLTextBlockParContext(
223    SwXMLTextBlockImport& rImport,
224    sal_uInt16 nPrefix,
225    const OUString& rLocalName,
226    const uno::Reference<
227    xml::sax::XAttributeList > & ) :
228 	SvXMLImportContext ( rImport, nPrefix, rLocalName ),
229 	rLocalRef(rImport)
230 {
231 }
232 
Characters(const::rtl::OUString & rChars)233 void SwXMLTextBlockParContext::Characters( const ::rtl::OUString& rChars )
234 {
235 	rLocalRef.m_rText.Append ( rChars.getStr());
236 }
~SwXMLTextBlockParContext(void)237 SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
238 {
239 	if (rLocalRef.bTextOnly)
240 		rLocalRef.m_rText.AppendAscii( "\015" );
241 	else
242 	{
243 		if (rLocalRef.m_rText.GetChar ( rLocalRef.m_rText.Len()) != ' ' )
244 			rLocalRef.m_rText.AppendAscii( " " );
245 	}
246 }
247