0

I updated my docx4j from version 2.8 to version 3.1.0, but i have a probnlem with the type CustomXmlDataStoragePart and CustomXmlPart. The following codes are the original ones from my application with version 2.8.0:

  HashMap<String, CustomXmlDataStoragePart> customXmlDataStorageParts = wml.getCustomXmlDataStorageParts();
    for (String string : customXmlDataStorageParts.keySet()) {
        CustomXmlDataStoragePart customXmlDataStoragePart = customXmlDataStorageParts.get(string);
        customXmlDataStoragePart.getData().setDocument(inputStream);
    }

But since the version 3.0 they changed getCustomXmlDataStorageParts() from CustomXmlDataStoragePart to CustomXmlPart, but CustomXmlPart doesn't have getData() and i can not set document with my inputStream directly. How can I now let the CustomXmlPart to getXML from inputStream? Thank you!

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Manuela
  • 1,379
  • 3
  • 16
  • 25

1 Answers1

1

CustomXmlPart is an interface:

/**
 * There are two types of these:
 * - JaxbCustomXmlDataStoragePart<E>
 * - CustomXmlDataStoragePart
 * 
 * This interface doesn't provide getData,
 * because the 2 types are quite different.
 * 
 * But it could allow storeItemId to be
 * get or set.
 * 
 * @author jharrop
 *
 */
public interface CustomXmlPart

If you have a CustomXmlDataStoragePart, you can cast to that.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • hello Jason, thanks for the answer. But i got the error, that it can not cast CustomXmlPart to CustomXmlDataStoragePart:( – Manuela May 28 '14 at 10:24
  • 1
    What object do you have? getClass().getName() – JasonPlutext May 28 '14 at 10:33
  • I got CustomXmlPart returned, but I need CustomXmlDataStoragePart. The problem is that CustomXmlDataStoragePart implements CustomXmlPart, so i can not cast the latter to the former. That is the problem of the new version of docx4j. The method wml.getCustomXmlDataStorageParts() returns now only CustomXmlPart instead of CustomXmlDataStorageParts (The method name lies...) – Manuela May 28 '14 at 11:46
  • Again, CustomXmlPart is an interface. What object was returned? – JasonPlutext May 28 '14 at 12:30
  • This method looks like this: [LinkToMethodGetCustomXmlDataStorageParts](http://grepcode.com/file/repo1.maven.org/maven2/org.docx4j/docx4j/3.0.1/org/docx4j/openpackaging/packages/OpcPackage.java#OpcPackage.getCustomXmlDataStorageParts%28%29) 'public HashMap [More ...] getCustomXmlDataStorageParts() { 125 return customXmlDataStorageParts; 126 }' – Manuela May 28 '14 at 13:43
  • And i use this class, which extends OpcPackage: [LinkToWordprocessingMLPackage](http://grepcode.com/file/repo1.maven.org/maven2/org.docx4j/docx4j/3.0.1/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java#WordprocessingMLPackage) Thank you very much, Jason! – Manuela May 28 '14 at 13:47
  • I can't help you if you (ignore or) don't understand my question! Please review the distinction between an interface and a class, and work out what object you have. – JasonPlutext May 28 '14 at 21:22
  • Thank you very much. I just tested with o.getclass().getName() and I noticed that I did really get CustomXmlDataStoragePart back, but not as the first object. I think I know now why I got error in this case, because the first returned object is BibliographyPart, and then CustomXmlDataStoragePart. So what i should do is just using the right key to get the right value. Thank you again! – Manuela May 30 '14 at 08:36