<changes>
<release version="3.8-beta5" date="2011-??-??">
+ <action dev="poi-developers" type="add">New PackagePart method getRelatedPart(PackageRelationship) to simplify navigation of relations between OPC Parts</action>
<action dev="poi-developers" type="fix">51832 - handle XLS files where the WRITEPROTECT record preceeds the FILEPASS one, rather than following as normal</action>
<action dev="poi-developers" type="fix">51809 - correct GTE handling in COUNTIF</action>
<action dev="poi-developers" type="add">Add HWPF API to update range text and delete bookmarks</action>
PackagePart[] parts = new PackagePart[partsC.size()];
int count = 0;
for (PackageRelationship rel : partsC) {
- parts[count] = getTargetPart(rel);
+ parts[count] = getPackagePart().getRelatedPart(rel);
count++;
}
return parts;
private POIXMLDocumentPart parent;
private Map<String,POIXMLDocumentPart> relations = new LinkedHashMap<String,POIXMLDocumentPart>();
- /**
- * Get the PackagePart that is the target of a relationship.
- *
- * @param rel The relationship
- * @param pkg The package to fetch from
- * @return The target part
- * @throws InvalidFormatException
- */
- protected static PackagePart getTargetPart(OPCPackage pkg, PackageRelationship rel)
- throws InvalidFormatException {
- PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
- PackagePart part = pkg.getPart(relName);
- if (part == null) {
- throw new IllegalArgumentException("No part found for relationship " + rel);
- }
- return part;
- }
/**
* Counter that provides the amount of incoming relations from other parts
* to this part.
);
}
packageRel = cores.getRelationship(0);
- packagePart = POIXMLDocument.getTargetPart(pkg, packageRel);
+ packagePart = packagePart.getRelatedPart(packageRel);
}
/**
}
}
}
+
+ /**
+ * Get the PackagePart that is the target of a relationship from this Part.
+ *
+ * @param rel The relationship
+ * @return The target part
+ * @throws InvalidFormatException
+ */
+ protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException {
+ return getPackagePart().getRelatedPart(rel);
+ }
+
/**
* Fired when a new package part is created
}
- /**
- * Get the PackagePart that is the target of a relationship.
- *
- * @param rel The relationship
- * @return The target part
- * @throws InvalidFormatException
- */
- protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException {
- return getTargetPart(getPackagePart().getPackage(), rel);
- }
-
/**
* Fired when a package part is about to be removed from the package
*/
return false;
}
+ /**
+ * Get the PackagePart that is the target of a relationship.
+ *
+ * @param rel A relationship from this part to another one
+ * @return The target part of the relationship
+ */
+ public PackagePart getRelatedPart(PackageRelationship rel) throws InvalidFormatException {
+ // Ensure this is one of ours
+ if(! isRelationshipExists(rel)) {
+ throw new IllegalArgumentException("Relationship " + rel + " doesn't start with this part " + _partName);
+ }
+
+ // Get the target URI, excluding any relative fragments
+ URI target = rel.getTargetURI();
+ if(target.getFragment() != null) {
+ String t = target.toString();
+ try {
+ target = new URI( t.substring(0, t.indexOf('#')) );
+ } catch(URISyntaxException e) {
+ throw new InvalidFormatException("Invalid target URI: " + target);
+ }
+ }
+
+ // Turn that into a name, and fetch
+ PackagePartName relName = PackagingURIHelper.createPartName(target);
+ PackagePart part = _container.getPart(relName);
+ if (part == null) {
+ throw new IllegalArgumentException("No part found for relationship " + rel);
+ }
+ return part;
+ }
+
/**
* Get the input stream of this part to read its content.
*
embedds = new LinkedList<PackagePart>();
for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) {
- PackagePart slidePart =
- getTargetPart(getCorePart().getRelationship(ctSlide.getId2()));
+ PackagePart corePart = getCorePart();
+ PackagePart slidePart = corePart.getRelatedPart(
+ corePart.getRelationship(ctSlide.getId2()));
for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE))
- embedds.add(getTargetPart(rel)); // TODO: Add this reference to each slide as well
+ embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well
for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE))
- embedds.add(getTargetPart(rel));
+ embedds.add(slidePart.getRelatedPart(rel));
}
}
public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException {
public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException {
try {
- return getTargetPart(
- getCorePart().getRelationship(master.getId2())
+ PackagePart corePart = getCorePart();
+ return corePart.getRelatedPart(
+ corePart.getRelationship(master.getId2())
);
} catch(InvalidFormatException e) {
throw new XmlException(e);
public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException {
try {
- return getTargetPart(
- getCorePart().getRelationship(slide.getId2())
- );
+ PackagePart corePart = getCorePart();
+ return corePart.getRelatedPart(
+ corePart.getRelationship(slide.getId2())
+ );
} catch(InvalidFormatException e) {
throw new XmlException(e);
}
}
try {
- return getTargetPart(notes.getRelationship(0));
+ return slidePart.getRelatedPart(notes.getRelationship(0));
} catch(InvalidFormatException e) {
throw new IllegalStateException(e);
}
}
try {
- PackagePart cPart = getTargetPart(
+ PackagePart cPart = slidePart.getRelatedPart(
commentRels.getRelationship(0)
);
CmLstDocument commDoc =
for(XSSFSheet sheet : sheets){
// Get the embeddings for the workbook
- for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
- embedds.add(getTargetPart(rel));
-
- for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
- embedds.add(getTargetPart(rel));
+ for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation())) {
+ embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
+ }
+ for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation())) {
+ embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
+ }
}
return embedds;
}
*/
public PackagePart getPartById(String id) {
try {
- return getTargetPart(getCorePart().getRelationship(id));
+ PackagePart corePart = getCorePart();
+ return corePart.getRelatedPart(corePart.getRelationship(id));
} catch (InvalidFormatException e) {
throw new IllegalArgumentException(e);
}
List<PackagePart> embedds = new LinkedList<PackagePart>();
// Get the embeddings for the workbook
+ PackagePart part = getPackagePart();
for (PackageRelationship rel : getPackagePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
- embedds.add(getTargetPart(rel));
+ embedds.add(part.getRelatedPart(rel));
}
for (PackageRelationship rel : getPackagePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
- embedds.add(getTargetPart(rel));
+ embedds.add(part.getRelatedPart(rel));
}
return embedds;