From b877d32d796ac226a78f208139ba705f55498ebe Mon Sep 17 00:00:00 2001
From: Jens-Heiner Rechtien
Date: Fri, 23 Jul 2004 12:59:58 +0000
Subject: INTEGRATION: CWS scriptingf7 (1.1.2); FILE ADDED 2004/07/09 18:07:52
npower 1.1.2.2: #i25260# changes to exception specifications to support error
handling, also changed to use ParsedUrl class 2004/07/05 15:22:57 npower
1.1.2.1: #i25269# new class for managing containment of uno-packages ( and
sub packages in and uno package bundle )
---
.../framework/container/UnoPkgContainer.java | 483 +++++++++++++++++++++
1 file changed, 483 insertions(+)
create mode 100644 scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java
(limited to 'scripting/java/com')
diff --git a/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java
new file mode 100644
index 000000000000..0d01f5db096a
--- /dev/null
+++ b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java
@@ -0,0 +1,483 @@
+/*************************************************************************
+ *
+ * $RCSfile: UnoPkgContainer.java,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: hr $ $Date: 2004-07-23 13:59:58 $
+ *
+ * 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 com.sun.star.script.framework.container;
+
+import com.sun.star.script.framework.log.LogUtils;
+import com.sun.star.script.framework.provider.PathUtils;
+import com.sun.star.script.framework.io.XOutputStreamWrapper;
+import com.sun.star.script.framework.io.XInputStreamWrapper;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+import java.io.OutputStream;
+import java.io.InputStream;
+
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.uno.UnoRuntime;
+
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.EventObject;
+import com.sun.star.lang.XComponent;
+
+import com.sun.star.io.XOutputStream;
+import com.sun.star.io.XTruncate;
+
+
+import com.sun.star.uno.Type;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Any;
+
+import com.sun.star.ucb.Command;
+import com.sun.star.ucb.XContentProvider;
+import com.sun.star.ucb.XContent;
+import com.sun.star.ucb.XCommandProcessor;
+import com.sun.star.ucb.XContentIdentifier;
+import com.sun.star.ucb.XContentIdentifierFactory;
+import com.sun.star.ucb.XSimpleFileAccess;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.Property;
+
+import com.sun.star.sdbc.XRow;
+
+import com.sun.star.deployment.XPackage;
+import com.sun.star.deployment.XPackageManager;
+import com.sun.star.deployment.XPackageManagerFactory;
+
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.lang.XMultiComponentFactory;
+
+import drafts.com.sun.star.script.provider.XScriptContext;
+
+public class UnoPkgContainer extends ParcelContainer
+{
+
+ private Map registeredPackages = new HashMap();
+
+ public UnoPkgContainer( XComponentContext xCtx, String locationURL, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
+ {
+ super( xCtx, locationURL, language, false );
+ init();
+ }
+
+ // gets the ParcelContainer for persisted uno packages
+ public ParcelContainer getRegisteredUnoPkgContainer( String url )
+ {
+ LogUtils.DEBUG("** getRegisterPackage ctx = " + containerUrl );
+ LogUtils.DEBUG("** getRegisterPackage for uri " + url );
+ LogUtils.DEBUG("** getRegisterPackage for langugage " + language );
+ ParcelContainer result = (ParcelContainer)registeredPackages.get( url );
+ LogUtils.DEBUG("getRegisterPackage result is " + result );
+ return result;
+ }
+
+ public boolean hasRegisteredUnoPkgContainer( String url )
+ {
+ boolean result = false;
+ if ( getRegisteredUnoPkgContainer( url ) != null )
+ {
+ result = true;
+ }
+ return result;
+ }
+
+ private void registerPackageContainer( String url, ParcelContainer c )
+ {
+ LogUtils.DEBUG("RegisterPackage ctx = " + containerUrl );
+ LogUtils.DEBUG("RegisterPackage language = " + language );
+ LogUtils.DEBUG("RegisterPackage " + c + " for url " + url );
+ registeredPackages.put( url, c );
+ }
+
+ public void deRegisterPackageContainer( String url )
+ {
+ LogUtils.DEBUG("In deRegisterPackageContainer for " + url );
+ if ( hasRegisteredUnoPkgContainer( url ) )
+ {
+ try
+ {
+ DeployedUnoPackagesDB db = getUnoPackagesDB();
+ if ( db != null )
+ {
+
+ if ( db.removePackage( language, url ) )
+ {
+ writeUnoPackageDB( db );
+ ParcelContainer container =
+ ( ParcelContainer ) registeredPackages.get( url );
+ if ( !container.hasElements() )
+ {
+ // When all libraries within a package bundle
+ // ( for this language ) are removed also
+ // remove the container from its parent
+ // Otherwise, a container ( with no containees )
+ // representing the uno package bundle will
+ // still exist and so will get displayed
+ if ( container.parent() != null )
+ {
+ container.parent().removeChildContainer( container );
+ }
+ }
+ registeredPackages.remove( url );
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ //TODO revisit exception handling and exception here
+ //means something very wrong
+ LogUtils.DEBUG("***** deRegisterPackageContainer() got exception " + e );
+ }
+ }
+ LogUtils.DEBUG("Leaving deRegisterPackageContainer for " + url );
+ }
+
+ private void init() throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
+ {
+ LogUtils.DEBUG("getting container for " + containerUrl );
+ DeployedUnoPackagesDB db = null;
+ try
+ {
+ db = getUnoPackagesDB();
+
+ if ( db != null )
+ {
+ String[] packages = db.getDeployedPackages( language );
+ for ( int i=0; i " + uri );
+ LogUtils.DEBUG("** processUnoPackage getName() -> " + dPackage.getName() );
+ LogUtils.DEBUG("** processUnoPackage getMediaType() -> " + dPackage.getMediaType() );
+ LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " + dPackage.getDisplayName() );
+ processUnoPackage( uri, language );
+ db = getUnoPackagesDB();
+ db.addPackage( language, uri );
+ writeUnoPackageDB( db );
+ }
+
+ private void processUnoPackage( String uri, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.container.ElementExistException
+ {
+ if ( hasRegisteredUnoPkgContainer( uri ) )
+ {
+ throw new com.sun.star.container.ElementExistException( "Already a registered uno package " + uri + " for language " + language );
+ }
+ LogUtils.DEBUG("processUnoPackage - URL = " + uri );
+ LogUtils.DEBUG("processUnoPackage - script library package");
+ String parentUrl = uri;
+
+
+ if ( uri.indexOf( "%2Funo_packages%2F" ) > -1 )
+ {
+ //its in a bundle need to determine the uno-package file its in
+ LogUtils.DEBUG("processUnoPackage - is part of a uno bundle");
+ int index = uri.lastIndexOf("/");
+ if ( index > -1 )
+ {
+ parentUrl = uri.substring( 0, index );
+ LogUtils.DEBUG("processUnoPackage - composition is contained in " + parentUrl);
+ }
+
+ ParcelContainer pkgContainer = getChildContainer( parentUrl );
+ if ( pkgContainer == null )
+ {
+ pkgContainer = new ParcelContainer( this, m_xCtx, parentUrl, language, false );
+ if ( pkgContainer.loadParcel( uri ) == null )
+ {
+ throw new com.sun.star.lang.IllegalArgumentException( "Couldn't load script library from composition package " + uri + " for language " + language );
+
+ }
+ addChildContainer( pkgContainer );
+ }
+ else
+ {
+ if ( pkgContainer.loadParcel( uri ) == null )
+ {
+ throw new com.sun.star.lang.IllegalArgumentException( "Couldn't load script library from composition package " + uri + " for language " + language );
+ }
+
+ }
+ registerPackageContainer( uri, pkgContainer );
+ }
+ else
+ {
+ // stand-alone library package, e.g. not contained in
+ // an uno package
+ if ( loadParcel( uri ) == null )
+ {
+ throw new com.sun.star.lang.IllegalArgumentException( "Couldn't load script library package " + uri + " for language " + language );
+ }
+ registerPackageContainer( uri, this );
+ }
+
+ }
+
+}
--
cgit