com.aspose.words
Class CustomPartCollection

java.lang.Object
    extended by com.aspose.words.CustomPartCollection
All Implemented Interfaces:
java.lang.Iterable

public class CustomPartCollection 
extends java.lang.Object

Represents a collection of CustomPart objects.

You do not normally need to create instances of this class. You access custom parts related to the OOXML package via the Document.PackageCustomParts property.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());
See Also:
CustomPart, Document.PackageCustomParts

Constructor Summary
CustomPartCollection()
          
 
Property Getters/Setters Summary
intgetCount()
           Gets the number of elements contained in the collection.
CustomPartget(int index)
voidset(int index, CustomPart value)
           Gets or sets an item at the specified index.
 
Method Summary
voidadd(CustomPart part)
           Adds an item to the collection.
voidclear()
           Removes all elements from the collection.
CustomPartCollectiondeepClone()
           Makes a deep copy of this collection and its items.
java.util.Iterator<CustomPart>iterator()
           Returns an iterator object that can be used to iterate over all items in the collection.
voidremoveAt(int index)
           Removes an item at the specified index.
 

Constructor Detail

CustomPartCollection

public CustomPartCollection()

Property Getters/Setters Detail

getCount

public int getCount()
Gets the number of elements contained in the collection.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

get/set

public CustomPart get(int index) / public void set(int index, CustomPart value)
Gets or sets an item at the specified index.
Parameters:
index - Zero-based index of the item.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

Method Detail

add

public void add(CustomPart part)
Adds an item to the collection.
Parameters:
part - The item to add.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

clear

public void clear()
Removes all elements from the collection.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

deepClone

public CustomPartCollection deepClone()
Makes a deep copy of this collection and its items.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

iterator

public java.util.Iterator<CustomPartiterator()
Returns an iterator object that can be used to iterate over all items in the collection.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

removeAt

public void removeAt(int index)
Removes an item at the specified index.
Parameters:
index - The zero based index.

Example:

Shows how to access a document's arbitrary custom parts collection.
Document doc = new Document(getMyDir() + "Custom parts OOXML package.docx");

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(3, doc.getPackageCustomParts().getCount());

// Enumerate over the collection and print every part.
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();

int index = 0;
while (enumerator.hasNext()) {
    CustomPart customPart = enumerator.next();
    System.out.println(MessageFormat.format("Part index {0}:", index));
    System.out.println(MessageFormat.format("\tName: {0}", customPart.getName()));
    System.out.println(MessageFormat.format("\tContentType: {0}", customPart.getContentType()));
    System.out.println(MessageFormat.format("\tRelationshipType: {0}", customPart.getRelationshipType()));
    if (customPart.isExternal()) {
        System.out.println("\tSourced from outside the document");
    } else {
        System.out.println(MessageFormat.format("\tSourced from within the document, length: {0} bytes", customPart.getData().length));
    }
    index++;
}

// We can remove elements from this collection individually, or all at once.
doc.getPackageCustomParts().removeAt(2);

Assert.assertEquals(2, doc.getPackageCustomParts().getCount());

doc.getPackageCustomParts().clear();

Assert.assertEquals(0, doc.getPackageCustomParts().getCount());

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.