You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2014/02/02 02:56:02 UTC

svn commit: r1563540 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/ trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/ trunk/test-data/spread...

Author: kiwiwings
Date: Sun Feb  2 01:56:02 2014
New Revision: 1563540

URL: http://svn.apache.org/r1563540
Log:
Bug 53282 - Hyperlink with a non-breaking space throws java.lang.IllegalStateException

Added:
    poi/trunk/test-data/spreadsheet/53282b.xlsx   (with props)
Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1563540&r1=1563539&r2=1563540&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sun Feb  2 01:56:02 2014
@@ -36,6 +36,7 @@
 
     <changes>
         <release version="3.11-beta1" date="2014-??-??">
+          <action dev="poi-developers" type="fix">53282 - Hyperlink with a non-breaking space throws java.lang.IllegalStateException</action>
           <action dev="poi-developers" type="fix">55802 - Special Letters not exported correct</action>
           <action dev="poi-developers" type="add">Expose the StyleIndex of HWPF CharacterRuns</action>
           <action dev="poi-developers" type="fix">51891 - Fix StringIndexOutOfBoundsException : Ole10Native.&lt;init&gt; (parsing word file)</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java?rev=1563540&r1=1563539&r2=1563540&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java Sun Feb  2 01:56:02 2014
@@ -22,14 +22,14 @@ import java.util.ArrayList;
 import java.util.Iterator;
 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.Document;
 import org.dom4j.Element;
 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
@@ -39,179 +39,179 @@ import org.apache.poi.util.POILogFactory
  * @version 0.1
  */
 public final class PackageRelationshipCollection implements
