Changeset 1648 for trunk/docx4j/src/main/java
- Timestamp:
- 09/02/11 03:35:43 (9 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j
- Files:
-
- 5 edited
-
openpackaging/Base.java (modified) (3 diffs)
-
openpackaging/io/LoadFromZipNG.java (modified) (1 diff)
-
openpackaging/io/SaveToZipFile.java (modified) (1 diff)
-
openpackaging/parts/relationships/RelationshipsPart.java (modified) (2 diffs)
-
samples/PartsList.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/Base.java
r1176 r1648 49 49 * so see Part for definition of a corresponding field.) 50 50 */ 51 protected RelationshipsPart relationships; 52 53 /** 54 * Get the relationship part 51 public RelationshipsPart relationships; 52 53 /** 54 * Get the relationship part. 55 * From 2.7.1, the part will be created if it 56 * doesn't exist. (SaveToZipFile will only 57 * save it if it contains rels) 55 58 * 56 59 * @return The relationship part name. 57 60 */ 58 61 public RelationshipsPart getRelationshipsPart() { 62 return getRelationshipsPart(true); 63 } 64 65 /** 66 * Get the relationship part. 67 * @since 2.7.1 68 * 69 * @param create whether to create it if it doesn't exist 70 * @return 71 */ 72 public RelationshipsPart getRelationshipsPart(boolean createIfAbsent) { 59 73 // throws InvalidOperationException { 60 74 if (this instanceof org.docx4j.openpackaging.parts.relationships.RelationshipsPart) { … … 63 77 //throw new InvalidOperationException(); 64 78 return null; 65 } else { 66 return relationships; 67 } 79 } 80 81 if (relationships == null 82 && createIfAbsent) { 83 relationships = RelationshipsPart.createRelationshipsPartForPart(this); 84 } 85 86 return relationships; 68 87 } 69 88 … … 194 213 throw new InvalidFormatException("You should add your part to the target part, not the target part's relationships part."); 195 214 } 196 197 // Create RelationshipsPart for this part if necessary198 if (this.getRelationshipsPart() == null )199 RelationshipsPart.createRelationshipsPartForPart(this);200 215 201 216 // Now add the targetpart to the relationships -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipNG.java
r1555 r1648 467 467 Part part) 468 468 throws Docx4JException, InvalidFormatException { 469 469 470 RelationshipsPart rrp = null; 470 471 // recurse via this parts relationships, if it has any -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/SaveToZipFile.java
r1604 r1648 413 413 414 414 // recurse via this parts relationships, if it has any 415 if (part.getRelationshipsPart()!= null ) { 416 RelationshipsPart rrp = part.getRelationshipsPart(); 417 log.debug("Found relationships " + rrp.getPartName() ); 418 String relPart = PartName.getRelationshipsPartName(resolvedPartUri); 419 log.debug("Cf constructed name " + relPart ); 420 421 //deprecatedSaveRawXmlPart(out, relPart, rrp.getDocument() ); 422 // 2008 06 12 - try this neater method 423 saveRawXmlPart(out, rrp, relPart ); 424 425 addPartsFromRelationships(out, rrp ); 426 } else { 427 log.debug("No relationships for " + resolvedPartUri ); 428 } 415 RelationshipsPart rrp = part.getRelationshipsPart(false); //don't create 416 if (rrp!= null ) { 417 418 //log.debug("Found relationships " + rrp.getPartName() ); 419 420 // Only save it if it actually has rels in it 421 if (rrp.getRelationships().getRelationship().size()>0) { 422 423 String relPart = PartName.getRelationshipsPartName(resolvedPartUri); 424 //log.debug("Cf constructed name " + relPart ); 425 426 saveRawXmlPart(out, rrp, relPart ); 427 428 addPartsFromRelationships(out, rrp ); 429 } 430 } 431 // else { 432 // log.debug("No relationships for " + resolvedPartUri ); 433 // } 429 434 } 430 435 -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/relationships/RelationshipsPart.java
r1488 r1648 200 200 Base sourcePart) { 201 201 202 if (sourcePart. getRelationshipsPart()!= null)203 return sourcePart. getRelationshipsPart();202 if (sourcePart.relationships != null) 203 return sourcePart.relationships; 204 204 205 205 RelationshipsPart rp = null; … … 207 207 rp = new RelationshipsPart(sourcePart); 208 208 } catch (InvalidFormatException e) { 209 // TODO Auto-generated catch block210 e.printStackTrace();209 // shouldn't happen 210 log.error(e); 211 211 } 212 212 rp.setPackage(sourcePart.getPackage()); 213 214 // sourcePart.setRelationships(rp);215 213 216 214 // Make sure content manager knows how to handle .rels -
trunk/docx4j/src/main/java/org/docx4j/samples/PartsList.java
r1232 r1648 29 29 import org.docx4j.XmlUtils; 30 30 import org.docx4j.openpackaging.contenttype.ContentTypeManager; 31 import org.docx4j.openpackaging.io.SaveToZipFile; 31 32 import org.docx4j.openpackaging.parts.Part; 32 33 import org.docx4j.openpackaging.parts.JaxbXmlPart; … … 53 54 // + "/sample-docs/test-docs/header-footer/header_sections_some-linked.xml"; 54 55 // inputfilepath = System.getProperty("user.dir") + "/sample-docs/xlsx/pivot.xlsm"; 55 inputfilepath = System.getProperty("user.dir") + "/sample-docs/ sample-docx.xml";56 inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/sample-docx.xml"; 56 57 // inputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx/lines.pptx"; 57 58 } … … 71 72 72 73 System.out.println(sb.toString()); 74 75 // SaveToZipFile saver = new SaveToZipFile(opcPackage); 76 // saver.save(System.getProperty("user.dir") + "/out.docx"); 77 73 78 } 74 79 … … 115 120 // TODO: order by rel id 116 121 122 // if (rp.getRelationships().getRelationship().size()==0) { 123 // System.out.println("In rels part .. empty"); 124 // } 125 117 126 for ( Relationship r : rp.getRelationships().getRelationship() ) { 118 127 … … 139 148 } 140 149 handled.put(part, part); 141 if (part.getRelationshipsPart( )==null) {150 if (part.getRelationshipsPart(false)==null) { 142 151 // sb.append(".. no rels" ); 143 152 } else { 144 traverseRelationships(wordMLPackage, part.getRelationshipsPart( ), sb, indent + " ");153 traverseRelationships(wordMLPackage, part.getRelationshipsPart(false), sb, indent + " "); 145 154 } 146 155
Note: See TracChangeset
for help on using the changeset viewer.
