incubator-ooo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rony G. Flatscher (Apache)" <r...@apache.org>
Subject Re: a question of Export custom file format?
Date Thu, 07 Jun 2012 17:24:09 GMT

On 07.06.2012 18:02, Oliver Brinzing wrote:
> Hi,
>
>> I write a extention.
>> In my  extention how can I get openoffice program path.
> Sub Test
> 	Dim oService as Object
> 	oService = CreateUnoService("com.sun.star.util.PathSubstitution")
> 	' see http://www.openoffice.org/api/docs/common/ref/com/sun/star/util/PathSubstitution.html
for details
> 	MsgBox oService.getSubstituteVariableValue("inst")
>
> 	' get your Extension Path
> 	' http://www.openoffice.org/api/docs/common/ref/com/sun/star/deployment/PackageInformationProvider.html
> 	oService =
> getDefaultContext().getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
> 	MsgBox oService. getPackageLocation("my.extension.identifier")
> End Sub
>
>
> Regards
>
> Oliver
>

Here is an example (ooRexx, "listPathSettings.rxo") which lists all path settings available
in AOO
to .stdout:

    xContext = UNO.connect()            -- connect to server and retrieve the XContext object
    XMcf = xContext~getServiceManager   -- retrieve XMultiComponentFactory
    oPathSettings=XMcf~createInstanceWithContext("com.sun.star.util.PathSettings", xContext)
    xpaths=oPathSettings~XPropertySet   -- get XPropertySet interface
    paths=xpaths~getPropertySetInfo~getProperties   -- get the sequence of properties

    do i=1 to paths~items               -- iterate over all properties (all path names)
       name=paths[i]~name               -- get the Property's name
       call printPathSetting i, name, xpaths~getPropertyValue(name) -- display on .stdout
    end

    -- end of program, start of directives (each led in by two colons '::')
    ::requires UNO.CLS   -- get the UNO/OOo support, which itself gets the Java support

    ::routine printPathSetting    /* print the PathSetting name with its value(s) */
      use arg i, name, propValue

      tmpStr=i~right(3)":" pp(name)

      resArr=processPathUrls(propValue) -- returns array
      say tmpStr || detTabs(tmpStr) pp(resArr[1])
      do k=2 to resArr~items
         say "090909"x pp(resArr[k])
      end

      return


    detTabs: procedure /* determine indentation, depends on length of path name */
      parse arg string

      len=length(string)
      if      len<8  then return "090909"x -- three tabs
      else if len<16 then return "0909"x   -- two tabs
      else if len<24 then return "09"x     -- one tab
      else    return ""                    -- no tab (empty string)

     
       /* take care of special case that multiple paths are encoded in a single
          value (instead of defining them as an array of java.lang.String;
          the URL-style will delimit different paths with the semi-colon char (;)
          on all platforms; will return a Rexx array of strings representing the
          defined URLs rendered to the operating system's file system representation. */
    processPathUrls: procedure
       use arg propValue

       resArr=.array~new

       if propValue~string~left(18)=="[Ljava.lang.String" then -- a String array in hand
       do
          if propValue~items=0 then     -- empty array
             resArr~append("")
          else
          do k=1 to propValue~items
             resArr~appendAll(convertPathUrl(propValue[k])) 
          end
       end
       else                             -- value is a string already (representing single
path)
       do
          resArr~appendAll(convertPathUrl(propValue))
       end
       return resArr


       /* parse string, could be that more than one path is encoded and delimited by semi-colon,
          return an array of converted strings */
    convertPathUrl: procedure
       parse arg str

       arr=.array~new
       if str="" then       -- path is explicitly an empty string
          arr~append(str)
       else
       do while str<>""
          parse var str before ";" str     -- parse using ";" as delimiter
          arr~append(uno.convertFromUrl(before)) -- turn URL into opsys' path notation
       end
       return arr

You'll get the idea looking at the code, such that you can map it to your preferred programming
language.

---rony


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message