EditorType

Inheritance: java.lang.Object

public class EditorType

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.

Examples:

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

 /// 
 /// Collects properties and contents of visited editable ranges in a string.
 /// 
 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;
     }

     /// 
     /// Called when an EditableRangeStart node is encountered in the document.
     /// 
     public 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;
     }

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

         mInsideEditableRange = false;

         return VisitorAction.CONTINUE;
     }

     /// 
     /// Called when a Run node is encountered in the document. This visitor only records runs that are inside editable ranges.
     /// 
     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;
 }
 

Fields

FieldDescription
ADMINISTRATORSSpecifies that users associated with the Administrators group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
CONTRIBUTORSSpecifies that users associated with the Contributors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
CURRENTSpecifies that users associated with the Current group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
DEFAULTSame as UNSPECIFIED.
EDITORSSpecifies that users associated with the Editors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
EVERYONESpecifies that all users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.
NONESpecifies 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.
OWNERSSpecifies that users associated with the Owners group shall be allowed to edit editable ranges using this editing type when document protection is enabled.
UNSPECIFIEDMeans that editor type is not specified.
length

Methods

MethodDescription
fromName(String editorTypeName)
getName(int editorType)
getValues()
toString(int editorType)

ADMINISTRATORS

public static 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

public static 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

public static 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.

DEFAULT

public static int DEFAULT

Same as UNSPECIFIED.

EDITORS

public static 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

public static 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

public static 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

public static 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.

UNSPECIFIED

public static int UNSPECIFIED

Means that editor type is not specified.

length

public static int length

fromName(String editorTypeName)

public static int fromName(String editorTypeName)

Parameters:

ParameterTypeDescription
editorTypeNamejava.lang.String

Returns: int

getName(int editorType)

public static String getName(int editorType)

Parameters:

ParameterTypeDescription
editorTypeint

Returns: java.lang.String

getValues()

public static int[] getValues()

Returns: int[]

toString(int editorType)

public static String toString(int editorType)

Parameters:

ParameterTypeDescription
editorTypeint

Returns: java.lang.String