Bug 54407

Summary: XmlValueDisconnectedException when merging slides from 2 slideshows
Product: POI Reporter: Georgi Sokolov <joro>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
URL: http://projects.liquidsoft.eu/FlexiaJava.zip
Attachments: PPTX 2
PPTX 1

Description Georgi Sokolov 2013-01-11 16:08:14 UTC
When I do the suggested code:

XSLFSlide srcSlide = slides[Integer.parseInt(args[2])];
XSLFSlideLayout src_sl = srcSlide.getSlideLayout();
XSLFSlideMaster src_sm = srcSlide.getSlideMaster();
                
XSLFSlide newSlide = ppto.createSlide(); 
XSLFSlideLayout new_sl = newSlide.getSlideLayout(); 
new_sl.importContent(src_sl); 
                
XSLFSlideMaster new_sm = newSlide.getSlideMaster();
new_sm.importContent(src_sm);
                
newSlide.importContent(srcSlide);

I get this exception:

Exception in thread "main"
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
at
org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1213)
at
org.openxmlformats.schemas.drawingml.x2006.main.impl.CTShapePropertiesImpl.getLn(Unknown
Source)
at
org.apache.poi.xslf.usermodel.RenderableShape$5.fetch(RenderableShape.java:401)
at
org.apache.poi.xslf.usermodel.XSLFSimpleShape.fetchShapeProperty(XSLFSimpleShape.java:602)
at
org.apache.poi.xslf.usermodel.RenderableShape.getLinePaint(RenderableShape.java:417)
at
org.apache.poi.xslf.usermodel.XSLFSimpleShape.getLineColor(XSLFSimpleShape.java:288)
at
org.apache.poi.xslf.usermodel.XSLFSimpleShape.copy(XSLFSimpleShape.java:663)
at org.apache.poi.xslf.usermodel.XSLFTextShape.copy(XSLFTextShape.java:561)
at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:310)
at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:226)

If I run it only with slides from the first slideshow, it works fine. Although if I try merging it with both PPTX files, it crashes with that exception.
Comment 1 Georgi Sokolov 2013-01-11 16:13:24 UTC
Created attachment 29846 [details]
PPTX 2
Comment 2 Georgi Sokolov 2013-01-11 16:15:51 UTC
Created attachment 29847 [details]
PPTX 1

This is not the original testing file, I can send the links to the original testing files, but it basically happens with any file
Comment 3 Yegor Kozlov 2013-01-13 10:50:27 UTC
XmlValueDisconnectedException  happens when you call importContent on the same sheets multuple times. In the current implementation you can do it only once:

layout.importContent(srcLayout); // OK
layout.importContent(srcLayout); // fails with XmlValueDisconnectedException  

the workaround is to track visited sheets and remember them in a set. Below is a modification of your code that passes without exceptions:

        XMLSlideShow ppt1 = new XMLSlideShow(new FileInputStream("/temp/54407/10steps.pptx"));
        XSLFSlide[] slides = ppt1.getSlides();


        XMLSlideShow ppt_out = new XMLSlideShow();
        // track already imported sheets
        HashSet<XSLFSheet> visited = new HashSet<XSLFSheet>();

        for(XSLFSlide srcSlide : slides) {
            XSLFSlideLayout src_sl = srcSlide.getSlideLayout();
            XSLFSlideMaster src_sm = srcSlide.getSlideMaster();

            XSLFSlide newSlide = ppt_out.createSlide();
            XSLFSlideLayout new_sl = newSlide.getSlideLayout();
            if(!visited.contains(new_sl)) {
                new_sl.importContent(src_sl);
                visited.add(new_sl);
            }

            XSLFSlideMaster new_sm = newSlide.getSlideMaster();
            if(!visited.contains(new_sm)) {
                new_sm.importContent(src_sm);
                visited.add(new_sm);
            }
            newSlide.importContent(srcSlide);
        }
Comment 4 Georgi Sokolov 2013-01-15 09:04:10 UTC
Since because of the file limitations, I have uploaded the original code + the test files here:

http://projects.liquidsoft.eu/FlexiaJava.zip

Here is my use case:

java -jar dist\FlexiaJava.jar out.pptx 10steps.pptx 3

java -jar dist\FlexiaJava.jar out.pptx 10steps.pptx 5

java -jar dist\FlexiaJava.jar out.pptx 10steps.pptx 2

java -jar dist\FlexiaJava.jar out.pptx dash.pptx 3

Strangly the first time importing from the other file works fine(although not producing the correct output).

Then we try to add another slide from the second presentation.

java -jar dist\FlexiaJava.jar out.pptx dash.pptx 5

And it crashes:

Exception in thread "main"
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
        at
org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1213)
        at
org.openxmlformats.schemas.drawingml.x2006.main.impl.CTShapePropertiesImpl.isSetNoFill(Unknown
Source)
        at
org.apache.poi.xslf.usermodel.RenderableShape$4.fetch(RenderableShape.java:352)
        at
org.apache.poi.xslf.usermodel.XSLFSimpleShape.fetchShapeProperty(XSLFSimpleShape.java:602)
        at
org.apache.poi.xslf.usermodel.RenderableShape.getFillPaint(RenderableShape.java:364)
        at
org.apache.poi.xslf.usermodel.XSLFSimpleShape.getFillColor(XSLFSimpleShape.java:490)
        at
org.apache.poi.xslf.usermodel.XSLFSimpleShape.copy(XSLFSimpleShape.java:649)

        at
org.apache.poi.xslf.usermodel.XSLFTextShape.copy(XSLFTextShape.java:561)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:310)
        at
org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:226)
        at flexiajava.FlexiaJava.main(FlexiaJava.java:73)
Comment 5 Georgi Sokolov 2013-01-21 16:41:41 UTC
I'm currently offering $500(over paypal) for a bugfix on this issue if I'm able to merge 2 presentations properly(no XMLDisconnects), proper master pages and styles. This has to be done today!
Comment 6 Yegor Kozlov 2013-01-21 18:07:54 UTC
OK, I will try to find time to look into it. Will give my feedback within 24 hours.

Yegor

(In reply to comment #5)
> I'm currently offering $500(over paypal) for a bugfix on this issue if I'm
> able to merge 2 presentations properly(no XMLDisconnects), proper master
> pages and styles. This has to be done today!
Comment 7 Yegor Kozlov 2013-01-22 13:58:08 UTC
Should be fixed in r1436913 and r1436608.

The following problems have been fixed:

 - image format .wdp was not supported. That resulted in NPE. 
 - image relations under ExtLst element were not imported. importContent silently passed but PowerPoint showed "unreadable content" when opening the result. 
 - cached placeholders were not invalidated after calling importContent. That resulted in XmlValueDisconnectedException
 - relationships for the diagram shapes were not copied. That resulted in "unreadable content" when opening the result in PowerPoint. 

All presentations attached in http://projects.liquidsoft.eu/FlexiaJava.zip merge without exceptions and PowerPoint is happy to open the result. 

Please try with the latest build from trunk. If there are still errors then please attach more test files/cases. 

Regards,
Yegor
Comment 8 Shea Brock 2014-01-24 15:14:54 UTC
Latest build from trunk solved this issue for me.  Thank you for the timely fix!