merge the formfield patch from ooo-build
[ooovba.git] / ucb / qa / complex / tdoc / CheckTransientDocumentsDocumentContent.java
blob8c27a50d6ea21e62bfd8b74019be142114d29a27
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CheckTransientDocumentsDocumentContent.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
30 package complex.tdoc;
32 import com.sun.star.beans.Property;
33 import com.sun.star.beans.PropertyValue;
34 import com.sun.star.document.XDocumentSubStorageSupplier;
35 import com.sun.star.embed.ElementModes;
36 import com.sun.star.embed.XStorage;
37 import com.sun.star.frame.XModel;
38 import com.sun.star.frame.XTransientDocumentsDocumentContentFactory;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.lang.XServiceInfo;
41 import com.sun.star.sdbc.XResultSet;
42 import com.sun.star.sdbc.XRow;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.ucb.Command;
45 import com.sun.star.ucb.ContentInfo;
46 import com.sun.star.ucb.InsertCommandArgument;
47 import com.sun.star.ucb.OpenCommandArgument2;
48 import com.sun.star.ucb.OpenMode;
49 import com.sun.star.ucb.XCommandProcessor;
50 import com.sun.star.ucb.XContent;
51 import com.sun.star.ucb.XContentAccess;
52 import com.sun.star.ucb.XContentCreator;
53 import com.sun.star.ucb.XContentIdentifier;
54 import com.sun.star.ucb.XContentIdentifierFactory;
55 import com.sun.star.ucb.XContentProvider;
56 import com.sun.star.ucb.XDynamicResultSet;
57 import com.sun.star.uno.UnoRuntime;
58 import complexlib.ComplexTestCase;
59 import util.WriterTools;
60 import util.utils;
63 /**
66 public class CheckTransientDocumentsDocumentContent extends ComplexTestCase {
67 private final String testDocuments = "sForm.sxw";
68 private final String folderName = "TestFolder";
69 private XMultiServiceFactory xMSF = null;
70 private XTextDocument xTextDoc = null;
72 public String[] getTestMethodNames() {
73 return new String[]{"checkTransientDocumentsDocumentContent"};
76 public void before() {
77 xMSF = (XMultiServiceFactory)param.getMSF();
78 log.println("Open a document.");
79 String fileName = utils.getFullTestURL(testDocuments);
80 xTextDoc = WriterTools.loadTextDoc(xMSF, fileName);
82 public void after() {
83 log.println("Close all documents.");
84 xTextDoc.dispose();
87 /**
88 * Check the provider of document content: open some documents
89 * and look if they are accessible.
91 public void checkTransientDocumentsDocumentContent() {
92 try {
93 // create a content provider
94 Object o = xMSF.createInstance("com.sun.star.comp.ucb.TransientDocumentsDocumentContentFactory");
96 XTransientDocumentsDocumentContentFactory xTransientDocumentsDocumentContentFactory =
97 (XTransientDocumentsDocumentContentFactory)UnoRuntime.queryInterface(
98 XTransientDocumentsDocumentContentFactory.class, o);
99 // get the model from the opened document
100 XModel xModel = xTextDoc.getCurrentController().getModel();
102 // a little additional check for 114733
103 XDocumentSubStorageSupplier xDocumentSubStorageSupplier = (XDocumentSubStorageSupplier)
104 UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class, xModel);
105 String[]names = xDocumentSubStorageSupplier.getDocumentSubStoragesNames();
106 for (int i=0; i<names.length; i++) {
107 log.println("SubStorage names " + i + ": " +names[i]);
109 XStorage xStorage = xDocumentSubStorageSupplier.getDocumentSubStorage(names[0], ElementModes.READWRITE);
110 assure("Could not get a storage from the XDocumentStorageSupplier.", xStorage != null);
111 // get content
112 XContent xContent = xTransientDocumentsDocumentContentFactory.createDocumentContent(xModel);
113 // actual test: execute some commands
114 XCommandProcessor xCommandProcessor = (XCommandProcessor)UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
116 // create the command and arguments
117 Command command = new Command();
118 OpenCommandArgument2 cmargs2 = new OpenCommandArgument2();
119 Property[]props = new Property[1];
120 props[0] = new Property();
121 props[0].Name = "Title";
122 props[0].Handle = -1;
123 cmargs2.Mode = OpenMode.ALL;
124 cmargs2.Properties = props;
126 command.Name = "open";
127 command.Argument = cmargs2;
129 Object result = xCommandProcessor.execute(command, 0, null);
130 XDynamicResultSet xDynamicResultSet = (XDynamicResultSet)UnoRuntime.queryInterface(XDynamicResultSet.class, result);
131 XResultSet xResultSet = xDynamicResultSet.getStaticResultSet();
132 XRow xRow = (XRow)UnoRuntime.queryInterface(XRow.class, xResultSet);
133 // create the new folder 'folderName': first, check if it's already there
134 while(xResultSet.next()) {
135 String existingFolderName = xRow.getString(1);
136 log.println("Found existing folder: '" + existingFolderName + "'");
137 if (folderName.equals(existingFolderName)) {
138 failed("Cannot create a new folder: folder already exists: adapt test or choose a different document.");
141 // create a folder
142 XContent xNewFolder = null;
143 log.println("Create new folder "+ folderName);
144 ContentInfo contentInfo = new ContentInfo();
145 contentInfo.Type = "application/vnd.sun.star.tdoc-folder";
146 XContentCreator xContentCreator = (XContentCreator)UnoRuntime.queryInterface(XContentCreator.class, xContent);
147 xNewFolder = xContentCreator.createNewContent(contentInfo);
148 XCommandProcessor xFolderCommandProcessor = (XCommandProcessor)UnoRuntime.queryInterface(XCommandProcessor.class, xNewFolder);
149 log.println("Got the new folder: " + utils.getImplName(xNewFolder));
151 // name the new folder
152 PropertyValue[] titleProp = new PropertyValue[1];
153 titleProp[0] = new PropertyValue();
154 titleProp[0].Name = "Title";
155 titleProp[0].Handle = -1;
156 titleProp[0].Value = folderName;
157 Command titleSetCommand = new Command();
158 titleSetCommand.Name = "setPropertyValues";
159 titleSetCommand.Argument = titleProp;
160 xFolderCommandProcessor.execute(titleSetCommand, 0, null);
162 // 2do: check all this stuff!
163 // commit changes
164 /* InsertCommandArgument insertArgs = new InsertCommandArgument();
165 insertArgs.Data = null;
166 insertArgs.ReplaceExisting = true;
167 Command commitCommand = new Command();
168 commitCommand.Name = "insert";
169 commitCommand.Argument = insertArgs;
170 xFolderCommandProcessor.execute(commitCommand, 0, null); */
172 catch (com.sun.star.uno.Exception e) {
173 e.printStackTrace((java.io.PrintWriter)log);
174 failed("Could not create test objects.");