com.aspose.words
Class CustomDocumentProperties

java.lang.Object
  extended by DocumentPropertyCollection
      extended by com.aspose.words.CustomDocumentProperties
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Cloneable, java.lang.Iterable

public class CustomDocumentProperties 
extends DocumentPropertyCollection

A collection of custom document properties.

Each DocumentProperty object represents a custom property of a container document.

The names of the properties are case-insensitive.

The properties in the collection are sorted alphabetically by name.

Example:

Enumerates through all built-in and custom properties in a document.
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 (DocumentProperty prop : doc.getBuiltInDocumentProperties())
    System.out.println(MessageFormat.format("{0} : {1}", prop.getName(), prop.getValue()));

System.out.println("3. Custom Properties");
for (DocumentProperty prop : doc.getCustomDocumentProperties())
    System.out.println(MessageFormat.format("{0} : {1}", prop.getName(), prop.getValue()));
See Also:
Document, Document.BuiltInDocumentProperties, Document.CustomDocumentProperties

Property Getters/Setters Summary
intgetCount()→ inherited from DocumentPropertyCollection
           Gets number of items in the collection.
DocumentPropertyget(int index)→ inherited from DocumentPropertyCollection
           Returns a DocumentProperty object by index.
DocumentPropertyget(java.lang.String name)→ inherited from DocumentPropertyCollection
           Returns a DocumentProperty object by the name of the property.
 
Method Summary
DocumentPropertyadd(java.lang.String name, boolean value)
           Creates a new custom document property of the PropertyType.Boolean data type.
DocumentPropertyadd(java.lang.String name, double value)
           Creates a new custom document property of the PropertyType.Float data type.
DocumentPropertyadd(java.lang.String name, int value)
           Creates a new custom document property of the PropertyType.Number data type.
DocumentPropertyadd(java.lang.String name, java.lang.String value)
           Creates a new custom document property of the PropertyType.String data type.
DocumentPropertyadd(java.lang.String name, java.util.Date value)
           Creates a new custom document property of the PropertyType.DateTime data type.
voidclear()→ inherited from DocumentPropertyCollection
           Removes all properties from the collection.
booleancontains(java.lang.String name)→ inherited from DocumentPropertyCollection
           Returns true if a property with the specified name exists in the collection.
intindexOf(java.lang.String name)→ inherited from DocumentPropertyCollection
           Gets the index of a property by name.
java.util.Iteratoriterator()→ inherited from DocumentPropertyCollection
           Returns an iterator object that can be used to iterate over all items in the collection.
voidremove(java.lang.String name)→ inherited from DocumentPropertyCollection
           Removes a property with the specified name from the collection.
voidremoveAt(int index)→ inherited from DocumentPropertyCollection
           Removes a property at the specified index.
 

Property Getters/Setters Detail

getCount

→ inherited from DocumentPropertyCollection
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()));
}

get

→ inherited from DocumentPropertyCollection
public DocumentProperty get(java.lang.String name)
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());
}

get

→ inherited from DocumentPropertyCollection
public DocumentProperty get(int index)
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()));
}

Method Detail

add

public DocumentProperty add(java.lang.String name, java.lang.String value)
Creates a new custom document property of the PropertyType.String data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Checks if a custom property with a given name exists in a document and adds few more custom document properties.
Document doc = new Document(getMyDir() + "Properties.doc");

CustomDocumentProperties props = doc.getCustomDocumentProperties();

if (props.get("Authorized") == null)
{
    props.add("Authorized", true);
    props.add("Authorized By", "John Smith");
    props.add("Authorized Date",new  Date());
    props.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
    props.add("Authorized Amount", 123.45);
}

add

public DocumentProperty add(java.lang.String name, int value)
Creates a new custom document property of the PropertyType.Number data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Checks if a custom property with a given name exists in a document and adds few more custom document properties.
Document doc = new Document(getMyDir() + "Properties.doc");

CustomDocumentProperties props = doc.getCustomDocumentProperties();

if (props.get("Authorized") == null)
{
    props.add("Authorized", true);
    props.add("Authorized By", "John Smith");
    props.add("Authorized Date",new  Date());
    props.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
    props.add("Authorized Amount", 123.45);
}

add

public DocumentProperty add(java.lang.String name, java.util.Date value)
Creates a new custom document property of the PropertyType.DateTime data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Checks if a custom property with a given name exists in a document and adds few more custom document properties.
Document doc = new Document(getMyDir() + "Properties.doc");

CustomDocumentProperties props = doc.getCustomDocumentProperties();

if (props.get("Authorized") == null)
{
    props.add("Authorized", true);
    props.add("Authorized By", "John Smith");
    props.add("Authorized Date",new  Date());
    props.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
    props.add("Authorized Amount", 123.45);
}

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());
}

add

public DocumentProperty add(java.lang.String name, boolean value)
Creates a new custom document property of the PropertyType.Boolean data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Checks if a custom property with a given name exists in a document and adds few more custom document properties.
Document doc = new Document(getMyDir() + "Properties.doc");

CustomDocumentProperties props = doc.getCustomDocumentProperties();

if (props.get("Authorized") == null)
{
    props.add("Authorized", true);
    props.add("Authorized By", "John Smith");
    props.add("Authorized Date",new  Date());
    props.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
    props.add("Authorized Amount", 123.45);
}

add

public DocumentProperty add(java.lang.String name, double value)
Creates a new custom document property of the PropertyType.Float data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Checks if a custom property with a given name exists in a document and adds few more custom document properties.
Document doc = new Document(getMyDir() + "Properties.doc");

CustomDocumentProperties props = doc.getCustomDocumentProperties();

if (props.get("Authorized") == null)
{
    props.add("Authorized", true);
    props.add("Authorized By", "John Smith");
    props.add("Authorized Date",new  Date());
    props.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
    props.add("Authorized Amount", 123.45);
}

iterator

→ inherited from DocumentPropertyCollection
public java.util.Iterator iterator()
Returns an iterator object that can be used to iterate over all items in the collection.

contains

→ inherited from DocumentPropertyCollection
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

→ inherited from DocumentPropertyCollection
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

→ inherited from DocumentPropertyCollection
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

→ inherited from DocumentPropertyCollection
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

→ inherited from DocumentPropertyCollection
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.