Ejemplo n.º 1
0
  public static XMultiServiceFactory connect(String sConnectStr)
      throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException, Exception {
    // Get component context
    XComponentContext xComponentContext =
        com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);

    // initial serviceManager
    XMultiComponentFactory xLocalServiceManager = xComponentContext.getServiceManager();

    // create a connector, so that it can contact the office
    Object oUrlResolver =
        xLocalServiceManager.createInstanceWithContext(
            "com.sun.star.bridge.UnoUrlResolver", xComponentContext);
    XUnoUrlResolver xUrlResolver = UnoRuntime.queryInterface(XUnoUrlResolver.class, oUrlResolver);

    Object oInitialObject = xUrlResolver.resolve(sConnectStr);
    XNamingService xName = UnoRuntime.queryInterface(XNamingService.class, oInitialObject);

    XMultiServiceFactory xMSF = null;
    if (xName != null) {
      System.err.println("got the remote naming service !");
      Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager");

      xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, oMSF);
    } else System.out.println("Error: Can't get XNamingService interface from url resolver!");

    return xMSF;
  }
  /** Create a new <code>ConfigurationDialogBase</code> */
  public ConfigurationDialogBase(XComponentContext xContext) {
    this.xContext = xContext;

    // Get the file picker
    filePicker = new FilePicker(xContext);

    // Get the SimpleFileAccess service
    try {
      Object sfaObject =
          xContext
              .getServiceManager()
              .createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", xContext);
      sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject);
    } catch (com.sun.star.uno.Exception e) {
      // failed to get SimpleFileAccess service (should not happen)
    }

    // Create the config file name
    try {
      Object psObject =
          xContext
              .getServiceManager()
              .createInstanceWithContext("com.sun.star.util.PathSubstitution", xContext);
      xPathSub =
          (XStringSubstitution) UnoRuntime.queryInterface(XStringSubstitution.class, psObject);
      sConfigFileName = xPathSub.substituteVariables("$(user)/" + getConfigFileName(), false);
    } catch (com.sun.star.uno.Exception e) {
      // failed to get PathSubstitution service (should not happen)
    }

    // Create the configuration
    config = ConverterFactory.createConverter(getMIMEType()).getConfig();
  }
Ejemplo n.º 3
0
 public Facade() {
   try {
     XComponentContext xContext = Bootstrap.bootstrap();
     _xMCF = xContext.getServiceManager();
     _loader =
         query(XComponentLoader.class, _xMCF.createInstanceWithContext(X_DESKTOP, _xContext));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 4
0
  // converts an ODT document into a PDF file
  public void convert(OOoInputStream input, OOoOutputStream output, String filterName)
      throws Exception {
    XMultiComponentFactory xMultiComponentFactory = xComponentContext.getServiceManager();
    Object desktopService =
        xMultiComponentFactory.createInstanceWithContext(
            "com.sun.star.frame.Desktop", xComponentContext);
    XComponentLoader xComponentLoader =
        (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktopService);

    PropertyValue[] conversionProperties = new PropertyValue[2];
    conversionProperties[0] = new PropertyValue();
    conversionProperties[1] = new PropertyValue();

    conversionProperties[0].Name = "InputStream";
    conversionProperties[0].Value = input;
    conversionProperties[1].Name = "Hidden";
    conversionProperties[1].Value = true;

    XComponent document =
        xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0, conversionProperties);

    conversionProperties[0].Name = "OutputStream";
    conversionProperties[0].Value = output;
    conversionProperties[1].Name = "FilterName";
    conversionProperties[1].Value = filterName;

    XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
    xstorable.storeToURL("private:stream", conversionProperties);

    XCloseable xclosable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document);
    xclosable.close(true);
  }
