Ignore:
Timestamp:
02/27/10 06:45:58 (2 years ago)
Author:
jharrop
Message:

traversal improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MainDocumentPart.java

    r1027 r1095  
    5555import org.docx4j.wml.Style; 
    5656import org.docx4j.wml.Styles; 
     57import org.docx4j.wml.Tc; 
    5758 
    5859 
     
    112113                                //log.debug("style in use: " + styleId ); 
    113114                    } 
    114                      
    115 //              if (!stylesInUse.contains("Normal") ) { 
    116 //                      stylesInUse.add("Normal"); 
    117 //              } 
    118 //              if (!stylesInUse.contains("DefaultParagraphFont") ) { 
    119 //                      stylesInUse.add("DefaultParagraphFont"); 
    120 //              }        
    121                      
     115                                     
    122116                    try { 
    123117                                getStyleDefinitionsPart().createVirtualStylesForDocDefaults(); 
     
    127121                        } 
    128122                 
     123                        // Get these first, so we can be sure they are defined...  
     124                        Style defaultParagraphStyle = getStyleDefinitionsPart().getDefaultParagraphStyle(); 
     125                        Style defaultCharacterStyle = getStyleDefinitionsPart().getDefaultCharacterStyle(); 
     126                         
    129127                        // Styles defined in StyleDefinitionsPart 
    130128                        Map<String, Style> allStyles = new HashMap<String, Style>(); 
     
    134132                                //log.debug("live style: " + s.getStyleId() ); 
    135133                        } 
    136                         styleTree = new StyleTree(stylesInUse, allStyles); 
     134                        styleTree = new StyleTree(stylesInUse, allStyles,  
     135                                        defaultParagraphStyle.getStyleId(), 
     136                                        defaultCharacterStyle.getStyleId()); 
    137137                                 
    138138                } 
     
    420420                                        fontsDiscovered.put(sym.getFont(), sym.getFont()); 
    421421 
     422                                } else if ( ((JAXBElement)o).getDeclaredType().getName().equals( 
     423                                                "org.docx4j.wml.CTBookmark") ) { 
     424                                        // Ignore                                        
    422425                                } else if ( log.isDebugEnabled() ){ 
    423426                                        log.debug( XmlUtils.JAXBElementDebug((JAXBElement)o) ); 
     
    450453//                              } 
    451454                                 
     455                        } else if (o instanceof org.docx4j.wml.ProofErr) { 
     456                                // Ignore eg <w:proofErr w:type="spellStart" /> 
    452457                        } else { 
    453458                                log.error( "UNEXPECTED: " + o.getClass().getName() ); 
     459                                 log.debug( XmlUtils.marshaltoString(o, true));                                           
    454460                        }  
    455461                } 
     
    476482                 for (Object o : tbl.getEGContentRowContent() ) { 
    477483                          
     484                         org.docx4j.wml.Tr tr = null; 
    478485                         if (o instanceof org.docx4j.wml.Tr) {                            
    479                                  log.debug( "\n in w:tr .. "); 
    480                                  org.docx4j.wml.Tr tr = (org.docx4j.wml.Tr)o;                             
    481                                  for (Object o2 : tr.getEGContentCellContent() ) {                                        
    482                                                 if ( o2 instanceof javax.xml.bind.JAXBElement) { 
    483                                                         // Usual content for w:tr is w:tc 
    484                                                         if ( ((JAXBElement)o2).getDeclaredType().getName().equals("org.docx4j.wml.Tc") ) { 
    485                                                                 log.debug( "\n  in w:tc .. "); 
    486                                                                 org.docx4j.wml.Tc tc = (org.docx4j.wml.Tc)((JAXBElement)o2).getValue(); 
    487                                                                  
    488                                                                 // Look at the paragraphs in the tc 
    489                                                                 traverseMainDocumentRecursive( tc.getEGBlockLevelElts(),  
    490                                                                                 fontsDiscovered, stylesInUse); 
    491                                                                  
    492                                                         } else { 
    493                                                                 // Could be custom markup (custom XML or sdt) 
    494                                                                 log.warn("TODO - not w:tc - handle:  " + XmlUtils.JAXBElementDebug((JAXBElement)o2) ); 
    495                                                         } 
    496                                                 } else if (o2 instanceof org.docx4j.wml.Tc) { 
    497                                                         // Again, it could be this or wrapped in a JAXBElement! 
    498                                                         traverseMainDocumentRecursive( ((org.docx4j.wml.Tc)o2).getEGBlockLevelElts(),  
    499                                                                         fontsDiscovered, stylesInUse);                                                   
    500                                                          
    501                                                 } else { 
    502                                                          // Could be custom markup (custom XML or sdt) 
    503                                                          log.warn("TODO - not w:tc - handle:  " + o2.getClass().getName() ); 
    504                                                 }                                         
    505                                  } 
     486                                 tr = (org.docx4j.wml.Tr)o;              
     487                         } else if (o instanceof javax.xml.bind.JAXBElement 
     488                                         && ((JAXBElement)o).getDeclaredType().getName().equals("org.docx4j.wml.Tr")) { 
     489                                 tr = (org.docx4j.wml.Tr)((JAXBElement)o).getValue(); 
    506490                         } else { 
    507491                                 // What? 
    508                                  log.warn("TODO - handle:  " + o.getClass().getName() ); 
     492                                 if (o instanceof javax.xml.bind.JAXBElement) { 
     493                                        if ( ((JAXBElement)o).getDeclaredType().getName().equals( 
     494                                                "org.docx4j.wml.CTMarkupRange") ) {  
     495                                                // Ignore w:bookmarkEnd 
     496                                        } else { 
     497                                                log.warn("TODO - skipping JAXBElement:  " + ((JAXBElement)o).getDeclaredType().getName() ); 
     498                                                 log.debug( XmlUtils.marshaltoString(o, true));                                           
     499                                        } 
     500                                 } else { 
     501                                         log.warn("TODO - skipping:  " + o.getClass().getName() ); 
     502                                         log.debug( XmlUtils.marshaltoString(o, true));                                           
     503                                 } 
     504                                 continue; 
     505                         } 
     506                          
     507                         for (Object o2 : tr.getEGContentCellContent() ) {       
     508                                  
     509                                        Tc tc = null; 
     510                                         if (o2 instanceof org.docx4j.wml.Tc) {                           
     511                                                 tc = (org.docx4j.wml.Tc)o2;             
     512                                         } else if (o2 instanceof javax.xml.bind.JAXBElement 
     513                                                         && ((JAXBElement)o2).getDeclaredType().getName().equals("org.docx4j.wml.Tc")) { 
     514                                                 tc = (org.docx4j.wml.Tc)((JAXBElement)o2).getValue(); 
     515                                         } else { 
     516                                                 // What? 
     517                                                 if (o2 instanceof javax.xml.bind.JAXBElement) { 
     518                                                         log.warn("TODO - skipping JAXBElement:  " + ((JAXBElement)o2).getDeclaredType().getName() ); 
     519                                                 } else { 
     520                                                         log.warn("TODO - skipping:  " + o2.getClass().getName() ); 
     521                                                 } 
     522                                                 log.debug( XmlUtils.marshaltoString(o2, true));                                                  
     523                                                 continue; 
     524                                         } 
     525                                  
     526                                        traverseMainDocumentRecursive( tc.getEGBlockLevelElts(),  
     527                                                        fontsDiscovered, stylesInUse); 
    509528                         } 
    510529                          
Note: See TracChangeset for help on using the changeset viewer.