Manage Sensitivity Labels in PowerPoint Presentations on Android

Overview

Microsoft Purview sensitivity labels help organizations classify and govern documents. During automated presentation processing, an application may need to preserve an existing label, apply a label selected by a policy, update its state, or migrate label metadata written by an older Microsoft Information Protection (MIP) workflow.

Aspose.Slides for Android via Java exposes modern sensitivity label metadata through IPresentation.getSensitivityLabels. This method returns an ISensitivityLabelCollection that can be inspected and modified before the presentation is saved as PPTX.

Understand Sensitivity Label Properties

Each ISensitivityLabel contains the following metadata:

Methods Purpose
ISensitivityLabel.getId and ISensitivityLabel.setId Get or set the sensitivity label identifier in the Purview policy.
ISensitivityLabel.getSiteId and ISensitivityLabel.setSiteId Get or set the site associated with the label policy.
ISensitivityLabel.isEnabled and ISensitivityLabel.setEnabled Get or set whether the label is enabled.
ISensitivityLabel.isRemoved and ISensitivityLabel.setRemoved Get or set whether the label has been removed. Set the value to true when the removal state must be retained in the metadata.
ISensitivityLabel.getAssignmentMethodType and ISensitivityLabel.setAssignmentMethodType Get or set whether the label was applied automatically or through a user decision.
ISensitivityLabel.getContentMarkTypes Get the content marking types associated with the label.

The SensitivityLabelAssignmentType class defines how a label was assigned:

The SensitivityLabelContentType class defines the marking associated with a label:

Value Meaning
SensitivityLabelContentType.None The label was applied by default or automatically.
SensitivityLabelContentType.Header Header content marking is associated with the label.
SensitivityLabelContentType.Footer Footer content marking is associated with the label.
SensitivityLabelContentType.Watermark Watermark content marking is associated with the label.
SensitivityLabelContentType.Encryption Encryption protection is associated with the label.

Multiple marking types can be associated with one label.

List Existing Sensitivity Labels

Read the modern label collection from IPresentation.getSensitivityLabels and enumerate it. The following example lists every property and content marking stored for each label:

import com.aspose.slides.*;

Presentation presentation = new Presentation("presentation.pptx");
try {
    ISensitivityLabelCollection sensitivityLabels = presentation.getSensitivityLabels();

    for (ISensitivityLabel sensitivityLabel : sensitivityLabels) {
        System.out.println("Label ID: " + sensitivityLabel.getId());
        System.out.println("Site ID: " + sensitivityLabel.getSiteId());
        System.out.println("Enabled: " + sensitivityLabel.isEnabled());
        System.out.println("Removed: " + sensitivityLabel.isRemoved());
        System.out.println("Assignment method: " + sensitivityLabel.getAssignmentMethodType());

        for (Integer contentMarkType : sensitivityLabel.getContentMarkTypes()) {
            System.out.println("Content marking: " + contentMarkType);
        }
    }
} finally {
    presentation.dispose();
}

Add a Sensitivity Label with Content Marking

Use ISensitivityLabelCollection.add with the label identifier, site identifier, enabled state, and assignment method. After the method returns the new ISensitivityLabel, add the required marking values through the list returned by ISensitivityLabel.getContentMarkTypes.

The following example adds a manually selected label associated with footer and watermark markings, and then saves the result as PPTX:

import com.aspose.slides.*;
import java.util.UUID;

