|
com.aspose.words
Class DocumentPropertyCollection
java.lang.Object
com.aspose.words.DocumentPropertyCollection
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Iterable
- Direct Known Subclasses:
- BuiltInDocumentProperties, CustomDocumentProperties
public abstract class DocumentPropertyCollection - extends java.lang.Object
Base class for BuiltInDocumentProperties and CustomDocumentProperties collections.
The names of the properties are case-insensitive. The properties in the collection are sorted alphabetically by name. - See Also:
- BuiltInDocumentProperties, CustomDocumentProperties
|
Method Summary |
void | clear() | |
|
Removes all properties from the collection.
|
boolean | contains(java.lang.String name) | |
|
Returns true if a property with the specified name exists in the collection.
|
int | indexOf(java.lang.String name) | |
|
Gets the index of a property by name.
|
java.util.Iterator | iterator() | |
|
Returns an iterator object that can be used to iterate over all items in the collection.
|
void | remove(java.lang.String name) | |
|
Removes a property with the specified name from the collection.
|
void | removeAt(int index) | |
|
Removes a property at the specified index.
|
|
Property Getters/Setters Detail |
getCount | |
public int getCount()
|
-
Gets number of items in the collection.
Example: Enumerates through all built-in and custom properties in a document using indexed access.
String fileName = getMyDir() + "Properties.doc";
Document doc = new Document(fileName);
System.out.println(MessageFormat.format("1. Document name: {0}", fileName));
System.out.println("2. Buil-in Properties");
for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++)
{
DocumentProperty prop = doc.getBuiltInDocumentProperties().get(i);
System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue()));
}
System.out.println("3. Custom Properties");
for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++)
{
DocumentProperty prop = doc.getCustomDocumentProperties().get(i);
System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue()));
}
-
Returns a DocumentProperty object by the name of the property.
Returns null if a property with the specified name is not found. - Parameters:
name - The case-insensitive name of the property to retrieve.
Example: Retrieves a custom document property by name.
Document doc = new Document(getMyDir() + "Properties.doc");
DocumentProperty prop = doc.getCustomDocumentProperties().get("Authorized Date");
if (prop != null)
{
System.out.println(prop.toDateTime());
}
else
{
System.out.println("The document is not authorized. Authorizing...");
doc.getCustomDocumentProperties().add("AuthorizedDate", new Date());
}
-
Returns a DocumentProperty object by index.
Note: In Java this method is slow because iterates over all nodes. - Parameters:
index - Zero-based index of the DocumentProperty to retrieve.
Example: Enumerates through all built-in and custom properties in a document using indexed access.
String fileName = getMyDir() + "Properties.doc";
Document doc = new Document(fileName);
System.out.println(MessageFormat.format("1. Document name: {0}", fileName));
System.out.println("2. Buil-in Properties");
for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++)
{
DocumentProperty prop = doc.getBuiltInDocumentProperties().get(i);
System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue()));
}
System.out.println("3. Custom Properties");
for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++)
{
DocumentProperty prop = doc.getCustomDocumentProperties().get(i);
System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue()));
}
iterator | |
public java.util.Iterator iterator() |
-
Returns an iterator object that can be used to iterate over all items in the collection.
contains | |
public boolean contains(java.lang.String name) |
-
Returns true if a property with the specified name exists in the collection.
- Parameters:
name - The case-insensitive name of the property.
- Returns:
- True if the property exists in the collection; false otherwise.
indexOf | |
public int indexOf(java.lang.String name) |
-
Gets the index of a property by name.
Note: In Java this method is slow because iterates over all nodes. - Parameters:
name - The case-insensitive name of the property.
- Returns:
- The zero based index. Negative value if not found.
remove | |
public void remove(java.lang.String name) |
-
Removes a property with the specified name from the collection.
- Parameters:
name - The case-insensitive name of the property.
Example: Removes a custom document property.
Document doc = new Document(getMyDir() + "Properties.doc");
doc.getCustomDocumentProperties().remove("Authorized Date");
removeAt | |
public void removeAt(int index) |
-
Removes a property at the specified index.
Note: In Java this method is slow because iterates over all nodes. - Parameters:
index - The zero based index.
clear | |
public void clear() |
-
Removes all properties from the collection.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.
|