public class EditorType
extends java.lang.Object
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());
}
/// <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 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;
}
| Modifier and Type | Field and Description |
|---|---|
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.
|
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.
|
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.
|
static int |
DEFAULT
Same as
UNSPECIFIED. |
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.
|
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.
|
static int |
length |
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.
|
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.
|
static int |
UNSPECIFIED
Means that editor type is not specified.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String editorTypeName) |
static java.lang.String |
getName(int editorType) |
static int[] |
getValues() |
static java.lang.String |
toString(int editorType) |
public static int UNSPECIFIED
public static int ADMINISTRATORS
public static int CONTRIBUTORS
public static int CURRENT
public static int EDITORS
public static int EVERYONE
public static int NONE
public static int OWNERS
public static int DEFAULT
UNSPECIFIED.public static int length