1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 package util.db; 20 21 import com.sun.star.beans.PropertyValue; 22 import com.sun.star.frame.XModel; 23 import com.sun.star.frame.XStorable; 24 import com.sun.star.io.IOException; 25 import com.sun.star.sdb.XDocumentDataSource; 26 import com.sun.star.sdb.XOfficeDatabaseDocument; 27 import com.sun.star.uno.UnoRuntime; 28 29 /** 30 * encapsulates a css.sdb.DatabaseDocument 31 */ 32 public class DatabaseDocument 33 { DatabaseDocument( final DataSource _dataSource )34 protected DatabaseDocument( final DataSource _dataSource ) 35 { 36 XDocumentDataSource docDataSource = UnoRuntime.queryInterface( 37 XDocumentDataSource.class, _dataSource.getDataSource() ); 38 m_databaseDocument = UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, 39 docDataSource.getDatabaseDocument() ); 40 41 m_model = UnoRuntime.queryInterface( XModel.class, m_databaseDocument ); 42 m_storeDoc = UnoRuntime.queryInterface( XStorable.class, m_databaseDocument ); 43 } 44 getDatabaseDocument()45 public XOfficeDatabaseDocument getDatabaseDocument() 46 { 47 return m_databaseDocument; 48 } 49 50 /** 51 * passes through to XModel.getURL. 52 */ getURL()53 public String getURL() 54 { 55 return m_model.getURL(); 56 } 57 58 /** 59 * simplified version (taking no arguments except the target URL) of XStorage.storeAsURL 60 * @param _url 61 * specifies the location to where to store the document 62 */ storeAsURL( final String _url )63 public void storeAsURL( final String _url ) throws IOException 64 { 65 m_storeDoc.storeAsURL( _url, new PropertyValue[] { } ); 66 } 67 68 private final XOfficeDatabaseDocument m_databaseDocument; 69 private final XModel m_model; 70 private final XStorable m_storeDoc; 71 } 72