Ejemplo n.º 5
0
 @Before
 public void before() throws Exception {
   m_xContext = connection.getComponentContext();
   assertNotNull("could not get component context.", m_xContext);
   m_xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xContext.getServiceManager());
   m_xGEB = theGlobalEventBroadcaster.get(m_xContext);
   m_TmpDir = util.utils.getOfficeTemp /*Dir*/(m_xMSF);
   System.out.println("tempdir: " + m_TmpDir);
   System.out.println("sourcedir: " + m_SourceDir);
   System.out.println("targetdir: " + m_TargetDir);
 }
  public static void main(String args[]) {
    try {
      HashMap<String, Object> table = new HashMap<String, Object>();
      table.put("bla1", new ComponentContextEntry(null, new Integer(1)));
      XComponentContext xInitialContext = Bootstrap.createInitialComponentContext(table);

      table = new HashMap<String, Object>();
      table.put("bla2", new ComponentContextEntry(new Integer(2)));
      table.put("bla3", new Integer(3));
      XComponentContext xContext = new ComponentContext(table, xInitialContext);

      XMultiComponentFactory xSMgr = xContext.getServiceManager();
      Object o = xSMgr.createInstanceWithContext("com.sun.star.loader.Java", xContext);
      if (o == null) System.err.println("### failed raising service: 1!");
      o = xSMgr.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", xContext);
      if (o == null) System.err.println("### failed raising service: 2!");
      o = xSMgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xContext);
      if (o == null) System.err.println("### failed raising service: 3!");
      o = xSMgr.createInstanceWithContext("com.sun.star.connection.Connector", xContext);
      if (o == null) System.err.println("### failed raising service: 4!");
      o = xSMgr.createInstanceWithContext("com.sun.star.connection.Acceptor", xContext);
      if (o == null) System.err.println("### failed raising service: 5!");
      o = xSMgr.createInstanceWithContext("com.sun.star.lang.ServiceManager", xContext);
      if (o == null) System.err.println("### failed raising service: 6!");

      if (xContext.getValueByName("bla1") == null
          || xContext.getValueByName("bla2") == null
          || xContext.getValueByName("bla3") == null
          || xInitialContext.getValueByName("bla2") != null
          || xInitialContext.getValueByName("bla3") != null) {
        System.err.println("### bootstrap context test failed: 1!");
      }
      if (((Integer) xContext.getValueByName("bla1")).intValue() != 1
          || ((Integer) xContext.getValueByName("bla2")).intValue() != 2
          || ((Integer) xContext.getValueByName("bla3")).intValue() != 3
          || ((Integer) xInitialContext.getValueByName("bla1")).intValue() != 1) {
        System.err.println("### bootstrap context test failed: 2!");
      }

      XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xInitialContext);
      xComp.dispose();
    } catch (Exception exception) {
      System.err.println("exception occurred:" + exception);
      exception.printStackTrace();
    }
  }
Ejemplo n.º 7
0
  private void init(int posX, int posY, int height, int width, String title, String name)
      throws Exception {

    xMultiComponentFactory = xComponentContext.getServiceManager();

    Object oDialogModel =
        xMultiComponentFactory.createInstanceWithContext(
            "com.sun.star.awt.UnoControlDialogModel", xComponentContext);

    // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls...
    xMultiComponentFactoryDialogModel =
        (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel);

    // The named container is used to insert the created controls into...
    xDialogModelNameContainer =
        (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel);

    // create the dialog...
    Object oUnoDialog =
        xMultiComponentFactory.createInstanceWithContext(
            "com.sun.star.awt.UnoControlDialog", xComponentContext);
    xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog);

    // The scope of the control container is public...
    xDialogContainer =
        (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog);

    // link the dialog and its model...
    XControlModel xControlModel =
        (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel);
    xDialogControl.setModel(xControlModel);

    // Create a unique name
    String uniqueName =
        createUniqueName(xDialogModelNameContainer, (name != null) ? name : "LiboDialog");

    // Define the dialog at the model
    XPropertySet xDialogPropertySet =
        (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xDialogModelNameContainer);
    xDialogPropertySet.setPropertyValue("PositionX", new Integer(posX));
    xDialogPropertySet.setPropertyValue("PositionY", new Integer(posY));
    xDialogPropertySet.setPropertyValue("Height", new Integer(height));
    xDialogPropertySet.setPropertyValue("Width", new Integer(width));
    xDialogPropertySet.setPropertyValue(
        "Title", (title != null) ? title : "LibreOffice.org Dialog");
    xDialogPropertySet.setPropertyValue("Name", uniqueName);
    xDialogPropertySet.setPropertyValue("Moveable", Boolean.TRUE);
    xDialogPropertySet.setPropertyValue("TabIndex", new Short((short) 0));
  }