-		Iterable<PackageRelationship> {
+        Iterable<PackageRelationship> {
 
     private static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
 
-	/**
-	 * Package relationships ordered by ID.
-	 */
-	private TreeMap<String, PackageRelationship> relationshipsByID;
-
-	/**
-	 * Package relationships ordered by type.
-	 */
-	private TreeMap<String, PackageRelationship> relationshipsByType;
-
-	/**
-	 * This relationshipPart.
-	 */
-	private PackagePart relationshipPart;
-
-	/**
-	 * Source part.
-	 */
-	private PackagePart sourcePart;
-
-	/**
-	 * This part name.
-	 */
-	private PackagePartName partName;
-
-	/**
-	 * Reference to the package.
-	 */
-	private OPCPackage container;
-	
-	/**
-	 * The ID number of the next rID# to generate, or -1
-	 *  if that is still to be determined.
-	 */
-	private int nextRelationshipId = -1;
-
-	/**
-	 * Constructor.
-	 */
-	PackageRelationshipCollection() {
-		relationshipsByID = new TreeMap<String, PackageRelationship>();
-		relationshipsByType = new TreeMap<String, PackageRelationship>();
-	}
-
-	/**
-	 * Copy constructor.
-	 *
-	 * This collection will contain only elements from the specified collection
-	 * for which the type is compatible with the specified relationship type
-	 * filter.
-	 *
-	 * @param coll
-	 *            Collection to import.
-	 * @param filter
-	 *            Relationship type filter.
-	 */
-	public PackageRelationshipCollection(PackageRelationshipCollection coll,
-			String filter) {
-		this();
-		for (PackageRelationship rel : coll.relationshipsByID.values()) {
-			if (filter == null || rel.getRelationshipType().equals(filter))
-				addRelationship(rel);
-		}
-	}
-
-	/**
-	 * Constructor.
-	 */
-	public PackageRelationshipCollection(OPCPackage container)
-			throws InvalidFormatException {
-		this(container, null);
-	}
-
-	/**
-	 * Constructor.
-	 *
-	 * @throws InvalidFormatException
-	 *             Throws if the format of the content part is invalid.
-	 *
-	 * @throws InvalidOperationException
-	 *             Throws if the specified part is a relationship part.
-	 */
-	public PackageRelationshipCollection(PackagePart part)
-			throws InvalidFormatException {
-		this(part._container, part);
-	}
-
-	/**
-	 * Constructor. Parse the existing package relationship part if one exists.
-	 *
-	 * @param container
-	 *            The parent package.
-	 * @param part
-	 *            The part that own this relationships collection. If <b>null</b>
-	 *            then this part is considered as the package root.
-	 * @throws InvalidFormatException
-	 *             If an error occurs during the parsing of the relatinships
-	 *             part fo the specified part.
-	 */
-	public PackageRelationshipCollection(OPCPackage container, PackagePart part)
-			throws InvalidFormatException {
-		this();
-
-		if (container == null)
-			throw new IllegalArgumentException("container");
-
-		// Check if the specified part is not a relationship part
-		if (part != null && part.isRelationshipPart())
-			throw new IllegalArgumentException("part");
-
-		this.container = container;
-		this.sourcePart = part;
-		this.partName = getRelationshipPartName(part);
-		if ((container.getPackageAccess() != PackageAccess.WRITE)
-				&& container.containPart(this.partName)) {
-			relationshipPart = container.getPart(this.partName);
-			parseRelationshipsPart(relationshipPart);
-		}
-	}
-
-	/**
-	 * Get the relationship part name of the specified part.
-	 *
-	 * @param part
-	 *            The part .
-	 * @return The relationship part name of the specified part. Be careful,
-	 *         only the correct name is returned, this method does not check if
-	 *         the part really exist in a package !
-	 * @throws InvalidOperationException
-	 *             Throws if the specified part is a relationship part.
-	 */
-	private static PackagePartName getRelationshipPartName(PackagePart part)
-			throws InvalidOperationException {
-		PackagePartName partName;
-		if (part == null) {
-			partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
-		} else {
-			partName = part.getPartName();
-		}
-		return PackagingURIHelper.getRelationshipPartName(partName);
-	}
-
-	/**
-	 * Add the specified relationship to the collection.
-	 *
-	 * @param relPart
-	 *            The relationship to add.
-	 */
-	public void addRelationship(PackageRelationship relPart) {
-		relationshipsByID.put(relPart.getId(), relPart);
-		relationshipsByType.put(relPart.getRelationshipType(), relPart);
-	}
-
-	/**
-	 * Add a relationship to the collection.
-	 *
-	 * @param targetUri
-	 *            Target URI.
-	 * @param targetMode
-	 *            The target mode : INTERNAL or EXTERNAL
-	 * @param relationshipType
-	 *            Relationship type.
-	 * @param id
-	 *            Relationship ID.
-	 * @return The newly created relationship.
-	 * @see PackageAccess
-	 */
-	public PackageRelationship addRelationship(URI targetUri,
-			TargetMode targetMode, String relationshipType, String id) {
+    /**
+     * Package relationships ordered by ID.
+     */
+    private TreeMap<String, PackageRelationship> relationshipsByID;
+
+    /**
+     * Package relationships ordered by type.
+     */
+    private TreeMap<String, PackageRelationship> relationshipsByType;
+
+    /**
+     * This relationshipPart.
+     */
+    private PackagePart relationshipPart;
+
+    /**
+     * Source part.
+     */
+    private PackagePart sourcePart;
+
+    /**
+     * This part name.
+     */
+    private PackagePartName partName;
+
+    /**
+     * Reference to the package.
+     */
+    private OPCPackage container;
+    
+    /**
+     * The ID number of the next rID# to generate, or -1
+     *  if that is still to be determined.
+     */
+    private int nextRelationshipId = -1;
+
+    /**
+     * Constructor.
+     */
+    PackageRelationshipCollection() {
+        relationshipsByID = new TreeMap<String, PackageRelationship>();
+        relationshipsByType = new TreeMap<String, PackageRelationship>();
+    }
+
+    /**
+     * Copy constructor.
+     *
+     * This collection will contain only elements from the specified collection
+     * for which the type is compatible with the specified relationship type
+     * filter.
+     *
+     * @param coll
+     *            Collection to import.
+     * @param filter
+     *            Relationship type filter.
+     */
+    public PackageRelationshipCollection(PackageRelationshipCollection coll,
+            String filter) {
+        this();
+        for (PackageRelationship rel : coll.relationshipsByID.values()) {
+            if (filter == null || rel.getRelationshipType().equals(filter))
+                addRelationship(rel);
+        }
+    }
+
+    /**
+     * Constructor.
+     */
+    public PackageRelationshipCollection(OPCPackage container)
+            throws InvalidFormatException {
+        this(container, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @throws InvalidFormatException
+     *             Throws if the format of the content part is invalid.
+     *
+     * @throws InvalidOperationException
+     *             Throws if the specified part is a relationship part.
+     */
+    public PackageRelationshipCollection(PackagePart part)
+            throws InvalidFormatException {
+        this(part._container, part);
+    }
+
+    /**
+     * Constructor. Parse the existing package relationship part if one exists.
+     *
+     * @param container
+     *            The parent package.
+     * @param part
+     *            The part that own this relationships collection. If <b>null</b>
+     *            then this part is considered as the package root.
+     * @throws InvalidFormatException
+     *             If an error occurs during the parsing of the relatinships
+     *             part fo the specified part.
+     */
+    public PackageRelationshipCollection(OPCPackage container, PackagePart part)
+            throws InvalidFormatException {
+        this();
+
+        if (container == null)
+            throw new IllegalArgumentException("container");
+
+        // Check if the specified part is not a relationship part
+        if (part != null && part.isRelationshipPart())
+            throw new IllegalArgumentException("part");
+
+        this.container = container;
+        this.sourcePart = part;
+        this.partName = getRelationshipPartName(part);
+        if ((container.getPackageAccess() != PackageAccess.WRITE)
+                && container.containPart(this.partName)) {
+            relationshipPart = container.getPart(this.partName);
+            parseRelationshipsPart(relationshipPart);
+        }
+    }
+
+    /**
+     * Get the relationship part name of the specified part.
+     *
+     * @param part
+     *            The part .
+     * @return The relationship part name of the specified part. Be careful,
+     *         only the correct name is returned, this method does not check if
+     *         the part really exist in a package !
+     * @throws InvalidOperationException
+     *             Throws if the specified part is a relationship part.
+     */
+    private static PackagePartName getRelationshipPartName(PackagePart part)
+            throws InvalidOperationException {
+        PackagePartName partName;
+        if (part == null) {
+            partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
+        } else {
+            partName = part.getPartName();
+        }
+        return PackagingURIHelper.getRelationshipPartName(partName);
+    }
+
+    /**
+     * Add the specified relationship to the collection.
+     *
+     * @param relPart
+     *            The relationship to add.
+     */
+    public void addRelationship(PackageRelationship relPart) {
+        relationshipsByID.put(relPart.getId(), relPart);
+        relationshipsByType.put(relPart.getRelationshipType(), relPart);
+    }
+
+    /**
+     * Add a relationship to the collection.
+     *
+     * @param targetUri
+     *            Target URI.
+     * @param targetMode
+     *            The target mode : INTERNAL or EXTERNAL
+     * @param relationshipType
+     *            Relationship type.
+     * @param id
+     *            Relationship ID.
+     * @return The newly created relationship.
+     * @see PackageAccess
+     */
+    public PackageRelationship addRelationship(URI targetUri,
+            TargetMode targetMode, String relationshipType, String id) {
       if (id == null) {
          // Generate a unique ID is id parameter is null.
          if (nextRelationshipId == -1) {
@@ -224,229 +224,230 @@ public final class PackageRelationshipCo
          } while (relationshipsByID.get(id) != null);
       }
 
-		PackageRelationship rel = new PackageRelationship(container,
-				sourcePart, targetUri, targetMode, relationshipType, id);
-		relationshipsByID.put(rel.getId(), rel);
-		relationshipsByType.put(rel.getRelationshipType(), rel);
-		return rel;
-	}
-
-	/**
-	 * Remove a relationship by its ID.
-	 *
-	 * @param id
-	 *            The relationship ID to remove.
-	 */
-	public void removeRelationship(String id) {
-		if (relationshipsByID != null && relationshipsByType != null) {
-			PackageRelationship rel = relationshipsByID.get(id);
-			if (rel != null) {
-				relationshipsByID.remove(rel.getId());
-				relationshipsByType.values().remove(rel);
-			}
-		}
-	}
-
-	/**
-	 * Remove a relationship by its reference.
-	 *
-	 * @param rel
-	 *            The relationship to delete.
-	 */
-	public void removeRelationship(PackageRelationship rel) {
-		if (rel == null)
-			throw new IllegalArgumentException("rel");
-
-		relationshipsByID.values().remove(rel);
-		relationshipsByType.values().remove(rel);
-	}
-
-	/**
-	 * Retrieves a relationship by its index in the collection.
-	 *
-	 * @param index
-	 *            Must be a value between [0-relationships_count-1]
-	 */
-	public PackageRelationship getRelationship(int index) {
-		if (index < 0 || index > relationshipsByID.values().size())
-			throw new IllegalArgumentException("index");
-
-		PackageRelationship retRel = null;
-		int i = 0;
-		for (PackageRelationship rel : relationshipsByID.values()) {
-			if (index == i++)
-				return rel;
-		}
-		return retRel;
-	}
-
-	/**
-	 * Retrieves a package relationship based on its id.
-	 *
-	 * @param id
-	 *            ID of the package relationship to retrieve.
-	 * @return The package relationship identified by the specified id.
-	 */
-	public PackageRelationship getRelationshipByID(String id) {
-		return relationshipsByID.get(id);
-	}
-
-	/**
-	 * Get the numbe rof relationships in the collection.
-	 */
-	public int size() {
-		return relationshipsByID.values().size();
-	}
-
-	/**
-	 * Parse the relationship part and add all relationship in this collection.
-	 *
-	 * @param relPart
-	 *            The package part to parse.
-	 * @throws InvalidFormatException
-	 *             Throws if the relationship part is invalid.
-	 */
-	private void parseRelationshipsPart(PackagePart relPart)
-			throws InvalidFormatException {
-		try {
-			SAXReader reader = new SAXReader();
-			logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
-			Document xmlRelationshipsDoc = reader
-					.read(relPart.getInputStream());
-
-			// Browse default types
-			Element root = xmlRelationshipsDoc.getRootElement();
-
-			// Check OPC compliance M4.1 rule
-			boolean fCorePropertiesRelationship = false;
-
-			for (Iterator i = root
-					.elementIterator(PackageRelationship.RELATIONSHIP_TAG_NAME); i
-					.hasNext();) {
-				Element element = (Element) i.next();
-				// Relationship ID
-				String id = element.attribute(
-						PackageRelationship.ID_ATTRIBUTE_NAME).getValue();
-				// Relationship type
-				String type = element.attribute(
-						PackageRelationship.TYPE_ATTRIBUTE_NAME).getValue();
-
-				/* Check OPC Compliance */
-				// Check Rule M4.1
-				if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES))
-					if (!fCorePropertiesRelationship)
-						fCorePropertiesRelationship = true;
-					else
-						throw new InvalidFormatException(
-								"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
-
-				/* End OPC Compliance */
-
-				// TargetMode (default value "Internal")
-				Attribute targetModeAttr = element
-						.attribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
-				TargetMode targetMode = TargetMode.INTERNAL;
-				if (targetModeAttr != null) {
-					targetMode = targetModeAttr.getValue().toLowerCase()
-							.equals("internal") ? TargetMode.INTERNAL
-							: TargetMode.EXTERNAL;
-				}
-
-				// Target converted in URI
-				URI target;
-				String value = "";
-				try {
-					value = element.attribute(
-							PackageRelationship.TARGET_ATTRIBUTE_NAME)
-							.getValue();
-
+        PackageRelationship rel = new PackageRelationship(container,
+                sourcePart, targetUri, targetMode, relationshipType, id);
+        relationshipsByID.put(rel.getId(), rel);
+        relationshipsByType.put(rel.getRelationshipType(), rel);
+        return rel;
+    }
+
+    /**
+     * Remove a relationship by its ID.
+     *
+     * @param id
+     *            The relationship ID to remove.
+     */
+    public void removeRelationship(String id) {
+        if (relationshipsByID != null && relationshipsByType != null) {
+            PackageRelationship rel = relationshipsByID.get(id);
+            if (rel != null) {
+                relationshipsByID.remove(rel.getId());
+                relationshipsByType.values().remove(rel);
+            }
+        }
+    }
+
+    /**
+     * Remove a relationship by its reference.
+     *
+     * @param rel
+     *            The relationship to delete.
+     */
+    public void removeRelationship(PackageRelationship rel) {
+        if (rel == null)
+            throw new IllegalArgumentException("rel");
+
+        relationshipsByID.values().remove(rel);
+        relationshipsByType.values().remove(rel);
+    }
+
+    /**
+     * Retrieves a relationship by its index in the collection.
+     *
+     * @param index
+     *            Must be a value between [0-relationships_count-1]
+     */
+    public PackageRelationship getRelationship(int index) {
+        if (index < 0 || index > relationshipsByID.values().size())
+            throw new IllegalArgumentException("index");
+
+        PackageRelationship retRel = null;
+        int i = 0;
+        for (PackageRelationship rel : relationshipsByID.values()) {
+            if (index == i++)
+                return rel;
+        }
+        return retRel;
+    }
+
+    /**
+     * Retrieves a package relationship based on its id.
+     *
+     * @param id
+     *            ID of the package relationship to retrieve.
+     * @return The package relationship identified by the specified id.
+     */
+    public PackageRelationship getRelationshipByID(String id) {
+        return relationshipsByID.get(id);
+    }
+
+    /**
+     * Get the numbe rof relationships in the collection.
+     */
+    public int size() {
+        return relationshipsByID.values().size();
+    }
+
+    /**
+     * Parse the relationship part and add all relationship in this collection.
+     *
+     * @param relPart
+     *            The package part to parse.
+     * @throws InvalidFormatException
+     *             Throws if the relationship part is invalid.
+     */
+    private void parseRelationshipsPart(PackagePart relPart)
+            throws InvalidFormatException {
+        try {
+            SAXReader reader = new SAXReader();
+            logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
+            Document xmlRelationshipsDoc = reader
+                    .read(relPart.getInputStream());
+
+            // Browse default types
+            Element root = xmlRelationshipsDoc.getRootElement();
+
+            // Check OPC compliance M4.1 rule
+            boolean fCorePropertiesRelationship = false;
+
+            @SuppressWarnings("unchecked")
+            Iterator<Element> iter = (Iterator<Element>)
+                root.elementIterator(PackageRelationship.RELATIONSHIP_TAG_NAME);
+            while (iter.hasNext()) {
+                Element element = iter.next();
+                // Relationship ID
+                String id = element.attribute(
+                        PackageRelationship.ID_ATTRIBUTE_NAME).getValue();
+                // Relationship type
+                String type = element.attribute(
+                        PackageRelationship.TYPE_ATTRIBUTE_NAME).getValue();
+
+                /* Check OPC Compliance */
+                // Check Rule M4.1
+                if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES))
+                    if (!fCorePropertiesRelationship)
+                        fCorePropertiesRelationship = true;
+                    else
+                        throw new InvalidFormatException(
+                                "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
+
+                /* End OPC Compliance */
+
+                // TargetMode (default value "Internal")
+                Attribute targetModeAttr = element
+                        .attribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
+                TargetMode targetMode = TargetMode.INTERNAL;
+                if (targetModeAttr != null) {
+                    targetMode = targetModeAttr.getValue().toLowerCase()
+                            .equals("internal") ? TargetMode.INTERNAL
+                            : TargetMode.EXTERNAL;
+                }
+
+                // 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);
-
-				} catch (URISyntaxException e) {
-					logger.log(POILogger.ERROR, "Cannot convert " + value
-							+ " in a valid relationship URI-> ignored", e);
-					continue;
-				}
-				addRelationship(target, targetMode, type, id);
-			}
-		} catch (Exception e) {
-			logger.log(POILogger.ERROR, e);
-			throw new InvalidFormatException(e.getMessage());
-		}
-	}
-
-	/**
-	 * Retrieves all relations with the specified type.
-	 *
-	 * @param typeFilter
-	 *            Relationship type filter. If <b>null</b> then all
-	 *            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.
-	 */
-	public Iterator<PackageRelationship> iterator() {
-		return relationshipsByID.values().iterator();
-	}
-
-	/**
-	 * Get an iterator of a collection with all relationship with the specified
-	 * type.
-	 *
-	 * @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();
-	}
-
-	/**
-	 * Clear all relationships.
-	 */
-	public void clear() {
-		relationshipsByID.clear();
-		relationshipsByType.clear();
-	}
-
-	@Override
-	public String toString() {
-		String str;
-		if (relationshipsByID == null) {
-			str = "relationshipsByID=null";
-		} else {
-			str = relationshipsByID.size() + " relationship(s) = [";
-		}
-		if ((relationshipPart != null) && (relationshipPart._partName != null)) {
-			str = str + "," + relationshipPart._partName;
-		} else {
-			str = str + ",relationshipPart=null";
-		}
-
-		// 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 + "]";
-	}
+                } 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());
+        }
+    }
+
+    /**
+     * Retrieves all relations with the specified type.
+     *
+     * @param typeFilter
+     *            Relationship type filter. If <b>null</b> then all
+     *            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.
+     */
+    public Iterator<PackageRelationship> iterator() {
+        return relationshipsByID.values().iterator();
+    }
+
+    /**
+     * Get an iterator of a collection with all relationship with the specified
+     * type.
+     *
+     * @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();
+    }
+
+    /**
+     * Clear all relationships.
+     */
+    public void clear() {
+        relationshipsByID.clear();
+        relationshipsByType.clear();
+    }
+
+    @Override
+    public String toString() {
+        String str;
+        if (relationshipsByID == null) {
+            str = "relationshipsByID=null";
+        } else {
+            str = relationshipsByID.size() + " relationship(s) = [";
+        }
+        if ((relationshipPart != null) && (relationshipPart._partName != null)) {
+            str = str + "," + relationshipPart._partName;
+        } else {
+            str = str + ",relationshipPart=null";
+        }
+
+        // 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 + "]";
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java?rev=1563540&r1=1563539&r2=1563540&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java Sun Feb  2 01:56:02 2014
@@ -30,6 +30,7 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackageRelationship;
 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.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -54,252 +55,278 @@ public final class XSSFRelation extends 
     protected static Map<String, XSSFRelation> _table = new HashMap<String, XSSFRelation>();
 
 
-	public static final XSSFRelation WORKBOOK = new XSSFRelation(
-			"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
-			"http://schemas.openxmlformats.org/officeDocument/2006/relationships/workbook",
-			"/xl/workbook.xml",
-			null
-	);
-	public static final XSSFRelation MACROS_WORKBOOK = new XSSFRelation(
-			"application/vnd.ms-excel.sheet.macroEnabled.main+xml",
-			"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
-			"/xl/workbook.xml",
-			null
-	);
+    public static final XSSFRelation WORKBOOK = new XSSFRelation(
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
+        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/workbook",
+        "/xl/workbook.xml",
+        null
+    );
+    public static final XSSFRelation MACROS_WORKBOOK = new XSSFRelation(
+        "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
+        PackageRelationshipTypes.CORE_DOCUMENT,
+        "/xl/workbook.xml",
+        null
+    );
     public static final XSSFRelation TEMPLATE_WORKBOOK = new XSSFRelation(
-              "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
-              "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
-              "/xl/workbook.xml",
-              null
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
+        PackageRelationshipTypes.CORE_DOCUMENT,
+        "/xl/workbook.xml",
+        null
     );
+
     public static final XSSFRelation MACRO_TEMPLATE_WORKBOOK = new XSSFRelation(
-              "application/vnd.ms-excel.template.macroEnabled.main+xml",
-              "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
-              "/xl/workbook.xml",
-              null
+        "application/vnd.ms-excel.template.macroEnabled.main+xml",
+        PackageRelationshipTypes.CORE_DOCUMENT,
+        "/xl/workbook.xml",
+        null
     );
+
     public static final XSSFRelation MACRO_ADDIN_WORKBOOK = new XSSFRelation(
-              "application/vnd.ms-excel.addin.macroEnabled.main+xml",
-              "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
-              "/xl/workbook.xml",
-              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(
-			"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
-	);
+        "application/vnd.ms-excel.addin.macroEnabled.main+xml",
+        PackageRelationshipTypes.CORE_DOCUMENT,
+        "/xl/workbook.xml",
+        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",
+        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(
-            null,
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		null,
-    		XSSFPictureData.class
+        null,
+        PackageRelationshipTypes.IMAGE_PART,
+        null,
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_EMF = new XSSFRelation(
-            "image/x-emf",
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		"/xl/media/image#.emf",
-    		XSSFPictureData.class
+        "image/x-emf",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.emf",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_WMF = new XSSFRelation(
-            "image/x-wmf",
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		"/xl/media/image#.wmf",
-    		XSSFPictureData.class
+        "image/x-wmf",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.wmf",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_PICT = new XSSFRelation(
-            "image/pict",
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		"/xl/media/image#.pict",
-    		XSSFPictureData.class
+        "image/pict",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.pict",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_JPEG = new XSSFRelation(
-            "image/jpeg",
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		"/xl/media/image#.jpeg",
-    		XSSFPictureData.class
+        "image/jpeg",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.jpeg",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_PNG = new XSSFRelation(
-            "image/png",
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		"/xl/media/image#.png",
-    		XSSFPictureData.class
+        "image/png",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.png",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_DIB = new XSSFRelation(
-            "image/dib",
-     		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-    		"/xl/media/image#.dib",
-    		XSSFPictureData.class
+        "image/dib",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.dib",
+        XSSFPictureData.class
     );
 
     public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
-            "image/gif",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/xl/media/image#.gif",
-            XSSFPictureData.class
+        "image/gif",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.gif",
+        XSSFPictureData.class
     );
 
     public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
-            "image/tiff",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/xl/media/image#.tiff",
-            XSSFPictureData.class
+        "image/tiff",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.tiff",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
-            "image/x-eps",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/xl/media/image#.eps",
-            XSSFPictureData.class
+        "image/x-eps",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.eps",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
-            "image/x-ms-bmp",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/xl/media/image#.bmp",
-            XSSFPictureData.class
+        "image/x-ms-bmp",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.bmp",
+        XSSFPictureData.class
     );
+
     public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
-            "image/x-wpg",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/xl/media/image#.wpg",
-            XSSFPictureData.class
-    );
-
-  public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
-		    "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
-		    "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
-		    "/xl/comments#.xml",
-		    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(
-            "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
-	);
+        "image/x-wpg",
+        PackageRelationshipTypes.IMAGE_PART,
+        "/xl/media/image#.wpg",
+        XSSFPictureData.class
+    );
+
+    public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
+        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
+        "/xl/comments#.xml",
+        CommentsTable.class
+    );
+
+    public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
+        null,
+        PackageRelationshipTypes.HYPERLINK_PART,
+        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(
+        "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(
-            "application/vnd.openxmlformats-officedocument.theme+xml",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
-            "/xl/theme/theme#.xml",
-            ThemesTable.class
+        "application/vnd.openxmlformats-officedocument.theme+xml",
+        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
+        "/xl/theme/theme#.xml",
+        ThemesTable.class
     );
