Changeset 118 for trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java
- Timestamp:
- 01/11/08 10:04:42 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java
r112 r118 21 21 22 22 23 import org.apache.log4j.Logger; 24 import org.docx4j.openpackaging.Base; 23 25 import org.docx4j.openpackaging.parts.DocPropsCorePart; 24 26 import org.docx4j.openpackaging.parts.DocPropsExtendedPart; … … 63 65 */ 64 66 67 protected static Logger log = Logger.getLogger(WordprocessingMLPackage.class); 65 68 66 69 … … 78 81 if (relationshipType.equals(Namespaces.PROPERTIES_CORE)) { 79 82 docPropsCorePart = (DocPropsCorePart)part; 83 log.info("Set shortcut for docPropsCorePart"); 80 84 return true; 81 85 } else if (relationshipType.equals(Namespaces.PROPERTIES_EXTENDED)) { 82 86 docPropsExtendedPart = (DocPropsExtendedPart)part; 87 log.info("Set shortcut for docPropsExtendedPart"); 83 88 return true; 84 89 } else if (relationshipType.equals(Namespaces.DOCUMENT)) { 85 90 mainDoc = (MainDocumentPart)part; 91 log.info("Set shortcut for mainDoc"); 86 92 return true; 87 93 } else { … … 98 104 99 105 // Create a package 100 WordprocessingMLPackage p= new WordprocessingMLPackage();106 WordprocessingMLPackage wmlPack = new WordprocessingMLPackage(); 101 107 102 108 // Add a ContentTypeManager to it 103 109 ContentTypeManager ctm = new ContentTypeManagerImpl(); 104 p.setContentTypeManager(ctm); 110 wmlPack.setContentTypeManager(ctm); 111 // TODO - move this to constructor? 112 113 114 // Create main document part 115 Part wordDocumentPart = new org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart(); 105 116 106 107 117 // Create main document part content 108 118 org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory(); … … 122 132 org.docx4j.wml.Document wmlDocumentEl = factory.createDocument(); 123 133 wmlDocumentEl.setBody(body); 124 125 126 // Create main document part 127 Part corePart = new org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart(); 128 134 129 135 // Put the content in the part 130 ((org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)corePart).setJaxbElement(wmlDocumentEl); 136 ((org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)wordDocumentPart).setJaxbElement(wmlDocumentEl); 137 138 // Add the main document part to the package relationships 139 // (creating it if necessary) 140 wmlPack.addTargetPart(wordDocumentPart); 131 141 132 // Make getMainDocumentPart() work133 p.setPartShortcut(corePart, corePart.getRelationshipType());134 135 // Create the PackageRelationships part136 RelationshipsPart rp = new RelationshipsPart( new PartName("/_rels/.rels"), p );137 138 // Make sure content manager knows how to handle .rels139 ctm.addDefaultContentType("rels", org.docx4j.openpackaging.contenttype.ContentTypes.RELATIONSHIPS_PART);140 141 // Add it to the package142 p.setRelationships(rp);143 // TODO - this should happen automatically?144 145 // Add the main document part to the package relationships146 // and to [Content_Types].xml147 rp.addPart(corePart, p.getContentTypeManager());148 149 150 142 // Create a styles part 151 143 Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart(); … … 154 146 .unmarshalDefaultStyles(); 155 147 156 // Now we need to add it the main document part's relationships 157 RelationshipsPart docRels = new RelationshipsPart( new PartName("/word/_rels/document.xml.rels"), corePart ); 158 // TODO - should construct the relationships part name from the source part name 159 corePart.setRelationships(docRels); 160 // TODO - this should happen automatically? 161 docRels.addPart(stylesPart, p.getContentTypeManager()); 148 // Add the styles part to the main document part relationships 149 // (creating it if necessary) 150 wordDocumentPart.addTargetPart(stylesPart); // NB - add it to main doc part, not package! 162 151 163 152 } catch (Exception e) { … … 166 155 } 167 156 // Return the new package 168 return p; 169 157 return wmlPack; 170 158 171 159 } 172 173 160 174 161 }
Note: See TracChangeset
for help on using the changeset viewer.
