List Info

Thread: How to get the Version?




How to get the Version?
user name
2007-02-27 20:48:50
Hello
I have switched to oo-2 and find that the package deployer
pushes
deployed files one level deeper than was the case for oo-1.
Since I use
an XCS/XCU setup to locate out suites of custom macros, I
need to know
the version (1 or 2) in spite of 'masterly advice'. In the
spirit of the
Pitonyak OO-Basic version getter, I offer this subset of my
helper class
(don't know how to make snippets):
==
public final class NxCallHelper {
  private XComponentContext       myContext = null;
  private XMultiComponentFactory  myServiceManager = null;
  private String                  myOVer = null;

  // == primed from successful access to OO via normal
means
  public NxCallHelper(XMultiComponentFactory
xServiceManager,
XComponentContext xContext) {
    myContext = xContext;
    myServiceManager = xServiceManager;
  }

  // == used in many other places in this helper
  public XInterface accessConfig(String sConfigPath) throws
Exception {
    XInterface xInt = null;
    // creation arguments: nodepath
    com.sun.star.beans.PropertyValue aPathArg = new
com.sun.star.beans.PropertyValue();
    aPathArg.Name = "nodepath";
    aPathArg.Value = sConfigPath;
    Object[] aArgs = new Object[] ;
    // get ro access
    xInt =
(XInterface)createConfigProvider().createInstanceWithArgumen
ts("com.sun.
star.configuration.ConfigurationAccess", aArgs);

    if (xInt == null) {
      throw new java.lang.InstantiationError("failed to
accessCfg");
    }
    return xInt;
  }

  // == get version
  public String officeVersion() {
    if (myOVer == null) {
      String sVersion = "??";
      try {
        XInterface xInt =
accessConfig("/org.openoffice.Setup/Product");
        XNameAccess xAccess =
(XNameAccess)UnoRuntime.queryInterface(XNameAccess.class,
xInt);
        boolean bVer =
xAccess.hasByName("ooSetupVersion");
        if (bVer) {
          Object obj =
xAccess.getByName("ooSetupVersion");
          if (obj instanceof String) {
            sVersion = (String)obj;
          }
        }
      }
      catch(Exception e) {
        // nada
      }
      finally {
        myOVer = sVersion;
      }
    }
    return myOVer;
  }

  // == used to provide the XCU key for oo-1 or oo-2
  public String getMacroUrlKey() throws Exception {
    switch(officeVersion().charAt(0)) {
      case '1':
        return "OoMacroLibsVer1/Url";
      case '2':
        return "OoMacroLibsVer2/Url";
      default:
        throw new java.lang.InstantiationError("failed
to determine
office version");
    }
  }
} //endclass

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )