| 1 | package org.docx4j.openpackaging.parts.WordprocessingML; |
|---|
| 2 | |
|---|
| 3 | import javax.xml.bind.JAXBContext; |
|---|
| 4 | import javax.xml.bind.JAXBElement; |
|---|
| 5 | |
|---|
| 6 | import org.apache.log4j.Logger; |
|---|
| 7 | import org.docx4j.XmlUtils; |
|---|
| 8 | import org.docx4j.bibliography.CTSourceType; |
|---|
| 9 | import org.docx4j.bibliography.CTSources; |
|---|
| 10 | import org.docx4j.openpackaging.exceptions.InvalidFormatException; |
|---|
| 11 | import org.docx4j.openpackaging.parts.PartName; |
|---|
| 12 | import org.docx4j.openpackaging.parts.opendope.JaxbCustomXmlDataStoragePart; |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * @since 2.7 |
|---|
| 16 | */ |
|---|
| 17 | public class BibliographyPart extends JaxbCustomXmlDataStoragePart<JAXBElement<org.docx4j.bibliography.CTSources>> { |
|---|
| 18 | |
|---|
| 19 | private static Logger log = Logger.getLogger(BibliographyPart.class); |
|---|
| 20 | |
|---|
| 21 | public BibliographyPart() throws InvalidFormatException { |
|---|
| 22 | super(new PartName("/customXml/item1.xml")); |
|---|
| 23 | init(); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | public BibliographyPart(PartName partName) throws InvalidFormatException { |
|---|
| 28 | super(partName); |
|---|
| 29 | init(); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | public BibliographyPart(PartName partName, JAXBContext jc) throws InvalidFormatException { |
|---|
| 33 | super(partName, jc); |
|---|
| 34 | init(); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public void importSources(BibliographyPart otherPart) { |
|---|
| 38 | |
|---|
| 39 | org.docx4j.bibliography.CTSources ourSources = (CTSources)XmlUtils.unwrap(this.getJaxbElement()); |
|---|
| 40 | |
|---|
| 41 | org.docx4j.bibliography.CTSources otherSourcesTmp = (CTSources)XmlUtils.unwrap(otherPart.getJaxbElement()); |
|---|
| 42 | org.docx4j.bibliography.CTSources otherSourcesCloned = XmlUtils.deepCopy(otherSourcesTmp); |
|---|
| 43 | |
|---|
| 44 | for (CTSourceType sourceType : otherSourcesCloned.getSource()) { |
|---|
| 45 | |
|---|
| 46 | // TODO duplicate detection. |
|---|
| 47 | |
|---|
| 48 | ourSources.getSource().add(sourceType); |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | } |
|---|