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_xmloff.hxx" 26 #include "XMLAutoTextEventExport.hxx" 27 #include <com/sun/star/frame/XModel.hpp> 28 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 29 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 30 #include <com/sun/star/document/XEventsSupplier.hpp> 31 #include <com/sun/star/container/XNameReplace.hpp> 32 #include <com/sun/star/container/XNameAccess.hpp> 33 #include <com/sun/star/uno/Reference.hxx> 34 #include <com/sun/star/uno/Sequence.hxx> 35 36 #ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP 37 #include <com/sun/star/uno/Exception.hpp> 38 #endif 39 40 // #110680# 41 //#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ 42 //#include <comphelper/processfactory.hxx> 43 //#endif 44 #include <rtl/ustrbuf.hxx> 45 #include "xmloff/xmlnmspe.hxx" 46 #include <xmloff/nmspmap.hxx> 47 #include <xmloff/xmltoken.hxx> 48 #include <xmloff/XMLEventExport.hxx> 49 #include <tools/debug.hxx> 50 51 52 using namespace ::com::sun::star; 53 using namespace ::xmloff::token; 54 55 // #110680# 56 // using ::comphelper::getProcessServiceFactory; 57 using ::rtl::OUString; 58 using ::rtl::OUStringBuffer; 59 using ::std::set; 60 using ::com::sun::star::beans::XPropertySet; 61 using ::com::sun::star::beans::PropertyValue; 62 using ::com::sun::star::container::XNameAccess; 63 using ::com::sun::star::container::XNameReplace; 64 using ::com::sun::star::document::XEventsSupplier; 65 using ::com::sun::star::frame::XModel; 66 using ::com::sun::star::lang::XMultiServiceFactory; 67 using ::com::sun::star::uno::Any; 68 using ::com::sun::star::uno::Exception; 69 using ::com::sun::star::uno::Reference; 70 using ::com::sun::star::uno::Sequence; 71 using ::com::sun::star::uno::XInterface; 72 using ::com::sun::star::uno::UNO_QUERY; 73 using ::com::sun::star::xml::sax::XDocumentHandler; 74 75 76 const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; 77 78 79 // #110680# 80 XMLAutoTextEventExport::XMLAutoTextEventExport( 81 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, 82 sal_uInt16 nFlags 83 ) 84 : SvXMLExport( xServiceFactory, MAP_INCH, XML_AUTO_TEXT, nFlags ), 85 sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), 86 sNone(RTL_CONSTASCII_USTRINGPARAM("None")) 87 { 88 } 89 90 // #110680# 91 XMLAutoTextEventExport::XMLAutoTextEventExport( 92 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, 93 const OUString& rFileName, 94 const Reference<XDocumentHandler> & rHandler, 95 const Reference<XModel> & rModel, 96 const Reference<XNameAccess> & rEvents, 97 sal_uInt16 /*nFlags*/ ) 98 : SvXMLExport( xServiceFactory, rFileName, rHandler, rModel, MAP_INCH ), 99 xEvents(rEvents), 100 sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), 101 sNone(RTL_CONSTASCII_USTRINGPARAM("None")) 102 { 103 } 104 105 XMLAutoTextEventExport::~XMLAutoTextEventExport() 106 { 107 } 108 109 110 void XMLAutoTextEventExport::initialize( 111 const Sequence<Any> & rArguments ) 112 { 113 if (rArguments.getLength() > 1) 114 { 115 Reference<XEventsSupplier> xSupplier; 116 rArguments[1] >>= xSupplier; 117 if (xSupplier.is()) 118 { 119 Reference<XNameAccess> xAccess(xSupplier->getEvents(), UNO_QUERY); 120 xEvents = xAccess; 121 } 122 else 123 { 124 Reference<XNameReplace> xReplace; 125 rArguments[1] >>= xReplace; 126 if (xReplace.is()) 127 { 128 Reference<XNameAccess> xAccess(xReplace, UNO_QUERY); 129 xEvents = xAccess; 130 } 131 else 132 { 133 rArguments[1] >>= xEvents; 134 } 135 } 136 } 137 138 // call super class (for XHandler) 139 SvXMLExport::initialize(rArguments); 140 } 141 142 143 sal_uInt32 XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum ) 144 { 145 if( (getExportFlags() & EXPORT_OASIS) == 0 ) 146 { 147 Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory(); 148 if( xFactory.is() ) 149 { 150 try 151 { 152 153 Sequence<Any> aArgs( 1 ); 154 aArgs[0] <<= GetDocHandler(); 155 156 // get filter component 157 Reference< xml::sax::XDocumentHandler > xTmpDocHandler( 158 xFactory->createInstanceWithArguments( 159 OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"), 160 aArgs), UNO_QUERY); 161 OSL_ENSURE( xTmpDocHandler.is(), 162 "can't instantiate OASIS transformer component" ); 163 if( xTmpDocHandler.is() ) 164 { 165 SetDocHandler( xTmpDocHandler ); 166 } 167 } 168 catch( com::sun::star::uno::Exception& ) 169 { 170 } 171 } 172 } 173 if (hasEvents()) 174 { 175 GetDocHandler()->startDocument(); 176 177 addNamespaces(); 178 179 { 180 // container element 181 SvXMLElementExport aContainerElement( 182 *this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS, 183 sal_True, sal_True); 184 185 exportEvents(); 186 } 187 188 // and close document again 189 GetDocHandler()->endDocument(); 190 } 191 192 return 0; 193 } 194 195 sal_Bool XMLAutoTextEventExport::hasEvents() 196 { 197 // TODO: provide full implementation that check for presence of events 198 return xEvents.is(); 199 } 200 201 void XMLAutoTextEventExport::addNamespaces() 202 { 203 // namespaces for office:, text: and script: 204 GetAttrList().AddAttribute( 205 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ), 206 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) ); 207 GetAttrList().AddAttribute( 208 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ), 209 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) ); 210 GetAttrList().AddAttribute( 211 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ), 212 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) ); 213 GetAttrList().AddAttribute( 214 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ), 215 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) ); 216 GetAttrList().AddAttribute( 217 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ), 218 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) ); 219 GetAttrList().AddAttribute( 220 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ), 221 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) ); 222 } 223 224 void XMLAutoTextEventExport::exportEvents() 225 { 226 DBG_ASSERT(hasEvents(), "no events to export!"); 227 228 GetEventExport().Export(xEvents, sal_True); 229 } 230 231 232 233 // methods without content: 234 235 void XMLAutoTextEventExport::_ExportMeta() {} 236 void XMLAutoTextEventExport::_ExportScripts() {} 237 void XMLAutoTextEventExport::_ExportFontDecls() {} 238 void XMLAutoTextEventExport::_ExportStyles( sal_Bool ) {} 239 void XMLAutoTextEventExport::_ExportAutoStyles() {} 240 void XMLAutoTextEventExport::_ExportMasterStyles() {} 241 void XMLAutoTextEventExport::_ExportChangeTracking() {} 242 void XMLAutoTextEventExport::_ExportContent() {} 243 244 245 246 // methods to support the component registration 247 248 Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames() 249 throw() 250 { 251 Sequence< OUString > aSeq( 1 ); 252 aSeq[0] = XMLAutoTextEventExport_getImplementationName(); 253 return aSeq; 254 } 255 256 OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw() 257 { 258 return OUString( RTL_CONSTASCII_USTRINGPARAM( 259 "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" ) ); 260 } 261 262 Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance( 263 const Reference< XMultiServiceFactory > & rSMgr) 264 { 265 // #110680# 266 // return (cppu::OWeakObject*)new XMLAutoTextEventExport; 267 return (cppu::OWeakObject*)new XMLAutoTextEventExport(rSMgr, EXPORT_ALL|EXPORT_OASIS); 268 } 269 270 // methods to support the component registration 271 272 Sequence< OUString > SAL_CALL XMLAutoTextEventExportOOO_getSupportedServiceNames() 273 throw() 274 { 275 Sequence< OUString > aSeq( 1 ); 276 aSeq[0] = XMLAutoTextEventExportOOO_getImplementationName(); 277 return aSeq; 278 } 279 280 OUString SAL_CALL XMLAutoTextEventExportOOO_getImplementationName() throw() 281 { 282 return OUString( RTL_CONSTASCII_USTRINGPARAM( 283 "com.sun.star.comp.Writer.XMLAutotextEventsExporter" ) ); 284 } 285 286 Reference< XInterface > SAL_CALL XMLAutoTextEventExportOOO_createInstance( 287 const Reference< XMultiServiceFactory > & rSMgr) 288 { 289 // #110680# 290 // return (cppu::OWeakObject*)new XMLAutoTextEventExport; 291 return (cppu::OWeakObject*)new XMLAutoTextEventExport(rSMgr,EXPORT_ALL); 292 } 293