Ignore:
Timestamp:
01/11/08 06:03:39 (4 years ago)
Author:
jharrop
Message:

createTestPackage() now adds a styles part with a small set of styles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java

    r108 r112  
    125125 
    126126                // Create main document part 
    127                 Part corePart = new org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart(new PartName("/word/document.xml")); 
     127                Part corePart = new org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart(); 
    128128                 
    129129                // Put the content in the part 
    130 //              ((org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)corePart).setDocumentObj(wmlDocumentEl); 
    131130                ((org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)corePart).setJaxbElement(wmlDocumentEl); 
    132                  
    133 //              corePart.setContentType(new  org.docx4j.openpackaging.contenttype.ContentType( org.docx4j.openpackaging.contenttype.ContentTypes.WORDPROCESSINGML_DOCUMENT)); 
    134 //              corePart.setRelationshipType(Namespaces.DOCUMENT); 
    135                  
     131                                 
    136132                // Make getMainDocumentPart() work 
    137133                p.setPartShortcut(corePart, corePart.getRelationshipType()); 
     
    145141                // Add it to the package 
    146142                p.setRelationships(rp); 
     143                        // TODO - this should happen automatically? 
    147144                                 
    148145                // Add the main document part to the package relationships 
     
    150147                rp.addPart(corePart, p.getContentTypeManager()); 
    151148                 
     149                 
     150                // Create a styles part 
     151                Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart(); 
     152                try { 
     153                        ((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart) 
     154                                        .unmarshalDefaultStyles(); 
     155                         
     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());                  
     162                         
     163                } catch (Exception e) { 
     164                        // TODO: handle exception 
     165                        e.printStackTrace();                     
     166                } 
    152167                // Return the new package 
    153168                return p; 
Note: See TracChangeset for help on using the changeset viewer.