/sw/source/core/swg/SwXMLBlockListContext.cxx

https://github.com/jonasfj/libreoffice-writer · C++ · 250 lines · 206 code · 17 blank · 27 comment · 32 complexity · dbd97ef62a3b3d136d73e0f3b21cea9a MD5 · raw file

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