1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLMetaImporter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.document
.XDocumentInfo
;
43 import com
.sun
.star
.document
.XDocumentInfoSupplier
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.comp.Math.XMLMetaImporter</code>. <p>
52 * Object implements the following interfaces :
54 * <li><code>com::sun::star::lang::XInitialization</code></li>
55 * <li><code>com::sun::star::document::XImporter</code></li>
56 * <li><code>com::sun::star::document::XFilter</code></li>
57 * <li><code>com::sun::star::document::ImportFilter</code></li>
58 * <li><code>com::sun::star::beans::XPropertySet</code></li>
59 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
61 * @see com.sun.star.lang.XInitialization
62 * @see com.sun.star.document.XImporter
63 * @see com.sun.star.document.XFilter
64 * @see com.sun.star.document.ImportFilter
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.xml.sax.XDocumentHandler
67 * @see ifc.lang._XInitialization
68 * @see ifc.document._XImporter
69 * @see ifc.document._XFilter
70 * @see ifc.document._XExporter
71 * @see ifc.beans._XPropertySet
72 * @see ifc.xml.sax._XDocumentHandler
74 public class XMLMetaImporter
extends TestCase
{
78 * New math document created.
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
84 xMathDoc
= SOF
.openDoc("smath","_blank");
85 } catch (com
.sun
.star
.uno
.Exception ex
) {
86 ex
.printStackTrace( log
);
87 throw new StatusException( "Couldn't create document", ex
);
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xMathDoc " );
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Creates an instance of the service
102 * <code>com.sun.star.comp.Math.XMLMetaImporter</code><p>
104 * The math document is set as a target document for importer.
105 * Imported XML-data contains the tag which specifies new user info
106 * field and a title of document.
107 * After import user fields info and the title of target document
109 * Object relations created :
111 * <li> <code>'XDocumentHandler.XMLData'</code> for
112 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
113 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
114 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
115 * <li> <code>'TargetDocument'</code> for
116 * {@link ifc.document._XImporter} interface </li>
119 public synchronized TestEnvironment createTestEnvironment
120 ( TestParameters Param
, PrintWriter log
)
121 throws StatusException
{
123 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
124 XInterface oObj
= null;
125 final String impName
= "XMLMetaImporter" ;
126 final String impValue
= "XMLMetaImporter_Value" ;
127 final String impTitle
= "XMLMetaImporter Title" ;
129 final XDocumentInfoSupplier xDocInfoSup
;
131 oObj
= (XInterface
)xMSF
.createInstance(
132 "com.sun.star.comp.Math.XMLMetaImporter");
134 xDocInfoSup
= (XDocumentInfoSupplier
) UnoRuntime
.queryInterface
135 (XDocumentInfoSupplier
.class, xMathDoc
) ;
136 } catch (com
.sun
.star
.uno
.Exception e
) {
137 e
.printStackTrace(log
);
138 throw new StatusException("Unexpected exception", e
);
141 TestEnvironment tEnv
= new TestEnvironment(oObj
);
143 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
145 String
[][] xml
= new String
[][] {
146 {"start", "office:document-meta",
147 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
148 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
149 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
150 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"
152 {"start", "office:meta"},
153 {"start", "dc:title"},
156 {"start", "meta:user-defined",
157 "meta:name", "CDATA", impName
},
159 {"end", "meta:user-defined"},
160 {"end", "office:meta"},
161 {"end", "office:document-meta"}} ;
163 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
165 final PrintWriter logF
= log
;
167 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
168 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
169 public boolean checkImport() {
171 XDocumentInfo xDocInfo
= xDocInfoSup
.getDocumentInfo() ;
172 XPropertySet xDocInfoProp
= (XPropertySet
)
173 UnoRuntime
.queryInterface
174 (XPropertySet
.class, xDocInfo
) ;
175 boolean result
= false ;
176 for (short i
= 0; i
< xDocInfo
.getUserFieldCount(); i
++) {
177 String gName
= xDocInfo
.getUserFieldName(i
) ;
178 String gValue
= xDocInfo
.getUserFieldValue(i
) ;
179 logF
.println("Field '" + gName
+ "' = '"
181 if (impName
.equals(gName
) && impValue
.equals(gValue
))
184 String gTitle
= (String
) xDocInfoProp
.getPropertyValue
186 logF
.println("Title returned : '" + gTitle
+ "'");
187 result
&= impTitle
.equals(gTitle
) ;
190 } catch (com
.sun
.star
.uno
.Exception e
) {
191 logF
.println("Exception occured while checking filter :") ;
192 e
.printStackTrace(logF
) ;