com.aspose.words
Interface IRevisionCriteria


public interface IRevisionCriteria 

Implement this interface if you want to control when certain Revision should be accepted/rejected or not by the RevisionCollection.accept(com.aspose.words.IRevisionCriteria)/RevisionCollection.reject(com.aspose.words.IRevisionCriteria) methods.

Example:

Shows how to accept or reject revision based on criteria.
public void revisionSpecifiedCriteria() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.write("This does not count as a revision. ");

    // To register our edits as revisions, we need to declare an author, and then start tracking them.
    doc.startTrackRevisions("John Doe", new Date());
    builder.write("This is insertion revision #1. ");
    doc.stopTrackRevisions();

    doc.startTrackRevisions("Jane Doe", new Date());
    builder.write("This is insertion revision #2. ");
    // Remove a run "This does not count as a revision.".
    doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0).remove();
    doc.stopTrackRevisions();

    Assert.assertEquals(3, doc.getRevisions().getCount());
    // We have two revisions from different authors, so we need to accept only one.
    doc.getRevisions().accept(new RevisionCriteria("John Doe", RevisionType.INSERTION));
    Assert.assertEquals(2, doc.getRevisions().getCount());
    // Reject revision with different author name and revision type.
    doc.getRevisions().reject(new RevisionCriteria("Jane Doe", RevisionType.DELETION));
    Assert.assertEquals(1, doc.getRevisions().getCount());

    doc.save(getArtifactsDir() + "Revision.RevisionSpecifiedCriteria.docx");
}

/// <summary>
/// Control when certain revision should be accepted/rejected.
/// </summary>
public static class RevisionCriteria implements IRevisionCriteria
{
    private String AuthorName;
    private int _RevisionType;

    public RevisionCriteria(String authorName, int revisionType)
    {
        AuthorName = authorName;
        _RevisionType = revisionType;
    }

    public boolean isMatch(Revision revision)
    {
        return AuthorName.equals(revision.getAuthor()) && revision.getRevisionType() == _RevisionType;
    }
}

Method Summary
abstract booleanisMatch(Revision revision)
           Checks whether or not specified revision matches criteria.
 

Method Detail

isMatch

public abstract boolean isMatch(Revision revision)
                             throws java.lang.Exception
Checks whether or not specified revision matches criteria. The method implementation should not accept/reject the revision or modify it in any way due to unexpected results.
Parameters:
revision - The Revision instance to match criteria.
Returns:
True if the revision matches criteria, otherwise False.

Example:

Shows how to accept or reject revision based on criteria.
public void revisionSpecifiedCriteria() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.write("This does not count as a revision. ");

    // To register our edits as revisions, we need to declare an author, and then start tracking them.
    doc.startTrackRevisions("John Doe", new Date());
    builder.write("This is insertion revision #1. ");
    doc.stopTrackRevisions();

    doc.startTrackRevisions("Jane Doe", new Date());
    builder.write("This is insertion revision #2. ");
    // Remove a run "This does not count as a revision.".
    doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0).remove();
    doc.stopTrackRevisions();

    Assert.assertEquals(3, doc.getRevisions().getCount());
    // We have two revisions from different authors, so we need to accept only one.
    doc.getRevisions().accept(new RevisionCriteria("John Doe", RevisionType.INSERTION));
    Assert.assertEquals(2, doc.getRevisions().getCount());
    // Reject revision with different author name and revision type.
    doc.getRevisions().reject(new RevisionCriteria("Jane Doe", RevisionType.DELETION));
    Assert.assertEquals(1, doc.getRevisions().getCount());

    doc.save(getArtifactsDir() + "Revision.RevisionSpecifiedCriteria.docx");
}

/// <summary>
/// Control when certain revision should be accepted/rejected.
/// </summary>
public static class RevisionCriteria implements IRevisionCriteria
{
    private String AuthorName;
    private int _RevisionType;

    public RevisionCriteria(String authorName, int revisionType)
    {
        AuthorName = authorName;
        _RevisionType = revisionType;
    }

    public boolean isMatch(Revision revision)
    {
        return AuthorName.equals(revision.getAuthor()) && revision.getRevisionType() == _RevisionType;
    }
}

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