Changeset 530

Show
Ignore:
Timestamp:
08/12/08 05:55:50 (3 months ago)
Author:
jharrop
Message:

Now a JaxbXmlPart?

Files:
1 modified

Legend:

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

    r301 r530  
    2121package org.docx4j.openpackaging.parts.WordprocessingML; 
    2222 
     23import javax.xml.bind.JAXBException; 
     24import javax.xml.bind.Unmarshaller; 
     25 
    2326import org.docx4j.openpackaging.exceptions.InvalidFormatException; 
    24 import org.docx4j.openpackaging.parts.Dom4jXmlPart; 
    2527import org.docx4j.openpackaging.parts.Part; 
    2628import org.docx4j.openpackaging.parts.PartName; 
    2729import org.docx4j.openpackaging.parts.relationships.Namespaces; 
    2830 
    29 import org.dom4j.Document; 
     31import org.docx4j.openpackaging.parts.JaxbXmlPart; 
    3032 
    3133 
    3234 
    33 public final class CommentsPart extends Dom4jXmlPart { 
     35public final class CommentsPart extends JaxbXmlPart { 
    3436         
    3537        public CommentsPart(PartName partName) throws InvalidFormatException { 
    3638                super(partName); 
    37                  
     39                init(); 
     40        } 
     41 
     42        public CommentsPart() throws InvalidFormatException { 
     43                super(new PartName("/word/comments.xml")); 
     44                init(); 
     45        } 
     46         
     47        public void init() {             
    3848                // Used if this Part is added to [Content_Types].xml  
    3949                setContentType(new  org.docx4j.openpackaging.contenttype.ContentType(  
     
    4555        } 
    4656 
    47         @Override 
    48         public Document getDocument() { 
    49                 return document; 
    50         }        
    51          
     57    /** 
     58     * Unmarshal XML data from the specified InputStream and return the  
     59     * resulting content tree.  Validation event location information may 
     60     * be incomplete when using this form of the unmarshal API. 
     61     * 
     62     * <p> 
     63     * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>. 
     64     *  
     65     * @param is the InputStream to unmarshal XML data from 
     66     * @return the newly created root object of the java content tree  
     67     * 
     68     * @throws JAXBException  
     69     *     If any unexpected errors occur while unmarshalling 
     70     */ 
     71    public Object unmarshal( java.io.InputStream is ) throws JAXBException { 
     72         
     73                try { 
     74                         
     75//                      if (jc==null) { 
     76//                              setJAXBContext(Context.jc);                              
     77//                      } 
     78                                     
     79                        Unmarshaller u = jc.createUnmarshaller(); 
     80                         
     81                        //u.setSchema(org.docx4j.jaxb.WmlSchema.schema); 
     82                        u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); 
     83 
     84                        System.out.println("unmarshalling " + this.getClass().getName() + " \n\n" );                                                                     
     85                                                 
     86                        jaxbElement = u.unmarshal( is ); 
     87                         
     88                         
     89                        System.out.println("\n\n" + this.getClass().getName() + " unmarshalled \n\n" );                                                                  
     90 
     91                } catch (Exception e ) { 
     92                        e.printStackTrace(); 
     93                } 
     94         
     95                return jaxbElement; 
     96         
     97    }    
    5298}