com.aspose.words

Class EditorType

  • java.lang.Object
    • com.aspose.words.EditorType
public class EditorType 
extends java.lang.Object

Utility class containing constants. Specifies the set of possible aliases (or editing groups) which can be used as aliases to determine if the current user shall be allowed to edit a single range defined by an editable range within a document.

Example:

Shows how to limit the editing rights of editable ranges to a specific group/user.
public void visitor() throws Exception {
    Document doc = new Document();
    doc.protect(ProtectionType.READ_ONLY, "MyPassword");

    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.writeln("Hello world! Since we have set the document's protection level to read-only," +
            " we cannot edit this paragraph without the password.");

    // When we write-protect documents, editable ranges allow us to pick specific areas that users may edit.
    // There are two mutually exclusive ways to narrow down the list of allowed editors.
    // 1 -  Specify a user:
    EditableRange editableRange = builder.startEditableRange().getEditableRange();
    editableRange.setSingleUser("john.doe@myoffice.com");
    builder.writeln(MessageFormat.format("This paragraph is inside the first editable range, can only be edited by {0}.", editableRange.getSingleUser()));
    builder.endEditableRange();

    Assert.assertEquals(EditorType.UNSPECIFIED, editableRange.getEditorGroup());

    // 2 -  Specify a group that allowed users are associated with:
    editableRange = builder.startEditableRange().getEditableRange();
    editableRange.setEditorGroup(EditorType.ADMINISTRATORS);
    builder.writeln(MessageFormat.format("This paragraph is inside the first editable range, can only be edited by {0}.", editableRange.getEditorGroup()));
    builder.endEditableRange();

    Assert.assertEquals("", editableRange.getSingleUser());

    builder.writeln("This paragraph is outside the editable range, and cannot be edited by anybody.");

    // Print details and contents of every editable range in the document.
    EditableRangePrinter editableRangePrinter = new EditableRangePrinter();

    doc.accept(editableRangePrinter);

    System.out.println(editableRangePrinter.toText());
}

/// <summary>
/// Collects properties and contents of visited editable ranges in a string.
/// </summary>
public static class EditableRangePrinter extends DocumentVisitor {
    public EditableRangePrinter() {
        mBuilder = new StringBuilder();
    }

    public String toText() {
        return mBuilder.toString();
    }

    public void reset() {
        mBuilder.setLength(0);
        mInsideEditableRange = false;
    }

    /// <summary>
    /// Called when an EditableRangeStart node is encountered in the document.
    /// </summary>
    public /*override*/ /*VisitorAction*/int visitEditableRangeStart(EditableRangeStart editableRangeStart) {
        mBuilder.append(" -- Editable range found! -- ");
        mBuilder.append("\tID:\t\t" + editableRangeStart.getId());
        if (editableRangeStart.getEditableRange().getSingleUser().equals(""))
            mBuilder.append("\tGroup:\t" + editableRangeStart.getEditableRange().getEditorGroup());
        else
            mBuilder.append("\tUser:\t" + editableRangeStart.getEditableRange().getSingleUser());
        mBuilder.append("\tContents:");

        mInsideEditableRange = true;

        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when an EditableRangeEnd node is encountered in the document.
    /// </summary>
    public int visitEditableRangeEnd(final EditableRangeEnd editableRangeEnd) {
        mBuilder.append(" -- End of editable range -- " + "\r\n");

        mInsideEditableRange = false;

        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Run node is encountered in the document. This visitor only records runs that are inside editable ranges.
    /// </summary>
    public int visitRun(final Run run) {
        if (mInsideEditableRange) {
            mBuilder.append("\t\"" + run.getText() + "\"" + "\r\n");
        }

        return VisitorAction.CONTINUE;
    }

    private boolean mInsideEditableRange;
    private final StringBuilder mBuilder;
}

Field Summary
static final intUNSPECIFIED = 0
Means that editor type is not specified.
static final intADMINISTRATORS = 1
Specifies that users associated with the Administrators group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intCONTRIBUTORS = 2
Specifies that users associated with the Contributors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intCURRENT = 3
Specifies that users associated with the Current group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intEDITORS = 4
Specifies that users associated with the Editors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intEVERYONE = 5
Specifies that all users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intNONE = 6
Specifies that none of the users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intOWNERS = 7
Specifies that users associated with the Owners group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
static final intDEFAULT = 0
Same as UNSPECIFIED.
 

    • Field Detail

      • UNSPECIFIED = 0

        public static final int UNSPECIFIED
        Means that editor type is not specified.
      • ADMINISTRATORS = 1

        public static final int ADMINISTRATORS
        Specifies that users associated with the Administrators group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • CONTRIBUTORS = 2

        public static final int CONTRIBUTORS
        Specifies that users associated with the Contributors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • CURRENT = 3

        public static final int CURRENT
        Specifies that users associated with the Current group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • EDITORS = 4

        public static final int EDITORS
        Specifies that users associated with the Editors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • EVERYONE = 5

        public static final int EVERYONE
        Specifies that all users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • NONE = 6

        public static final int NONE
        Specifies that none of the users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • OWNERS = 7

        public static final int OWNERS
        Specifies that users associated with the Owners group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
      • DEFAULT = 0

        public static final int DEFAULT
        Same as UNSPECIFIED.