1

I am currently working on converting doc to docx files in a java project. I use some lib from com.sun.star that I manage to get working on a previous iteration, but now everything is crashing at the first try of conversion.

My code is :

            String sourceUrl = "file:///" + listOfFile[i].getAbsolutePath().replace('\\', fileSeparator);
            String targetUrl = "file:///" + listOfFile[i].getAbsolutePath().replace('\\', fileSeparator) + 'x';

            // Setup the source file for libreoffice
            PropertyValue propertyValue[] = new PropertyValue[1];
            propertyValue[0] = new PropertyValue();
            propertyValue[0].Name = "Hidden";
            propertyValue[0].Value = Boolean.TRUE;

            Object oDocToStor = DocConverter.xCompLoader.loadComponentFromURL(sourceUrl, "_blank", 0, propertyValue);

            XStorable xStorable = UnoRuntime.queryInterface(XStorable.class, oDocToStor);

            // Setting up the converter by giving him the source file qnd the tqrget type
            propertyValue = new PropertyValue[2];
            propertyValue[0] = new PropertyValue();
            propertyValue[0].Name = "Overwrite";
            propertyValue[0].Value = Boolean.TRUE;
            propertyValue[1] = new PropertyValue();
            propertyValue[1].Name = "FilterName";
            propertyValue[1].Value = "MS Word 2007 XML";

            // Apply convertion !!! It crash at this step !!!
            xStorable.storeAsURL(targetUrl, propertyValue);

            XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xStorable);
            if (xCloseable != null) {
                xCloseable.close();
            } else {
                XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xStorable);
                xComp.dispose();
            }

and I get the following exception :

java.lang.AssertionError: com.sun.star.task.ErrorCodeIOException: SfxBaseModel::impl_store <file:///D:\my\file.docx> failed: 0x31c
    at org.junit.Assert.fail(Assert.java:93)
    at fr.gouv.travail.utils.service.impl.DocConverterTest.testDirectory(DocConverterTest.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

When I launch it the second time, I get a null pointer exception since the first iteration do not free ressource in libreoffice and can not open them again.

My socket looks correctly opened, my file are in the rigth place since I target a entire non empty directory and coworker do not get the error too.

edit : I check all write permission in my folder and everything is fine.

Thanks in advance for the help :)

slg
  • 36
  • 4
  • I can't make sense of the error message, but since the error is raised from an assertion in a `testDirectory` method, I'd expect it not to like the path you've provided it. I see you're using backslashes, you might want to change these to forward slashes. I'm also not sure the `:` after the disk label is necessary nor accepted in a `file:///` url – Aaron Aug 07 '17 at 13:31
  • About the slashes : I see they're handled by the `.replace('\\', fileSeparator)` , which seems to be `\\ ` in your case, seeing the error. You might want to try with `/` instead of `fileSeparator` (and maybe the replace should instead be `.replace(fileSeparator, "/")`) – Aaron Aug 07 '17 at 13:34
  • @Aaron : I change the ligne as you suggested and it works. Now I have to get where spring is getting his // since both my properties file contain a '/' inside them. Thanks a lot ! – slg Aug 07 '17 at 13:50
  • You're welcome. Spring probably translate them to `\\ ` because it handles them as `File`s or `Path`s on a Windows platform, where backslashes are the expected file separator. Having to translate them to `/` in order to construct an URL doesn't seem unusual to me. – Aaron Aug 07 '17 at 13:57
  • Also check [this question](https://stackoverflow.com/questions/6098472/pass-a-local-file-in-to-url-in-java) which might make for cleaner code :) – Aaron Aug 07 '17 at 14:01

1 Answers1

0

Thanks to Aaron, I figured out the problem was the injection of the fileSeparator variable, which I wanted and set as '/' in my properties file but seems to end up as '\' in my debuger. I'll investigate this later and edit my qnser if I found more.

slg
  • 36
  • 4