Changeset 1189


Ignore:
Timestamp:
08/24/10 15:46:38 (18 months ago)
Author:
jharrop
Message:

Support multiple table rows in an sdt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/model/table/TableModel.java

    r1188 r1189  
    294294                int r = 0; 
    295295                for (Object o : rows) { 
    296                         startRow();                      
    297296                        Tr tr = null; 
    298                          if (o instanceof org.docx4j.wml.Tr) {                            
    299                                  log.debug( "\n in w:tr .. "); 
    300                                  tr = (org.docx4j.wml.Tr)o;              
    301                          } else if (o instanceof javax.xml.bind.JAXBElement 
    302                                          && ((JAXBElement)o).getDeclaredType().getName().equals("org.docx4j.wml.Tr")) { 
    303                                  tr = (org.docx4j.wml.Tr)((JAXBElement)o).getValue(); 
    304                          } else if (o instanceof javax.xml.bind.JAXBElement 
    305                                          && ((JAXBElement)o).getDeclaredType().getName().equals("org.docx4j.wml.CTSdtRow")) { 
    306                                   
    307 //                               log.debug("Inspecting CTSdtRow"); 
    308                                   
    309                                  CTSdtRow sdt = (org.docx4j.wml.CTSdtRow)((JAXBElement)o).getValue(); 
    310                                   
    311                                  if (sdt.getSdtContent().getEGContentRowContent().size()>0 ) { 
    312                                   
    313                                          Object content0 = sdt.getSdtContent().getEGContentRowContent().get(0);                                   
    314                                           
    315                                          if (content0  instanceof org.docx4j.wml.Tr) { 
    316                                                  tr = (org.docx4j.wml.Tr)content0; 
    317                                          } else { 
    318                                                  log.warn("Unexpected " + content0.getClass().getName() );                                                
    319                                                  continue; 
    320                                          } 
    321                                  } else { 
    322                                          log.warn("Empty sdt!" );                                                 
    323                                          continue;                                        
    324                                  } 
    325                                   
    326                          } else { 
    327                                  // What? 
     297                        if (o instanceof org.docx4j.wml.Tr) { 
     298                                startRow(); 
     299                                tr = (org.docx4j.wml.Tr) o; 
     300                                handleRow(cellContents, tr, r); 
     301                                r++; 
     302                        } else if (o instanceof javax.xml.bind.JAXBElement 
     303                                        && ((JAXBElement) o).getDeclaredType().getName().equals( 
     304                                                        "org.docx4j.wml.Tr")) { 
     305                                startRow(); 
     306                                tr = (org.docx4j.wml.Tr) ((JAXBElement) o).getValue(); 
     307                                handleRow(cellContents, tr, r); 
     308                                r++; 
     309                        } else if (o instanceof javax.xml.bind.JAXBElement 
     310                                        && ((JAXBElement) o).getDeclaredType().getName().equals( 
     311                                                        "org.docx4j.wml.CTSdtRow")) { 
     312 
     313                                CTSdtRow sdt = (org.docx4j.wml.CTSdtRow) ((JAXBElement) o).getValue(); 
     314 
     315                                for (Object content0 : sdt.getSdtContent().getEGContentRowContent()) { 
     316 
     317                                        if (content0 instanceof org.docx4j.wml.Tr) { 
     318                                                startRow(); 
     319                                                tr = (org.docx4j.wml.Tr) content0; 
     320                                                handleRow(cellContents, tr, r); 
     321                                                r++; 
     322                                        } else { 
     323                                                log.warn("Unexpected " + content0.getClass().getName()); 
     324                                        } 
     325                                } 
     326 
     327                        } else { 
     328                                // What? 
    328329                                if (o instanceof javax.xml.bind.JAXBElement) { 
    329330                                        if (((JAXBElement) o).getDeclaredType().getName().equals( 
     
    331332                                                // Ignore w:bookmarkEnd 
    332333                                        } else { 
    333                                                 log.warn("TODO - skipping JAXBElement:  " 
     334                                                log 
     335                                                                .warn("TODO - skipping JAXBElement:  " 
    334336                                                                                + ((JAXBElement) o).getDeclaredType() 
    335337                                                                                                .getName()); 
     
    341343                                } 
    342344                                continue; 
    343                          }                       
    344                          
    345                         if (borderConflictResolutionRequired && tr.getTblPrEx()!=null 
    346                                         && tr.getTblPrEx().getTblCellSpacing()!=null) { 
    347                                 borderConflictResolutionRequired = false;                                
    348345                        } 
    349                         List<Object> cells = tr.getEGContentCellContent(); 
    350                         int c = 0; 
    351                         for (Object o2 : cells) { 
    352  
    353                                 Tc tc = null; 
    354                                  if (o2 instanceof org.docx4j.wml.Tc) {                           
    355                                          tc = (org.docx4j.wml.Tc)o2;             
    356                                  } else if (o2 instanceof javax.xml.bind.JAXBElement 
    357                                                  && ((JAXBElement)o2).getDeclaredType().getName().equals("org.docx4j.wml.Tc")) { 
    358                                          tc = (org.docx4j.wml.Tc)((JAXBElement)o2).getValue(); 
    359                                  } else if (o2 instanceof javax.xml.bind.JAXBElement 
    360                                                  && ((JAXBElement)o2).getDeclaredType().getName().equals("org.docx4j.wml.CTSdtCell")) { 
    361                                          org.docx4j.wml.CTSdtCell sdtCell = (org.docx4j.wml.CTSdtCell)((JAXBElement)o2).getValue(); 
    362                                          Object o3 = sdtCell.getSdtContent().getEGContentCellContent().get(0); 
    363                                          if (o3 instanceof javax.xml.bind.JAXBElement 
    364                                                          && ((JAXBElement)o3).getDeclaredType().getName().equals("org.docx4j.wml.Tc")) { 
    365                                                  tc =(org.docx4j.wml.Tc)((JAXBElement)o3).getValue(); 
    366                                          } else { 
    367                                                  if (o3 instanceof javax.xml.bind.JAXBElement) { 
    368                                                          log.warn("TODO - skipping JAXBElement:  " + ((JAXBElement)o3).getDeclaredType().getName() ); 
    369                                                  } else { 
    370                                                          log.warn("TODO - skipping:  " + o3.getClass().getName() ); 
    371                                                  } 
    372                                          } 
    373                                          if (sdtCell.getSdtContent().getEGContentCellContent().size()>1)  
    374                                                  log.warn("w:sdtContent contains more than 1 cell. TODO"); 
    375                                  } else { 
    376                                          // What? 
    377                                          if (o2 instanceof javax.xml.bind.JAXBElement) { 
    378                                                  log.warn("TODO - skipping JAXBElement:  " + ((JAXBElement)o2).getDeclaredType().getName() ); 
    379                                          } else { 
    380                                                  log.warn("TODO - skipping:  " + o2.getClass().getName() ); 
    381                                          } 
    382                                          log.debug( XmlUtils.marshaltoString(o2, true)); 
    383                                          continue; 
    384                                  } 
    385                                  
    386                                 Node wtrNode = cellContents.item(r); //w:tr 
    387                                 addCell(tc, wtrNode.getChildNodes().item(c)); 
    388                                 // addCell(tc, cellContents.item(i)); 
    389                                 // i++; 
    390                                 c++; 
    391  
     346 
     347                } 
     348        } 
     349 
     350        private void handleRow(NodeList cellContents, Tr tr, int r) { 
     351 
     352                if (borderConflictResolutionRequired && tr.getTblPrEx() != null 
     353                                && tr.getTblPrEx().getTblCellSpacing() != null) { 
     354                        borderConflictResolutionRequired = false; 
     355                } 
     356                List<Object> cells = tr.getEGContentCellContent(); 
     357                int c = 0; 
     358                for (Object o2 : cells) { 
     359 
     360                        Tc tc = null; 
     361                        if (o2 instanceof org.docx4j.wml.Tc) { 
     362                                tc = (org.docx4j.wml.Tc) o2; 
     363                        } else if (o2 instanceof javax.xml.bind.JAXBElement 
     364                                        && ((JAXBElement) o2).getDeclaredType().getName().equals( 
     365                                                        "org.docx4j.wml.Tc")) { 
     366                                tc = (org.docx4j.wml.Tc) ((JAXBElement) o2).getValue(); 
     367                        } else if (o2 instanceof javax.xml.bind.JAXBElement 
     368                                        && ((JAXBElement) o2).getDeclaredType().getName().equals( 
     369                                                        "org.docx4j.wml.CTSdtCell")) { 
     370                                org.docx4j.wml.CTSdtCell sdtCell = (org.docx4j.wml.CTSdtCell) ((JAXBElement) o2) 
     371                                                .getValue(); 
     372                                Object o3 = sdtCell.getSdtContent().getEGContentCellContent() 
     373                                                .get(0); 
     374                                if (o3 instanceof javax.xml.bind.JAXBElement 
     375                                                && ((JAXBElement) o3).getDeclaredType().getName() 
     376                                                                .equals("org.docx4j.wml.Tc")) { 
     377                                        tc = (org.docx4j.wml.Tc) ((JAXBElement) o3).getValue(); 
     378                                } else { 
     379                                        if (o3 instanceof javax.xml.bind.JAXBElement) { 
     380                                                log.warn("TODO - skipping JAXBElement:  " 
     381                                                                + ((JAXBElement) o3).getDeclaredType() 
     382                                                                                .getName()); 
     383                                        } else { 
     384                                                log 
     385                                                                .warn("TODO - skipping:  " 
     386                                                                                + o3.getClass().getName()); 
     387                                        } 
     388                                } 
     389                                if (sdtCell.getSdtContent().getEGContentCellContent().size() > 1) 
     390                                        log.warn("w:sdtContent contains more than 1 cell. TODO"); 
     391                        } else { 
     392                                // What? 
     393                                if (o2 instanceof javax.xml.bind.JAXBElement) { 
     394                                        log.warn("TODO - skipping JAXBElement:  " 
     395                                                        + ((JAXBElement) o2).getDeclaredType().getName()); 
     396                                } else { 
     397                                        log.warn("TODO - skipping:  " + o2.getClass().getName()); 
     398                                } 
     399                                log.debug(XmlUtils.marshaltoString(o2, true)); 
     400                                continue; 
    392401                        } 
    393                         r++; 
    394                 } 
     402 
     403                        Node wtrNode = cellContents.item(r); // w:tr 
     404                        addCell(tc, wtrNode.getChildNodes().item(c)); 
     405                        // addCell(tc, cellContents.item(i)); 
     406                        // i++; 
     407                        c++; 
     408                } 
     409 
    395410        } 
    396411 
Note: See TracChangeset for help on using the changeset viewer.