Ejemplo n.º 8
0
  public static void dispatchCommand(String command) throws java.lang.Exception {

    com.sun.star.frame.XFrame xFrame = SpeechOO.m_xFrame.getController().getFrame();
    lParams[0] = new com.sun.star.beans.PropertyValue();
    lParams[0].Name = "nodepath";
    lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";
    xRemoteContext =
        (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, SpeechOO.m_xContext);
    xRemoteServiceManager = xRemoteContext.getServiceManager();
    Object transformer =
        xRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.util.URLTransformer", xRemoteContext);
    xTransformer =
        (com.sun.star.util.XURLTransformer)
            UnoRuntime.queryInterface(com.sun.star.util.XURLTransformer.class, transformer);
    XDispatchProvider xDispatchProvider =
        (com.sun.star.frame.XDispatchProvider)
            UnoRuntime.queryInterface(com.sun.star.frame.XDispatchProvider.class, xFrame);
    com.sun.star.util.URL[] aURL = new com.sun.star.util.URL[1];
    aURL[0] = new com.sun.star.util.URL();
    com.sun.star.frame.XDispatch xDispatch = null;
    aURL[0].Complete = command;
    xTransformer.parseSmart(aURL, ".uno");
    xDispatch = xDispatchProvider.queryDispatch(aURL[0], "", 0);
    com.sun.star.frame.XNotifyingDispatch xNotifyingDispatcher =
        (com.sun.star.frame.XNotifyingDispatch)
            UnoRuntime.queryInterface(com.sun.star.frame.XNotifyingDispatch.class, xDispatch);
    if (xDispatch != null) {
      xNotifyingDispatcher.dispatchWithNotification(
          aURL[0],
          lParams,
          new XDispatchResultListener() {

            public void dispatchFinished(DispatchResultEvent arg0) {
              System.out.println(arg0);
              throw new UnsupportedOperationException("Not supported yet.");
            }

            public void disposing(EventObject eo) {
              throw new UnsupportedOperationException("Not supported yet.");
            }
          });
    }
    // SpeechOO.m_xFrame.setComponent(null, null);
  }
  ScriptImpl(
      XComponentContext ctx,
      ScriptMetaData metaData,
      XModel xModel,
      XScriptInvocationContext xContext)
      throws com.sun.star.uno.RuntimeException {
    this.metaData = metaData;
    this.m_xContext = ctx;
    this.m_xModel = xModel;
    this.m_xInvocContext = xContext;

    try {
      this.m_xMultiComponentFactory = m_xContext.getServiceManager();
    } catch (Exception e) {
      LogUtils.DEBUG(LogUtils.getTrace(e));
      throw new com.sun.star.uno.RuntimeException(
          "Error constructing  ScriptImpl [beanshell]: " + e.getMessage());
    }

    LogUtils.DEBUG("ScriptImpl [beanshell] script data = " + metaData);
  }
 public LoggerConfigurationAccess(XComponentContext _xContext) {
   // cannot use logger, called before instantiating the logger
   m_xContext = _xContext;
   m_xServiceManager = m_xContext.getServiceManager();
   getProvider();
 }
Ejemplo n.º 11
0
 /** Creates a new instance of UnoNode */
 public UnoNode(Object _oUnoObject) {
   m_xComponentContext = Introspector.getIntrospector().getXComponentContext();
   m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
   m_oUnoObject = _oUnoObject;
 }
