From 26ebdfc472be16f0eb4110aab0335666d2ba5e62 Mon Sep 17 00:00:00 2001 From: Stephan Wunderlich Date: Mon, 27 Jan 2003 17:20:08 +0000 Subject: NEW: initial version --- .../java/mod/_xmloff/Draw/XMLContentExporter.java | 247 +++++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLContentImporter.java | 246 ++++++++++++++++++++ .../tests/java/mod/_xmloff/Draw/XMLExporter.java | 247 +++++++++++++++++++++ .../tests/java/mod/_xmloff/Draw/XMLImporter.java | 246 ++++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLMetaExporter.java | 237 ++++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLMetaImporter.java | 222 ++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLSettingsExporter.java | 243 ++++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLSettingsImporter.java | 234 +++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLStylesExporter.java | 246 ++++++++++++++++++++ .../java/mod/_xmloff/Draw/XMLStylesImporter.java | 232 +++++++++++++++++++ 10 files changed, 2400 insertions(+) create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java create mode 100644 qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java (limited to 'qadevOOo/tests/java/mod/_xmloff/Draw') diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java new file mode 100644 index 000000000000..5ba54d7c5951 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java @@ -0,0 +1,247 @@ +/************************************************************************* + * + * $RCSfile: XMLContentExporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:03 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.container.XNamed; +import com.sun.star.document.XExporter; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLContentExporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLContentExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New text document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Document disposed here. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLContentExporter with + * argument which is an implementation of XDocumentHandler + * and which can check if required tags and character data is + * exported.

+ * The draw document is set as a source document for exporter + * created. Then a new page (Slide) created in this document and + * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this + * filter checks that new tags exist in the XML output. + * Object relations created : + *

+ */ + protected synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + FilterChecker filter = new FilterChecker(log); + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + // Adding tags for checking existance of head tag and other tags + filter.addTag(new XMLTools.Tag("office:document-content")); + filter.addTag(new XMLTools.Tag("office:body")); + filter.addTagEnclosed( + new XMLTools.Tag("draw:page"), + new XMLTools.Tag("office:body")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide1")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide2")); + + try { + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLContentExporter", + new Object[] {arg}); + XExporter xEx = (XExporter) + UnoRuntime.queryInterface(XExporter.class,oObj); + //xEx.setSourceDocument(xDrawDoc); + + XDrawPagesSupplier supp = (XDrawPagesSupplier) + UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); + XDrawPages set = supp.getDrawPages(); + + // This is an XML-export BUG (new slide named "NewSlide2" + // can not be exported to XML) + set.insertNewByIndex(1); + + XDrawPage page1 = (XDrawPage) + UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(0)); + XNamed NPage1 = (XNamed) + UnoRuntime.queryInterface(XNamed.class,page1); + NPage1.setName("NewSlide1"); + XDrawPage page2 = (XDrawPage) + UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(1)); + XNamed NPage2 = (XNamed) + UnoRuntime.queryInterface(XNamed.class,page2); + NPage2.setName("NewSlide2"); + xEx.setSourceDocument(xDrawDoc); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument",xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to XFilter interface test. All + * the information about errors occured in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + protected class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + public FilterChecker(PrintWriter log) { + super(log,true) ; + } + /** + * _XFilter.FilterChecker interface method + * which returns the result of XML checking. + * @return true if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * false if some errors occured. + */ + public boolean checkFilter() { + return check(); + } + } +} + + diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java new file mode 100644 index 000000000000..831ab4972747 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java @@ -0,0 +1,246 @@ +/************************************************************************* + * + * $RCSfile: XMLContentImporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:02 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.container.XNamed; +import com.sun.star.document.XImporter; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLContentImporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLContentImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New spreadsheet document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Spreadsheet document destroyed. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLContentImporter

