Changeset 1086


Ignore:
Timestamp:
02/26/10 13:02:07 (2 years ago)
Author:
jharrop
Message:

Tidy up XSLT to JAXB object creation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/pptx4j/java/org/pptx4j/convert/out/svginhtml/SvgExporter.java

    r1085 r1086  
    2525import org.docx4j.dml.CTTextParagraphProperties; 
    2626import org.docx4j.dml.CTTransform2D; 
     27import org.docx4j.dml.wordprocessingDrawing.Inline; 
    2728import org.docx4j.jaxb.Context; 
    2829import org.docx4j.model.styles.StyleTree; 
    2930import org.docx4j.model.styles.Tree; 
    3031import org.docx4j.model.styles.StyleTree.AugmentedStyle; 
     32import org.docx4j.openpackaging.exceptions.Docx4JException; 
    3133import org.docx4j.openpackaging.exceptions.InvalidFormatException; 
    3234import org.docx4j.openpackaging.packages.PresentationMLPackage; 
    3335import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
    3436import org.docx4j.wml.PPr; 
     37import org.docx4j.wml.Pict; 
    3538import org.docx4j.wml.Style; 
    3639import org.plutext.jaxb.svg11.Line; 
     
    4952import org.w3c.dom.Node; 
    5053import org.w3c.dom.NodeList; 
     54import org.w3c.dom.Text; 
    5155import org.w3c.dom.traversal.NodeIterator; 
    5256 
     
    355359                NodeIterator shapeIt ) { 
    356360         
     361        DocumentFragment docfrag=null; 
     362        Document d=null; 
     363         
    357364        try { 
    358                 Object shape = null; 
    359                  
     365                Object shape = null;                     
    360366                if (shapeIt!=null) { 
    361367                        Node n = shapeIt.nextNode(); 
    362                          
    363                         log.debug(n.getClass().getName()); 
    364 //                      cxnSp 
    365 //                      System.out.println(n.getLocalName()); 
    366 //                      p:cxnSp 
    367 //                      System.out.println(n.getNodeName()); 
    368                          
    369                         String str = XmlUtils.w3CDomNodeToString(n); 
    370                         System.out.println("STRING-->" + str); 
    371                         if (str.equals("")) { 
    372                                  
    373                         } else if (str.startsWith("<p:cxnSp") ){ 
    374                                 shape = XmlUtils.unmarshalString(str, Context.jcPML, CxnSp.class); 
    375                                 Document d = CxnSpToSVG( (CxnSp)shape); 
    376                                  
    377                                 // Machinery 
    378                                 DocumentFragment docfrag = d.createDocumentFragment(); 
    379                                 docfrag.appendChild(d.getDocumentElement()); 
    380                                 return docfrag; 
    381                         } 
    382                          
    383                         log.info("** GOT " + shape.getClass().getName() ); 
    384                         if (shape instanceof JAXBElement) { 
    385                                 log.info( 
    386                                                 XmlUtils.JAXBElementDebug( (JAXBElement)shape) 
    387                                         ); 
     368                        if (n==null) { 
     369                                d=makeErr( "[null node?!]" ); 
     370                        } else { 
     371                                log.debug("Handling " + n.getNodeName()); 
     372                                 
     373                                if (n.getNodeName().equals("p:cxnSp") ) { 
     374                                         
     375                                        shape = nodeToObjectModel(n, CxnSp.class);                               
     376                                        d = CxnSpToSVG( (CxnSp)shape); 
     377                                         
     378                                } else {                         
     379                                        log.info("** TODO " + n.getNodeName() ); 
     380                                        d=makeErr( "[" + n.getNodeName() + "]" ); 
     381                                } 
    388382                        } 
    389383                } 
    390384        } catch (Exception e) { 
    391                 // TODO Auto-generated catch block 
    392                 e.printStackTrace(); 
    393         }  
    394         return null; 
    395          
     385                        log.error(e); 
     386                        d=makeErr(e.getMessage() ); 
     387                } 
     388         
     389                // Machinery 
     390                docfrag = d.createDocumentFragment(); 
     391                docfrag.appendChild(d.getDocumentElement()); 
     392                return docfrag;          
    396393    } 
    397394     
    398395     
     396    /** 
     397     * Connection (line) 
     398     */ 
    399399    public static Document CxnSpToSVG(CxnSp cxnSp) { 
    400          
    401400         
    402401        // Geometrical transforms 
     
    423422                // Firefox needs the following; Chrome doesn't 
    424423                xhtmlDiv.setAttribute("style",  
    425                                 "position: absolute; width:100%; height:100%; left:0px; top:0px;"); 
    426                  
     424                                "position: absolute; width:100%; height:100%; left:0px; top:0px;");              
    427425                Node n = document.appendChild(xhtmlDiv); 
    428                 // TODO - set style 
    429426         
    430427        // Convert the object itself to SVG 
     
    449446        return document; 
    450447         
     448    } 
     449 
     450    private static Document makeErr(String msg) { 
     451        Document d=null; 
     452        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();         
     453                 try { 
     454                        d = factory.newDocumentBuilder().newDocument(); 
     455                } catch (ParserConfigurationException e1) { 
     456                        // TODO Auto-generated catch block 
     457                        e1.printStackTrace(); 
     458                } 
     459                Element span = d.createElement("span"); 
     460                span.setAttribute("style", "color:red;"); 
     461                d.appendChild(span); 
     462                 
     463                Text err = d.createTextNode( msg ); 
     464                span.appendChild(err); 
     465                return d; 
     466    } 
     467 
     468    public static Object nodeToObjectModel(Node n, Class declaredType) throws Docx4JException { 
     469                Object jaxb=null; 
     470                try { 
     471                        jaxb = XmlUtils.unmarshal(n, Context.jcPML, declaredType);  
     472                } catch (JAXBException e1) { 
     473                        throw new Docx4JException("Couldn't unmarshall " + XmlUtils.w3CDomNodeToString(n), e1); 
     474                } 
     475                try { 
     476                        if (jaxb instanceof JAXBElement ) { 
     477                                 
     478                                JAXBElement jb = (JAXBElement)jaxb; 
     479                                if (jb.getDeclaredType().getName().equals(declaredType.getName() )) { 
     480                                        return jb.getValue(); 
     481                                } else { 
     482                                log.error("UNEXPECTED " + 
     483                                                XmlUtils.JAXBElementDebug(jb) 
     484                                                ); 
     485                                throw new Docx4JException("Expected " + declaredType.getName() + " but got " + 
     486                                                XmlUtils.JAXBElementDebug(jb) ); 
     487                                } 
     488                        } else if (jaxb.getClass().getName().equals(declaredType.getName() )) {                                  
     489                                return jaxb; 
     490                        } else { 
     491                                log.error( jaxb.getClass().getName() );  
     492                                throw new Docx4JException("Expected " + declaredType.getName() + " but got " + 
     493                                                jaxb.getClass().getName() ); 
     494                        } 
     495                } catch (ClassCastException e) { 
     496                        throw new Docx4JException("Expected " + declaredType.getName() + " but got " + 
     497                                        jaxb.getClass().getName(), e ); 
     498                }                                                        
    451499    } 
    452500     
Note: See TracChangeset for help on using the changeset viewer.