XComponentLoader.loadComponentFromURL returns null

Java, C++, C#, Delphi, ??? - Using the UNO bridges

XComponentLoader.loadComponentFromURL returns null

Postby ayverma » Wed Nov 13, 2019 8:34 pm

Below is the java code used to create XComponentLoader object for .docx file present at a server location using loadComponentFromUrl().

Code: Select all   Expand viewCollapse view
                        XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null);
         XUnoUrlResolver urlResolver = UnoUrlResolver.create(xcomponentcontext);
         Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
         XMultiComponentFactory xOfficeFactory = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, initialObject);
         XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xOfficeFactory);
         Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");
         XComponentContext xOfficeComponentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);
         Object oDesktop = xOfficeFactory.createInstanceWithContext("com.sun.star.frame.Desktop",xOfficeComponentContext);
         XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop);
                        File f = new File(fileNamePath);
         if (!f.canRead() || f == null || !f.exists()) {
            try {
               errorJson.put("Msg", "Cannot load template:" + fileNamePath);
               errorJson.put("Status", "Error");
            } catch (JSONException ex) {
            return excelDataArr.toString();
                        xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, xDesktop);
                        String docURL = "file:///" + fileNamePath.replace(File.separatorChar, '/');
              PropertyValue[] propertyValues = new PropertyValue[0];
         propertyValues = new PropertyValue[1];
         propertyValues[0] = new PropertyValue();
         propertyValues[0].Name = "Hidden";
         propertyValues[0].Value = new Boolean(false);
         XComponent xComp = xCompLoader.loadComponentFromURL(docURL, "_blank", 0, propertyValues); //returns null

I have read various questions in the forum and couldn't get to know for what reason the method returns null. Alos, please suggest some alternative or permanent fix to the problem.

Thank you.
Last edited by MrProgrammer on Thu Nov 14, 2019 12:29 am, edited 1 time in total.
Reason: Moved from General Discussion forum to External Programs
LibreOffice 5.4 on RedHatEnterpriseLinux 5.6
Posts: 1
Joined: Wed Nov 13, 2019 7:50 pm

Re: XComponentLoader.loadComponentFromURL returns null

Postby JeJe » Thu Nov 14, 2019 6:56 pm

I don't know Java but I'd look at the URL first... make sure its a valid URL and check the file exists.
Openoffice 4.1.6
Windows 8
Posts: 1144
Joined: Wed Mar 09, 2016 2:40 pm

Return to External Programs

Who is online

Users browsing this forum: No registered users and 4 guests