+ * + * The Draw document is set as a target document for importer. + * Imported XML-data contains only content tags including pages + * named 'NewSlide1' and 'NewSlide2'. + * Pages getting from target document is checked after import + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws StatusException { + + XInterface oObj = null; + Object oInt = null ; + final String impValue = "XMLImporter_test" ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + try { + oInt = xMSF.createInstance + ("com.sun.star.comp.Draw.XMLContentImporter") ; + XImporter imp = (XImporter) + UnoRuntime.queryInterface(XImporter.class, oInt) ; + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + // New XML document generated to be imported to Draw document + String[][] xml = new String[][] { + {"start", "office:document", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing", + "office:class", "CDATA", "drawing" + ,"office:version", "CDATA", "1.0" + }, + {"start", "office:body"}, + {"start", "draw:page", + "draw:name", "CDATA", "NewSlide1", + "draw:master-page-name", "CDATA", "Default"}, + {"end", "draw:page"}, + {"start", "draw:page", "draw:name", "CDATA", "NewSlide2", + "draw:master-page-name", "CDATA", "Default"}, + {"end","draw:page"}, + {"end", "draw:page"}, + {"end", "office:body"}, + {"end", "office:document"}}; + + // adding relation for XDocumentHandler + tEnv.addObjRelation("XDocumentHandler.XMLData", xml); + + //save to log content before import + final PrintWriter fLog = log; + + // Checking target document after import + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + XDrawPagesSupplier supp = (XDrawPagesSupplier) + UnoRuntime.queryInterface + (XDrawPagesSupplier.class, xDrawDoc); + final XDrawPages xPages = supp.getDrawPages(); + XNamed[] pageArray = new XNamed[ xPages.getCount() ]; + for (int i=0; i < xPages.getCount(); i++) { + try { + pageArray[i] = (XNamed) UnoRuntime.queryInterface + (XNamed.class, xPages.getByIndex(i)); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(fLog) ; + throw new StatusException + ("Can't get page name by index.", e) ; + } + } + fLog.println("Slide names after import:"); + for ( int i = 0; i < xPages.getCount(); i++ ) { + if ((pageArray[i].getName().equals("NewSlide1")) + || (pageArray[i].getName().equals("NewSlide2"))) { + fLog.println(" " + pageArray[i].getName()); + } + else { + fLog.println("Error: some imported values are not exist in target document!"); + return false; + } + } + return true; + } + }); + + return tEnv; + } +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java new file mode 100644 index 000000000000..c2aa62f54e2e --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java @@ -0,0 +1,247 @@ +/************************************************************************* + * + * $RCSfile: XMLExporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:02 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.container.XNamed; +import com.sun.star.document.XExporter; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLExporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New text document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Document disposed here. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLExporter with + * argument which is an implementation of XDocumentHandler + * and which can check if required tags and character data is + * exported.

+ * The draw document is set as a source document for exporter + * created. Then a new page (Slide) created in this document and + * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this + * filter checks that new tags exist in the XML output. + * Object relations created : + *

+ */ + protected synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + FilterChecker filter = new FilterChecker(log); + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + // Adding tags for checking existance of head tag and other tags + filter.addTag(new XMLTools.Tag("office:document")); + filter.addTag(new XMLTools.Tag("office:body")); + filter.addTagEnclosed( + new XMLTools.Tag("draw:page"), + new XMLTools.Tag("office:body")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide1")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide2")); + + try { + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLExporter", new Object[] {arg}); + + + XDrawPagesSupplier supp = (XDrawPagesSupplier) + UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); + XDrawPages set = supp.getDrawPages(); + + // This is an XML-export BUG (new slide named "NewSlide2" can not be exported to XML) + set.insertNewByIndex(1); + + XDrawPage page1 = (XDrawPage) + UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(0)); + XNamed NPage1 = (XNamed) + UnoRuntime.queryInterface(XNamed.class,page1); + NPage1.setName("NewSlide1"); + XDrawPage page2 = (XDrawPage) + UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(1)); + XNamed NPage2 = (XNamed) + UnoRuntime.queryInterface(XNamed.class,page2); + NPage2.setName("NewSlide2"); + + XExporter xEx = (XExporter) + UnoRuntime.queryInterface(XExporter.class,oObj); + xEx.setSourceDocument(xDrawDoc); + + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument",xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to XFilter interface test. All + * the information about errors occured in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + protected class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + public FilterChecker(PrintWriter log) { + super(log,true) ; + } + /** + * _XFilter.FilterChecker interface method + * which returns the result of XML checking. + * @return true if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * false if some errors occured. + */ + public boolean checkFilter() { + return check(); + } + } + +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java new file mode 100644 index 000000000000..dea96e412ffa --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java @@ -0,0 +1,246 @@ +/************************************************************************* + * + * $RCSfile: XMLImporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.container.XNamed; +import com.sun.star.document.XImporter; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLImporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New spreadsheet document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Spreadsheet document destroyed. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLImporter

+ * + * The Draw document is set as a target document for importer. + * Imported XML-data contains only content tags including pages + * named 'NewSlide1' and 'NewSlide2'. + * Pages getting from target document are checked after import. + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws StatusException { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + try { + oInt = xMSF.createInstance("com.sun.star.comp.Draw.XMLImporter") ; + XImporter imp = (XImporter) + UnoRuntime.queryInterface(XImporter.class, oInt) ; + //imp.setTargetDocument(xDrawDoc); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing", + "office:class", "CDATA", "drawing" + ,"office:version", "CDATA", "1.0" + }, + {"start", "office:body"}, + {"start", "draw:page", + "draw:name", "CDATA", "NewSlide1", + "draw:master-page-name", "CDATA", "Default"}, + {"end", "draw:page"}, + {"start", "draw:page", + "draw:name", "CDATA", "NewSlide2", + "draw:master-page-name", "CDATA", "Default"}, + {"end","draw:page"}, + {"end", "draw:page"}, + {"end", "office:body"}, + {"end", "office:document"}} ; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; + + //save to log content before import + final PrintWriter fLog = log; + + // Checking target document after import + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + XDrawPagesSupplier supp = (XDrawPagesSupplier) + UnoRuntime.queryInterface + (XDrawPagesSupplier.class, xDrawDoc); + final XDrawPages xPages = supp.getDrawPages(); + XNamed[] pageArray = new XNamed[ xPages.getCount() ]; + for (int i=0; i < xPages.getCount(); i++) { + try { + pageArray[i] = (XNamed) UnoRuntime.queryInterface + (XNamed.class, xPages.getByIndex(i)); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(fLog) ; + throw new StatusException + ("Can't get page name by index.", e) ; + } + } + fLog.println("Slide names after import:"); + for ( int i = 0; i < xPages.getCount(); i++ ) { + if ((pageArray[i].getName().equals("NewSlide1")) + || (pageArray[i].getName().equals("NewSlide2"))) { + fLog.println(" " + pageArray[i].getName()); + } + else { + fLog.println("Error: some imported values are not exist in target document!"); + return false; + } + } + return true; + } + }); + + return tEnv; + } // end of getTestEnvironment + +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java new file mode 100644 index 000000000000..944a10894c82 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java @@ -0,0 +1,237 @@ +/************************************************************************* + * + * $RCSfile: XMLMetaExporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.document.XDocumentInfoSupplier; +import com.sun.star.document.XExporter; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLMetaExporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLMetaExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Document disposed here. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLMetaExporter with + * argument which is an implementation of XDocumentHandler + * and which can check if required tags and character data is + * exported.

+ * The draw document is set as a source document for exporter + * created. Set title of document to 'XMLMetaExporter'. + * This made for checking if this title is successfully exported within + * the document meta information. + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws StatusException { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + final String TITLE = "XMLMetaExporter"; + + FilterChecker filter = new FilterChecker(log) ; + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + try { + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLMetaExporter", new Object[] {arg}); + XExporter xEx = (XExporter) + UnoRuntime.queryInterface(XExporter.class, oObj); + xEx.setSourceDocument(xDrawDoc); + + //set some meta data + XDocumentInfoSupplier infoSup = (XDocumentInfoSupplier) + UnoRuntime.queryInterface(XDocumentInfoSupplier.class, + xDrawDoc) ; + XPropertySet docInfo = (XPropertySet) UnoRuntime.queryInterface + (XPropertySet.class, infoSup.getDocumentInfo()) ; + docInfo.setPropertyValue("Title", TITLE); + + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + // Checking Head Tag existance and that property has changed + filter.addTag(new XMLTools.Tag ("office:document-meta")); + filter.addTagEnclosed( + new XMLTools.Tag("office:meta"), + new XMLTools.Tag("office:document-meta") ); + filter.addTagEnclosed( + new XMLTools.Tag("dc:title"), + new XMLTools.Tag("office:meta") ); + filter.addCharactersEnclosed( TITLE, + new XMLTools.Tag("dc:title") ); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument", xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to XFilter interface test. All + * the information about errors occured in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + protected class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + public FilterChecker(PrintWriter log) { + super(log, true) ; + } + + /** + * _XFilter.FilterChecker interface method + * which returns the result of XML checking. + * @return true if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * false if some errors occured. + */ + public boolean checkFilter() { + return check(); + } + } +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java new file mode 100644 index 000000000000..fee99d07d146 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java @@ -0,0 +1,222 @@ +/************************************************************************* + * + * $RCSfile: XMLMetaImporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.document.XDocumentInfoSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLMetaImporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLMetaImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Draw document destroyed. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLMetaImporter

+ * + * The draw document is set as a target document for importer. + * Imported XML-data contains only meta tags including + * title tag with test name. + * After import title name getting from target document is checked. + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment + (TestParameters tParam,PrintWriter log ) { + + XInterface oObj = null; + Object oInt = null ; + final String impValue = "XMLImporter_test" ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + try { + oInt = xMSF.createInstance("com.sun.star.comp.Draw.XMLMetaImporter") ; + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + final String impTitle = "XMLMetaImporter" ; + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document-meta", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta", + "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/" + }, + {"start", "office:meta"}, + {"start", "dc:title"}, + {"chars", impTitle}, + {"end", "dc:title"}, + {"end", "office:meta"}, + {"end", "office:document-meta"}} ; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; + + //set some meta data + XDocumentInfoSupplier infoSup = (XDocumentInfoSupplier) + UnoRuntime.queryInterface + (XDocumentInfoSupplier.class, xDrawDoc); + final XPropertySet docInfo = (XPropertySet) UnoRuntime.queryInterface + (XPropertySet.class, infoSup.getDocumentInfo()); + final PrintWriter logF = log ; + + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + try { + String title = (String) docInfo.getPropertyValue + ("Title") ; + logF.println("Title returned = '" + title + "'") ; + return impTitle.equals(title) ; + } catch (com.sun.star.uno.Exception e) { + logF.println("Exception occured while checking filter :") ; + e.printStackTrace(logF) ; + return false ; + } + } + }) ; + + return tEnv; + } // finish method getTestEnvironment +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java new file mode 100644 index 000000000000..5d26bf2db99f --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java @@ -0,0 +1,243 @@ +/************************************************************************* + * + * $RCSfile: XMLSettingsExporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.document.XExporter; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLSettingsExporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLSettingsExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Document disposed here. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * om.sun.star.comp.Draw.XMLSettingsExporter with + * argument which is an implementation of XDocumentHandler + * and which can check if required tags and character data is + * exported.

+ * The draw document is set as a source document for exporter + * created. Property 'IsLayerMode' set to true. + * This made for checking if this property is successfully exported within + * the document styles information. + * Object relations created : + *

+ */ + protected synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + + FilterChecker filter = new FilterChecker(log) ; + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + try { + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLSettingsExporter", + new Object[] {arg}); + XExporter xEx = (XExporter) + UnoRuntime.queryInterface(XExporter.class, oObj); + xEx.setSourceDocument(xDrawDoc); + + //set some settings + XModel xDrawModel = (XModel) + UnoRuntime.queryInterface(XModel.class, xDrawDoc); + XController xController = xDrawModel.getCurrentController(); + XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xController); + xPropSet.setPropertyValue("IsLayerMode", new Boolean("true")); + + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + // Checking Head Tag existance and that property has changed + filter.addTag(new XMLTools.Tag ("office:document-settings")); + filter.addTagEnclosed( + new XMLTools.Tag ("office:settings"), + new XMLTools.Tag ("office:document-settings") ); + filter.addTagEnclosed( + new XMLTools.Tag ("config:config-item-set"), + new XMLTools.Tag ("office:settings") ); + filter.addTagEnclosed( + new XMLTools.Tag ("config:config-item-map-indexed"), + new XMLTools.Tag ("config:config-item-set") ); + filter.addCharactersEnclosed( "true", + new XMLTools.Tag( "config:config-item", + "config:name", + "IsLayerMode" )); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument", xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to XFilter interface test. All + * the information about errors occured in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + protected class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + public FilterChecker(PrintWriter log) { + super(log, false) ; + } + + /** + * _XFilter.FilterChecker interface method + * which returns the result of XML checking. + * @return true if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * false if some errors occured. + */ + public boolean checkFilter() { + return check(); + } + } +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java new file mode 100644 index 000000000000..6fda8b714d24 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java @@ -0,0 +1,234 @@ +/************************************************************************* + * + * $RCSfile: XMLSettingsImporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:20:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.document.XImporter; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLSettingsImporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLSettingsImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Text draw destroyed. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLSettingsImporter

+ * + * The draw document is set as a target document for importer. + * Imported XML-data contains only settings tags including + * tag with property 'IsLayerMode'. + * After import property 'IsLayerMode' getting from target + * document is checked. + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) throws StatusException { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + try { + oInt = xMSF.createInstance + ("com.sun.star.comp.Draw.XMLSettingsImporter") ; + XImporter imp = (XImporter) + UnoRuntime.queryInterface(XImporter.class, oInt) ; + //imp.setTargetDocument(xDrawDoc); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document-settings", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:config", "CDATA", "http://openoffice.org/2001/config"}, + {"start", "office:settings"}, + {"start", "config:config-item-set", + "config:name", "CDATA", "view-settings"}, + {"start", "config:config-item-map-indexed", + "config:name", "CDATA", "Views"}, + {"start", "config:config-item-map-entry"}, + {"start", "config:config-item", + "config:name", "CDATA", "IsLayerMode", + "config:type", "CDATA", "boolean"}, + {"chars", "true"}, + {"end", "config:config-item"}, + {"end", "config:config-item-map-entry"}, + {"end", "config:config-item-map-indexed"}, + {"end", "config:config-item-set"}, + {"end", "office:settings"}, + {"end", "office:document-settings"} }; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml); + final PrintWriter logF = log; + XModel xDrawModel = (XModel) + UnoRuntime.queryInterface(XModel.class, xDrawDoc); + XController xController = xDrawModel.getCurrentController(); + final XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xController); + + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + try { + Boolean value = (Boolean) + xPropSet.getPropertyValue("IsLayerMode"); + logF.println("'IsLayerMode' property value is '" + + value + "'"); + return value.booleanValue() == true; + } catch (com.sun.star.uno.Exception e) { + logF.println("Exception while checking import :") ; + e.printStackTrace(logF) ; + return false ; + } + } + }) ; + + return tEnv; + } // finish method getTestEnvironment +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java new file mode 100644 index 000000000000..9bbe279c3363 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java @@ -0,0 +1,246 @@ +/************************************************************************* + * + * $RCSfile: XMLStylesExporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:19:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.document.XExporter; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.style.XStyle; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLStylesExporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLStylesExporter extends TestCase { + XComponent xDrawDoc = null; + protected static int counter = 0; + + /** + * New draw document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Document disposed here. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLStylesExporter with + * argument which is an implementation of XDocumentHandler + * and which can check if required tags and character data is + * exported.

+ * The draw document is set as a source document for exporter + * created. New style is added to the style family 'graphics' with unique name + * every time. This made for checking if this style is successfully exported + * within the document styles information. + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment( + TestParameters tParam, PrintWriter log) throws StatusException { + + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() ); + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + FilterChecker filter = new FilterChecker(log) ; + Any arg = new Any(new Type(XDocumentHandler.class),filter); + final String STYLE_NAME = "New style" + counter++ ; + + try { + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLStylesExporter", new Object[] {arg}); + XExporter xEx = (XExporter) + UnoRuntime.queryInterface(XExporter.class,oObj); + xEx.setSourceDocument(xDrawDoc); + + //obtain style families + XStyleFamiliesSupplier styleSup = (XStyleFamiliesSupplier) + UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xDrawDoc); + XNameAccess StyleFamilies = styleSup.getStyleFamilies(); + //obtain all style family names + String[] styleFamiliesNames = StyleFamilies.getElementNames(); + String styleFamilyName = styleFamiliesNames[0]; + //obtain style family with name[0] + Object objectStyle = StyleFamilies.getByName(styleFamilyName); + XNameContainer xStyleFamilyName = (XNameContainer) + UnoRuntime.queryInterface(XNameContainer.class, objectStyle); + //creat new style + Object SC = SOF.createInstance(xDrawDoc, "com.sun.star.style.Style"); + XStyle Style = (XStyle) UnoRuntime.queryInterface(XStyle.class,SC); + //add new style to style familiy with name[0] + xStyleFamilyName.insertByName(STYLE_NAME,Style); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + // Checking Head Tag existance and that property has changed + filter.addTag(new XMLTools.Tag ("office:document-styles")); + filter.addTag(new XMLTools.Tag ("office:styles")); + filter.addTagEnclosed( + new XMLTools.Tag("style:style"), + new XMLTools.Tag("office:styles") ); + filter.addTag(new XMLTools.Tag("style:style", "style:name", STYLE_NAME)); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument",xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to XFilter interface test. All + * the information about errors occured in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + protected class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + public FilterChecker(PrintWriter log) { + super(log, false) ; + } + + /** + * _XFilter.FilterChecker interface method + * which returns the result of XML checking. + * @return true if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * false if some errors occured. + */ + public boolean checkFilter() { + return check(); + } + } +} + diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java new file mode 100644 index 000000000000..13b07abc5597 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java @@ -0,0 +1,232 @@ +/************************************************************************* + * + * $RCSfile: XMLStylesImporter.java,v $ + * + * $Revision: 1.1 $ + * + * last change:$Date: 2003-01-27 18:19:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package mod._xmloff.Draw; + +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.document.XImporter; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +/** + * Test for object which is represented by service + * com.sun.star.comp.Draw.XMLStylesImporter.

+ * Object implements the following interfaces : + *

+ * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLStylesImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + try { + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } catch ( Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Text draw destroyed. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a Testenvironment for the interfaces to be tested. + * Creates an instance of the service + * com.sun.star.comp.Draw.XMLStylesImporter

+ * + * The draw document is set as a target document for importer. + * Imported XML-data contains only styles tags including + * tag with new style. + * After import checked existing of this new style in style + * collection obtained from target document. + * Object relations created : + *

+ */ + public synchronized TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws StatusException { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + try { + oInt = xMSF.createInstance + ("com.sun.star.comp.Draw.XMLStylesImporter") ; + XImporter imp = (XImporter) + UnoRuntime.queryInterface(XImporter.class, oInt) ; + //imp.setTargetDocument(xDrawDoc); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(log) ; + throw new StatusException("Can't create component.", e) ; + } + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + final String impStyleName = "New style for test XMLStylesImporter"; + final String impFamilyName = "graphics"; + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document-styles", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:style", "CDATA", "http://openoffice.org/2000/style"}, + {"start", "office:styles"}, + {"start", "style:style", + "style:name", "CDATA", impStyleName, + "style:family", "CDATA", impFamilyName}, + {"end", "style:style"}, + {"end", "office:styles"}, + {"end", "office:document"}} ; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; + + final PrintWriter logF = log; + //obtain style families + XStyleFamiliesSupplier styleSup = (XStyleFamiliesSupplier) + UnoRuntime.queryInterface (XStyleFamiliesSupplier.class, xDrawDoc) ; + final XNameAccess StyleFamilies = styleSup.getStyleFamilies(); + + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + try { + Object objectStyle = + StyleFamilies.getByName(impFamilyName); + XNameContainer StyleFamilyName = (XNameContainer) + UnoRuntime.queryInterface + (XNameContainer.class, objectStyle); + boolean hasStyle = + StyleFamilyName.hasByName(impStyleName); + logF.println("Does style with name '" + impStyleName + + "' exist? " + String.valueOf(hasStyle) ); + return hasStyle; + } catch (com.sun.star.uno.Exception e) { + logF.println("Exception while checking import :") ; + e.printStackTrace(logF) ; + return false ; + } + } + }) ; + + return tEnv; + } // finish method getTestEnvironment +} -- cgit