Trusted Extensions Developer's Guide

Exit Print View

Updated: July 2014
 
 

Translating Between Labels and Strings

The SolarisLabel abstract class includes methods for translating between labels and strings, which are inherited by its subclasses.

These methods translate the internal representation of a label (m_label_t) to String objects.

You can use the toInternal method to translate a label into a string that hides the classification name. This format is suitable for storing labels in public objects.

The running Java virtual machine must dominate the label to be translated, or it must have the sys_trans_label privilege. See the label_to_str(3TSOL) man page.

Some of the label values are based on data in the label_encodings file.

The following methods mimic the label_to_str() routine. See the label_to_str(3TSOL) man page.

public final java.lang.String toColor()

This method returns the color of the SolarisLabel object. The value is suitable for use by HTML.

public final java.lang.String toInternal()

This method returns the internal representation of the label that is safe for storing in a public object. An internal conversion can later be parsed to its same value. This is the same as using the toString method.

These two methods differ in the way that they handle errors. If the toInternal method encounters an error, it returns a java.io.IOException. However, if the toString method encounters an error, it returns a null.

public java.lang.String toString()

This method returns the internal hexadecimal version of the label in string form, which is the same as using the toInternal method.

These two methods differ in the way that they handle errors. If the toString method encounters an error, it returns a null. However, if the toInternal method encounters an error, it returns a java.io.IOException.

public java.lang.String toText()

This method returns a human-readable text string of the SolarisLabel object.

public java.lang.String toTextLong()

This method returns the long human-readable text string of the SolarisLabel object.

public java.lang.String toTextShort()

This method returns the short human-readable text string of the SolarisLabel object.

The following methods perform label translations that are suitable for output. These methods mimic some of the functionality of the label_to_str() routine. See the label_to_str(3TSOL) and m_label(3TSOL) man pages.

public java.lang.String toCaveats()

This method returns a human-readable text string that is suitable for output.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toChannels()

This method returns a human-readable text string that is suitable for output.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toFooter()

This method returns a human-readable text string that is appropriate for use as the sensitivity label. This sensitivity label appears at the bottom of banner and trailer pages.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toHeader()

This method returns a human-readable text string that is appropriate for use as the sensitivity label. This sensitivity label appears at the top of banner and trailer pages.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toProtectAs()

This method returns a human-readable text string that is suitable for the downgrade section of the banner page.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

Methods such as toText, toInternal, and toColor do not translate from a string to a label. To translate a string to a sensitivity label or to a clearance label, you must call the getSensitivityLabel or getClearanceLabel static factories, respectively. The following static factories mimic the str_to_label() routine. See the str_to_label(3TSOL) and m_label(3TSOL) man pages.

public static ClearanceLabel getClearanceLabel(java.lang.String label)

This static factory creates a clearance label from the specified string. The following examples create new clearance labels based on a label name and the internal hexadecimal name of a label:

ClearanceLabel cl = SolarisLabel.getClearanceLabel("PUBLIC");
ClearanceLabel cl = SolarisLabel.getClearanceLabel("0x0002-08-08");
public static SensitivityLabel getSensitivityLabel(java.lang.String label)

This static factory creates a sensitivity label from the specified string. The following examples create new sensitivity labels based on a label name and the internal hexadecimal name of a label:

SensitivityLabel sl = SolarisLabel.getSensitivityLabel("PUBLIC");
SensitivityLabel sl = SolarisLabel.getSensitivityLabel("0x0002-08-08");