Ignore:
Timestamp:
01/10/08 13:54:06 (4 years ago)
Author:
jharrop
Message:

Complete refactoring into new packages org.docx4j.wml and org.docx4j.jaxb

File:
1 edited

Legend:

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

    r69 r106  
    6363         */ 
    6464         
    65          
    66         // 20070812 - nb although io.LoadFromJCR will  
    67         // detect a WordprocessingMLPackage and instantiate 
    68         // this class, at present this class doesn't  
    69         // do anything that Package doesn't do! 
    70          
     65                 
    7166         
    7267        // Main document 
     
    7873        public WordprocessingMLPackage() { 
    7974                super(); 
    80                 try {    
    81                          
    82                         //for (PackagePart part : p.getParts() ) { 
    83                         //      log.debug(part.getPartName() + " --- " + part.getContentType()); 
    84                         //} 
    85                          
    86                         // Have to do this for side effect or org.openxml4j.opc.Package.getRelationshipsByType 
    87                         // will later give a NullPointerException 
    88 //                      PackageRelationshipCollection packageRelationshipCollection =  
    89 //                              p.getRelationships(); 
    90 //       
    91 //                      // CORE_DOCUMENT 
    92 //                      PackageRelationship pRelationship = p 
    93 //                                      .getRelationshipsByType( 
    94 //                                                      PackageRelationshipTypes.CORE_DOCUMENT ) 
    95 //                                      .getRelationship(0); 
    96 //                      // Get the Core Document part from the relationship 
    97 //                      PackagePart mainDocPart = p 
    98 //                                      .getPart(pRelationship); 
    99 //                      InputStream inStream = mainDocPart.getInputStream(); 
    100 //                      mainDoc = new MainDocumentPart(); 
    101                          
    102                         // can't just do  
    103                         //      MainDocumentPart mainDoc = (MainDocumentPart)p.getPart(pRelationship); 
    104                         //      InputStream inStream = mainDoc.getInputStream(); 
    105                         // since this is casting ZipPackagePart to MainDocumentPart 
    106                         // Should I make MainDocumentPart extend ZipPackagePart?  
    107                          
    108 //                      mainDoc.load(inStream); 
    109 //                      inStream.close(); 
    110  
    111                         // STYLE_DOCUMENT 
    112 /* 
    113                         PackageRelationshipCollection mainDocRelationshipCollection =  
    114                                 new PackageRelationshipCollection(mainDocPart); 
    115  
    116                         // Add those to the relationships known to the package 
    117                         for (Iterator i = mainDocRelationshipCollection.iterator(); i.hasNext(); ) { 
    118                                 // add the relation to the other PCR 
    119                                 PackageRelationship rel = (PackageRelationship)i.next(); 
    120                                 log.debugprintln("Adding " + (rel.getTargetURI()).toString() + rel.getTargetMode()  
    121                                                 + rel.getRelationshipType() + rel.getId()); 
    122                                 p.addRelationship(new PackagePartName(rel.getTargetURI(), true), rel.getTargetMode(),  
    123                                                 rel.getRelationshipType()); 
    124                         } 
    125 */ 
    126                          
    127 /*                      //getPart gives NullPointerException 
    128                         pRelationship = p 
    129                                         .getRelationshipsByType( 
    130                                                         PackageRelationshipTypes.STYLE_PART ) 
    131                                         .getRelationship(0); 
    132                         PackagePart pPart = p 
    133                                         .getPart(pRelationship); 
    134 */                
    135 //                      PackagePart pPart = p.getPart(new PackagePartName("/word/styles.xml", true)); 
    136 //                      inStream = pPart.getInputStream(); 
    137 //                      StyleDefinitionsPart stylePart =  
    138 //                              new StyleDefinitionsPart(p, pPart.getPartName()); 
    139 //                      stylePart.load(inStream); 
    140 //                      //mainDoc.setStyleDefinitionsPart( stylePart ); 
    141 //                      inStream.close();                        
    142                          
    143                         /** Then we want to do something like: 
    144                          *  
    145                          *  coreDoc.setNumberingDefinitionsPart ( xxx ); 
    146                          *  
    147                          */ 
    148                          
    149                          
    150                         // Add a paragraph to the end of the document 
    151                          
    152                          
    153                          
    154                         /* Now save the document. 
    155                          *  
    156                          *  How to do this? 
    157                          *   
    158                          *  We simply use the methods in the existing Parts. 
    159                          *   
    160                          *  Alternative approaches which rely on my Parts extending 
    161                          *  the existing Parts. 
    162                          *   
    163                          *  Approach 1: 
    164                          *  ----------- 
    165                          *  // remove the original CORE_DOCUMENT 
    166                          *  removePart(PackagePartName partName) 
    167                          *  // add our new one in its place 
    168                          *  addPackagePart(PackagePart part) 
    169                          *  // (Then what about its rel listing?) 
    170                          *   
    171                          *  Approach 2: 
    172                          *  ----------- 
    173                          *  Keep the original Part (ie mainDocPart), but replace its contents 
    174                          *   
    175                         */ 
    176                          
    177                         //p.setPackageAccess(PackageAccess.READ_WRITE); // had to create this if not opened it READ_WRITE in the first place! 
    178  
    179                         // Save the XML structure into the part 
    180 //                      mainDoc.save(mainDocPart.getOutputStream()); 
    181                          
    182                         // The document will save using: 
    183                         //p.save(new java.io.File("/home/jharrop/text.docx")); 
    184                          
    185                          
    186                 } catch (Exception e ) { 
    187                         e.printStackTrace(); 
    188                 } 
    18975        } 
    19076         
     
    220106 
    221107                // Create main document part content 
    222                 org.docx4j.jaxb.document.ObjectFactory factory = new org.docx4j.jaxb.document.ObjectFactory(); 
     108                org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory(); 
    223109 
    224                 org.docx4j.jaxb.document.Text  t = factory.createText(); 
     110                org.docx4j.wml.Text  t = factory.createText(); 
    225111                t.setValue("Hello world, from docx4j"); 
    226112 
    227                 org.docx4j.jaxb.document.R  run = factory.createR(); 
     113                org.docx4j.wml.R  run = factory.createR(); 
    228114                run.getRunContent().add(t);              
    229115                 
    230                 org.docx4j.jaxb.document.P  para = factory.createP(); 
     116                org.docx4j.wml.P  para = factory.createP(); 
    231117                para.getParagraphContent().add(run); 
    232118                 
    233                 org.docx4j.jaxb.document.Body  body = factory.createBody(); 
     119                org.docx4j.wml.Body  body = factory.createBody(); 
    234120                body.getBlockLevelElements().add(para); 
    235121                 
    236                 org.docx4j.jaxb.document.Document wmlDocumentEl = factory.createDocument(); 
     122                org.docx4j.wml.Document wmlDocumentEl = factory.createDocument(); 
    237123                wmlDocumentEl.setBody(body); 
    238124                 
Note: See TracChangeset for help on using the changeset viewer.