mirror of https://github.com/apache/poi.git
Bug 53282 - Hyperlink with a non-breaking space throws java.lang.IllegalStateException
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1563540 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3fb8fc3830
commit
54d462a3f6
|
@ -22,14 +22,14 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
import org.dom4j.Attribute;
|
import org.dom4j.Attribute;
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a collection of PackageRelationship elements that are owned by a
|
* Represents a collection of PackageRelationship elements that are owned by a
|
||||||
|
@ -39,179 +39,179 @@ import org.apache.poi.util.POILogFactory;
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
public final class PackageRelationshipCollection implements
|
public final class PackageRelationshipCollection implements
|
||||||
Iterable<PackageRelationship> {
|
Iterable<PackageRelationship> {
|
||||||
|
|
||||||
private static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
|
private static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package relationships ordered by ID.
|
* Package relationships ordered by ID.
|
||||||
*/
|
*/
|
||||||
private TreeMap<String, PackageRelationship> relationshipsByID;
|
private TreeMap<String, PackageRelationship> relationshipsByID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package relationships ordered by type.
|
* Package relationships ordered by type.
|
||||||
*/
|
*/
|
||||||
private TreeMap<String, PackageRelationship> relationshipsByType;
|
private TreeMap<String, PackageRelationship> relationshipsByType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This relationshipPart.
|
* This relationshipPart.
|
||||||
*/
|
*/
|
||||||
private PackagePart relationshipPart;
|
private PackagePart relationshipPart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source part.
|
* Source part.
|
||||||
*/
|
*/
|
||||||
private PackagePart sourcePart;
|
private PackagePart sourcePart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This part name.
|
* This part name.
|
||||||
*/
|
*/
|
||||||
private PackagePartName partName;
|
private PackagePartName partName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the package.
|
* Reference to the package.
|
||||||
*/
|
*/
|
||||||
private OPCPackage container;
|
private OPCPackage container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID number of the next rID# to generate, or -1
|
* The ID number of the next rID# to generate, or -1
|
||||||
* if that is still to be determined.
|
* if that is still to be determined.
|
||||||
*/
|
*/
|
||||||
private int nextRelationshipId = -1;
|
private int nextRelationshipId = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
PackageRelationshipCollection() {
|
PackageRelationshipCollection() {
|
||||||
relationshipsByID = new TreeMap<String, PackageRelationship>();
|
relationshipsByID = new TreeMap<String, PackageRelationship>();
|
||||||
relationshipsByType = new TreeMap<String, PackageRelationship>();
|
relationshipsByType = new TreeMap<String, PackageRelationship>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor.
|
* Copy constructor.
|
||||||
*
|
*
|
||||||
* This collection will contain only elements from the specified collection
|
* This collection will contain only elements from the specified collection
|
||||||
* for which the type is compatible with the specified relationship type
|
* for which the type is compatible with the specified relationship type
|
||||||
* filter.
|
* filter.
|
||||||
*
|
*
|
||||||
* @param coll
|
* @param coll
|
||||||
* Collection to import.
|
* Collection to import.
|
||||||
* @param filter
|
* @param filter
|
||||||
* Relationship type filter.
|
* Relationship type filter.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(PackageRelationshipCollection coll,
|
public PackageRelationshipCollection(PackageRelationshipCollection coll,
|
||||||
String filter) {
|
String filter) {
|
||||||
this();
|
this();
|
||||||
for (PackageRelationship rel : coll.relationshipsByID.values()) {
|
for (PackageRelationship rel : coll.relationshipsByID.values()) {
|
||||||
if (filter == null || rel.getRelationshipType().equals(filter))
|
if (filter == null || rel.getRelationshipType().equals(filter))
|
||||||
addRelationship(rel);
|
addRelationship(rel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(OPCPackage container)
|
public PackageRelationshipCollection(OPCPackage container)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this(container, null);
|
this(container, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* Throws if the format of the content part is invalid.
|
* Throws if the format of the content part is invalid.
|
||||||
*
|
*
|
||||||
* @throws InvalidOperationException
|
* @throws InvalidOperationException
|
||||||
* Throws if the specified part is a relationship part.
|
* Throws if the specified part is a relationship part.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(PackagePart part)
|
public PackageRelationshipCollection(PackagePart part)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this(part._container, part);
|
this(part._container, part);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Parse the existing package relationship part if one exists.
|
* Constructor. Parse the existing package relationship part if one exists.
|
||||||
*
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* The parent package.
|
* The parent package.
|
||||||
* @param part
|
* @param part
|
||||||
* The part that own this relationships collection. If <b>null</b>
|
* The part that own this relationships collection. If <b>null</b>
|
||||||
* then this part is considered as the package root.
|
* then this part is considered as the package root.
|
||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If an error occurs during the parsing of the relatinships
|
* If an error occurs during the parsing of the relatinships
|
||||||
* part fo the specified part.
|
* part fo the specified part.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
|
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
if (container == null)
|
if (container == null)
|
||||||
throw new IllegalArgumentException("container");
|
throw new IllegalArgumentException("container");
|
||||||
|
|
||||||
// Check if the specified part is not a relationship part
|
// Check if the specified part is not a relationship part
|
||||||
if (part != null && part.isRelationshipPart())
|
if (part != null && part.isRelationshipPart())
|
||||||
throw new IllegalArgumentException("part");
|
throw new IllegalArgumentException("part");
|
||||||
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.sourcePart = part;
|
this.sourcePart = part;
|
||||||
this.partName = getRelationshipPartName(part);
|
this.partName = getRelationshipPartName(part);
|
||||||
if ((container.getPackageAccess() != PackageAccess.WRITE)
|
if ((container.getPackageAccess() != PackageAccess.WRITE)
|
||||||
&& container.containPart(this.partName)) {
|
&& container.containPart(this.partName)) {
|
||||||
relationshipPart = container.getPart(this.partName);
|
relationshipPart = container.getPart(this.partName);
|
||||||
parseRelationshipsPart(relationshipPart);
|
parseRelationshipsPart(relationshipPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the relationship part name of the specified part.
|
* Get the relationship part name of the specified part.
|
||||||
*
|
*
|
||||||
* @param part
|
* @param part
|
||||||
* The part .
|
* The part .
|
||||||
* @return The relationship part name of the specified part. Be careful,
|
* @return The relationship part name of the specified part. Be careful,
|
||||||
* only the correct name is returned, this method does not check if
|
* only the correct name is returned, this method does not check if
|
||||||
* the part really exist in a package !
|
* the part really exist in a package !
|
||||||
* @throws InvalidOperationException
|
* @throws InvalidOperationException
|
||||||
* Throws if the specified part is a relationship part.
|
* Throws if the specified part is a relationship part.
|
||||||
*/
|
*/
|
||||||
private static PackagePartName getRelationshipPartName(PackagePart part)
|
private static PackagePartName getRelationshipPartName(PackagePart part)
|
||||||
throws InvalidOperationException {
|
throws InvalidOperationException {
|
||||||
PackagePartName partName;
|
PackagePartName partName;
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
|
partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
|
||||||
} else {
|
} else {
|
||||||
partName = part.getPartName();
|
partName = part.getPartName();
|
||||||
}
|
}
|
||||||
return PackagingURIHelper.getRelationshipPartName(partName);
|
return PackagingURIHelper.getRelationshipPartName(partName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the specified relationship to the collection.
|
* Add the specified relationship to the collection.
|
||||||
*
|
*
|
||||||
* @param relPart
|
* @param relPart
|
||||||
* The relationship to add.
|
* The relationship to add.
|
||||||
*/
|
*/
|
||||||
public void addRelationship(PackageRelationship relPart) {
|
public void addRelationship(PackageRelationship relPart) {
|
||||||
relationshipsByID.put(relPart.getId(), relPart);
|
relationshipsByID.put(relPart.getId(), relPart);
|
||||||
relationshipsByType.put(relPart.getRelationshipType(), relPart);
|
relationshipsByType.put(relPart.getRelationshipType(), relPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a relationship to the collection.
|
* Add a relationship to the collection.
|
||||||
*
|
*
|
||||||
* @param targetUri
|
* @param targetUri
|
||||||
* Target URI.
|
* Target URI.
|
||||||
* @param targetMode
|
* @param targetMode
|
||||||
* The target mode : INTERNAL or EXTERNAL
|
* The target mode : INTERNAL or EXTERNAL
|
||||||
* @param relationshipType
|
* @param relationshipType
|
||||||
* Relationship type.
|
* Relationship type.
|
||||||
* @param id
|
* @param id
|
||||||
* Relationship ID.
|
* Relationship ID.
|
||||||
* @return The newly created relationship.
|
* @return The newly created relationship.
|
||||||
* @see PackageAccess
|
* @see PackageAccess
|
||||||
*/
|
*/
|
||||||
public PackageRelationship addRelationship(URI targetUri,
|
public PackageRelationship addRelationship(URI targetUri,
|
||||||
TargetMode targetMode, String relationshipType, String id) {
|
TargetMode targetMode, String relationshipType, String id) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
// Generate a unique ID is id parameter is null.
|
// Generate a unique ID is id parameter is null.
|
||||||
if (nextRelationshipId == -1) {
|
if (nextRelationshipId == -1) {
|
||||||
|
@ -224,229 +224,230 @@ public final class PackageRelationshipCollection implements
|
||||||
} while (relationshipsByID.get(id) != null);
|
} while (relationshipsByID.get(id) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageRelationship rel = new PackageRelationship(container,
|
PackageRelationship rel = new PackageRelationship(container,
|
||||||
sourcePart, targetUri, targetMode, relationshipType, id);
|
sourcePart, targetUri, targetMode, relationshipType, id);
|
||||||
relationshipsByID.put(rel.getId(), rel);
|
relationshipsByID.put(rel.getId(), rel);
|
||||||
relationshipsByType.put(rel.getRelationshipType(), rel);
|
relationshipsByType.put(rel.getRelationshipType(), rel);
|
||||||
return rel;
|
return rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a relationship by its ID.
|
* Remove a relationship by its ID.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* The relationship ID to remove.
|
* The relationship ID to remove.
|
||||||
*/
|
*/
|
||||||
public void removeRelationship(String id) {
|
public void removeRelationship(String id) {
|
||||||
if (relationshipsByID != null && relationshipsByType != null) {
|
if (relationshipsByID != null && relationshipsByType != null) {
|
||||||
PackageRelationship rel = relationshipsByID.get(id);
|
PackageRelationship rel = relationshipsByID.get(id);
|
||||||
if (rel != null) {
|
if (rel != null) {
|
||||||
relationshipsByID.remove(rel.getId());
|
relationshipsByID.remove(rel.getId());
|
||||||
relationshipsByType.values().remove(rel);
|
relationshipsByType.values().remove(rel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a relationship by its reference.
|
* Remove a relationship by its reference.
|
||||||
*
|
*
|
||||||
* @param rel
|
* @param rel
|
||||||
* The relationship to delete.
|
* The relationship to delete.
|
||||||
*/
|
*/
|
||||||
public void removeRelationship(PackageRelationship rel) {
|
public void removeRelationship(PackageRelationship rel) {
|
||||||
if (rel == null)
|
if (rel == null)
|
||||||
throw new IllegalArgumentException("rel");
|
throw new IllegalArgumentException("rel");
|
||||||
|
|
||||||
relationshipsByID.values().remove(rel);
|
relationshipsByID.values().remove(rel);
|
||||||
relationshipsByType.values().remove(rel);
|
relationshipsByType.values().remove(rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a relationship by its index in the collection.
|
* Retrieves a relationship by its index in the collection.
|
||||||
*
|
*
|
||||||
* @param index
|
* @param index
|
||||||
* Must be a value between [0-relationships_count-1]
|
* Must be a value between [0-relationships_count-1]
|
||||||
*/
|
*/
|
||||||
public PackageRelationship getRelationship(int index) {
|
public PackageRelationship getRelationship(int index) {
|
||||||
if (index < 0 || index > relationshipsByID.values().size())
|
if (index < 0 || index > relationshipsByID.values().size())
|
||||||
throw new IllegalArgumentException("index");
|
throw new IllegalArgumentException("index");
|
||||||
|
|
||||||
PackageRelationship retRel = null;
|
PackageRelationship retRel = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (PackageRelationship rel : relationshipsByID.values()) {
|
for (PackageRelationship rel : relationshipsByID.values()) {
|
||||||
if (index == i++)
|
if (index == i++)
|
||||||
return rel;
|
return rel;
|
||||||
}
|
}
|
||||||
return retRel;
|
return retRel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a package relationship based on its id.
|
* Retrieves a package relationship based on its id.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* ID of the package relationship to retrieve.
|
* ID of the package relationship to retrieve.
|
||||||
* @return The package relationship identified by the specified id.
|
* @return The package relationship identified by the specified id.
|
||||||
*/
|
*/
|
||||||
public PackageRelationship getRelationshipByID(String id) {
|
public PackageRelationship getRelationshipByID(String id) {
|
||||||
return relationshipsByID.get(id);
|
return relationshipsByID.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the numbe rof relationships in the collection.
|
* Get the numbe rof relationships in the collection.
|
||||||
*/
|
*/
|
||||||
public int size() {
|
public int size() {
|
||||||
return relationshipsByID.values().size();
|
return relationshipsByID.values().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the relationship part and add all relationship in this collection.
|
* Parse the relationship part and add all relationship in this collection.
|
||||||
*
|
*
|
||||||
* @param relPart
|
* @param relPart
|
||||||
* The package part to parse.
|
* The package part to parse.
|
||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* Throws if the relationship part is invalid.
|
* Throws if the relationship part is invalid.
|
||||||
*/
|
*/
|
||||||
private void parseRelationshipsPart(PackagePart relPart)
|
private void parseRelationshipsPart(PackagePart relPart)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
try {
|
try {
|
||||||
SAXReader reader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
|
logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
|
||||||
Document xmlRelationshipsDoc = reader
|
Document xmlRelationshipsDoc = reader
|
||||||
.read(relPart.getInputStream());
|
.read(relPart.getInputStream());
|
||||||
|
|
||||||
// Browse default types
|
// Browse default types
|
||||||
Element root = xmlRelationshipsDoc.getRootElement();
|
Element root = xmlRelationshipsDoc.getRootElement();
|
||||||
|
|
||||||
// Check OPC compliance M4.1 rule
|
// Check OPC compliance M4.1 rule
|
||||||
boolean fCorePropertiesRelationship = false;
|
boolean fCorePropertiesRelationship = false;
|
||||||
|
|
||||||
for (Iterator i = root
|
@SuppressWarnings("unchecked")
|
||||||
.elementIterator(PackageRelationship.RELATIONSHIP_TAG_NAME); i
|
Iterator<Element> iter = (Iterator<Element>)
|
||||||
.hasNext();) {
|
root.elementIterator(PackageRelationship.RELATIONSHIP_TAG_NAME);
|
||||||
Element element = (Element) i.next();
|
while (iter.hasNext()) {
|
||||||
// Relationship ID
|
Element element = iter.next();
|
||||||
String id = element.attribute(
|
// Relationship ID
|
||||||
PackageRelationship.ID_ATTRIBUTE_NAME).getValue();
|
String id = element.attribute(
|
||||||
// Relationship type
|
PackageRelationship.ID_ATTRIBUTE_NAME).getValue();
|
||||||
String type = element.attribute(
|
// Relationship type
|
||||||
PackageRelationship.TYPE_ATTRIBUTE_NAME).getValue();
|
String type = element.attribute(
|
||||||
|
PackageRelationship.TYPE_ATTRIBUTE_NAME).getValue();
|
||||||
|
|
||||||
/* Check OPC Compliance */
|
/* Check OPC Compliance */
|
||||||
// Check Rule M4.1
|
// Check Rule M4.1
|
||||||
if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES))
|
if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES))
|
||||||
if (!fCorePropertiesRelationship)
|
if (!fCorePropertiesRelationship)
|
||||||
fCorePropertiesRelationship = true;
|
fCorePropertiesRelationship = true;
|
||||||
else
|
else
|
||||||
throw new InvalidFormatException(
|
throw new InvalidFormatException(
|
||||||
"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
|
"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
|
||||||
|
|
||||||
/* End OPC Compliance */
|
/* End OPC Compliance */
|
||||||
|
|
||||||
// TargetMode (default value "Internal")
|
// TargetMode (default value "Internal")
|
||||||
Attribute targetModeAttr = element
|
Attribute targetModeAttr = element
|
||||||
.attribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
|
.attribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
|
||||||
TargetMode targetMode = TargetMode.INTERNAL;
|
TargetMode targetMode = TargetMode.INTERNAL;
|
||||||
if (targetModeAttr != null) {
|
if (targetModeAttr != null) {
|
||||||
targetMode = targetModeAttr.getValue().toLowerCase()
|
targetMode = targetModeAttr.getValue().toLowerCase()
|
||||||
.equals("internal") ? TargetMode.INTERNAL
|
.equals("internal") ? TargetMode.INTERNAL
|
||||||
: TargetMode.EXTERNAL;
|
: TargetMode.EXTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Target converted in URI
|
|
||||||
URI target;
|
|
||||||
String value = "";
|
|
||||||
try {
|
|
||||||
value = element.attribute(
|
|
||||||
PackageRelationship.TARGET_ATTRIBUTE_NAME)
|
|
||||||
.getValue();
|
|
||||||
|
|
||||||
|
// Target converted in URI
|
||||||
|
URI target = PackagingURIHelper.toURI("http://invalid.uri"); // dummy url
|
||||||
|
String value = element.attribute(
|
||||||
|
PackageRelationship.TARGET_ATTRIBUTE_NAME)
|
||||||
|
.getValue();
|
||||||
|
try {
|
||||||
|
// when parsing of the given uri fails, we can either
|
||||||
|
// ignore this relationship, which leads to IllegalStateException
|
||||||
|
// later on, or use a dummy value and thus enable processing of the
|
||||||
|
// package
|
||||||
target = PackagingURIHelper.toURI(value);
|
target = PackagingURIHelper.toURI(value);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
logger.log(POILogger.ERROR, "Cannot convert " + value
|
||||||
|
+ " in a valid relationship URI-> dummy-URI used", e);
|
||||||
|
}
|
||||||
|
addRelationship(target, targetMode, type, id);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(POILogger.ERROR, e);
|
||||||
|
throw new InvalidFormatException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (URISyntaxException e) {
|
/**
|
||||||
logger.log(POILogger.ERROR, "Cannot convert " + value
|
* Retrieves all relations with the specified type.
|
||||||
+ " in a valid relationship URI-> ignored", e);
|
*
|
||||||
continue;
|
* @param typeFilter
|
||||||
}
|
* Relationship type filter. If <b>null</b> then all
|
||||||
addRelationship(target, targetMode, type, id);
|
* relationships are returned.
|
||||||
}
|
* @return All relationships of the type specified by the filter.
|
||||||
} catch (Exception e) {
|
*/
|
||||||
logger.log(POILogger.ERROR, e);
|
public PackageRelationshipCollection getRelationships(String typeFilter) {
|
||||||
throw new InvalidFormatException(e.getMessage());
|
PackageRelationshipCollection coll = new PackageRelationshipCollection(
|
||||||
}
|
this, typeFilter);
|
||||||
}
|
return coll;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all relations with the specified type.
|
* Get this collection's iterator.
|
||||||
*
|
*/
|
||||||
* @param typeFilter
|
public Iterator<PackageRelationship> iterator() {
|
||||||
* Relationship type filter. If <b>null</b> then all
|
return relationshipsByID.values().iterator();
|
||||||
* relationships are returned.
|
}
|
||||||
* @return All relationships of the type specified by the filter.
|
|
||||||
*/
|
|
||||||
public PackageRelationshipCollection getRelationships(String typeFilter) {
|
|
||||||
PackageRelationshipCollection coll = new PackageRelationshipCollection(
|
|
||||||
this, typeFilter);
|
|
||||||
return coll;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get this collection's iterator.
|
* Get an iterator of a collection with all relationship with the specified
|
||||||
*/
|
* type.
|
||||||
public Iterator<PackageRelationship> iterator() {
|
*
|
||||||
return relationshipsByID.values().iterator();
|
* @param typeFilter
|
||||||
}
|
* Type filter.
|
||||||
|
* @return An iterator to a collection containing all relationships with the
|
||||||
|
* specified type contain in this collection.
|
||||||
|
*/
|
||||||
|
public Iterator<PackageRelationship> iterator(String typeFilter) {
|
||||||
|
ArrayList<PackageRelationship> retArr = new ArrayList<PackageRelationship>();
|
||||||
|
for (PackageRelationship rel : relationshipsByID.values()) {
|
||||||
|
if (rel.getRelationshipType().equals(typeFilter))
|
||||||
|
retArr.add(rel);
|
||||||
|
}
|
||||||
|
return retArr.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an iterator of a collection with all relationship with the specified
|
* Clear all relationships.
|
||||||
* type.
|
*/
|
||||||
*
|
public void clear() {
|
||||||
* @param typeFilter
|
relationshipsByID.clear();
|
||||||
* Type filter.
|
relationshipsByType.clear();
|
||||||
* @return An iterator to a collection containing all relationships with the
|
}
|
||||||
* specified type contain in this collection.
|
|
||||||
*/
|
|
||||||
public Iterator<PackageRelationship> iterator(String typeFilter) {
|
|
||||||
ArrayList<PackageRelationship> retArr = new ArrayList<PackageRelationship>();
|
|
||||||
for (PackageRelationship rel : relationshipsByID.values()) {
|
|
||||||
if (rel.getRelationshipType().equals(typeFilter))
|
|
||||||
retArr.add(rel);
|
|
||||||
}
|
|
||||||
return retArr.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Clear all relationships.
|
public String toString() {
|
||||||
*/
|
String str;
|
||||||
public void clear() {
|
if (relationshipsByID == null) {
|
||||||
relationshipsByID.clear();
|
str = "relationshipsByID=null";
|
||||||
relationshipsByType.clear();
|
} else {
|
||||||
}
|
str = relationshipsByID.size() + " relationship(s) = [";
|
||||||
|
}
|
||||||
|
if ((relationshipPart != null) && (relationshipPart._partName != null)) {
|
||||||
|
str = str + "," + relationshipPart._partName;
|
||||||
|
} else {
|
||||||
|
str = str + ",relationshipPart=null";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
// Source of this relationship
|
||||||
public String toString() {
|
if ((sourcePart != null) && (sourcePart._partName != null)) {
|
||||||
String str;
|
str = str + "," + sourcePart._partName;
|
||||||
if (relationshipsByID == null) {
|
} else {
|
||||||
str = "relationshipsByID=null";
|
str = str + ",sourcePart=null";
|
||||||
} else {
|
}
|
||||||
str = relationshipsByID.size() + " relationship(s) = [";
|
if (partName != null) {
|
||||||
}
|
str = str + "," + partName;
|
||||||
if ((relationshipPart != null) && (relationshipPart._partName != null)) {
|
} else {
|
||||||
str = str + "," + relationshipPart._partName;
|
str = str + ",uri=null)";
|
||||||
} else {
|
}
|
||||||
str = str + ",relationshipPart=null";
|
return str + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source of this relationship
|
|
||||||
if ((sourcePart != null) && (sourcePart._partName != null)) {
|
|
||||||
str = str + "," + sourcePart._partName;
|
|
||||||
} else {
|
|
||||||
str = str + ",sourcePart=null";
|
|
||||||
}
|
|
||||||
if (partName != null) {
|
|
||||||
str = str + "," + partName;
|
|
||||||
} else {
|
|
||||||
str = str + ",uri=null)";
|
|
||||||
}
|
|
||||||
return str + "]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
||||||
|
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
|
@ -54,252 +55,278 @@ public final class XSSFRelation extends POIXMLRelation {
|
||||||
protected static Map<String, XSSFRelation> _table = new HashMap<String, XSSFRelation>();
|
protected static Map<String, XSSFRelation> _table = new HashMap<String, XSSFRelation>();
|
||||||
|
|
||||||
|
|
||||||
public static final XSSFRelation WORKBOOK = new XSSFRelation(
|
public static final XSSFRelation WORKBOOK = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/workbook",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/workbook",
|
||||||
"/xl/workbook.xml",
|
"/xl/workbook.xml",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
public static final XSSFRelation MACROS_WORKBOOK = new XSSFRelation(
|
public static final XSSFRelation MACROS_WORKBOOK = new XSSFRelation(
|
||||||
"application/vnd.ms-excel.sheet.macroEnabled.main+xml",
|
"application/vnd.ms-excel.sheet.macroEnabled.main+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
PackageRelationshipTypes.CORE_DOCUMENT,
|
||||||
"/xl/workbook.xml",
|
"/xl/workbook.xml",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
public static final XSSFRelation TEMPLATE_WORKBOOK = new XSSFRelation(
|
public static final XSSFRelation TEMPLATE_WORKBOOK = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
PackageRelationshipTypes.CORE_DOCUMENT,
|
||||||
"/xl/workbook.xml",
|
"/xl/workbook.xml",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation MACRO_TEMPLATE_WORKBOOK = new XSSFRelation(
|
public static final XSSFRelation MACRO_TEMPLATE_WORKBOOK = new XSSFRelation(
|
||||||
"application/vnd.ms-excel.template.macroEnabled.main+xml",
|
"application/vnd.ms-excel.template.macroEnabled.main+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
PackageRelationshipTypes.CORE_DOCUMENT,
|
||||||
"/xl/workbook.xml",
|
"/xl/workbook.xml",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation MACRO_ADDIN_WORKBOOK = new XSSFRelation(
|
public static final XSSFRelation MACRO_ADDIN_WORKBOOK = new XSSFRelation(
|
||||||
"application/vnd.ms-excel.addin.macroEnabled.main+xml",
|
"application/vnd.ms-excel.addin.macroEnabled.main+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
PackageRelationshipTypes.CORE_DOCUMENT,
|
||||||
"/xl/workbook.xml",
|
"/xl/workbook.xml",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
public static final XSSFRelation WORKSHEET = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
|
|
||||||
"/xl/worksheets/sheet#.xml",
|
|
||||||
XSSFSheet.class
|
|
||||||
);
|
|
||||||
public static final XSSFRelation CHARTSHEET = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
|
|
||||||
"/xl/chartsheets/sheet#.xml",
|
|
||||||
XSSFChartSheet.class
|
|
||||||
);
|
|
||||||
public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
|
|
||||||
"/xl/sharedStrings.xml",
|
|
||||||
SharedStringsTable.class
|
|
||||||
);
|
|
||||||
public static final XSSFRelation STYLES = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
|
|
||||||
"/xl/styles.xml",
|
|
||||||
StylesTable.class
|
|
||||||
);
|
|
||||||
public static final XSSFRelation DRAWINGS = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.drawing+xml",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
|
|
||||||
"/xl/drawings/drawing#.xml",
|
|
||||||
XSSFDrawing.class
|
|
||||||
);
|
|
||||||
public static final XSSFRelation VML_DRAWINGS = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.vmlDrawing",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",
|
|
||||||
"/xl/drawings/vmlDrawing#.vml",
|
|
||||||
XSSFVMLDrawing.class
|
|
||||||
);
|
|
||||||
public static final XSSFRelation CHART = new XSSFRelation(
|
|
||||||
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
|
|
||||||
"/xl/charts/chart#.xml",
|
|
||||||
XSSFChart.class
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final XSSFRelation CUSTOM_XML_MAPPINGS = new XSSFRelation(
|
public static final XSSFRelation WORKSHEET = new XSSFRelation(
|
||||||
"application/xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
|
||||||
"/xl/xmlMaps.xml",
|
"/xl/worksheets/sheet#.xml",
|
||||||
MapInfo.class
|
XSSFSheet.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation SINGLE_XML_CELLS = new XSSFRelation(
|
public static final XSSFRelation CHARTSHEET = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
|
||||||
"/xl/tables/tableSingleCells#.xml",
|
"/xl/chartsheets/sheet#.xml",
|
||||||
SingleXmlCells.class
|
XSSFChartSheet.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation TABLE = new XSSFRelation(
|
public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
|
||||||
"/xl/tables/table#.xml",
|
"/xl/sharedStrings.xml",
|
||||||
XSSFTable.class
|
SharedStringsTable.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation STYLES = new XSSFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
|
||||||
|
PackageRelationshipTypes.STYLE_PART,
|
||||||
|
"/xl/styles.xml",
|
||||||
|
StylesTable.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation DRAWINGS = new XSSFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.drawing+xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
|
||||||
|
"/xl/drawings/drawing#.xml",
|
||||||
|
XSSFDrawing.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation VML_DRAWINGS = new XSSFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.vmlDrawing",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",
|
||||||
|
"/xl/drawings/vmlDrawing#.vml",
|
||||||
|
XSSFVMLDrawing.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation CHART = new XSSFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
|
||||||
|
"/xl/charts/chart#.xml",
|
||||||
|
XSSFChart.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation CUSTOM_XML_MAPPINGS = new XSSFRelation(
|
||||||
|
"application/xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps",
|
||||||
|
"/xl/xmlMaps.xml",
|
||||||
|
MapInfo.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation SINGLE_XML_CELLS = new XSSFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells",
|
||||||
|
"/xl/tables/tableSingleCells#.xml",
|
||||||
|
SingleXmlCells.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation TABLE = new XSSFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",
|
||||||
|
"/xl/tables/table#.xml",
|
||||||
|
XSSFTable.class
|
||||||
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGES = new XSSFRelation(
|
public static final XSSFRelation IMAGES = new XSSFRelation(
|
||||||
null,
|
null,
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
null,
|
null,
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_EMF = new XSSFRelation(
|
public static final XSSFRelation IMAGE_EMF = new XSSFRelation(
|
||||||
"image/x-emf",
|
"image/x-emf",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.emf",
|
"/xl/media/image#.emf",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_WMF = new XSSFRelation(
|
public static final XSSFRelation IMAGE_WMF = new XSSFRelation(
|
||||||
"image/x-wmf",
|
"image/x-wmf",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.wmf",
|
"/xl/media/image#.wmf",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_PICT = new XSSFRelation(
|
public static final XSSFRelation IMAGE_PICT = new XSSFRelation(
|
||||||
"image/pict",
|
"image/pict",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.pict",
|
"/xl/media/image#.pict",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_JPEG = new XSSFRelation(
|
public static final XSSFRelation IMAGE_JPEG = new XSSFRelation(
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.jpeg",
|
"/xl/media/image#.jpeg",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_PNG = new XSSFRelation(
|
public static final XSSFRelation IMAGE_PNG = new XSSFRelation(
|
||||||
"image/png",
|
"image/png",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.png",
|
"/xl/media/image#.png",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_DIB = new XSSFRelation(
|
public static final XSSFRelation IMAGE_DIB = new XSSFRelation(
|
||||||
"image/dib",
|
"image/dib",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.dib",
|
"/xl/media/image#.dib",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
|
public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
|
||||||
"image/gif",
|
"image/gif",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.gif",
|
"/xl/media/image#.gif",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
|
public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
|
||||||
"image/tiff",
|
"image/tiff",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.tiff",
|
"/xl/media/image#.tiff",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
|
public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
|
||||||
"image/x-eps",
|
"image/x-eps",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.eps",
|
"/xl/media/image#.eps",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
|
public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
|
||||||
"image/x-ms-bmp",
|
"image/x-ms-bmp",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.bmp",
|
"/xl/media/image#.bmp",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
|
public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
|
||||||
"image/x-wpg",
|
"image/x-wpg",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
PackageRelationshipTypes.IMAGE_PART,
|
||||||
"/xl/media/image#.wpg",
|
"/xl/media/image#.wpg",
|
||||||
XSSFPictureData.class
|
XSSFPictureData.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
|
public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
||||||
"/xl/comments#.xml",
|
"/xl/comments#.xml",
|
||||||
CommentsTable.class
|
CommentsTable.class
|
||||||
);
|
|
||||||
public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
|
|
||||||
null,
|
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
public static final XSSFRelation OLEEMBEDDINGS = new XSSFRelation(
|
|
||||||
null,
|
|
||||||
POIXMLDocument.OLE_OBJECT_REL_TYPE,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
public static final XSSFRelation PACKEMBEDDINGS = new XSSFRelation(
|
|
||||||
null,
|
|
||||||
POIXMLDocument.PACK_OBJECT_REL_TYPE,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation VBA_MACROS = new XSSFRelation(
|
public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
|
||||||
"application/vnd.ms-office.vbaProject",
|
null,
|
||||||
"http://schemas.microsoft.com/office/2006/relationships/vbaProject",
|
PackageRelationshipTypes.HYPERLINK_PART,
|
||||||
"/xl/vbaProject.bin",
|
null,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
public static final XSSFRelation ACTIVEX_CONTROLS = new XSSFRelation(
|
|
||||||
"application/vnd.ms-office.activeX+xml",
|
public static final XSSFRelation OLEEMBEDDINGS = new XSSFRelation(
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/control",
|
null,
|
||||||
"/xl/activeX/activeX#.xml",
|
POIXMLDocument.OLE_OBJECT_REL_TYPE,
|
||||||
null
|
null,
|
||||||
);
|
null
|
||||||
public static final XSSFRelation ACTIVEX_BINS = new XSSFRelation(
|
);
|
||||||
"application/vnd.ms-office.activeX",
|
|
||||||
"http://schemas.microsoft.com/office/2006/relationships/activeXControlBinary",
|
public static final XSSFRelation PACKEMBEDDINGS = new XSSFRelation(
|
||||||
"/xl/activeX/activeX#.bin",
|
null,
|
||||||
null
|
POIXMLDocument.PACK_OBJECT_REL_TYPE,
|
||||||
);
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation VBA_MACROS = new XSSFRelation(
|
||||||
|
"application/vnd.ms-office.vbaProject",
|
||||||
|
"http://schemas.microsoft.com/office/2006/relationships/vbaProject",
|
||||||
|
"/xl/vbaProject.bin",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation ACTIVEX_CONTROLS = new XSSFRelation(
|
||||||
|
"application/vnd.ms-office.activeX+xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/control",
|
||||||
|
"/xl/activeX/activeX#.xml",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final XSSFRelation ACTIVEX_BINS = new XSSFRelation(
|
||||||
|
"application/vnd.ms-office.activeX",
|
||||||
|
"http://schemas.microsoft.com/office/2006/relationships/activeXControlBinary",
|
||||||
|
"/xl/activeX/activeX#.bin",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
public static final XSSFRelation THEME = new XSSFRelation(
|
public static final XSSFRelation THEME = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.theme+xml",
|
"application/vnd.openxmlformats-officedocument.theme+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
|
||||||
"/xl/theme/theme#.xml",
|
"/xl/theme/theme#.xml",
|
||||||
ThemesTable.class
|
ThemesTable.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation CALC_CHAIN = new XSSFRelation(
|
public static final XSSFRelation CALC_CHAIN = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
|
||||||
"/xl/calcChain.xml",
|
"/xl/calcChain.xml",
|
||||||
CalculationChain.class
|
CalculationChain.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation(
|
public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
|
||||||
"/xl/printerSettings/printerSettings#.bin",
|
"/xl/printerSettings/printerSettings#.bin",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
private XSSFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
|
private XSSFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
|
||||||
super(type, rel, defaultName, cls);
|
super(type, rel, defaultName, cls);
|
||||||
|
|
||||||
if(cls != null && !_table.containsKey(rel)) _table.put(rel, this);
|
if(cls != null && !_table.containsKey(rel)) _table.put(rel, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the InputStream to read the contents, based
|
* Fetches the InputStream to read the contents, based
|
||||||
* of the specified core part, for which we are defined
|
* of the specified core part, for which we are defined
|
||||||
* as a suitable relationship
|
* as a suitable relationship
|
||||||
*/
|
*/
|
||||||
public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
|
public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
|
||||||
PackageRelationshipCollection prc =
|
PackageRelationshipCollection prc =
|
||||||
corePart.getRelationshipsByType(_relation);
|
corePart.getRelationshipsByType(_relation);
|
||||||
Iterator<PackageRelationship> it = prc.iterator();
|
Iterator<PackageRelationship> it = prc.iterator();
|
||||||
if(it.hasNext()) {
|
if(it.hasNext()) {
|
||||||
PackageRelationship rel = it.next();
|
PackageRelationship rel = it.next();
|
||||||
|
@ -309,8 +336,7 @@ public final class XSSFRelation extends POIXMLRelation {
|
||||||
}
|
}
|
||||||
log.log(POILogger.WARN, "No part " + _defaultName + " found");
|
log.log(POILogger.WARN, "No part " + _defaultName + " found");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get POIXMLRelation by relation type
|
* Get POIXMLRelation by relation type
|
||||||
|
|
|
@ -26,7 +26,6 @@ import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
|
@ -1414,30 +1413,31 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
* error message when called via WorkbookFactory.
|
* error message when called via WorkbookFactory.
|
||||||
* (You need to supply a password explicitly for them)
|
* (You need to supply a password explicitly for them)
|
||||||
*/
|
*/
|
||||||
|
@Test(expected=EncryptedDocumentException.class)
|
||||||
|
public void bug55692_stream() throws Exception {
|
||||||
|
// Directly on a Stream
|
||||||
|
WorkbookFactory.create(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=EncryptedDocumentException.class)
|
||||||
|
public void bug55692_poifs() throws Exception {
|
||||||
|
// Via a POIFSFileSystem
|
||||||
|
POIFSFileSystem fsP = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
|
||||||
|
WorkbookFactory.create(fsP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=EncryptedDocumentException.class)
|
||||||
|
public void bug55692_npoifs() throws Exception {
|
||||||
|
// Via a NPOIFSFileSystem
|
||||||
|
NPOIFSFileSystem fsNP = new NPOIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
|
||||||
|
WorkbookFactory.create(fsNP);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug55692() throws Exception {
|
public void bug53282() {
|
||||||
InputStream inpA = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53282b.xlsx");
|
||||||
InputStream inpB = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
|
Cell c = wb.getSheetAt(0).getRow(1).getCell(0);
|
||||||
InputStream inpC = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
|
assertEquals("#@_#", c.getStringCellValue());
|
||||||
|
assertEquals("http://invalid.uri", c.getHyperlink().getAddress());
|
||||||
// Directly on a Stream
|
|
||||||
try {
|
|
||||||
WorkbookFactory.create(inpA);
|
|
||||||
fail("Should've raised a EncryptedDocumentException error");
|
|
||||||
} catch (EncryptedDocumentException e) {}
|
|
||||||
|
|
||||||
// Via a POIFSFileSystem
|
|
||||||
POIFSFileSystem fsP = new POIFSFileSystem(inpB);
|
|
||||||
try {
|
|
||||||
WorkbookFactory.create(fsP);
|
|
||||||
fail("Should've raised a EncryptedDocumentException error");
|
|
||||||
} catch (EncryptedDocumentException e) {}
|
|
||||||
|
|
||||||
// Via a NPOIFSFileSystem
|
|
||||||
NPOIFSFileSystem fsNP = new NPOIFSFileSystem(inpC);
|
|
||||||
try {
|
|
||||||
WorkbookFactory.create(fsNP);
|
|
||||||
fail("Should've raised a EncryptedDocumentException error");
|
|
||||||
} catch (EncryptedDocumentException e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue