poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1172853 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/org/apache/poi/xslf/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/java/org/apache/poi/xwpf/usermodel/
Date Mon, 19 Sep 2011 21:40:40 GMT
Author: nick
Date: Mon Sep 19 21:40:39 2011
New Revision: 1172853

URL: http://svn.apache.org/viewvc?rev=1172853&view=rev
Log:
New PackagePart method getRelatedPart(PackageRelationship) to simplify navigation of relations
between OPC Parts

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Sep 19 21:40:39 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="add">New PackagePart method getRelatedPart(PackageRelationship)
to simplify navigation of relations between OPC Parts</action>
            <action dev="poi-developers" type="fix">51832 - handle XLS files where the
WRITEPROTECT record preceeds the FILEPASS one, rather than following as normal</action>
            <action dev="poi-developers" type="fix">51809 - correct GTE handling in
COUNTIF</action>
            <action dev="poi-developers" type="add">Add HWPF API to update range text
and delete bookmarks</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Mon Sep 19 21:40:39 2011
@@ -90,7 +90,7 @@ public abstract class POIXMLDocument ext
         PackagePart[] parts = new PackagePart[partsC.size()];
         int count = 0;
         for (PackageRelationship rel : partsC) {
-            parts[count] = getTargetPart(rel);
+            parts[count] = getPackagePart().getRelatedPart(rel);
             count++;
         }
         return parts;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java Mon Sep 19 21:40:39 2011
@@ -62,23 +62,6 @@ public class POIXMLDocumentPart {
     private Map<String,POIXMLDocumentPart> relations = new LinkedHashMap<String,POIXMLDocumentPart>();
 
     /**
-     * Get the PackagePart that is the target of a relationship.
-     *
-     * @param rel The relationship
-     * @param pkg The package to fetch from
-     * @return The target part
-     * @throws InvalidFormatException
-     */
-    protected static PackagePart getTargetPart(OPCPackage pkg, PackageRelationship rel)
-    throws InvalidFormatException {
-        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
-        PackagePart part = pkg.getPart(relName);
-        if (part == null) {
-            throw new IllegalArgumentException("No part found for relationship " + rel);
-        }
-        return part;
-    }
-    /**
      * Counter that provides the amount of incoming relations from other parts
      * to this part.
      */
@@ -159,7 +142,7 @@ public class POIXMLDocumentPart {
             );
         }
         packageRel = cores.getRelationship(0);
-        packagePart = POIXMLDocument.getTargetPart(pkg, packageRel);
+        packagePart = packagePart.getRelatedPart(packageRel);
     }
 
     /**
@@ -425,6 +408,18 @@ public class POIXMLDocumentPart {
             }
         }
     }
+    
+    /**
+     * Get the PackagePart that is the target of a relationship from this Part.
+     *
+     * @param rel The relationship
+     * @return The target part
+     * @throws InvalidFormatException
+     */
+    protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException
{
+        return getPackagePart().getRelatedPart(rel);
+    }
+
 
     /**
      * Fired when a new package part is created
@@ -441,17 +436,6 @@ public class POIXMLDocumentPart {
     }
 
     /**
-     * Get the PackagePart that is the target of a relationship.
-     *
-     * @param rel The relationship
-     * @return The target part
-     * @throws InvalidFormatException
-     */
-    protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException
{
-        return getTargetPart(getPackagePart().getPackage(), rel);
-    }
-
-    /**
      * Fired when a package part is about to be removed from the package
      */
     protected void onDocumentRemove() throws IOException {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java Mon Sep 19 21:40:39
2011
@@ -456,6 +456,38 @@ public abstract class PackagePart implem
         return false;
 	}
 
+   /**
+    * Get the PackagePart that is the target of a relationship.
+    *
+    * @param rel A relationship from this part to another one 
+    * @return The target part of the relationship
+    */
+   public PackagePart getRelatedPart(PackageRelationship rel) throws InvalidFormatException
{
+       // Ensure this is one of ours
+       if(! isRelationshipExists(rel)) {
+          throw new IllegalArgumentException("Relationship " + rel + " doesn't start with
this part " + _partName);
+       }
+       
+       // Get the target URI, excluding any relative fragments
+       URI target = rel.getTargetURI();
+       if(target.getFragment() != null) {
+          String t = target.toString();
+          try {
+             target = new URI( t.substring(0, t.indexOf('#')) );
+          } catch(URISyntaxException e) {
+             throw new InvalidFormatException("Invalid target URI: " + target);
+          }
+       }
+   
+       // Turn that into a name, and fetch
+       PackagePartName relName = PackagingURIHelper.createPartName(target);
+       PackagePart part = _container.getPart(relName);
+       if (part == null) {
+           throw new IllegalArgumentException("No part found for relationship " + rel);
+       }
+       return part;
+   }
+   
 	/**
 	 * Get the input stream of this part to read its content.
 	 *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java Mon Sep 19 21:40:39 2011
@@ -78,14 +78,15 @@ public class XSLFSlideShow extends POIXM
 		
       embedds = new LinkedList<PackagePart>();
       for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) {
-	          PackagePart slidePart =
-	                getTargetPart(getCorePart().getRelationship(ctSlide.getId2()));
+             PackagePart corePart = getCorePart();
+	          PackagePart slidePart = corePart.getRelatedPart(
+	                corePart.getRelationship(ctSlide.getId2()));
 
 	          for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE))
-	              embedds.add(getTargetPart(rel)); // TODO: Add this reference to each slide
as well
+	              embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to
each slide as well
 
 	          for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE))
-                  embedds.add(getTargetPart(rel));
+                  embedds.add(slidePart.getRelatedPart(rel));
 		}
 	}
 	public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException {
@@ -129,8 +130,9 @@ public class XSLFSlideShow extends POIXM
 	
 	public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException,
XmlException {
 		try {
-			return getTargetPart(
-				getCorePart().getRelationship(master.getId2())
+		   PackagePart corePart = getCorePart(); 
+			return corePart.getRelatedPart(
+				corePart.getRelationship(master.getId2())
 			);
 		} catch(InvalidFormatException e) {
 			throw new XmlException(e);
@@ -150,9 +152,10 @@ public class XSLFSlideShow extends POIXM
 
 	public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException
{
 		try {
-			return getTargetPart(
-					getCorePart().getRelationship(slide.getId2())
-			);
+	      PackagePart corePart = getCorePart(); 
+	      return corePart.getRelatedPart(
+	         corePart.getRelationship(slide.getId2())
+	      );
 		} catch(InvalidFormatException e) {
 			throw new XmlException(e);
 		}
@@ -192,7 +195,7 @@ public class XSLFSlideShow extends POIXM
 		}
 		
 		try {
-			return getTargetPart(notes.getRelationship(0));
+		   return slidePart.getRelatedPart(notes.getRelationship(0));
 		} catch(InvalidFormatException e) {
 			throw new IllegalStateException(e);
 		}
@@ -236,7 +239,7 @@ public class XSLFSlideShow extends POIXM
 		}
 		
 		try {
-			PackagePart cPart = getTargetPart(
+			PackagePart cPart = slidePart.getRelatedPart(
 					commentRels.getRelationship(0)
 			);
 			CmLstDocument commDoc = 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Mon Sep 19 21:40:39
2011
@@ -1333,12 +1333,13 @@ public class XSSFWorkbook extends POIXML
 
         for(XSSFSheet sheet : sheets){
             // Get the embeddings for the workbook
-            for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
-                embedds.add(getTargetPart(rel));
-
-            for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
-                embedds.add(getTargetPart(rel));
-
+            for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
{
+                embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
+            }
+
+            for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
{
+               embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
+            }
         }
         return embedds;
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1172853&r1=1172852&r2=1172853&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Mon Sep 19 21:40:39
2011
@@ -387,7 +387,8 @@ public class XWPFDocument extends POIXML
      */
     public PackagePart getPartById(String id) {
         try {
-            return getTargetPart(getCorePart().getRelationship(id));
+            PackagePart corePart = getCorePart();
+            return corePart.getRelatedPart(corePart.getRelationship(id));
         } catch (InvalidFormatException e) {
             throw new IllegalArgumentException(e);
         }
@@ -428,12 +429,13 @@ public class XWPFDocument extends POIXML
         List<PackagePart> embedds = new LinkedList<PackagePart>();
 
         // Get the embeddings for the workbook
+        PackagePart part = getPackagePart();
         for (PackageRelationship rel : getPackagePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE))
{
-            embedds.add(getTargetPart(rel));
+            embedds.add(part.getRelatedPart(rel));
         }
 
         for (PackageRelationship rel : getPackagePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE))
{
-            embedds.add(getTargetPart(rel));
+            embedds.add(part.getRelatedPart(rel));
         }
 
         return embedds;



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


Mime
View raw message