aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2009-07-12 07:18:42 +0000
committerYegor Kozlov <yegor@apache.org>2009-07-12 07:18:42 +0000
commit3601f7f8c60b971f77ef80f51c2e91bc28be59b0 (patch)
tree708d3615407214d3b3d492bb5ddf45e991b66ec2 /src/ooxml/java/org/apache/poi
parent431be7dc97704780a8d2ad24842bc875ca68a8c3 (diff)
downloadpoi-3601f7f8c60b971f77ef80f51c2e91bc28be59b0.tar.gz
poi-3601f7f8c60b971f77ef80f51c2e91bc28be59b0.zip
fixed XSSF and OpenXml4J to read/write relationships with targets starting with '#' (internal locations), see Bugzilla 47504
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@793280 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi')
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/POIXMLDocumentPart.java26
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java8
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/util/PackageHelper.java17
3 files changed, 37 insertions, 14 deletions
diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
index 09030222c2..76671d1e10 100755
--- a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
+++ b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
@@ -19,6 +19,7 @@ package org.apache.poi;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
+import java.net.URI;
import org.apache.xmlbeans.XmlOptions;
import org.apache.poi.util.POILogger;
@@ -142,7 +143,7 @@ public class POIXMLDocumentPart {
@Override
public String toString(){
- return packagePart.toString();
+ return packagePart == null ? null : packagePart.toString();
}
/**
@@ -231,17 +232,28 @@ public class POIXMLDocumentPart {
PackageRelationshipCollection rels = packagePart.getRelationships();
for (PackageRelationship rel : rels) {
if(rel.getTargetMode() == TargetMode.INTERNAL){
- PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
- PackagePart p = packagePart.getPackage().getPart(relName);
- if(p == null) {
- logger.log(POILogger.ERROR, "Skipped invalid entry " + rel.getTargetURI());
- continue;
+ URI uri = rel.getTargetURI();
+
+ PackagePart p;
+ if(uri.getRawFragment() != null) {
+ /*
+ * For internal references (e.g. '#Sheet1!A1') the package part is null
+ */
+ p = null;
+ } else {
+ PackagePartName relName = PackagingURIHelper.createPartName(uri);
+ p = packagePart.getPackage().getPart(relName);
+ if(p == null) {
+ logger.log(POILogger.ERROR, "Skipped invalid entry " + rel.getTargetURI());
+ continue;
+ }
}
+
POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);
childPart.parent = this;
addRelation(childPart);
- if(p.hasRelationships()) childPart.read(factory);
+ if(p != null && p.hasRelationships()) childPart.read(factory);
}
}
}
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
index b59a78b74c..cfe0fb0a5d 100755
--- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
@@ -161,8 +161,12 @@ public final class ZipPartMarshaller implements PartMarshaller {
PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
"External");
} else {
- targetValue = PackagingURIHelper.relativizeURI(
- sourcePartURI, rel.getTargetURI()).getPath();
+ URI targetURI = rel.getTargetURI();
+ targetValue = PackagingURIHelper.relativizeURI(
+ sourcePartURI, targetURI).getPath();
+ if (targetURI.getRawFragment() != null) {
+ targetValue += "#" + targetURI.getRawFragment();
+ }
}
relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME,
targetValue);
diff --git a/src/ooxml/java/org/apache/poi/util/PackageHelper.java b/src/ooxml/java/org/apache/poi/util/PackageHelper.java
index 78468d5b94..186d85acc3 100755
--- a/src/ooxml/java/org/apache/poi/util/PackageHelper.java
+++ b/src/ooxml/java/org/apache/poi/util/PackageHelper.java
@@ -22,6 +22,7 @@ import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.util.IOUtils;
import java.io.*;
+import java.net.URI;
/**
* Provides handy methods to work with OOXML packages
@@ -83,11 +84,10 @@ public class PackageHelper {
* Creates an empty file in the default temporary-file directory,
*/
public static File createTempFile() throws IOException {
- File file = File.createTempFile("poi-ooxml-", ".tmp");
+ File file = TempFile.createTempFile("poi-ooxml-", ".tmp");
//there is no way to pass an existing file to Package.create(file),
//delete first, the file will be re-created in Packe.create(file)
file.delete();
- file.deleteOnExit();
return file;
}
@@ -104,11 +104,18 @@ public class PackageHelper {
//external relations don't have associated package parts
continue;
} else {
- PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
- p = pkg.getPart(relName);
+ URI uri = rel.getTargetURI();
+
+ if(uri.getRawFragment() != null) {
+ part_tgt.addRelationship(uri, rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
+ continue;
+ } else {
+ PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
+ p = pkg.getPart(relName);
+ part_tgt.addRelationship(p.getPartName(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
+ }
}
- part_tgt.addRelationship(p.getPartName(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
PackagePart dest;
if(!tgt.containPart(p.getPartName())){