Page 1 of 1

Couldn't locate part by storeItemId

PostPosted: Wed May 25, 2011 7:57 pm
by verrnum
Hi everybody ,

I am trying to add a pict/ shape in my MainDocumentPart.
The shape provides from an another OpenXML document.
I retrieve it by browsing the document Tree :

pict/shape xml code :

Code: Select all
<w:pict>
         <v:shapetype id="_x0000_t202" path="m,l,21600r21600,l21600,xe" coordsize="21600,21600" o:spt="202.0">
            <v:stroke joinstyle="miter"/>
            <v:path gradientshapeok="t" o:connecttype="rect"/>
         </v:shapetype>
         <v:shape id="ADDR_BLOCK" type="#_x0000_t202" stroked="f" style="position:absolute;left:0;text-align:left;margin-left:266.65pt;margin-top:134.25pt;width:282.35pt;height:70.3pt;z-index:-251658752;mso-position-horizontal-relative:page;mso-position-vertical-relative:page;mso-width-relative:margin;mso-height-relative:margin" wrapcoords="-57 0 -57 21319 21600 21319 21600 0 -57 0" o:allowincell="f" o:allowoverlap="f" o:spid="_x0000_s1029">
            <v:textbox inset="0,0,0,0" style="mso-next-textbox:#ADDR_BLOCK;mso-fit-shape-to-text:t">
               <w:txbxContent>
                  <w:p w:rsidRPr="00440B49" w:rsidR="00440B49" w:rsidP="00956480" w:rsidRDefault="00501CFB">
                     <w:pPr>
                        <w:jc w:val="left"/>
                        <w:outlineLvl w:val="9"/>
                        <w:rPr>
                           <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                           <w:lang w:val="en-US"/>
                        </w:rPr>
                     </w:pPr>
                     <w:sdt>
                        <w:sdtPr>
                           <w:rPr>
                              <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                              <w:lang w:val="en-US"/>
                           </w:rPr>
                           <w:alias w:val="ADDR_BLOCK"/>
                           <w:tag w:val="ADDR_BLOCK"/>
                           <w:id w:val="544502323"/>
                           <w:lock w:val="sdtContentLocked"/>
                           <w:dataBinding w:xpath="/variables/variable[@name='ADDR_BLOCK']" w:storeItemID="{D596218A-15D1-49DD-AC23-D9CE5EDEB61C}"/>
                           <w:text w:multiLine="true"/>
                        </w:sdtPr>
                        <w:sdtContent>
                           <w:r w:rsidR="00440B49">
                              <w:rPr>
                                 <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                                 <w:lang w:val="en-US"/>
                              </w:rPr>
                              <w:t/>
                           </w:r>
                           <w:r w:rsidR="00956480">
                              <w:rPr>
                                 <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                                 <w:lang w:val="en-US"/>
                              </w:rPr>
                              <w:t/>
                           </w:r>
                           <w:r w:rsidR="00440B49">
                              <w:rPr>
                                 <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                                 <w:lang w:val="en-US"/>
                              </w:rPr>
                              <w:t/>
                           </w:r>
                        </w:sdtContent>
                     </w:sdt>
                  </w:p>
               </w:txbxContent>
            </v:textbox>
            <w10:wrap xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" anchorx="page" anchory="page" type="topAndBottom"/>
         </v:shape>
      </w:pict>




After the Pict object retrieving , i add it to MainDocumentPart :

Code: Select all
MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();
       org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)mainDocumentPart.getJaxbElement();
       Body body = wmlDocumentEl.getBody();
       body.getContent().add(pict);


Then i build the CustomXmlDataStoragePart (item1.xml / itemProps1.mxl) to bind it :

Code: Select all
//item1.xml
      CustomXmlDataStoragePart customXMLDataStoragePart
         = CreateDocxWithCustomXml.injectCustomXmlDataStoragePart(wordMLPackage.getMainDocumentPart(),
               wordMLPackage.getParts());
      
      //create custom XML document
      customXMLDataStoragePart.setPartName(new PartName(customXMLUriVariables));
      
      org.w3c.dom.Document newDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      Element newDocumentElement
          = newDoc.createElement("variables");
      
      newDoc.appendChild(newDocumentElement);
      
      customXMLDataStoragePart.getData().setDocument(newDoc);
      
      //add the getCustomXmlDataStorageParts to wordMLPackage
      wordMLPackage.getCustomXmlDataStorageParts().put("item1", customXMLDataStoragePart);
      
      
      //itemProps1.xml
      CustomXmlDataStoragePart customXMLDataStoragePart2
         = CreateDocxWithCustomXml.injectCustomXmlDataStoragePart(wordMLPackage.getMainDocumentPart(),
            wordMLPackage.getParts());
      
      customXMLDataStoragePart2.setPartName(new PartName(customXMLUriProps));
      
      org.w3c.dom.Document newDoc2
         = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      
      
      Element newDocumentElement2
          = newDoc2.createElement("datastoreItem");
      
      newDoc2.appendChild(newDocumentElement2);
      
      newDocumentElement2.setAttribute("itemID", "{D596218A-15D1-49DD-AC23-D9CE5EDEB61C}");
      
      newDocumentElement2.appendChild(newDoc2.createElement("schemaRefs"));
      
      wordMLPackage.getCustomXmlDataStorageParts().put("itemProps1", customXMLDataStoragePart2);
      
      customXMLDataStoragePart2.getData().setDocument(newDoc2);


And when i try the binding :
Code: Select all
BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart());


I have the next exception :
ERROR[org.docx4j.model.datastorage.BindingHandler] Couldn't locate part by storeItemId {D596218A-15D1-49DD-AC23-D9CE5EDEB61C}


I don't understand why ?

Thanks for your help..

Re: Couldn't locate part by storeItemId

PostPosted: Wed May 25, 2011 8:12 pm
by tinne
Did you a) add that itemProps1.xml to the rels section of your document and b) add a line to the content types file announcing its datatype?

Re: Couldn't locate part by storeItemId

PostPosted: Wed May 25, 2011 9:10 pm
by verrnum
Hi,

Thanks you for your response !!

You are right i forgot it...i didn't know this notion of rel.

Have you please an example of rel handling ??

Thanks a lot

Re: Couldn't locate part by storeItemId

PostPosted: Thu May 26, 2011 9:40 pm
by tinne
Chapter 11.2 of part I of the spec explains it precisely.

Re: Couldn't locate part by storeItemId

PostPosted: Thu May 26, 2011 9:54 pm
by jason
See also docx4'j addTargetPart method.