public class EditorType
Example:
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 are allowed to 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 attributes 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 StringBuilder mBuilder;
}
Field Summary | ||
---|---|---|
static final int | UNSPECIFIED | |
Means that editor type is not specified.
|
||
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.
|
||
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.
|
||
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.
|
||
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.
|
||
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.
|
||
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.
|
||
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.
|
||
static final int | DEFAULT | |
Same as |
public static final int UNSPECIFIED
public static final int ADMINISTRATORS
public static final int CONTRIBUTORS
public static final int CURRENT
public static final int EDITORS
public static final int EVERYONE
public static final int NONE
public static final int OWNERS
public static final int DEFAULT