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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.beans
.XPropertySetInfo
;
31 import com
.sun
.star
.beans
.Property
;
32 import com
.sun
.star
.document
.XDocumentPropertiesSupplier
;
33 import com
.sun
.star
.document
.XDocumentProperties
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.comp.Math.XMLMetaImporter</code>. <p>
42 * Object implements the following interfaces :
44 * <li><code>com::sun::star::lang::XInitialization</code></li>
45 * <li><code>com::sun::star::document::XImporter</code></li>
46 * <li><code>com::sun::star::document::XFilter</code></li>
47 * <li><code>com::sun::star::document::ImportFilter</code></li>
48 * <li><code>com::sun::star::beans::XPropertySet</code></li>
49 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.XImporter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.ImportFilter
55 * @see com.sun.star.beans.XPropertySet
56 * @see com.sun.star.xml.sax.XDocumentHandler
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._XImporter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
62 * @see ifc.xml.sax._XDocumentHandler
64 public class XMLMetaImporter
extends TestCase
{
68 * New math document created.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
74 xMathDoc
= SOF
.openDoc("smath","_blank");
75 } catch (com
.sun
.star
.uno
.Exception ex
) {
76 ex
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", ex
);
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xMathDoc " );
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Math.XMLMetaImporter</code><p>
94 * The math document is set as a target document for importer.
95 * Imported XML-data contains the tag which specifies new user info
96 * field and a title of document.
97 * After import user fields info and the title of target document
99 * Object relations created :
101 * <li> <code>'XDocumentHandler.XMLData'</code> for
102 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
103 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
104 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
105 * <li> <code>'TargetDocument'</code> for
106 * {@link ifc.document._XImporter} interface </li>
109 public synchronized TestEnvironment createTestEnvironment
110 ( TestParameters Param
, PrintWriter log
)
111 throws StatusException
{
113 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
114 XInterface oObj
= null;
115 final String impName
= "XMLMetaImporter" ;
116 final String impValue
= "XMLMetaImporter_Value" ;
117 final String impTitle
= "XMLMetaImporter Title" ;
120 oObj
= (XInterface
)xMSF
.createInstance(
121 "com.sun.star.comp.Math.XMLMetaImporter");
122 } catch (com
.sun
.star
.uno
.Exception e
) {
123 e
.printStackTrace(log
);
124 throw new StatusException("Unexpected exception", e
);
127 TestEnvironment tEnv
= new TestEnvironment(oObj
);
129 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
131 String
[][] xml
= new String
[][] {
132 {"start", "office:document-meta",
133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
134 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
135 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
136 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"
138 {"start", "office:meta"},
139 {"start", "dc:title"},
142 {"start", "meta:user-defined",
143 "meta:name", "CDATA", impName
},
145 {"end", "meta:user-defined"},
146 {"end", "office:meta"},
147 {"end", "office:document-meta"}} ;
149 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
151 final PrintWriter logF
= log
;
153 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
154 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
155 public boolean checkImport() {
157 XDocumentPropertiesSupplier xPropSup
=
158 UnoRuntime
.queryInterface
159 (XDocumentPropertiesSupplier
.class, xMathDoc
);
160 final XDocumentProperties xDocProps
=
161 xPropSup
.getDocumentProperties();
163 XPropertySet xUDProps
= UnoRuntime
.queryInterface(
165 xDocProps
.getUserDefinedProperties());
166 XPropertySetInfo xInfo
=
167 xUDProps
.getPropertySetInfo();
168 Property
[] props
= xInfo
.getProperties();
169 boolean result
= false;
170 for (int i
= 0; i
< props
.length
; i
++) {
171 String gName
= props
[i
].Name
;
172 String gValue
= (String
)
173 xUDProps
.getPropertyValue(gName
);
174 logF
.println("Field '" + gName
+ "' = '"
176 if (impName
.equals(gName
) && impValue
.equals(gValue
))
179 String gTitle
= xDocProps
.getTitle();
180 logF
.println("Title returned : '" + gTitle
+ "'");
181 result
&= impTitle
.equals(gTitle
) ;
184 } catch (com
.sun
.star
.uno
.Exception e
) {
185 logF
.println("Exception occurred while checking filter :") ;
186 e
.printStackTrace(logF
) ;