2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.beans
.XPropertySetInfo
;
30 import com
.sun
.star
.beans
.Property
;
31 import com
.sun
.star
.document
.XDocumentPropertiesSupplier
;
32 import com
.sun
.star
.document
.XDocumentProperties
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
39 * Test for object which is represented by service
40 * <code>com.sun.star.comp.Math.XMLMetaImporter</code>. <p>
41 * Object implements the following interfaces :
43 * <li><code>com::sun::star::lang::XInitialization</code></li>
44 * <li><code>com::sun::star::document::XImporter</code></li>
45 * <li><code>com::sun::star::document::XFilter</code></li>
46 * <li><code>com::sun::star::document::ImportFilter</code></li>
47 * <li><code>com::sun::star::beans::XPropertySet</code></li>
48 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLMetaImporter
extends TestCase
{
67 * New math document created.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
73 xMathDoc
= SOF
.openDoc("smath","_blank");
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xMathDoc " );
86 * Creating a TestEnvironment for the interfaces to be tested.
87 * Creates an instance of the service
88 * <code>com.sun.star.comp.Math.XMLMetaImporter</code><p>
90 * The math document is set as a target document for importer.
91 * Imported XML-data contains the tag which specifies new user info
92 * field and a title of document.
93 * After import user fields info and the title of target document
95 * Object relations created :
97 * <li> <code>'XDocumentHandler.XMLData'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'TargetDocument'</code> for
102 * {@link ifc.document._XImporter} interface </li>
106 public TestEnvironment createTestEnvironment
107 ( TestParameters Param
, PrintWriter log
)
110 XMultiServiceFactory xMSF
= Param
.getMSF();
111 XInterface oObj
= null;
112 final String impName
= "XMLMetaImporter" ;
113 final String impValue
= "XMLMetaImporter_Value" ;
114 final String impTitle
= "XMLMetaImporter Title" ;
116 oObj
= (XInterface
)xMSF
.createInstance(
117 "com.sun.star.comp.Math.XMLMetaImporter");
119 TestEnvironment tEnv
= new TestEnvironment(oObj
);
121 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
123 String
[][] xml
= new String
[][] {
124 {"start", "office:document-meta",
125 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
126 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
127 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
128 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"
130 {"start", "office:meta"},
131 {"start", "dc:title"},
134 {"start", "meta:user-defined",
135 "meta:name", "CDATA", impName
},
137 {"end", "meta:user-defined"},
138 {"end", "office:meta"},
139 {"end", "office:document-meta"}} ;
141 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
143 final PrintWriter logF
= log
;
145 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
146 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
147 public boolean checkImport() {
149 XDocumentPropertiesSupplier xPropSup
=
150 UnoRuntime
.queryInterface
151 (XDocumentPropertiesSupplier
.class, xMathDoc
);
152 final XDocumentProperties xDocProps
=
153 xPropSup
.getDocumentProperties();
155 XPropertySet xUDProps
= UnoRuntime
.queryInterface(
157 xDocProps
.getUserDefinedProperties());
158 XPropertySetInfo xInfo
=
159 xUDProps
.getPropertySetInfo();
160 Property
[] props
= xInfo
.getProperties();
161 boolean result
= false;
162 for (int i
= 0; i
< props
.length
; i
++) {
163 String gName
= props
[i
].Name
;
164 String gValue
= (String
)
165 xUDProps
.getPropertyValue(gName
);
166 logF
.println("Field '" + gName
+ "' = '"
168 if (impName
.equals(gName
) && impValue
.equals(gValue
))
171 String gTitle
= xDocProps
.getTitle();
172 logF
.println("Title returned : '" + gTitle
+ "'");
173 result
&= impTitle
.equals(gTitle
) ;
176 } catch (com
.sun
.star
.uno
.Exception e
) {
177 logF
.println("Exception occurred while checking filter :") ;
178 e
.printStackTrace(logF
) ;