1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.script.framework.provider; 24 25 import com.sun.star.container.XNameContainer; 26 27 import com.sun.star.uno.Exception; 28 import com.sun.star.uno.XComponentContext; 29 import com.sun.star.lang.XMultiComponentFactory; 30 import com.sun.star.lang.XInitialization; 31 import com.sun.star.lang.XTypeProvider; 32 import com.sun.star.lang.XServiceInfo; 33 import com.sun.star.frame.XModel; 34 35 import com.sun.star.util.XMacroExpander; 36 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.AnyConverter; 39 import com.sun.star.uno.Type; 40 41 import com.sun.star.beans.XPropertySet; 42 import com.sun.star.beans.XVetoableChangeListener; 43 import com.sun.star.beans.XPropertyChangeListener; 44 import com.sun.star.beans.XPropertySetInfo; 45 import com.sun.star.beans.Property; 46 47 import com.sun.star.beans.XIntrospectionAccess; 48 import com.sun.star.script.XInvocation; 49 50 import com.sun.star.script.provider.XScriptContext; 51 import com.sun.star.script.provider.XScriptProvider; 52 import com.sun.star.script.provider.XScript; 53 import com.sun.star.script.provider.ScriptFrameworkErrorException; 54 import com.sun.star.script.provider.ScriptFrameworkErrorType; 55 56 import com.sun.star.script.browse.XBrowseNode; 57 import com.sun.star.script.browse.BrowseNodeTypes; 58 59 import com.sun.star.script.framework.log.LogUtils; 60 61 import com.sun.star.script.framework.container.ScriptMetaData; 62 import com.sun.star.script.framework.container.XMLParserFactory; 63 import com.sun.star.script.framework.container.ParcelContainer; 64 import com.sun.star.script.framework.container.ParsedScriptUri; 65 import com.sun.star.script.framework.container.UnoPkgContainer; 66 67 import com.sun.star.ucb.Command; 68 import com.sun.star.ucb.XContentProvider; 69 import com.sun.star.ucb.XContent; 70 import com.sun.star.ucb.XCommandProcessor; 71 import com.sun.star.ucb.XContentIdentifier; 72 import com.sun.star.ucb.XContentIdentifierFactory; 73 74 import com.sun.star.sdbc.XRow; 75 76 import com.sun.star.script.framework.browse.ProviderBrowseNode; 77 import com.sun.star.script.framework.browse.DialogFactory; 78 79 import com.sun.star.deployment.XPackage; 80 81 82 import com.sun.star.document.XScriptInvocationContext; 83 import com.sun.star.frame.XTransientDocumentsDocumentContentFactory; 84 import com.sun.star.uno.TypeClass; 85 86 public abstract class ScriptProvider 87 implements XScriptProvider, XBrowseNode, XPropertySet, XInvocation, 88 XInitialization, XTypeProvider, XServiceInfo, XNameContainer 89 { 90 private final String[] __serviceNames = { 91 "com.sun.star.script.provider.ScriptProviderFor", 92 "com.sun.star.script.provider.LanguageScriptProvider" 93 }; 94 95 public final static String CLASSPATH = "classpath"; 96 97 protected String language; 98 99 protected XComponentContext m_xContext; 100 protected XMultiComponentFactory m_xMultiComponentFactory; 101 protected XModel m_xModel; 102 protected XScriptInvocationContext m_xInvocContext; 103 protected ParcelContainer m_container; 104 105 // proxies to helper objects which implement interfaces 106 private XPropertySet m_xPropertySetProxy; 107 private XInvocation m_xInvocationProxy; 108 // TODO should this be implemented in this class 109 private XBrowseNode m_xBrowseNodeProxy; 110 private XScriptContext m_xScriptContext; 111 ScriptProvider( XComponentContext ctx, String language )112 public ScriptProvider( XComponentContext ctx, String language ) 113 { 114 this.language = language; 115 __serviceNames[0] += language; 116 117 LogUtils.DEBUG( "ScriptProvider: constructor - start. " + language ); 118 119 m_xContext = ctx; 120 121 // Initialize DialogFactory class in case dialogs are required 122 DialogFactory.createDialogFactory(m_xContext); 123 124 try 125 { 126 m_xMultiComponentFactory = m_xContext.getServiceManager(); 127 128 if ( m_xMultiComponentFactory == null ) 129 { 130 throw new Exception( "Error could not obtain a " + 131 "multicomponent factory - rethrowing Exception." ); 132 } 133 134 Object serviceObj = m_xContext.getValueByName( 135 "/singletons/com.sun.star.util.theMacroExpander"); 136 137 XMacroExpander me = (XMacroExpander) AnyConverter.toObject( 138 new Type(XMacroExpander.class), serviceObj); 139 140 XMLParserFactory.setOfficeDTDURL(me.expandMacros( 141 "${$OOO_BASE_DIR/program/bootstraprc::BaseInstallation}/share/dtd/officedocument/1_0/")); 142 143 } 144 catch ( Exception e ) 145 { 146 LogUtils.DEBUG( LogUtils.getTrace( e ) ); 147 throw new com.sun.star.uno.RuntimeException( 148 "Error constructing ScriptProvider: " 149 + e.getMessage() ); 150 } 151 152 LogUtils.DEBUG( "ScriptProvider: constructor - finished." ); 153 } 154 getScriptingContext()155 synchronized public XScriptContext getScriptingContext() 156 { 157 if ( m_xScriptContext == null ) 158 { 159 m_xScriptContext = ScriptContext.createContext( m_xModel, m_xInvocContext, m_xContext, m_xMultiComponentFactory ); 160 } 161 return m_xScriptContext; 162 } initialize( Object[] aArguments )163 public void initialize( Object[] aArguments ) 164 throws com.sun.star.uno.Exception 165 { 166 LogUtils.DEBUG( "entering XInit for language " + language); 167 boolean isPkgProvider = false; 168 if( aArguments.length == 1 ) 169 { 170 String contextUrl = null; 171 if ( AnyConverter.getType(aArguments[0]).getTypeClass().equals(TypeClass.INTERFACE) ) 172 { 173 // try whether it denotes a XScriptInvocationContext 174 m_xInvocContext = (XScriptInvocationContext)UnoRuntime.queryInterface( 175 XScriptInvocationContext.class, aArguments[0]); 176 if ( m_xInvocContext != null ) 177 { 178 // if so, obtain the document - by definition, this must be 179 // the ScriptContainer 180 m_xModel = (XModel)UnoRuntime.queryInterface( XModel.class, 181 m_xInvocContext.getScriptContainer() ); 182 } 183 else 184 { 185 // otherwise, check whether it's an XModel 186 m_xModel = (XModel)UnoRuntime.queryInterface( XModel.class, 187 m_xInvocContext.getScriptContainer() ); 188 } 189 if ( m_xModel == null ) 190 { 191 throw new com.sun.star.uno.Exception( 192 "ScriptProvider argument must be either a string, a valid XScriptInvocationContext, " + 193 "or an XModel", this); 194 } 195 196 contextUrl = getDocUrlFromModel( m_xModel ); 197 m_container = new ParcelContainer( m_xContext, contextUrl, language ); 198 } 199 else if (AnyConverter.isString(aArguments[0]) == true) 200 { 201 String originalContextURL = AnyConverter.toString(aArguments[0]); 202 LogUtils.DEBUG("creating Application, path: " + originalContextURL ); 203 contextUrl = originalContextURL; 204 // TODO no support for packages in documents yet 205 if ( originalContextURL.startsWith( "vnd.sun.star.tdoc" ) ) 206 { 207 m_container = new ParcelContainer( m_xContext, contextUrl, language ); 208 m_xModel = getModelFromDocUrl( originalContextURL ); 209 } 210 else 211 { 212 String extensionDb = null; 213 String extensionRepository = null; 214 if ( originalContextURL.startsWith( "bundled" ) ) 215 { 216 contextUrl = "vnd.sun.star.expand:$BUNDLED_EXTENSIONS"; 217 extensionDb = "vnd.sun.star.expand:${$OOO_BASE_DIR/program/" + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; 218 extensionRepository = "bundled"; 219 } 220 221 if ( originalContextURL.startsWith( "share" ) ) 222 { 223 contextUrl = "vnd.sun.star.expand:${$OOO_BASE_DIR/program/" + PathUtils.BOOTSTRAP_NAME + "::BaseInstallation}/share"; 224 extensionDb = "vnd.sun.star.expand:${$OOO_BASE_DIR/program/" + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; 225 extensionRepository = "shared"; 226 } 227 else if ( originalContextURL.startsWith( "user" ) ) 228 { 229 contextUrl = "vnd.sun.star.expand:${$OOO_BASE_DIR/program/" + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; 230 extensionDb = "vnd.sun.star.expand:${$OOO_BASE_DIR/program/" + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; 231 extensionRepository = "user"; 232 } 233 234 if ( originalContextURL.endsWith( "uno_packages") ) 235 { 236 isPkgProvider = true; 237 } 238 if ( originalContextURL.endsWith( "uno_packages") && !originalContextURL.equals( contextUrl ) 239 && !extensionRepository.equals("bundled")) 240 { 241 contextUrl = PathUtils.make_url( contextUrl, "uno_packages" ); 242 } 243 if ( isPkgProvider ) 244 { 245 m_container = new UnoPkgContainer( m_xContext, contextUrl, extensionDb, extensionRepository, language ); 246 } 247 else 248 { 249 m_container = new ParcelContainer( m_xContext, contextUrl, language ); 250 } 251 } 252 } 253 else 254 { 255 throw new com.sun.star.uno.RuntimeException( 256 "ScriptProvider created with invalid argument"); 257 } 258 259 LogUtils.DEBUG("Modified Application path is: " + contextUrl ); 260 LogUtils.DEBUG("isPkgProvider is: " + isPkgProvider ); 261 262 // TODO should all be done in this class instead of 263 // deleagation???? 264 m_xBrowseNodeProxy = new ProviderBrowseNode( this, 265 m_container, m_xContext ); 266 267 m_xInvocationProxy = (XInvocation)UnoRuntime.queryInterface(XInvocation.class, m_xBrowseNodeProxy); 268 m_xPropertySetProxy = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, m_xBrowseNodeProxy); 269 } 270 else 271 { 272 // this is ok, for example when executing a script from the 273 // command line 274 LogUtils.DEBUG( "ScriptProviderFor" + language + 275 " initialized without a context"); 276 } 277 LogUtils.DEBUG( "leaving XInit" ); 278 } 279 280 /** 281 * Gets the types attribute of the ScriptProvider object 282 * 283 * @return The types value 284 */ getTypes()285 public com.sun.star.uno.Type[] getTypes() 286 { 287 Type[] retValue = new Type[ 8 ]; 288 retValue[ 0 ] = new Type( XScriptProvider.class ); 289 retValue[ 1 ] = new Type( XBrowseNode.class ); 290 retValue[ 2 ] = new Type( XInitialization.class ); 291 retValue[ 3 ] = new Type( XTypeProvider.class ); 292 retValue[ 4 ] = new Type( XServiceInfo.class ); 293 retValue[ 5 ] = new Type( XPropertySet.class ); 294 retValue[ 6 ] = new Type( XInvocation.class ); 295 retValue[ 7 ] = new Type( com.sun.star.container.XNameContainer.class ); 296 return retValue; 297 } 298 299 /** 300 * Gets the implementationId attribute of the ScriptProvider object 301 * 302 * @return The implementationId value 303 */ getImplementationId()304 public byte[] getImplementationId() 305 { 306 return this.getClass().getName().getBytes(); 307 } 308 309 /** 310 * Gets the implementationName attribute of the ScriptProvider object 311 * 312 * @return The implementationName value 313 */ getImplementationName()314 public String getImplementationName() 315 { 316 return getClass().getName(); 317 } 318 319 /** 320 * Description of the Method 321 * 322 * @param serviceName Description of the Parameter 323 * @return Description of the Return Value 324 */ supportsService( String serviceName )325 public boolean supportsService( String serviceName ) 326 { 327 for ( int index = __serviceNames.length; index-- > 0; ) 328 { 329 if ( serviceName.equals( __serviceNames[ index ] ) ) 330 { 331 return true; 332 } 333 } 334 return false; 335 } 336 337 /** 338 * Gets the supportedServiceNames attribute of the ScriptProvider object 339 * 340 * @return The supportedServiceNames value 341 */ getSupportedServiceNames()342 public String[] getSupportedServiceNames() 343 { 344 return __serviceNames; 345 } 346 347 348 getScript( String scriptURI )349 public abstract XScript getScript( /*IN*/String scriptURI ) 350 throws com.sun.star.uno.RuntimeException, 351 ScriptFrameworkErrorException; 352 353 // TODO need to encapsulate this better, 354 // Some factory concept for creating/accessing Editor 355 // How this is passed down or how it is accessable by BrowseNode 356 // implementations needs thinking about 357 // This method is used to determine whether the ScriptProvider 358 // has a ScriptEditor hasScriptEditor()359 public abstract boolean hasScriptEditor(); 360 // TODO see above 361 // This method is used to get the ScriptEditor for this ScriptProvider getScriptEditor()362 public abstract ScriptEditor getScriptEditor(); 363 getScriptData( String scriptURI )364 public ScriptMetaData getScriptData( /*IN*/String scriptURI ) throws ScriptFrameworkErrorException 365 366 { 367 ParsedScriptUri details = null; 368 try 369 { 370 details = m_container.parseScriptUri( scriptURI ); 371 ScriptMetaData scriptData = m_container.findScript( details ); 372 if ( scriptData == null ) 373 { 374 throw new ScriptFrameworkErrorException( details.function + " does not exist", 375 null, details.function, language, ScriptFrameworkErrorType.NO_SUCH_SCRIPT ); 376 } 377 return scriptData; 378 } 379 catch ( com.sun.star.lang.IllegalArgumentException ila ) 380 { 381 // TODO specify the correct error Type 382 throw new ScriptFrameworkErrorException( ila.getMessage(), 383 null, scriptURI, language, ScriptFrameworkErrorType.UNKNOWN ); 384 } 385 catch ( com.sun.star.container.NoSuchElementException nse ) 386 { 387 throw new ScriptFrameworkErrorException( nse.getMessage(), 388 null, details.function, language, ScriptFrameworkErrorType.NO_SUCH_SCRIPT ); 389 } 390 catch ( com.sun.star.lang.WrappedTargetException wta ) 391 { 392 // TODO specify the correct error Type 393 Exception wrapped = (Exception)wta.TargetException; 394 String message = wta.getMessage(); 395 if ( wrapped != null ) 396 { 397 message = wrapped.getMessage(); 398 } 399 throw new ScriptFrameworkErrorException( message, 400 null, details.function, language, ScriptFrameworkErrorType.UNKNOWN ); 401 } 402 403 } 404 405 406 // Implementation of XBrowseNode interface getName()407 public String getName() 408 { 409 return language; 410 } 411 getChildNodes()412 public XBrowseNode[] getChildNodes() 413 { 414 if ( m_xBrowseNodeProxy == null ) 415 { 416 LogUtils.DEBUG("No Nodes available "); 417 return new XBrowseNode[0]; 418 } 419 return m_xBrowseNodeProxy .getChildNodes(); 420 } 421 hasChildNodes()422 public boolean hasChildNodes() 423 { 424 if ( m_xBrowseNodeProxy == null ) 425 { 426 LogUtils.DEBUG("No Nodes available "); 427 return false; 428 } 429 return m_xBrowseNodeProxy.hasChildNodes(); 430 } 431 getType()432 public short getType() 433 { 434 return BrowseNodeTypes.CONTAINER; 435 } 436 toString()437 public String toString() 438 { 439 return getName(); 440 } 441 442 // implementation of XInvocation interface getIntrospection()443 public XIntrospectionAccess getIntrospection() { 444 return m_xInvocationProxy.getIntrospection(); 445 } 446 invoke(String aFunctionName, Object[] aParams, short[][] aOutParamIndex, Object[][] aOutParam)447 public Object invoke(String aFunctionName, Object[] aParams, 448 short[][] aOutParamIndex, Object[][] aOutParam) 449 throws com.sun.star.lang.IllegalArgumentException, 450 com.sun.star.script.CannotConvertException, 451 com.sun.star.reflection.InvocationTargetException 452 { 453 return m_xInvocationProxy.invoke( 454 aFunctionName, aParams, aOutParamIndex, aOutParam); 455 } 456 setValue(String aPropertyName, Object aValue)457 public void setValue(String aPropertyName, Object aValue) 458 throws com.sun.star.beans.UnknownPropertyException, 459 com.sun.star.script.CannotConvertException, 460 com.sun.star.reflection.InvocationTargetException 461 { 462 m_xInvocationProxy.setValue(aPropertyName, aValue); 463 } 464 getValue(String aPropertyName)465 public Object getValue(String aPropertyName) 466 throws com.sun.star.beans.UnknownPropertyException 467 { 468 return m_xInvocationProxy.getValue(aPropertyName); 469 } 470 hasMethod(String aName)471 public boolean hasMethod(String aName) { 472 return m_xInvocationProxy.hasMethod(aName); 473 } 474 hasProperty(String aName)475 public boolean hasProperty(String aName) { 476 return m_xInvocationProxy.hasProperty(aName); 477 } 478 getPropertySetInfo()479 public XPropertySetInfo getPropertySetInfo() 480 { 481 return m_xPropertySetProxy.getPropertySetInfo(); 482 } 483 setPropertyValue(String aPropertyName, Object aValue)484 public void setPropertyValue(String aPropertyName, Object aValue) 485 throws com.sun.star.beans.UnknownPropertyException, 486 com.sun.star.beans.PropertyVetoException, 487 com.sun.star.lang.IllegalArgumentException, 488 com.sun.star.lang.WrappedTargetException 489 { 490 m_xPropertySetProxy.setPropertyValue(aPropertyName, aValue); 491 } 492 getPropertyValue(String PropertyName)493 public Object getPropertyValue(String PropertyName) 494 throws com.sun.star.beans.UnknownPropertyException, 495 com.sun.star.lang.WrappedTargetException 496 { 497 return m_xPropertySetProxy.getPropertyValue(PropertyName); 498 } 499 addPropertyChangeListener( String aPropertyName, XPropertyChangeListener xListener)500 public void addPropertyChangeListener( 501 String aPropertyName, XPropertyChangeListener xListener) 502 throws com.sun.star.beans.UnknownPropertyException, 503 com.sun.star.lang.WrappedTargetException 504 { 505 m_xPropertySetProxy.addPropertyChangeListener(aPropertyName, xListener); 506 } 507 removePropertyChangeListener( String aPropertyName, XPropertyChangeListener aListener)508 public void removePropertyChangeListener( 509 String aPropertyName, XPropertyChangeListener aListener) 510 throws com.sun.star.beans.UnknownPropertyException, 511 com.sun.star.lang.WrappedTargetException 512 { 513 m_xPropertySetProxy.removePropertyChangeListener( 514 aPropertyName, aListener); 515 } 516 addVetoableChangeListener( String PropertyName, XVetoableChangeListener aListener)517 public void addVetoableChangeListener( 518 String PropertyName, XVetoableChangeListener aListener) 519 throws com.sun.star.beans.UnknownPropertyException, 520 com.sun.star.lang.WrappedTargetException 521 { 522 m_xPropertySetProxy.addVetoableChangeListener(PropertyName, aListener); 523 } 524 removeVetoableChangeListener( String PropertyName, XVetoableChangeListener aListener)525 public void removeVetoableChangeListener( 526 String PropertyName, XVetoableChangeListener aListener) 527 throws com.sun.star.beans.UnknownPropertyException, 528 com.sun.star.lang.WrappedTargetException 529 { 530 m_xPropertySetProxy.removeVetoableChangeListener( 531 PropertyName, aListener); 532 } getByName( String aName )533 public java.lang.Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException 534 { 535 // TODO needs implementing? 536 if ( true ) 537 { 538 throw new com.sun.star.uno.RuntimeException( 539 "getByName not implemented" ); 540 } 541 return new Object(); 542 } 543 getElementNames()544 public String[] getElementNames() 545 { 546 // TODO needs implementing? 547 String[] result = new String[0]; 548 if ( true ) 549 { 550 throw new com.sun.star.uno.RuntimeException( 551 "getElementNames not implemented" ); 552 553 } 554 return result; 555 } 556 557 558 // Performs the getRegStatus functionality for the PkgMgr hasByName( String aName )559 public boolean hasByName( String aName ) 560 { 561 boolean result = false; 562 if ( ((UnoPkgContainer)m_container).hasRegisteredUnoPkgContainer( aName ) ) 563 { 564 result = true; 565 } 566 return result; 567 } 568 getElementType()569 public com.sun.star.uno.Type getElementType() 570 { 571 // TODO at the moment this returns void indicating 572 // type is unknown should indicate XPackage ? do we implement XPackage 573 return new Type(); 574 } 575 hasElements()576 public boolean hasElements() 577 { 578 // TODO needs implementing? 579 boolean result = false; 580 if ( true ) 581 { 582 throw new com.sun.star.uno.RuntimeException( 583 "hasElements not implemented" ); 584 585 } 586 return result; 587 } replaceByName( String aName, java.lang.Object aElement )588 public void replaceByName( String aName, java.lang.Object aElement ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException 589 { 590 // TODO needs implementing 591 if ( true ) 592 { 593 throw new com.sun.star.uno.RuntimeException( 594 "replaceByName not implemented" ); 595 596 } 597 } 598 insertByName( String aName, java.lang.Object aElement )599 public void insertByName( String aName, java.lang.Object aElement ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.ElementExistException, com.sun.star.lang.WrappedTargetException 600 { 601 LogUtils.DEBUG("Provider for " + language + " received register for package " + aName ); 602 XPackage newPackage = ( XPackage ) UnoRuntime.queryInterface( XPackage.class, aElement ); 603 if ( aName.length() == 0 ) 604 { 605 throw new com.sun.star.lang.IllegalArgumentException( "Empty name" ); 606 } 607 if ( newPackage == null ) 608 { 609 throw new com.sun.star.lang.IllegalArgumentException( "No package supplied" ); 610 } 611 612 ((UnoPkgContainer)m_container).processUnoPackage( newPackage, language ); 613 } 614 615 // de-register for library only !! removeByName( String Name )616 public void removeByName( String Name ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException 617 { 618 LogUtils.DEBUG("In ScriptProvider.removeByName() for " + Name + " this provider = " + language ); 619 ParcelContainer c = ((UnoPkgContainer)m_container).getRegisteredUnoPkgContainer( Name ); 620 if ( c != null ) 621 { 622 String libName; 623 if (Name.endsWith("/")) 624 { 625 String tmp = Name.substring( 0, Name.lastIndexOf( "/" ) ); 626 libName = tmp.substring( tmp.lastIndexOf( "/" ) + 1 ); 627 } 628 else 629 { 630 libName = Name.substring( Name.lastIndexOf( "/" ) + 1 ); 631 } 632 LogUtils.DEBUG("Deregistering library " + libName ); 633 if ( c.removeParcel( libName ) ) 634 { 635 ((UnoPkgContainer)m_container).deRegisterPackageContainer( Name ); 636 } 637 else 638 { 639 throw new com.sun.star.container.NoSuchElementException( libName + " cannot be removed from container." ); 640 } 641 } 642 else 643 { 644 throw new com.sun.star.container.NoSuchElementException( Name + " doesn't exist for " + language ); 645 } 646 // TODO see if we want to remove the ParcelContainer is no Parcels/Libraries left 647 } 648 getDocUrlFromModel( XModel document )649 private String getDocUrlFromModel( XModel document ) 650 { 651 XTransientDocumentsDocumentContentFactory factory = null; 652 try 653 { 654 factory = (XTransientDocumentsDocumentContentFactory)UnoRuntime.queryInterface( 655 XTransientDocumentsDocumentContentFactory.class, 656 m_xMultiComponentFactory.createInstanceWithContext( 657 "com.sun.star.frame.TransientDocumentsDocumentContentFactory", 658 m_xContext 659 ) 660 ); 661 } 662 catch (Exception ex) 663 { 664 } 665 666 if ( factory == null ) 667 throw new com.sun.star.uno.RuntimeException( "ScriptProvider: unable to create a TDOC context factory.", this ); 668 669 try 670 { 671 XContent content = factory.createDocumentContent( document ); 672 return content.getIdentifier().getContentIdentifier(); 673 } 674 catch( Exception ex ) 675 { 676 } 677 678 LogUtils.DEBUG("unable to determine the model's TDOC URL"); 679 return ""; 680 } 681 getModelFromDocUrl( String docUrl )682 private XModel getModelFromDocUrl( String docUrl ) 683 { 684 LogUtils.DEBUG("getModelFromDocUrl - searching for match for ->" + docUrl + "<-" ); 685 XModel xModel = null; 686 try 687 { 688 Object[] args = new String[] {"Local", "Office" }; 689 690 Object ucb = m_xMultiComponentFactory.createInstanceWithArgumentsAndContext( "com.sun.star.ucb.UniversalContentBroker", args, m_xContext ); 691 692 693 XContentIdentifierFactory xFac = ( XContentIdentifierFactory ) 694 UnoRuntime.queryInterface( XContentIdentifierFactory.class, 695 ucb ); 696 697 698 XContentIdentifier xCntId = xFac.createContentIdentifier( docUrl ); 699 700 701 XContentProvider xCntAccess = ( XContentProvider ) 702 UnoRuntime.queryInterface( XContentProvider.class, 703 ucb ); 704 705 706 XContent xCnt = xCntAccess.queryContent( xCntId ); 707 708 709 XCommandProcessor xCmd = ( XCommandProcessor ) 710 UnoRuntime.queryInterface( XCommandProcessor.class, xCnt ); 711 712 713 Property[] pArgs = new Property[ ] { new Property() }; 714 pArgs[ 0 ].Name = "DocumentModel"; 715 pArgs[ 0 ].Handle = -1; 716 717 Command command = new Command(); 718 719 command.Handle = -1; 720 command.Name = "getPropertyValues"; 721 command.Argument = pArgs; 722 723 com.sun.star.ucb.XCommandEnvironment env = null ; 724 Object result = xCmd.execute( command, 0, env ) ; 725 726 XRow values = ( XRow ) UnoRuntime.queryInterface( XRow.class, 727 result ); 728 729 xModel = ( XModel ) UnoRuntime.queryInterface( XModel.class, 730 values.getObject( 1, null ) ); 731 } 732 catch ( Exception ignore ) 733 { 734 LogUtils.DEBUG("Failed to get model exception " + ignore ); 735 736 } 737 return xModel; 738 } 739 740 741 } 742