+
     public static final XSSFRelation CALC_CHAIN = new XSSFRelation(
-            "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
-            "/xl/calcChain.xml",
-            CalculationChain.class
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
+        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
+        "/xl/calcChain.xml",
+        CalculationChain.class
     );
+
     public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation(
-          "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
-          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
-          "/xl/printerSettings/printerSettings#.bin",
-          null
-   );
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
+        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
+        "/xl/printerSettings/printerSettings#.bin",
+        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);
 
         if(cls != null && !_table.containsKey(rel)) _table.put(rel, this);
     }
 
     /**
-	 *  Fetches the InputStream to read the contents, based
-	 *  of the specified core part, for which we are defined
-	 *  as a suitable relationship
-	 */
-	public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
+     *  Fetches the InputStream to read the contents, based
+     *  of the specified core part, for which we are defined
+     *  as a suitable relationship
+     */
+    public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
         PackageRelationshipCollection prc =
-        	corePart.getRelationshipsByType(_relation);
+            corePart.getRelationshipsByType(_relation);
         Iterator<PackageRelationship> it = prc.iterator();
         if(it.hasNext()) {
             PackageRelationship rel = it.next();
@@ -309,8 +336,7 @@ public final class XSSFRelation extends 
         }
         log.log(POILogger.WARN, "No part " + _defaultName + " found");
         return null;