Ejemplo n.º 12
0
 public MessageBox(XComponentContext _xContext) {
   this.m_xMCF = _xContext.getServiceManager();
   this.m_xContext = _xContext;
 }
Ejemplo n.º 13
0
  public void drawOrganigram() throws java.lang.Exception {
    // get the remote office component context
    xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
    System.out.println("Connected to a running office ...");
    // get the remote service manager
    xRemoteServiceManager = xRemoteContext.getServiceManager();

    Object desktop =
        xRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", xRemoteContext);
    XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop);

    PropertyValue[] loadProps = new PropertyValue[0];
    XComponent xDrawComponent =
        xComponentLoader.loadComponentFromURL("private:factory/sdraw", "_blank", 0, loadProps);

    // get draw page by index
    com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent);
    com.sun.star.drawing.XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
    Object drawPage = xDrawPages.getByIndex(0);
    com.sun.star.drawing.XDrawPage xDrawPage =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, drawPage);

    com.sun.star.lang.XMultiServiceFactory xDocumentFactory =
        UnoRuntime.queryInterface(com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent);

    com.sun.star.beans.XPropertySet xPageProps =
        UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xDrawPage);

    int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width"));
    int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height"));
    int pageBorderTop = AnyConverter.toInt(xPageProps.getPropertyValue("BorderTop"));
    int pageBorderLeft = AnyConverter.toInt(xPageProps.getPropertyValue("BorderLeft"));
    int pageBorderRight = AnyConverter.toInt(xPageProps.getPropertyValue("BorderRight"));
    int drawWidth = pageWidth - pageBorderLeft - pageBorderRight;
    int horCenter = pageBorderLeft + drawWidth / 2;

    String[][] orgUnits = new String[2][4];
    orgUnits[0][0] = "Management";
    orgUnits[1][0] = "Production";
    orgUnits[1][1] = "Purchasing";
    orgUnits[1][2] = "IT Services";
    orgUnits[1][3] = "Sales";
    int[] levelCount = {1, 4};

    int horSpace = 300;
    int verSpace = 3000;

    int shapeWidth = (drawWidth - (levelCount[1] - 1) * horSpace) / levelCount[1];
    int shapeHeight = pageHeight / 20;
    int shapeX = pageWidth / 2 - shapeWidth / 2;
    int shapeY = pageBorderTop;

    int levelY;
    int levelX;

    com.sun.star.drawing.XShape xStartShape = null;

    for (int level = 0; level <= 1; level++) {
      levelY = pageBorderTop + 2000 + level * (shapeHeight + verSpace);
      for (int i = levelCount[level] - 1; i > -1; i--) {
        shapeX =
            horCenter
                - (levelCount[level] * shapeWidth + (levelCount[level] - 1) * horSpace) / 2
                + i * shapeWidth
                + i * horSpace;
        Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape");
        com.sun.star.drawing.XShape xShape =
            UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, shape);
        xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY));
        xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight));
        xDrawPage.add(xShape);

        com.sun.star.text.XText xText =
            UnoRuntime.queryInterface(com.sun.star.text.XText.class, xShape);

        xText.setString(orgUnits[level][i]);

        // memorize the root shape
        if (level == 0 && i == 0) xStartShape = xShape;

        if (level == 1) {
          Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape");
          com.sun.star.beans.XPropertySet xConnectorProps =
              UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, connector);
          com.sun.star.drawing.XShape xConnector =
              UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, connector);
          xDrawPage.add(xConnector);
          xConnectorProps.setPropertyValue("StartShape", xStartShape);
          xConnectorProps.setPropertyValue("EndShape", xShape);
          xConnectorProps.setPropertyValue(
              "StartGluePointIndex", new Integer(2)); // 2 = bottom glue point
          xConnectorProps.setPropertyValue(
              "EndGluePointIndex", new Integer(0)); // 0 = top glue point
        }
      }
    }
  }
