1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sw_XMLContentExporter" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32***** 33'************************************************************************* 34 35 36 37' Be sure that all variables are dimensioned: 38option explicit 39 40 41' REQUIRED VARIABLES for interface/service tests: 42 43' Required for com.sun.star.lang.XInitialization: 44 Global aInitArgs() As Variant 45 46' Required for com.sun.star.document.XFilter: 47 Global oFilterDescriptor As Variant 48 49' Required for com.sun.star.document.XExporter: 50 Global oSrcDocument As Object 51 52' Required for com.sun.star.container.XNamed: 53Global cNameToSet As String 54 55 56Sub CreateObj() 57 58'************************************************************************* 59' COMPONENT: 60' sw.XMLContentExporter 61'************************************************************************* 62On Error Goto ErrHndl 63 Dim initArgs(0) As Object 64 Dim oMSF As Object 65 Dim filter As Variant 66 Dim printXML As Boolean 67 Dim Tag1, Tag2, Tag3, Tag4 As Variant 68 Dim expString As String 69 Dim oText As Object 70 Dim oCursor As Object 71 72 printXML = true 73 expString = "XMLContentExporter" 74 oMSF = getProcessServiceManager() 75 oDoc = utils.createDocument("swriter", cObjectName) 76 oDocHandler = oMSF.createInstanceWithArguments("basichelper.DocumentHandler", Array(printXML)) 77 78 Tag1 = Array("office:document-content") 79 Tag2 = Array("office:body") 80 Tag3 = Array("office:script") 81 Tag4 = Array("text:p") 82 filter = Array( _ 83 Array("TagExists", Tag1), _ 84 Array("TagEnclosed", Tag2, Tag1), _ 85 Array("TagEnclosed", Tag3, Tag1), _ 86 Array("CharsEnclosed", Tag4, expString) _ 87 ) 88 89 oDocHandler.initialize(filter) 90 91 initArgs(0) = oDocHandler 92 aInitArgs = initArgs() 93 oObj = oMSF.createInstanceWithArguments("com.sun.star.comp.Writer.XMLContentExporter", initArgs()) 94 95 oText = oDoc.getText() 96 oCursor = oText.createTextCursor() 97 oText.insertString(oCursor, expString, false) 98 99 oObj.setSourceDocument(oDoc) 100 101 Dim aFilterDescr(0) As New com.sun.star.beans.PropertyValue 102 aFilterDescr(0).Name = "FilterName" 103 aFilterDescr(0).Value = "swriter: StarOffice XML (text)" 104 oFilterDescriptor = aFilterDescr() 105 106 oSrcDocument = oDoc 107 cNameToSet = "fixed" 108 109Exit Sub 110ErrHndl: 111 Test.Exception() 112End Sub 113 114Global oDocHandler As Object 115 116Function checkFilter() As Boolean 117 checkFilter = oDocHandler.getByName("XMLIsCorrect") 118 Out.Log(oDocHandler.getByName("XMLCode")) 119End Function 120</script:module> 121