-	}
-
+    }
 
     /**
      * Get POIXMLRelation by relation type

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1563540&r1=1563539&r2=1563540&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Sun Feb  2 01:56:02 2014
@@ -26,7 +26,6 @@ import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
 import java.util.List;
 
 import org.apache.poi.EncryptedDocumentException;
@@ -1414,30 +1413,31 @@ public final class TestXSSFBugs extends 
      *  error message when called via WorkbookFactory.
      * (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
-    public void bug55692() throws Exception {
-    	InputStream inpA = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
-    	InputStream inpB = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
-    	InputStream inpC = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
-
-    	// 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) {}
+    public void bug53282() {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53282b.xlsx");
+        Cell c = wb.getSheetAt(0).getRow(1).getCell(0);
+        assertEquals("#@_#", c.getStringCellValue()); 
+        assertEquals("http://invalid.uri", c.getHyperlink().getAddress()); 
     }
 }

Added: poi/trunk/test-data/spreadsheet/53282b.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/53282b.xlsx?rev=1563540&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/53282b.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Re: svn commit: r1563540 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/ trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/ trunk/test-data/spread...

Posted by Nick Burch <ap...@gagravarr.org>.
On Sun, 2 Feb 2014, kiwiwings@apache.org wrote:
> public final class PackageRelationshipCollection implements
> -		Iterable<PackageRelationship> {
> +        Iterable<PackageRelationship> {
>
>     private static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
>
> -	/**
> -	 * Package relationships ordered by ID.
> -	 */

Minor thing, but if you find yourself working on a file with inconsistent 
line endings / whitespace, it's generally better to do two commits. One 
commit to fix up the whitespace, a second for the actual logic changes.

If they're split out, then it's very easy to review the change from the 
diff email. If they go in together, reviewing means more faffing with svn 
diff to exclude whitespace, so it's a lot harder, and hence fewer people 
will review!

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org