java.lang.Object
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 open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
- See Also:
- CustomPart, Document.PackageCustomParts
Property Getters/Setters Summary |
int | getCount() | |
|
Gets the number of elements contained in the collection.
|
CustomPart | get(int index) | |
void | set(int index, CustomPart value) | |
|
Gets or sets an item at the specified index.
|
Method Summary |
void | add(CustomPart part) | |
Adds an item to the collection.
|
void | clear() | |
Removes all elements from the collection.
|
CustomPartCollection | deepClone() | |
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.
|
void | removeAt(int index) | |
Removes an item at the specified index.
|
CustomPartCollection
public CustomPartCollection()
-
Property Getters/Setters Detail |
getCount | |
public int getCount()
|
-
Gets the number of elements contained in the collection.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
-
Gets or sets an item at the specified index.
- Parameters:
index
- Zero-based index of the item.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
-
Adds an item to the collection.
- Parameters:
part
- The item to add.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
clear | |
public void clear() |
-
Removes all elements from the collection.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
-
Makes a deep copy of this collection and its items.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
iterator | |
public java.util.Iterator<CustomPart> iterator() |
-
Returns an iterator object that can be used to iterate over all items in the collection.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
removeAt | |
public void removeAt(int index) |
-
Removes an item at the specified index.
- Parameters:
index
- The zero based index.
Example:
Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(getMyDir() + "Document.PackageCustomParts.docx");
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Clone the second part
CustomPart clonedPart = doc.getPackageCustomParts().get(1).deepClone();
// Add the clone to the collection
doc.getPackageCustomParts().add(clonedPart);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 3);
// Use an enumerator to print information about the contents of each part
Iterator<CustomPart> enumerator = doc.getPackageCustomParts().iterator();
int index = 0;
while (enumerator.hasNext()) {
CustomPart 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++;
}
// Delete parts one at a time based on index
doc.getPackageCustomParts().removeAt(2);
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 2);
// Delete all parts
doc.getPackageCustomParts().clear();
Assert.assertEquals(doc.getPackageCustomParts().getCount(), 0);
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.