Ejemplo n.º 14
0
  public static void main(String args[]) {
    if (args.length < 3) {
      System.out.println(
          "usage: java -jar DocumentLoader.jar "
              + "\"<Favoured printer>\" \"<URL|path>\" \"<Pages>\"");
      System.out.println("\ne.g.:");
      System.out.println(
          "java -jar DocumentLoader.jar \"amadeus\" " + "\"file:///f:/TestPrint.odt\" \"1-3;7;9\"");
      System.exit(1);
    }

    com.sun.star.uno.XComponentContext xContext = null;

    try {
      // get the remote office component context
      xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
      System.out.println("Connected to a running office ...");

      // get the remote office service manager
      com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();

      Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);

      com.sun.star.frame.XComponentLoader xCompLoader =
          UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, oDesktop);

      java.io.File sourceFile = new java.io.File(args[1]);
      StringBuffer sUrl = new StringBuffer("file:///");
      sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));

      // Load a Writer document, which will be automatically displayed
      com.sun.star.lang.XComponent xComp =
          xCompLoader.loadComponentFromURL(
              sUrl.toString(), "_blank", 0, new com.sun.star.beans.PropertyValue[0]);

      // Querying for the interface XPrintable on the loaded document
      com.sun.star.view.XPrintable xPrintable =
          UnoRuntime.queryInterface(com.sun.star.view.XPrintable.class, xComp);

      // Setting the property "Name" for the favoured printer (name of
      // IP address)
      com.sun.star.beans.PropertyValue propertyValue[] = new com.sun.star.beans.PropertyValue[1];
      propertyValue[0] = new com.sun.star.beans.PropertyValue();
      propertyValue[0].Name = "Name";
      propertyValue[0].Value = args[0];

      // Setting the name of the printer
      xPrintable.setPrinter(propertyValue);

      // Setting the property "Pages" so that only the desired pages
      // will be printed.
      propertyValue[0] = new com.sun.star.beans.PropertyValue();
      propertyValue[0].Name = "Pages";
      propertyValue[0].Value = args[2];

      // Printing the loaded document
      xPrintable.print(propertyValue);

      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace(System.err);
      System.exit(1);
    }
  }
Ejemplo n.º 15
0
  public static void main(String args[]) {
    UnoMenu2 oUnoMenu2 = null;
    try {
      XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
      if (xContext != null) System.out.println("Connected to a running office ...");
      XMultiComponentFactory xMCF = xContext.getServiceManager();
      oUnoMenu2 = new UnoMenu2(xContext, xMCF);
      oUnoMenu2.initialize(
          new String[] {
            "Height",
            "Moveable",
            "Name",
            "PositionX",
            "PositionY",
            "Step",
            "TabIndex",
            "Title",
            "Width"
          },
          new Object[] {
            Integer.valueOf(140),
            Boolean.TRUE,
            "Dialog1",
            Integer.valueOf(102),
            Integer.valueOf(41),
            Integer.valueOf(1),
            Short.valueOf((short) 0),
            "Menu-Dialog",
            Integer.valueOf(200)
          });

      Object oFTHeaderModel =
          oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
      XMultiPropertySet xFTHeaderModelMPSet =
          UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel);
      xFTHeaderModelMPSet.setPropertyValues(
          new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
          new Object[] {
            Integer.valueOf(8),
            "This code-sample demonstrates the creation of a popup-menu",
            "HeaderLabel",
            Integer.valueOf(6),
            Integer.valueOf(6),
            Integer.valueOf(200)
          });
      // add the model to the NameContainer of the dialog model
      oUnoMenu2.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel);
      oUnoMenu2.addLabelForPopupMenu();
      oUnoMenu2.executeDialog();
    } catch (Exception ex) {
      ex.printStackTrace(System.err);
    } finally {
      // make sure always to dispose the component and free the memory!
      if (oUnoMenu2 != null) {
        if (oUnoMenu2.m_xComponent != null) {
          oUnoMenu2.m_xComponent.dispose();
        }
      }
      System.exit(0);
    }
  }