Changeset 1647 for trunk/docx4j/src/main/java
- Timestamp:
- 08/30/11 15:53:03 (9 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j/model/datastorage
- Files:
-
- 3 edited
-
BindingHandler.java (modified) (5 diffs)
-
OpenDoPEHandler.java (modified) (1 diff)
-
RemovalHandler.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/model/datastorage/BindingHandler.java
r1645 r1647 9 9 import javax.xml.bind.JAXBException; 10 10 import javax.xml.bind.Unmarshaller; 11 import javax.xml.parsers.DocumentBuilderFactory;12 11 import javax.xml.transform.Source; 13 12 import javax.xml.transform.Templates; … … 23 22 import org.docx4j.dml.wordprocessingDrawing.Inline; 24 23 import org.docx4j.jaxb.Context; 25 import org.docx4j.jaxb.NamespacePrefixMappings;26 24 import org.docx4j.openpackaging.exceptions.Docx4JException; 27 25 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 28 26 import org.docx4j.openpackaging.parts.CustomXmlDataStoragePart; 29 import org.docx4j.openpackaging.parts.DefaultXmlPart;30 27 import org.docx4j.openpackaging.parts.JaxbXmlPart; 31 import org.docx4j.openpackaging.parts.XmlPart;32 28 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; 29 import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; 30 import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; 33 31 import org.docx4j.openpackaging.parts.relationships.Namespaces; 34 import org.docx4j.wml.CTSimpleField; 32 import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 33 import org.docx4j.relationships.Relationship; 34 import org.docx4j.wml.P.Hyperlink; 35 35 import org.docx4j.wml.RPr; 36 import org.docx4j.wml.P.Hyperlink;37 36 import org.w3c.dom.Document; 38 37 import org.w3c.dom.DocumentFragment; … … 62 61 xPath = xPathFactory.newXPath(); 63 62 } 63 64 65 /** 66 * Configure, how the handler handles links found in Custom XML. 67 * 68 * If set to <code>null</code>, strings containing 'http://' 69 * are not converted to w:hyperlink. This is the default behavior. 70 * 71 * If set to <code>true</code>, strings containing 'http://' 72 * are converted to w:hyperlink. If you do this, you will 73 * need to post-process with RemovalHandler, since a 74 * content control with SdtPr w:dataBinding and w:text 75 * which contains a w:hyperlink will prevent Word 2007 from 76 * opening the docx. 77 * 78 * Due to the architecture of this class, this is a static flag changing the 79 * behavior of all following calls to {@link #applyBindings}. 80 * 81 * @param hyperlinkStyle 82 * The style to use for hyperlinks (eg Hyperlink) 83 */ 84 public static void setHyperlinkStyle ( 85 String hyperlinkStyleID) { 86 hyperlinkStyleId = hyperlinkStyleID; 87 } 88 private static String hyperlinkStyleId = null; 64 89 65 90 … … 84 109 */ 85 110 111 public static void applyBindings(WordprocessingMLPackage wordMLPackage) throws Docx4JException { 112 113 // A component can apply in both the main document part, 114 // and in headers/footers. See further 115 // http://forums.opendope.org/Support-components-in-headers-footers-tp2964174p2964174.html 116 117 if (hyperlinkStyleId !=null 118 && wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId)) { 119 } 120 121 applyBindings(wordMLPackage.getMainDocumentPart()); 122 123 // Add headers/footers 124 RelationshipsPart rp = wordMLPackage.getMainDocumentPart() 125 .getRelationshipsPart(); 126 for (Relationship r : rp.getRelationships().getRelationship()) { 127 128 if (r.getType().equals(Namespaces.HEADER)) { 129 applyBindings((HeaderPart) rp.getPart(r)); 130 } else if (r.getType().equals(Namespaces.FOOTER)) { 131 applyBindings((FooterPart) rp.getPart(r)); 132 } 133 } 134 } 135 86 136 public static void applyBindings(JaxbXmlPart part) throws Docx4JException { 87 137 … … 341 391 "<w:r>" + 342 392 "<w:rPr>" + 343 "<w:rStyle w:val=\" Hyperlink\" />" + // TODO: enable this style in the document!393 "<w:rStyle w:val=\"" + hyperlinkStyleId + "\" />" + // TODO: enable this style in the document! 344 394 "</w:rPr>" + 345 395 "<w:t>" + url + "</w:t>" + -
trunk/docx4j/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java
r1641 r1647 219 219 } 220 220 221 pr ivateSet<ContentAccessor> getParts(WordprocessingMLPackage srcPackage) {221 protected static Set<ContentAccessor> getParts(WordprocessingMLPackage srcPackage) { 222 222 223 223 Set<ContentAccessor> partList = new HashSet<ContentAccessor>(); -
trunk/docx4j/src/main/java/org/docx4j/model/datastorage/RemovalHandler.java
r1579 r1647 37 37 import org.docx4j.jaxb.Context; 38 38 import org.docx4j.openpackaging.exceptions.Docx4JException; 39 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 39 40 import org.docx4j.openpackaging.parts.JaxbXmlPart; 41 import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; 42 import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; 43 import org.docx4j.openpackaging.parts.relationships.Namespaces; 44 import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 45 import org.docx4j.relationships.Relationship; 40 46 import org.w3c.dom.Document; 41 47 … … 91 97 } 92 98 99 public void removeSDTs(WordprocessingMLPackage wordMLPackage, 100 final Quantifier quantifier, final String... keys) throws Docx4JException { 101 102 // A component can apply in both the main document part, 103 // and in headers/footers. See further 104 // http://forums.opendope.org/Support-components-in-headers-footers-tp2964174p2964174.html 105 106 107 removeSDTs(wordMLPackage.getMainDocumentPart(), quantifier, keys); 108 109 // Add headers/footers 110 RelationshipsPart rp = wordMLPackage.getMainDocumentPart() 111 .getRelationshipsPart(); 112 for (Relationship r : rp.getRelationships().getRelationship()) { 113 114 if (r.getType().equals(Namespaces.HEADER)) { 115 removeSDTs((HeaderPart) rp.getPart(r), quantifier, keys); 116 } else if (r.getType().equals(Namespaces.FOOTER)) { 117 removeSDTs((FooterPart) rp.getPart(r), quantifier, keys); 118 } 119 } 120 } 121 93 122 /** 94 123 * Removes Structured Document Tags from a document part, preserving their
Note: See TracChangeset
for help on using the changeset viewer.
