Changeset 1555


Ignore:
Timestamp:
06/22/11 01:36:38 (11 months ago)
Author:
jharrop
Message:

Apply Dave Brown's "assorted patches" of 28 April, as described at
 http://dev.plutext.org/forums/docx-java-f6/assorted-patches-t712.html

Location:
trunk/docx4j/src/main/java/org/docx4j
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/XmlUtils.java

    r1367 r1555  
    5959 
    6060import org.apache.log4j.Logger; 
     61import org.apache.xalan.trace.PrintTraceListener; 
     62import org.apache.xalan.trace.TraceManager; 
     63import org.apache.xalan.transformer.TransformerImpl; 
    6164import org.docx4j.jaxb.Context; 
    6265import org.docx4j.jaxb.NamespacePrefixMapperUtils; 
     
    8184        // TRANSFORMER_FACTORY_PROCESSOR_SUN .. JDK/JRE does not include anything like com.sun.org.apache.xalan.TransformerFactoryImpl 
    8285         
    83         //public static String TRANSFORMER_FACTORY_SAXON = "net.sf.saxon.TransformerFactoryImpl"; 
     86//      public static String TRANSFORMER_FACTORY_SAXON = "net.sf.saxon.TransformerFactoryImpl"; 
    8487 
    8588        // *.xsltc.trax.TransformerImpl don't 
     
    126129                        System.setProperty("javax.xml.transform.TransformerFactory", 
    127130                                        TRANSFORMER_FACTORY_PROCESSOR_XALAN); 
     131//                                      TRANSFORMER_FACTORY_SAXON); 
    128132                         
    129133                        tfactory = javax.xml.transform.TransformerFactory 
     
    703707        return tfactory.newTemplates(xsltSource); 
    704708    }     
    705      
     709 
    706710    /** 
    707711     *  
     
    762766                } 
    763767 
     768        /* SUPER DEBUGGING 
     769            // http://xml.apache.org/xalan-j/usagepatterns.html#debugging 
     770            // debugging 
     771            // Set up a PrintTraceListener object to print to a file. 
     772            java.io.FileWriter fw = new java.io.FileWriter("/tmp/xslt-events" + xsltCount++ + ".log"); 
     773            java.io.PrintWriter pw = new java.io.PrintWriter(fw); 
     774            PrintTraceListener ptl = new PrintTraceListener(pw); 
     775 
     776            // Print information as each node is 'executed' in the stylesheet. 
     777            ptl.m_traceElements = true; 
     778            // Print information after each result-tree generation event. 
     779            ptl.m_traceGeneration = true; 
     780            // Print information after each selection event. 
     781            ptl.m_traceSelection = true; 
     782            // Print information whenever a template is invoked. 
     783            ptl.m_traceTemplates = true; 
     784            // Print information whenever an extension is called. 
     785            ptl.m_traceExtension = true; 
     786            TransformerImpl transformerImpl = (TransformerImpl)xformer; 
     787 
     788              // Register the TraceListener with the TraceManager associated 
     789              // with the TransformerImpl. 
     790              TraceManager trMgr = transformerImpl.getTraceManager(); 
     791              trMgr.addTraceListener(ptl); 
     792 
     793*/ 
    764794                // DEBUGGING 
    765795                // use the identity transform if you want to send wordDocument; 
    766796                // otherwise you'll get the XHTML 
    767797                // javax.xml.transform.Transformer xformer = tfactory.newTransformer(); 
    768  
    769                 xformer.transform(source, result); 
     798        try { 
     799            xformer.transform(source, result); 
     800        } finally { 
     801            //pw.flush(); 
     802        } 
    770803         
    771804    } 
     
    832865        } catch (XPathExpressionException e) { 
    833866            e.printStackTrace(); 
    834             return Collections.emptyList(); 
     867            throw new RuntimeException(e); 
    835868        } 
    836869    }    
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/html/docx2xhtmlNG2.xslt

    r1450 r1555  
    7979                                        /*font definitions*/ 
    8080 
    81                                         /*element styles*/ del 
     81                                        /*element styles*/ .del 
    8282                                        {text-decoration:line-through;color:red;} 
    8383                                        <xsl:choose> 
    8484                                                <xsl:when test="/w:document/w:settings/w:trackRevisions"> 
    85                                                         ins 
    86                                                         {text-decoration:underline;color:teal;} 
     85                                                  .ins {text-decoration:none;background:#c0ffc0;padding:1px;} 
    8786                                                </xsl:when> 
    8887                                                <xsl:otherwise> 
    89                                                         ins {text-decoration:none;} 
     88                                                  .ins {text-decoration:none;background:#c0ffc0;padding:1px;} 
    9089                                                </xsl:otherwise> 
    9190                                        </xsl:choose> 
     
    592591 
    593592  <xsl:template match="w:ins"> 
    594         <span style="color:blue; text-decoration:underline"> 
     593        <span class="ins"> 
    595594                <xsl:apply-templates/> 
    596595        </span> 
     
    602601 
    603602  <xsl:template match="w:delText"> 
    604         <span style="color:red; text-decoration:line-through"> 
     603        <span class="del"> 
    605604                <xsl:apply-templates/> 
    606605        </span> 
  • trunk/docx4j/src/main/java/org/docx4j/dml/CTBlip.java

    r1201 r1555  
    2222package org.docx4j.dml; 
    2323 
     24import org.jvnet.jaxb2_commons.ppp.Child; 
     25 
    2426import java.util.ArrayList; 
    2527import java.util.List; 
    26 import javax.xml.bind.annotation.XmlAccessType; 
    27 import javax.xml.bind.annotation.XmlAccessorType; 
    28 import javax.xml.bind.annotation.XmlAttribute; 
    29 import javax.xml.bind.annotation.XmlElement; 
    30 import javax.xml.bind.annotation.XmlElements; 
    31 import javax.xml.bind.annotation.XmlType; 
     28import javax.xml.bind.Unmarshaller; 
     29import javax.xml.bind.annotation.*; 
    3230 
    3331 
     
    7775    "extLst" 
    7876}) 
    79 public class CTBlip { 
     77public class CTBlip implements Child { 
    8078 
    8179    @XmlElements({ 
     
    106104    @XmlAttribute(namespace = "http://schemas.openxmlformats.org/officeDocument/2006/relationships") 
    107105    protected String link; 
     106    @XmlTransient 
     107    private Object parent; 
    108108 
    109109    /** 
     
    259259        this.link = value; 
    260260    } 
    261  
     261   /** 
     262     * Gets the parent object in the object tree representing the unmarshalled xml document. 
     263     * 
     264     * @return 
     265     *     The parent object. 
     266     */ 
     267    public Object getParent() { 
     268        return this.parent; 
     269    } 
     270 
     271    public void setParent(Object parent) { 
     272        this.parent = parent; 
     273    } 
     274 
     275    /** 
     276     * This method is invoked by the JAXB implementation on each instance when unmarshalling completes. 
     277     * 
     278     * @param parent 
     279     *     The parent object in the object tree. 
     280     * @param unmarshaller 
     281     *     The unmarshaller that generated the instance. 
     282     */ 
     283    public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { 
     284        setParent(parent); 
     285    } 
    262286} 
  • trunk/docx4j/src/main/java/org/docx4j/dml/wordprocessingDrawing/Anchor.java

    r1041 r1555  
    2222package org.docx4j.dml.wordprocessingDrawing; 
    2323 
    24 import javax.xml.bind.annotation.XmlAccessType; 
    25 import javax.xml.bind.annotation.XmlAccessorType; 
    26 import javax.xml.bind.annotation.XmlAttribute; 
    27 import javax.xml.bind.annotation.XmlElement; 
    28 import javax.xml.bind.annotation.XmlSchemaType; 
    29 import javax.xml.bind.annotation.XmlType; 
     24import javax.xml.bind.Unmarshaller; 
     25import javax.xml.bind.annotation.*; 
     26 
    3027import org.docx4j.dml.CTNonVisualDrawingProps; 
    3128import org.docx4j.dml.CTNonVisualGraphicFrameProperties; 
     
    3330import org.docx4j.dml.CTPositiveSize2D; 
    3431import org.docx4j.dml.Graphic; 
     32import org.jvnet.jaxb2_commons.ppp.Child; 
    3533 
    3634 
     
    8987    "graphic" 
    9088}) 
    91 public class Anchor { 
     89public class Anchor implements Child { 
    9290 
    9391    @XmlElement(required = true) 
     
    133131    @XmlAttribute(required = true) 
    134132    protected boolean allowOverlap; 
    135  
     133    @XmlTransient 
     134    private Object parent; 
    136135    /** 
    137136     * Gets the value of the simplePos property. 
     
    670669    } 
    671670 
     671   /** 
     672     * Gets the parent object in the object tree representing the unmarshalled xml document. 
     673     * 
     674     * @return 
     675     *     The parent object. 
     676     */ 
     677    public Object getParent() { 
     678        return this.parent; 
     679    } 
     680 
     681    public void setParent(Object parent) { 
     682        this.parent = parent; 
     683    } 
     684 
     685    /** 
     686     * This method is invoked by the JAXB implementation on each instance when unmarshalling completes. 
     687     * 
     688     * @param parent 
     689     *     The parent object in the object tree. 
     690     * @param unmarshaller 
     691     *     The unmarshaller that generated the instance. 
     692     */ 
     693    public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { 
     694        setParent(parent); 
     695    } 
    672696} 
  • trunk/docx4j/src/main/java/org/docx4j/dml/wordprocessingDrawing/Inline.java

    r1041 r1555  
    2222package org.docx4j.dml.wordprocessingDrawing; 
    2323 
    24 import javax.xml.bind.annotation.XmlAccessType; 
    25 import javax.xml.bind.annotation.XmlAccessorType; 
    26 import javax.xml.bind.annotation.XmlAttribute; 
    27 import javax.xml.bind.annotation.XmlElement; 
    28 import javax.xml.bind.annotation.XmlType; 
     24import javax.xml.bind.Unmarshaller; 
     25import javax.xml.bind.annotation.*; 
     26 
    2927import org.docx4j.dml.CTNonVisualDrawingProps; 
    3028import org.docx4j.dml.CTNonVisualGraphicFrameProperties; 
    3129import org.docx4j.dml.CTPositiveSize2D; 
    3230import org.docx4j.dml.Graphic; 
     31import org.jvnet.jaxb2_commons.ppp.Child; 
    3332 
    3433 
     
    6867    "graphic" 
    6968}) 
    70 public class Inline { 
     69public class Inline implements Child { 
    7170 
    7271    @XmlElement(required = true) 
     
    8685    @XmlAttribute 
    8786    protected Long distR; 
    88  
     87    @XmlTransient 
     88    private Object parent; 
    8989    /** 
    9090     * Gets the value of the extent property. 
     
    302302        this.distR = value; 
    303303    } 
    304  
     304    /** 
     305     * Gets the parent object in the object tree representing the unmarshalled xml document. 
     306     * 
     307     * @return 
     308     *     The parent object. 
     309     */ 
     310    public Object getParent() { 
     311        return this.parent; 
     312    } 
     313 
     314    public void setParent(Object parent) { 
     315        this.parent = parent; 
     316    } 
     317 
     318    /** 
     319     * This method is invoked by the JAXB implementation on each instance when unmarshalling completes. 
     320     * 
     321     * @param parent 
     322     *     The parent object in the object tree. 
     323     * @param unmarshaller 
     324     *     The unmarshaller that generated the instance. 
     325     */ 
     326    public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { 
     327        setParent(parent); 
     328    } 
    305329} 
  • trunk/docx4j/src/main/java/org/docx4j/fonts/IdentityPlusMapper.java

    r995 r1555  
    5959                 
    6060                if (System.getProperty("os.name").toLowerCase().indexOf("windows")<0) { 
    61                         log.error("WARNING! SubstituterWindowsPlatformImpl works best " + 
     61                        log.warn("WARNING! SubstituterWindowsPlatformImpl works best " + 
    6262                                        "on Windows.  To get good results on other platforms, you'll probably  " + 
    6363                                        "need to have installed Windows fonts."); 
  • trunk/docx4j/src/main/java/org/docx4j/fonts/PhysicalFonts.java

    r1383 r1555  
    160160                        // Quite a few fonts exist that we can't seem to get 
    161161                        // EmbedFontInfo for. To be investigated. 
    162                         log.error("Aborting: " + fontUrl.toString() +  " (can't get EmbedFontInfo[] .. try deleting fop-fonts.cache?)"); 
     162                        log.warn("Aborting: " + fontUrl.toString() +  " (can't get EmbedFontInfo[] .. try deleting fop-fonts.cache?)"); 
    163163                        return; 
    164164                } 
  • trunk/docx4j/src/main/java/org/docx4j/model/properties/PropertyFactory.java

    r1398 r1555  
    403403                                if (wmlPackage instanceof WordprocessingMLPackage) { 
    404404                                        NumberingDefinitionsPart ndp = ((WordprocessingMLPackage)wmlPackage).getMainDocumentPart().getNumberingDefinitionsPart(); 
     405                    if (ndp != null) { 
    405406                                        ind = ndp.getInd(pPr.getNumPr()); 
    406407                                        if (ind!=null) { 
     
    408409                                                log.debug("Using w:ind from list level"); 
    409410                                        } 
     411                    } 
    410412                                } 
    411413                        } 
  • trunk/docx4j/src/main/java/org/docx4j/model/properties/run/Font.java

    r1056 r1555  
    5757                        return composeCss(CSS_NAME, font ); 
    5858                } else { 
    59                         log.error("No mapping from " + font); 
     59                        log.warn("No mapping from " + font); 
    6060                        return CSS_NULL; 
    6161                } 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipNG.java

    r1493 r1555  
    425425                String relationshipType = r.getType();           
    426426                         
    427                 Part part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); 
     427                Part part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); // will throw exception if null 
     428 
    428429                if (part instanceof BinaryPart 
    429430                                || part instanceof DefaultXmlPart) { 
     
    492493         * @see  To get a Part and all its related parts, and add all to a package, use 
    493494         * getPart. 
    494          * @param zf 
     495         * @param partByteArrays 
     496         * @param ctm 
    495497         * @param resolvedPartUri 
     498         * @param rel 
    496499         * @return 
    497          * @throws URISyntaxException 
    498          * @throws InvalidFormatException 
     500         * @throws Docx4JException including if result is null 
    499501         */ 
    500         //public static Part getRawPart(ZipFile zf, ContentTypeManager ctm, String resolvedPartUri) 
    501502        public static Part getRawPart(HashMap<String, ByteArray> partByteArrays, 
    502503                        ContentTypeManager ctm, String resolvedPartUri, Relationship rel)        
     
    617618                                } else if (part instanceof org.docx4j.openpackaging.parts.XmlPart ) { 
    618619                                         
    619                                         try { 
     620//                                      try { 
    620621                                                ((XmlPart)part).setDocument(is); 
    621                                         } catch (Docx4JException d) { 
    622                                                 // This isn't an XML part after all, 
    623                                                 // even though ContentTypeManager detected it as such 
    624                                                 // So get it as a binary part 
    625                                                 part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 
    626                                                 log.warn("Could not parse as XML, so using BinaryPart for "  
    627                                                                 + resolvedPartUri);                                              
    628                                                 ((BinaryPart)part).setBinaryData(is); 
    629                                         } 
     622                                                 
     623                                        // Experimental 22/6/2011; don't fall back to binary (which we used to)  
     624                                                 
     625//                                      } catch (Docx4JException d) { 
     626//                                              // This isn't an XML part after all, 
     627//                                              // even though ContentTypeManager detected it as such 
     628//                                              // So get it as a binary part 
     629//                                              part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 
     630//                                              log.warn("Could not parse as XML, so using BinaryPart for "  
     631//                                                              + resolvedPartUri);                                              
     632//                                              ((BinaryPart)part).setBinaryData(is); 
     633//                                      } 
    630634                                         
    631635                                } else { 
     
    639643                         
    640644                        } catch (PartUnrecognisedException e) { 
    641                                 log.warn("PartUnrecognisedException shouldn't happen anymore!"); 
     645                                log.error("PartUnrecognisedException shouldn't happen anymore!", e); 
    642646                                // Try to get it as a binary part 
    643647                                part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 
     
    660664                        } 
    661665                } 
     666                 
     667        if (part == null) { 
     668            throw new Docx4JException("cannot find part " + resolvedPartUri + " from rel "+ rel.getId() + "=" + rel.getTarget()); 
     669        } 
     670                 
    662671                return part; 
    663672        } 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/XmlPart.java

    r1399 r1555  
    7070                super(); 
    7171        } 
    72          
     72 
    7373        /** 
    7474         * This part's XML contents.  Not guaranteed to be up to date. 
     
    8080        private static XPathFactory xPathFactory; 
    8181        private static XPath xPath; 
    82          
     82 
    8383        private static DocumentBuilderFactory documentFactory; 
    84         private static DocumentBuilder documentBuilder; 
     84 
    8585         
    8686        static { 
     
    109109                 
    110110                documentFactory.setNamespaceAware(true); 
    111                 try { 
    112                         documentBuilder = documentFactory.newDocumentBuilder(); 
    113                 } catch (ParserConfigurationException e) { 
    114                         e.printStackTrace(); 
    115                 }                
    116                  
     111 
    117112        } 
    118113         
     
    129124        public void setDocument(InputStream is) throws Docx4JException { 
    130125                try { 
    131                         doc = documentBuilder.parse(is); 
     126            DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder(); // DocumentBuilder is not thread safe, so it needs to be local  
     127            doc = documentBuilder.parse(is); 
    132128                } catch (Exception e) { 
    133129                        throw new Docx4JException("Problems parsing InputStream for part " + this.partName.getName(), e); 
Note: See TracChangeset for help on using the changeset viewer.