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: XMLMetaExporter.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
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.document
.XDocumentInfoSupplier
;
44 import com
.sun
.star
.document
.XExporter
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.text
.XTextDocument
;
47 import com
.sun
.star
.uno
.Any
;
48 import com
.sun
.star
.uno
.Type
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
51 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
54 * Test for object which is represented by service
55 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code>. <p>
56 * Object implements the following interfaces :
58 * <li><code>com::sun::star::lang::XInitialization</code></li>
59 * <li><code>com::sun::star::document::ExportFilter</code></li>
60 * <li><code>com::sun::star::document::XFilter</code></li>
61 * <li><code>com::sun::star::document::XExporter</code></li>
62 * <li><code>com::sun::star::beans::XPropertySet</code></li>
64 * @see com.sun.star.lang.XInitialization
65 * @see com.sun.star.document.ExportFilter
66 * @see com.sun.star.document.XFilter
67 * @see com.sun.star.document.XExporter
68 * @see com.sun.star.beans.XPropertySet
69 * @see ifc.lang._XInitialization
70 * @see ifc.document._ExportFilter
71 * @see ifc.document._XFilter
72 * @see ifc.document._XExporter
73 * @see ifc.beans._XPropertySet
75 public class XMLMetaExporter
extends TestCase
{
77 XTextDocument xTextDoc
;
78 MetaFilterChecker Filter
;
81 * New text document created.
83 protected void initialize( TestParameters tParam
, PrintWriter log
) {
84 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
86 log
.println( "creating a textdocument" );
87 xTextDoc
= SOF
.createTextDoc( null );
89 } catch ( com
.sun
.star
.uno
.Exception e
) {
90 // Some exception occures.FAILED
91 e
.printStackTrace( log
);
92 throw new StatusException( "Couldn't create document", e
);
97 * Document disposed here.
99 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
100 log
.println( " disposing xTextDoc " );
101 util
.DesktopTools
.closeDoc(xTextDoc
);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Creates an instance of the service
107 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code> with
108 * argument which is an implementation of <code>XDocumentHandler</code>
109 * and which can check if required tags and character data is
111 * The text document is set as a source document for exporter
112 * created. The 'Title' metadata property is set to a value. This made
113 * for checking if this property is successfully exported within
114 * the document metadata.
115 * Object relations created :
117 * <li> <code>'MediaDescriptor'</code> for
118 * {@link ifc.document._XFilter} interface </li>
119 * <li> <code>'XFilter.Checker'</code> for
120 * {@link ifc.document._XFilter} interface </li>
121 * <li> <code>'SourceDocument'</code> for
122 * {@link ifc.document._XExporter} interface </li>
125 public synchronized TestEnvironment createTestEnvironment
126 ( TestParameters tParam
, PrintWriter log
) throws StatusException
{
127 final String TITLE
= "Title for testing of XMLMetaExporter";
129 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
130 XInterface oObj
= null;
132 Filter
= new MetaFilterChecker(log
);
133 Any arg
= new Any(new Type(XDocumentHandler
.class), Filter
);
136 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
137 "com.sun.star.comp.Writer.XMLMetaExporter",
139 XExporter xEx
= (XExporter
) UnoRuntime
.queryInterface
140 (XExporter
.class,oObj
);
141 xEx
.setSourceDocument(xTextDoc
);
144 XDocumentInfoSupplier infoSup
= (XDocumentInfoSupplier
)
145 UnoRuntime
.queryInterface
146 (XDocumentInfoSupplier
.class, xTextDoc
) ;
147 XPropertySet docInfo
= (XPropertySet
) UnoRuntime
.queryInterface
148 (XPropertySet
.class, infoSup
.getDocumentInfo()) ;
149 docInfo
.setPropertyValue("Title", TITLE
);
151 } catch (com
.sun
.star
.uno
.Exception e
) {
152 e
.printStackTrace(log
) ;
153 throw new StatusException("Can't create component.", e
) ;
156 // adding tags which must be contained in XML output
157 Filter
.addTag("office:document-meta");
158 Filter
.addTagEnclosed("office:meta", "office:document-meta");
159 Filter
.addCharactersEnclosed(TITLE
, "dc:title");
161 // create testobject here
162 log
.println( "creating a new environment" );
163 TestEnvironment tEnv
= new TestEnvironment( oObj
);
165 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
166 new String
[] {"FilterName"},
167 new Object
[] {"swriter: StarOffice XML (Writer)"}));
168 tEnv
.addObjRelation("SourceDocument", xTextDoc
);
169 tEnv
.addObjRelation("XFilter.Checker", Filter
);
174 * This class checks the XML for tags and data required and returns
175 * checking result to <code>XFilter</code> interface test. All
176 * the information about errors occured in XML data is written
178 * @see ifc.document._XFilter
180 protected class MetaFilterChecker
extends XMLTools
.XMLTagsChecker
181 implements ifc
.document
._XFilter
.FilterChecker
{
184 * Creates a class which will write information
185 * into log specified.
187 public MetaFilterChecker(PrintWriter log
) {
192 * <code>_XFilter.FilterChecker</code> interface method
193 * which returns the result of XML checking.
194 * @return <code>true</code> if the XML data exported was
195 * valid (i.e. all necessary tags and character data exists),
196 * <code>false</code> if some errors occured.
198 public boolean checkFilter() {