| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | /*************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *  OpenOffice.org - a multi-platform office productivity suite | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *  $RCSfile: SwXMLTextBlocks1.cxx,v $ | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-01-19 17:20:43 +00:00
										 |  |  |  *  $Revision: 1.12 $ | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-01-19 17:20:43 +00:00
										 |  |  |  *  last change: $Author: obo $ $Date: 2006-01-19 18:20:43 $ | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *  The Contents of this file are made available subject to | 
					
						
							|  |  |  |  *  the terms of GNU Lesser General Public License Version 2.1. | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *    GNU Lesser General Public License Version 2.1 | 
					
						
							|  |  |  |  *    ============================================= | 
					
						
							|  |  |  |  *    Copyright 2005 by Sun Microsystems, Inc. | 
					
						
							|  |  |  |  *    901 San Antonio Road, Palo Alto, CA 94303, USA | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *    This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *    modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  *    License version 2.1, as published by the Free Software Foundation. | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *    This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  *    Lesser General Public License for more details. | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 03:43:40 +00:00
										 |  |  |  *    You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  *    License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 
					
						
							|  |  |  |  *    MA  02111-1307  USA | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  ************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma hdrstop
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  | #ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/embed/ElementModes.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _COM_SUN_STAR_EMBED_XTRANSACTEDOBJECT_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/embed/XTransactedObject.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | #ifndef _SFXMACITEM_HXX
 | 
					
						
							|  |  |  | #include <svtools/macitem.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SVTOOLS_UNOEVENT_HXX_
 | 
					
						
							|  |  |  | #include <svtools/unoevent.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SFXDOCFILE_HXX
 | 
					
						
							|  |  |  | #include <sfx2/docfile.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _UTL_STREAM_WRAPPER_HXX_
 | 
					
						
							|  |  |  | #include <unotools/streamwrap.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _COMPHELPER_PROCESSFACTORY_HXX_
 | 
					
						
							|  |  |  | #include <comphelper/processfactory.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _COM_SUN_STAR_XML_SAX_INPUTSOURCE_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/xml/sax/InputSource.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-09-17 14:03:04 +00:00
										 |  |  | #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/io/XActiveDataSource.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/xml/sax/XParser.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _DOC_HXX
 | 
					
						
							|  |  |  | #include <doc.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _DOCSH_HXX
 | 
					
						
							|  |  |  | #include <docsh.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SHELLIO_HXX
 | 
					
						
							|  |  |  | #include <shellio.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SW_XMLTEXTBLOCKS_HXX
 | 
					
						
							|  |  |  | #include <SwXMLTextBlocks.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SW_XMLBLOCKIMPORT_HXX
 | 
					
						
							|  |  |  | #include <SwXMLBlockImport.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SW_XMLBLOCKEXPORT_HXX
 | 
					
						
							|  |  |  | #include <SwXMLBlockExport.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SWEVENT_HXX
 | 
					
						
							|  |  |  | #include <swevent.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-07-13 08:05:30 +00:00
										 |  |  | #ifndef _SOT_FORMATS_HXX
 | 
					
						
							|  |  |  | #include <sot/formats.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef _SWSWERROR_H
 | 
					
						
							|  |  |  | #include <swerror.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _ERRHDL_HXX //autogen wg. ASSERT
 | 
					
						
							|  |  |  | #include <errhdl.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define STREAM_STGREAD  ( STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE )
 | 
					
						
							|  |  |  | #define STREAM_STGWRITE ( STREAM_READ | STREAM_WRITE | STREAM_SHARE_DENYWRITE )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sal_Char __FAR_DATA XMLN_BLOCKLIST[] = "BlockList.xml"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace ::com::sun::star; | 
					
						
							|  |  |  | using namespace ::com::sun::star::uno; | 
					
						
							|  |  |  | using namespace ::com::sun::star::container; | 
					
						
							|  |  |  | using namespace ::rtl; | 
					
						
							|  |  |  | using ::xmloff::token::XML_BLOCK_LIST; | 
					
						
							|  |  |  | using ::xmloff::token::XML_UNFORMATTED_TEXT; | 
					
						
							|  |  |  | using ::xmloff::token::GetXMLToken; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ULONG SwXMLTextBlocks::GetDoc( USHORT nIdx ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     String aFolderName ( GetPackageName ( nIdx ) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!IsOnlyTextBlock ( nIdx ) ) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::READ ); | 
					
						
							| 
									
										
										
										
											2005-01-11 11:21:50 +00:00
										 |  |  |             xMedium = new SfxMedium(xRoot, GetBaseURL()); | 
					
						
							|  |  |  |             SwReader aReader(*xMedium,aFolderName, pDoc ); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             ReadXML->SetBlockMode( sal_True ); | 
					
						
							|  |  |  |             aReader.Read( *ReadXML ); | 
					
						
							|  |  |  |             ReadXML->SetBlockMode( sal_False ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( uno::Exception& ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         xRoot = 0; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-10-06 18:01:23 +00:00
										 |  |  |         String aStreamName = aFolderName + (OUString) String::CreateFromAscii(".xml"); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         try | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::READ ); | 
					
						
							|  |  |  |             uno::Reference < io::XStream > xStream = xRoot->openStreamElement( aStreamName, embed::ElementModes::READ ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |                 comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |             ASSERT( xServiceFactory.is(), "XMLReader::Read: got no service manager" ); | 
					
						
							|  |  |  |             if( !xServiceFactory.is() ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 // Throw an exception ?
 | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             xml::sax::InputSource aParserInput; | 
					
						
							|  |  |  |             aParserInput.sSystemId = aNames [ nIdx ] ->aPackageName; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             aParserInput.aInputStream = xStream->getInputStream(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             // get parser
 | 
					
						
							|  |  |  |             Reference< XInterface > xXMLParser = xServiceFactory->createInstance( | 
					
						
							|  |  |  |                     OUString::createFromAscii("com.sun.star.xml.sax.Parser") ); | 
					
						
							|  |  |  |             ASSERT( xXMLParser.is(), | 
					
						
							|  |  |  |                     "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" ); | 
					
						
							|  |  |  |             if( !xXMLParser.is() ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 // Maybe throw an exception?
 | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             // get filter
 | 
					
						
							|  |  |  |             // #110680#
 | 
					
						
							|  |  |  |             // Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, aCur, sal_True );
 | 
					
						
							|  |  |  |             Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xServiceFactory, *this, aCur, sal_True ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             // connect parser and filter
 | 
					
						
							|  |  |  |             Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY ); | 
					
						
							|  |  |  |             xParser->setDocumentHandler( xFilter ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // parse
 | 
					
						
							|  |  |  |             try | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 xParser->parseStream( aParserInput ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             catch( xml::sax::SAXParseException&  ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 // re throw ?
 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             catch( xml::sax::SAXException&  ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 // re throw ?
 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             catch( io::IOException& ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 // re throw ?
 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             bInfoChanged = FALSE; | 
					
						
							|  |  |  |             MakeBlockText(aCur); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         catch( uno::Exception& ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         xRoot = 0; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // event description for autotext events; this constant should really be
 | 
					
						
							|  |  |  | // taken from unocore/unoevents.cxx or ui/unotxt.cxx
 | 
					
						
							|  |  |  | const struct SvEventDescription aAutotextEvents[] = | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     { SW_EVENT_START_INS_GLOSSARY,  "OnInsertStart" }, | 
					
						
							|  |  |  |     { SW_EVENT_END_INS_GLOSSARY,    "OnInsertDone" }, | 
					
						
							|  |  |  |     { 0, NULL } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ULONG SwXMLTextBlocks::GetMacroTable( USHORT nIdx, | 
					
						
							|  |  |  |                                       SvxMacroTableDtor& rMacroTbl, | 
					
						
							|  |  |  |                                       sal_Bool bFileAlreadyOpen ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // set current auto text
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     aShort = aNames[ nIdx ]->aShort; | 
					
						
							|  |  |  |     aLong = aNames[ nIdx ]->aLong; | 
					
						
							|  |  |  |     aPackageName = aNames[ nIdx ]->aPackageName; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ULONG nRet = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // open stream in proper sub-storage
 | 
					
						
							|  |  |  |     if( !bFileAlreadyOpen ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         CloseFile(); | 
					
						
							|  |  |  |         nRet = OpenFile ( TRUE ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ( 0 == nRet ) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         try | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             xRoot = xBlkRoot->openStorageElement( aPackageName, embed::ElementModes::READ ); | 
					
						
							|  |  |  |             sal_Bool bOasis = ( SotStorage::GetVersion( xRoot ) > SOT_FORMATSTR_ID_STARWRITER_60 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             OUString sStreamName = OUString::createFromAscii("atevent.xml"); | 
					
						
							|  |  |  |             uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( | 
					
						
							| 
									
										
										
										
											2005-01-18 14:25:56 +00:00
										 |  |  |                 sStreamName, embed::ElementModes::READ ); | 
					
						
							|  |  |  |             DBG_ASSERT(xDocStream.is(), "Can't create stream"); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             if ( xDocStream.is() ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |                 Reference<io::XInputStream> xInputStream = xDocStream->getInputStream(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // prepare ParserInputSrouce
 | 
					
						
							|  |  |  |                 xml::sax::InputSource aParserInput; | 
					
						
							|  |  |  |                 aParserInput.sSystemId = aName; | 
					
						
							|  |  |  |                 aParserInput.aInputStream = xInputStream; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |                 // get service factory
 | 
					
						
							|  |  |  |                 Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |                     comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |                 if ( xServiceFactory.is() ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     // get parser
 | 
					
						
							|  |  |  |                     OUString sParserService( RTL_CONSTASCII_USTRINGPARAM( | 
					
						
							|  |  |  |                         "com.sun.star.xml.sax.Parser" ) ); | 
					
						
							|  |  |  |                     Reference< xml::sax::XParser > xParser( | 
					
						
							|  |  |  |                         xServiceFactory->createInstance(sParserService), | 
					
						
							|  |  |  |                         UNO_QUERY ); | 
					
						
							|  |  |  |                     DBG_ASSERT( xParser.is(), "Can't create parser" ); | 
					
						
							|  |  |  |                     if( xParser.is() ) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // create descriptor and reference to it. Either
 | 
					
						
							|  |  |  |                         // both or neither must be kept because of the
 | 
					
						
							|  |  |  |                         // reference counting!
 | 
					
						
							|  |  |  |                         SvMacroTableEventDescriptor* pDescriptor = | 
					
						
							|  |  |  |                             new SvMacroTableEventDescriptor(aAutotextEvents); | 
					
						
							|  |  |  |                         Reference<XNameReplace> xReplace = pDescriptor; | 
					
						
							|  |  |  |                         Sequence<Any> aFilterArguments( 1 ); | 
					
						
							|  |  |  |                         aFilterArguments[0] <<= xReplace; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         // get filter
 | 
					
						
							|  |  |  |                         OUString sFilterComponent( OUString::createFromAscii( | 
					
						
							| 
									
										
										
										
											2004-07-13 08:05:30 +00:00
										 |  |  |                             bOasis | 
					
						
							|  |  |  |                             ? "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" | 
					
						
							|  |  |  |                             : "com.sun.star.comp.Writer.XMLAutotextEventsImporter")); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |                         Reference< xml::sax::XDocumentHandler > xFilter( | 
					
						
							|  |  |  |                             xServiceFactory->createInstanceWithArguments( | 
					
						
							|  |  |  |                                 sFilterComponent, aFilterArguments), | 
					
						
							|  |  |  |                             UNO_QUERY ); | 
					
						
							|  |  |  |                         DBG_ASSERT( xFilter.is(), | 
					
						
							|  |  |  |                                     "can't instantiate atevents filter"); | 
					
						
							|  |  |  |                         if ( xFilter.is() ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |                         { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |                             // connect parser and filter
 | 
					
						
							|  |  |  |                             xParser->setDocumentHandler( xFilter ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             // connect model and filter
 | 
					
						
							|  |  |  |                             Reference<document::XImporter> xImporter( xFilter, | 
					
						
							|  |  |  |                                                                     UNO_QUERY ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             // we don't need a model
 | 
					
						
							|  |  |  |                             // xImporter->setTargetDocument( xModelComponent );
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             // parse the stream
 | 
					
						
							|  |  |  |                             try | 
					
						
							|  |  |  |                             { | 
					
						
							|  |  |  |                                 xParser->parseStream( aParserInput ); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             catch( xml::sax::SAXParseException& ) | 
					
						
							|  |  |  |                             { | 
					
						
							|  |  |  |                                 // workaround for #83452#: SetSize doesn't work
 | 
					
						
							|  |  |  |                                 // nRet = ERR_SWG_READ_ERROR;
 | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             catch( xml::sax::SAXException& ) | 
					
						
							|  |  |  |                             { | 
					
						
							|  |  |  |                                 nRet = ERR_SWG_READ_ERROR; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             catch( io::IOException& ) | 
					
						
							|  |  |  |                             { | 
					
						
							|  |  |  |                                 nRet = ERR_SWG_READ_ERROR; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             // and finally, copy macro into table
 | 
					
						
							|  |  |  |                             if (0 == nRet) | 
					
						
							|  |  |  |                                 pDescriptor->copyMacrosIntoTable(rMacroTbl); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |                         else | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |                             nRet = ERR_SWG_READ_ERROR; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     else | 
					
						
							|  |  |  |                         nRet = ERR_SWG_READ_ERROR; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                     nRet = ERR_SWG_READ_ERROR; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 nRet = ERR_SWG_READ_ERROR; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         catch( uno::Exception& ) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |             nRet = ERR_SWG_READ_ERROR; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         nRet = ERR_SWG_READ_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // success!
 | 
					
						
							|  |  |  |     return nRet; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ULONG SwXMLTextBlocks::GetBlockText( const String& rShort, String& rText ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ULONG n = 0; | 
					
						
							|  |  |  |     sal_Bool bTextOnly = sal_True; | 
					
						
							|  |  |  |     String aFolderName; | 
					
						
							|  |  |  |     GeneratePackageName ( rShort, aFolderName ); | 
					
						
							| 
									
										
										
										
											2003-10-06 18:01:23 +00:00
										 |  |  |     String aStreamName = aFolderName + (OUString) String::CreateFromAscii(".xml"); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     rText.Erase(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     try | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::READ ); | 
					
						
							|  |  |  |         uno::Reference < container::XNameAccess > xAccess( xRoot, uno::UNO_QUERY ); | 
					
						
							|  |  |  |         if ( !xAccess->hasByName( aStreamName ) || !xRoot->isStreamElement( aStreamName ) ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             bTextOnly = sal_False; | 
					
						
							|  |  |  |             aStreamName = String::CreateFromAscii("content.xml"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         uno::Reference < io::XStream > xContents = xRoot->openStreamElement( aStreamName, embed::ElementModes::READ ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |             comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |         ASSERT( xServiceFactory.is(), "XMLReader::Read: got no service manager" ); | 
					
						
							|  |  |  |         if( !xServiceFactory.is() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Throw an exception ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         xml::sax::InputSource aParserInput; | 
					
						
							|  |  |  |         aParserInput.sSystemId = aName; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         aParserInput.aInputStream = xContents->getInputStream(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // get parser
 | 
					
						
							|  |  |  |         Reference< XInterface > xXMLParser = xServiceFactory->createInstance( | 
					
						
							|  |  |  |                 OUString::createFromAscii("com.sun.star.xml.sax.Parser") ); | 
					
						
							|  |  |  |         ASSERT( xXMLParser.is(), | 
					
						
							|  |  |  |                 "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" ); | 
					
						
							|  |  |  |         if( !xXMLParser.is() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Maybe throw an exception?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get filter
 | 
					
						
							| 
									
										
										
										
											2004-05-03 12:14:15 +00:00
										 |  |  |         // #110680#
 | 
					
						
							|  |  |  |         // Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, rText, bTextOnly );
 | 
					
						
							|  |  |  |         Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xServiceFactory, *this, rText, bTextOnly ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // connect parser and filter
 | 
					
						
							|  |  |  |         Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY ); | 
					
						
							|  |  |  |         xParser->setDocumentHandler( xFilter ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // parse
 | 
					
						
							|  |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             xParser->parseStream( aParserInput ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( xml::sax::SAXParseException&  ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // re throw ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( xml::sax::SAXException&  ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // re throw ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( io::IOException& ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // re throw ?
 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         xRoot = 0; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     catch ( uno::Exception& ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ASSERT( sal_False, "Tried to open non-existent folder or stream!"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     return n; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ULONG SwXMLTextBlocks::PutBlockText( const String& rShort, const String& rName, | 
					
						
							|  |  |  |                                      const String& rText,  const String& rPackageName ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     USHORT nIndex = GetIndex ( rShort ); | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |     if (xBlkRoot->IsContained ( rPackageName ) ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         xBlkRoot->Remove ( rPackageName ); | 
					
						
							|  |  |  |         xBlkRoot->Commit ( ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     String aFolderName( rPackageName ); | 
					
						
							| 
									
										
										
										
											2003-10-06 18:01:23 +00:00
										 |  |  |     String aStreamName = aFolderName + (OUString) String::CreateFromAscii(".xml"); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |         comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |     ASSERT( xServiceFactory.is(), | 
					
						
							|  |  |  |             "XMLReader::Read: got no service manager" ); | 
					
						
							|  |  |  |     if( !xServiceFactory.is() ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Throw an exception ?
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        Reference < XInterface > xWriter (xServiceFactory->createInstance( | 
					
						
							|  |  |  |            OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer")))); | 
					
						
							|  |  |  |        DBG_ASSERT(xWriter.is(),"com.sun.star.xml.sax.Writer service missing"); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     ULONG nRes = 0; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     try | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::WRITE ); | 
					
						
							|  |  |  |     uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( aStreamName, | 
					
						
							|  |  |  |                 embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) ); | 
					
						
							|  |  |  |     OUString aMime ( RTL_CONSTASCII_USTRINGPARAM ( "text/xml") ); | 
					
						
							|  |  |  |     Any aAny; | 
					
						
							|  |  |  |     aAny <<= aMime; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     xSet->setPropertyValue( aPropName, aAny ); | 
					
						
							|  |  |  |     Reference < io::XOutputStream > xOut = xDocStream->getOutputStream(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |        uno::Reference<io::XActiveDataSource> xSrc(xWriter, uno::UNO_QUERY); | 
					
						
							|  |  |  |        xSrc->setOutputStream(xOut); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        uno::Reference<xml::sax::XDocumentHandler> xHandler(xWriter, | 
					
						
							|  |  |  |         uno::UNO_QUERY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-03 12:14:15 +00:00
										 |  |  |     // #110680#
 | 
					
						
							|  |  |  |        // SwXMLTextBlockExport aExp(*this, GetXMLToken ( XML_UNFORMATTED_TEXT ), xHandler);
 | 
					
						
							|  |  |  |        SwXMLTextBlockExport aExp( xServiceFactory, *this, GetXMLToken ( XML_UNFORMATTED_TEXT ), xHandler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     aExp.exportDoc( rText ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     uno::Reference < embed::XTransactedObject > xTrans( xRoot, uno::UNO_QUERY ); | 
					
						
							|  |  |  |     if ( xTrans.is() ) | 
					
						
							|  |  |  |         xTrans->commit(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (! (nFlags & SWXML_NOROOTCOMMIT) ) | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY ); | 
					
						
							|  |  |  |         if ( xTrans.is() ) | 
					
						
							|  |  |  |             xTrans->commit(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     catch ( uno::Exception& ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         nRes = ERR_SWG_WRITE_ERROR; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     xRoot = 0; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     //TODO/LATER: error handling
 | 
					
						
							|  |  |  |     /*
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     ULONG nErr = xBlkRoot->GetError(); | 
					
						
							|  |  |  |     ULONG nRes = 0; | 
					
						
							|  |  |  |     if( nErr == SVSTREAM_DISK_FULL ) | 
					
						
							|  |  |  |         nRes = ERR_W4W_WRITE_FULL; | 
					
						
							|  |  |  |     else if( nErr != SVSTREAM_OK ) | 
					
						
							|  |  |  |         nRes = ERR_SWG_WRITE_ERROR; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     */ | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     if( !nRes )         // damit ueber GetText & nCur aufs Doc zugegriffen
 | 
					
						
							|  |  |  |         MakeBlockText( rText ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return nRes; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SwXMLTextBlocks::ReadInfo( void ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     try | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     const OUString sDocName( RTL_CONSTASCII_USTRINGPARAM( XMLN_BLOCKLIST ) ); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     uno::Reference < container::XNameAccess > xAccess( xBlkRoot, uno::UNO_QUERY ); | 
					
						
							| 
									
										
										
										
											2005-01-07 08:44:47 +00:00
										 |  |  |     if ( xAccess.is() && xAccess->hasByName( sDocName ) && xBlkRoot->isStreamElement( sDocName ) ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |                 comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |         ASSERT( xServiceFactory.is(), | 
					
						
							|  |  |  |                 "XMLReader::Read: got no service manager" ); | 
					
						
							|  |  |  |         if( !xServiceFactory.is() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Throw an exception ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         xml::sax::InputSource aParserInput; | 
					
						
							|  |  |  |         aParserInput.sSystemId = sDocName; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         uno::Reference < io::XStream > xDocStream = xBlkRoot->openStreamElement( sDocName, embed::ElementModes::READ ); | 
					
						
							|  |  |  |         aParserInput.aInputStream = xDocStream->getInputStream(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // get parser
 | 
					
						
							|  |  |  |         Reference< XInterface > xXMLParser = xServiceFactory->createInstance( | 
					
						
							|  |  |  |             OUString::createFromAscii("com.sun.star.xml.sax.Parser") ); | 
					
						
							|  |  |  |         ASSERT( xXMLParser.is(), | 
					
						
							|  |  |  |             "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" ); | 
					
						
							|  |  |  |         if( !xXMLParser.is() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Maybe throw an exception?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get filter
 | 
					
						
							| 
									
										
										
										
											2004-05-03 12:14:15 +00:00
										 |  |  |         // #110680#
 | 
					
						
							|  |  |  |         // Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLBlockListImport( *this );
 | 
					
						
							|  |  |  |         Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLBlockListImport( xServiceFactory, *this ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // connect parser and filter
 | 
					
						
							|  |  |  |         Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY ); | 
					
						
							|  |  |  |         xParser->setDocumentHandler( xFilter ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // parse
 | 
					
						
							|  |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             xParser->parseStream( aParserInput ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( xml::sax::SAXParseException&  ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // re throw ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( xml::sax::SAXException&  ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // re throw ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch( io::IOException& ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // re throw ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     catch ( uno::Exception& ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | void SwXMLTextBlocks::WriteInfo( void ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |     if ( xBlkRoot.is() || 0 == OpenFile ( FALSE ) ) | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |             comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |         DBG_ASSERT( xServiceFactory.is(), | 
					
						
							|  |  |  |                 "XMLReader::Read: got no service manager" ); | 
					
						
							|  |  |  |         if( !xServiceFactory.is() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Throw an exception ?
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Reference < XInterface > xWriter (xServiceFactory->createInstance( | 
					
						
							|  |  |  |             OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer")))); | 
					
						
							|  |  |  |         DBG_ASSERT(xWriter.is(),"com.sun.star.xml.sax.Writer service missing"); | 
					
						
							|  |  |  |         OUString sDocName( RTL_CONSTASCII_USTRINGPARAM( XMLN_BLOCKLIST ) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |         if ( xBlkRoot->IsContained( sDocName) ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             xBlkRoot->Remove ( sDocName ); | 
					
						
							|  |  |  |             xBlkRoot->Commit(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |         uno::Reference < io::XStream > xDocStream = xBlkRoot->openStreamElement( sDocName, | 
					
						
							|  |  |  |                     embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) ); | 
					
						
							|  |  |  |         OUString aMime ( RTL_CONSTASCII_USTRINGPARAM ( "text/xml") ); | 
					
						
							|  |  |  |         Any aAny; | 
					
						
							|  |  |  |         aAny <<= aMime; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         xSet->setPropertyValue( aPropName, aAny ); | 
					
						
							|  |  |  |         Reference < io::XOutputStream > xOut = xDocStream->getOutputStream(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         uno::Reference<io::XActiveDataSource> xSrc(xWriter, uno::UNO_QUERY); | 
					
						
							|  |  |  |         xSrc->setOutputStream(xOut); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         uno::Reference<xml::sax::XDocumentHandler> xHandler(xWriter, uno::UNO_QUERY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-03 12:14:15 +00:00
										 |  |  |         // #110680#
 | 
					
						
							|  |  |  |         // SwXMLBlockListExport aExp(*this, OUString::createFromAscii(XMLN_BLOCKLIST), xHandler);
 | 
					
						
							|  |  |  |         SwXMLBlockListExport aExp( xServiceFactory, *this, OUString::createFromAscii(XMLN_BLOCKLIST), xHandler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         aExp.exportDoc( XML_BLOCK_LIST ); | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY ); | 
					
						
							|  |  |  |         if ( xTrans.is() ) | 
					
						
							|  |  |  |             xTrans->commit(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch ( uno::Exception& ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         bInfoChanged = FALSE; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ULONG SwXMLTextBlocks::SetMacroTable( | 
					
						
							|  |  |  |     USHORT nIdx, | 
					
						
							|  |  |  |     const SvxMacroTableDtor& rMacroTbl, | 
					
						
							|  |  |  |     sal_Bool bFileAlreadyOpen ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // set current autotext
 | 
					
						
							|  |  |  |     aShort = aNames[ nIdx ]->aShort; | 
					
						
							|  |  |  |     aLong = aNames[ nIdx ]->aLong; | 
					
						
							|  |  |  |     aPackageName = aNames[ nIdx ]->aPackageName; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // start XML autotext event export
 | 
					
						
							|  |  |  |     ULONG nRes = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Reference< lang::XMultiServiceFactory > xServiceFactory = | 
					
						
							|  |  |  |         comphelper::getProcessServiceFactory(); | 
					
						
							|  |  |  |     ASSERT( xServiceFactory.is(), | 
					
						
							|  |  |  |             "XML autotext event write:: got no service manager" ); | 
					
						
							|  |  |  |     if( !xServiceFactory.is() ) | 
					
						
							|  |  |  |         return ERR_SWG_WRITE_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Get model
 | 
					
						
							|  |  |  |     Reference< lang::XComponent > xModelComp( | 
					
						
							|  |  |  |         pDoc->GetDocShell()->GetModel(), UNO_QUERY ); | 
					
						
							|  |  |  |     ASSERT( xModelComp.is(), "XMLWriter::Write: got no model" ); | 
					
						
							|  |  |  |     if( !xModelComp.is() ) | 
					
						
							|  |  |  |         return ERR_SWG_WRITE_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // open stream in proper sub-storage
 | 
					
						
							|  |  |  |     if( !bFileAlreadyOpen ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         CloseFile();    // close (it may be open in read-only-mode)
 | 
					
						
							|  |  |  |         nRes = OpenFile ( FALSE ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ( 0 == nRes ) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         try | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             xRoot = xBlkRoot->openStorageElement( aPackageName, embed::ElementModes::WRITE ); | 
					
						
							|  |  |  |             OUString sStreamName( RTL_CONSTASCII_USTRINGPARAM("atevent.xml") ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             sal_Bool bOasis = ( SotStorage::GetVersion( xRoot ) > SOT_FORMATSTR_ID_STARWRITER_60 ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( sStreamName, | 
					
						
							|  |  |  |                         embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY ); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |             String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) ); | 
					
						
							|  |  |  |             OUString aMime ( RTL_CONSTASCII_USTRINGPARAM ( "text/xml") ); | 
					
						
							|  |  |  |             Any aAny; | 
					
						
							|  |  |  |             aAny <<= aMime; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             xSet->setPropertyValue( aPropName, aAny ); | 
					
						
							|  |  |  |             Reference < io::XOutputStream > xOutputStream = xDocStream->getOutputStream(); | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // get XML writer
 | 
					
						
							|  |  |  |             Reference< io::XActiveDataSource > xSaxWriter( | 
					
						
							|  |  |  |                 xServiceFactory->createInstance( | 
					
						
							|  |  |  |                     OUString::createFromAscii("com.sun.star.xml.sax.Writer") ), | 
					
						
							|  |  |  |                 UNO_QUERY ); | 
					
						
							|  |  |  |             ASSERT( xSaxWriter.is(), "can't instantiate XML writer" ); | 
					
						
							|  |  |  |             if( xSaxWriter.is() ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // connect XML writer to output stream
 | 
					
						
							|  |  |  |                 xSaxWriter->setOutputStream( xOutputStream ); | 
					
						
							|  |  |  |                 Reference<xml::sax::XDocumentHandler> xDocHandler( | 
					
						
							|  |  |  |                     xSaxWriter, UNO_QUERY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // construct events object
 | 
					
						
							|  |  |  |                 Reference<XNameAccess> xEvents = | 
					
						
							|  |  |  |                     new SvMacroTableEventDescriptor(rMacroTbl,aAutotextEvents); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // prepare arguments (prepend doc handler to given arguments)
 | 
					
						
							|  |  |  |                 Sequence<Any> aParams(2); | 
					
						
							|  |  |  |                 aParams[0] <<= xDocHandler; | 
					
						
							|  |  |  |                 aParams[1] <<= xEvents; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // get filter component
 | 
					
						
							|  |  |  |                 Reference< document::XExporter > xExporter( | 
					
						
							|  |  |  |                     xServiceFactory->createInstanceWithArguments( | 
					
						
							|  |  |  |                         OUString::createFromAscii( | 
					
						
							| 
									
										
										
										
											2004-07-13 08:05:30 +00:00
										 |  |  |                          bOasis | 
					
						
							|  |  |  |                              ? "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" | 
					
						
							|  |  |  |                             : "com.sun.star.comp.Writer.XMLAutotextEventsExporter"), | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |                         aParams), UNO_QUERY); | 
					
						
							|  |  |  |                 ASSERT( xExporter.is(), | 
					
						
							|  |  |  |                         "can't instantiate export filter component" ); | 
					
						
							|  |  |  |                 if( xExporter.is() ) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     // connect model and filter
 | 
					
						
							|  |  |  |                     xExporter->setSourceDocument( xModelComp ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     // filter!
 | 
					
						
							|  |  |  |                     Sequence<beans::PropertyValue> aFilterProps( 0 ); | 
					
						
							|  |  |  |                     Reference < document::XFilter > xFilter( xExporter, | 
					
						
							|  |  |  |                                                              UNO_QUERY ); | 
					
						
							|  |  |  |                     xFilter->filter( aFilterProps ); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                     nRes = ERR_SWG_WRITE_ERROR; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 nRes = ERR_SWG_WRITE_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // finally, commit stream, sub-storage and storage
 | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             uno::Reference < embed::XTransactedObject > xTrans( xRoot, uno::UNO_QUERY ); | 
					
						
							|  |  |  |             if ( xTrans.is() ) | 
					
						
							|  |  |  |                 xTrans->commit(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |             if ( !bFileAlreadyOpen ) | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |             { | 
					
						
							|  |  |  |                 uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY ); | 
					
						
							|  |  |  |                 if ( xTrans.is() ) | 
					
						
							|  |  |  |                     xTrans->commit(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             xRoot = 0; | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         catch ( uno::Exception& ) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  |             nRes = ERR_SWG_WRITE_ERROR; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:11:48 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-10-19 08:42:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if( !bFileAlreadyOpen ) | 
					
						
							|  |  |  |             CloseFile(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         nRes = ERR_SWG_WRITE_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return nRes; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |