コード例 #1
0
ファイル: PackagePart.cs プロジェクト: IMULMUL/npoi
        /**
         * Add a relationship to a part (except relationships part).
         * <p>
         * Check rule M1.25: The Relationships part shall not have relationships to
         * any other part. Package implementers shall enforce this requirement upon
         * the attempt to create such a relationship and shall treat any such
         * relationship as invalid.
         * </p>
         * @param targetURI
         *            URI of the target part. Must be relative to the source root
         *            directory of the part.
         * @param targetMode
         *            Mode [Internal|External].
         * @param relationshipType
         *            Type of relationship.
         * @param id
         *            Relationship unique id.
         * @return The newly created and added relationship
         *
         * @throws InvalidFormatException
         *             If the URI point to a relationship part URI.
         * @see org.apache.poi.OpenXml4Net.opc.RelationshipSource#AddRelationship(org.apache.poi.OpenXml4Net.opc.PackagePartName,
         *      org.apache.poi.OpenXml4Net.opc.TargetMode, java.lang.String, java.lang.String)
         */
        public PackageRelationship AddRelationship(Uri targetURI,
                                                   TargetMode targetMode, String relationshipType, String id)
        {
            _container.ThrowExceptionIfReadOnly();

            if (targetURI == null)
            {
                throw new ArgumentException("targetPartName");
            }
            //if (targetMode == null)
            //{
            //    throw new ArgumentException("targetMode");
            //}
            if (relationshipType == null)
            {
                throw new ArgumentException("relationshipType");
            }

            // Try to retrieve the target part

            if (this.IsRelationshipPart ||
                PackagingUriHelper.IsRelationshipPartURI(targetURI))
            {
                throw new InvalidOperationException(
                          "Rule M1.25: The Relationships part shall not have relationships to any other part.");
            }

            if (_relationships == null)
            {
                _relationships = new PackageRelationshipCollection();
            }

            return(_relationships.AddRelationship(targetURI,
                                                  targetMode, relationshipType, id));
        }
コード例 #2
0
        /**
         * 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);
        }
コード例 #3
0
ファイル: PackagePart.cs プロジェクト: IMULMUL/npoi
        /**
         * Adds an external relationship to a part (except relationships part).
         *
         * The targets of external relationships are not subject to the same
         * validity checks that internal ones are, as the contents is potentially
         * any file, URL or similar.
         *
         * @param target
         *            External target of the relationship
         * @param relationshipType
         *            Type of relationship.
         * @param id
         *            Relationship unique id.
         * @return The newly created and added relationship
         * @see org.apache.poi.OpenXml4Net.opc.RelationshipSource#addExternalRelationship(java.lang.String,
         *      java.lang.String)
         */
        public PackageRelationship AddExternalRelationship(String target,
                                                           String relationshipType, String id)
        {
            if (target == null)
            {
                throw new ArgumentException("target");
            }
            if (relationshipType == null)
            {
                throw new ArgumentException("relationshipType");
            }

            if (_relationships == null)
            {
                _relationships = new PackageRelationshipCollection();
            }

            Uri targetURI;

            try
            {
                targetURI = PackagingUriHelper.ParseUri(target, UriKind.RelativeOrAbsolute);
            }
            catch (UriFormatException e)
            {
                throw new ArgumentException("Invalid target - " + e);
            }

            return(_relationships.AddRelationship(targetURI, TargetMode.External,
                                                  relationshipType, id));
        }
コード例 #4
0
ファイル: PackagePart.cs プロジェクト: thachgiasoft/shuijin
        /**
         * Add a relationship to a part (except relationships part).
         * <p>
         * Check rule M1.25: The Relationships part shall not have relationships to
         * any other part. Package implementers shall enforce this requirement upon
         * the attempt to create such a relationship and shall treat any such
         * relationship as invalid.
         * </p>
         * @param targetPartName
         *            Name of the target part. This one must be relative to the
         *            source root directory of the part.
         * @param targetMode
         *            Mode [Internal|External].
         * @param relationshipType
         *            Type of relationship.
         * @param id
         *            Relationship unique id.
         * @return The newly created and added relationship
         *
         * @throws InvalidFormatException
         *             If the URI point to a relationship part URI.
         * @see org.apache.poi.OpenXml4Net.opc.RelationshipSource#AddRelationship(org.apache.poi.OpenXml4Net.opc.PackagePartName,
         *      org.apache.poi.OpenXml4Net.opc.TargetMode, java.lang.String, java.lang.String)
         */
        public PackageRelationship AddRelationship(PackagePartName targetPartName,
                                                   TargetMode targetMode, String relationshipType, String id)
        {
            container.ThrowExceptionIfReadOnly();

            if (targetPartName == null)
            {
                throw new ArgumentException("targetPartName");
            }
            //if (targetMode == null)
            //{
            //    throw new ArgumentException("targetMode");
            //}
            if (relationshipType == null)
            {
                throw new ArgumentException("relationshipType");
            }

            if (this.IsRelationshipPart || targetPartName.IsRelationshipPartURI())
            {
                throw new InvalidOperationException(
                          "Rule M1.25: The Relationships part shall not have relationships to any other part.");
            }

            if (relationships == null)
            {
                relationships = new PackageRelationshipCollection();
            }

            return(relationships.AddRelationship(targetPartName.URI,
                                                 targetMode, relationshipType, id));
        }
コード例 #5
0
ファイル: PackagePart.cs プロジェクト: IMULMUL/npoi
 /**
  * Ensure the package relationships collection instance is built.
  *
  * @throws InvalidFormatException
  *             Throws if
  */
 private void LoadRelationships()
 {
     if (this._relationships == null && !this.IsRelationshipPart)
     {
         this.ThrowExceptionIfRelationship();
         _relationships = new PackageRelationshipCollection(this);
     }
 }
コード例 #6
0
ファイル: PackagePart.cs プロジェクト: IMULMUL/npoi
 /**
  * Implementation of the getRelationships method().
  *
  * @param filter
  *            Relationship type filter. If <i>null</i> then the filter is
  *            disabled and return all the relationships.
  * @return All relationships from this part that have the specified type.
  * @throws InvalidFormatException
  *             Throws if an error occurs during parsing the relationships
  *             part.
  * @throws InvalidOperationException
  *             Throws if the package is open en write only mode.
  * @see #getRelationshipsByType(String)
  */
 private PackageRelationshipCollection GetRelationshipsCore(String filter)
 {
     this._container.ThrowExceptionIfWriteOnly();
     if (_relationships == null)
     {
         this.ThrowExceptionIfRelationship();
         _relationships = new PackageRelationshipCollection(this);
     }
     return(new PackageRelationshipCollection(_relationships, filter));
 }
コード例 #7
0
 /**
  * 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()
 {
     foreach (PackageRelationship rel in coll.relationshipsByID.Values)
     {
         if (filter == null || rel.RelationshipType.Equals(filter))
         {
             AddRelationship(rel);
         }
     }
 }