Presentation presentation = new Presentation("presentation.pptx");
try {
    ISensitivityLabelCollection sensitivityLabels = presentation.getSensitivityLabels();

    String labelIdentifier = "{11111111-2222-3333-4444-555555555555}";
    UUID siteIdentifier = UUID.fromString("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
    boolean isEnabled = true;
    int assignmentMethod = SensitivityLabelAssignmentType.Privileged;

    ISensitivityLabel sensitivityLabel = sensitivityLabels.add(
            labelIdentifier,
            siteIdentifier,
            isEnabled,
            assignmentMethod);

    sensitivityLabel.getContentMarkTypes().addItem(SensitivityLabelContentType.Footer);
    sensitivityLabel.getContentMarkTypes().addItem(SensitivityLabelContentType.Watermark);

    presentation.save("presentation_with_label.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Update a Sensitivity Label

The ISensitivityLabel values are read/write, except that the list returned by ISensitivityLabel.getContentMarkTypes is modified through its list operations. After locating the required label, you can update its identifier, site identifier, enabled state, assignment method, removal state, and content marking types. Save the presentation to persist the changes.

The following example updates the enabled state and assignment method of the first label:

import com.aspose.slides.*;

Presentation presentation = new Presentation("presentation.pptx");
try {
    ISensitivityLabelCollection sensitivityLabels = presentation.getSensitivityLabels();

    if (sensitivityLabels.getCount() > 0) {
        ISensitivityLabel sensitivityLabel = sensitivityLabels.get_Item(0);
        sensitivityLabel.setEnabled(true);
        sensitivityLabel.setAssignmentMethodType(SensitivityLabelAssignmentType.Privileged);
    }

    presentation.save("presentation_with_updated_label.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Mark a Sensitivity Label as Removed

To preserve the fact that a label was removed, find the label and call ISensitivityLabel.setRemoved with true. This retains the label entry while recording its removed state. If you instead need to delete an entry from the modern collection, use ISensitivityLabelCollection.removeAt; use ISensitivityLabelCollection.clear to delete every entry.

The following example marks a specific label as removed and saves the updated presentation:

import com.aspose.slides.*;

Presentation presentation = new Presentation("presentation.pptx");
try {
    ISensitivityLabelCollection sensitivityLabels = presentation.getSensitivityLabels();
    String targetLabelIdentifier = "{11111111-2222-3333-4444-555555555555}";

    for (ISensitivityLabel sensitivityLabel : sensitivityLabels) {
        boolean isTargetLabel = sensitivityLabel.getId().equalsIgnoreCase(targetLabelIdentifier);

        if (isTargetLabel) {
            sensitivityLabel.setRemoved(true);
            break;
        }
    }

    presentation.save("presentation_with_removed_label.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Read and Migrate Legacy MIP Sensitivity Labels

Older MIP-based workflows can store sensitivity label metadata in custom document properties instead of the modern label collection. Read that metadata with IDocumentProperties.getSensitivityLabels. The method parses the legacy custom properties and returns an array of ISensitivityLabel objects.

To migrate the metadata, add each returned label to the modern ISensitivityLabelCollection through ISensitivityLabelCollection.add. Because adding a duplicate label identifier raises an exception, the example checks the destination collection before copying each label. You can add further validation to confirm that each legacy label still exists in the current Purview policy.

import com.aspose.slides.*;

Presentation presentation = new Presentation("presentation_with_legacy_labels.pptx");
try {
    ISensitivityLabel[] legacySensitivityLabels = presentation.getDocumentProperties().getSensitivityLabels();
    ISensitivityLabelCollection modernSensitivityLabels = presentation.getSensitivityLabels();

    for (ISensitivityLabel legacySensitivityLabel : legacySensitivityLabels) {
        boolean labelAlreadyExists = false;

        for (ISensitivityLabel modernSensitivityLabel : modernSensitivityLabels) {
            labelAlreadyExists = modernSensitivityLabel.getId().equalsIgnoreCase(
                    legacySensitivityLabel.getId());

            if (labelAlreadyExists) {
                break;
            }
        }

        if (!labelAlreadyExists) {
            modernSensitivityLabels.add(legacySensitivityLabel);
        }
    }

    presentation.save("presentation_with_modern_labels.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

The migration copies the parsed label objects into the modern collection. It does not require clearing all custom document properties, so unrelated document metadata remains intact. Use IPresentation.save with SaveFormat.Pptx to write the modern label metadata to a PPTX file.

FAQ

Does adding a content marking type create a visible header, footer, or watermark on slides?

No. Values added through the list returned by ISensitivityLabel.getContentMarkTypes describe the markings associated with the sensitivity label. They do not create visible text or shapes in the presentation. Add the corresponding slide content separately if your workflow must render those markings.

What is the difference between marking a label as removed and deleting it from the collection?

Calling ISensitivityLabel.setRemoved with true keeps the label entry and records its removed state. Calling ISensitivityLabelCollection.removeAt deletes the entry from the modern collection. Choose the operation that matches your organization’s metadata retention requirements.

Can a presentation contain both legacy MIP metadata and modern sensitivity labels?

Yes. Legacy labels can remain in custom document properties while modern labels are available through IPresentation.getSensitivityLabels. Use IDocumentProperties.getSensitivityLabels to read the legacy metadata and migrate only the valid labels that are not already present in the modern collection.

What happens when a label with the same identifier is added more than once?

ISensitivityLabelCollection.add raises an exception when the collection already contains a label with the same identifier. Check existing values returned by ISensitivityLabel.getId before adding or migrating labels.

Which output format should be used to preserve updated sensitivity labels?

Save the presentation as PPTX by calling IPresentation.save with SaveFormat.Pptx, as shown in the examples above.