public class EditableRangeStart extends Node
To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.
Remarks:
A complete editable range in a Word document consists of a EditableRangeStart and a matching EditableRangeEnd with the same Id.
EditableRangeStart and EditableRangeEnd are just markers inside a document that specify where the editable range starts and ends.
Use the getEditableRange() class as a "facade" to work with an editable range as a single object.
Paragraph, but editable range start and editable range end can be in different paragraphs.
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 | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
int |
getDisplacedByCustomXml() |
EditableRange |
getEditableRange()
Gets the facade object that encapsulates this editable range start and end.
|
int |
getId()
Specifies the identifier of the editable range.
|
int |
getIdInternal() |
int |
getNodeType()
Returns
NodeType.EDITABLE_RANGE_START. |
int |
getParentIdInternal() |
void |
setDisplacedByCustomXml(int value) |
void |
setId(int value)
Specifies the identifier of the editable range.
|
void |
setIdInternal(int value) |
void |
setParentIdInternal(int value) |
deepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, getText, isComposite, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Calls DocumentVisitor.visitEditableRangeStart(com.aspose.words.EditableRangeStart).
For more info see the Visitor design pattern.
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;
}
public int getId()
Examples:
Shows how to work with an editable range.
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.");
// Editable ranges allow us to leave parts of protected documents open for editing.
EditableRangeStart editableRangeStart = builder.startEditableRange();
builder.writeln("This paragraph is inside an editable range, and can be edited.");
EditableRangeEnd editableRangeEnd = builder.endEditableRange();
// A well-formed editable range has a start node, and end node.
// These nodes have matching IDs and encompass editable nodes.
EditableRange editableRange = editableRangeStart.getEditableRange();
Assert.assertEquals(editableRangeStart.getId(), editableRange.getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getId());
// Different parts of the editable range link to each other.
Assert.assertEquals(editableRangeStart.getId(), editableRange.getEditableRangeStart().getId());
Assert.assertEquals(editableRangeStart.getId(), editableRangeEnd.getEditableRangeStart().getId());
Assert.assertEquals(editableRange.getId(), editableRangeStart.getEditableRange().getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getEditableRangeEnd().getId());
// We can access the node types of each part like this. The editable range itself is not a node,
// but an entity which consists of a start, an end, and their enclosed contents.
Assert.assertEquals(NodeType.EDITABLE_RANGE_START, editableRangeStart.getNodeType());
Assert.assertEquals(NodeType.EDITABLE_RANGE_END, editableRangeEnd.getNodeType());
builder.writeln("This paragraph is outside the editable range, and cannot be edited.");
doc.save(getArtifactsDir() + "EditableRange.CreateAndRemove.docx");
// Remove an editable range. All the nodes that were inside the range will remain intact.
editableRange.remove();
int value.public void setId(int value)
Examples:
Shows how to work with an editable range.
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.");
// Editable ranges allow us to leave parts of protected documents open for editing.
EditableRangeStart editableRangeStart = builder.startEditableRange();
builder.writeln("This paragraph is inside an editable range, and can be edited.");
EditableRangeEnd editableRangeEnd = builder.endEditableRange();
// A well-formed editable range has a start node, and end node.
// These nodes have matching IDs and encompass editable nodes.
EditableRange editableRange = editableRangeStart.getEditableRange();
Assert.assertEquals(editableRangeStart.getId(), editableRange.getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getId());
// Different parts of the editable range link to each other.
Assert.assertEquals(editableRangeStart.getId(), editableRange.getEditableRangeStart().getId());
Assert.assertEquals(editableRangeStart.getId(), editableRangeEnd.getEditableRangeStart().getId());
Assert.assertEquals(editableRange.getId(), editableRangeStart.getEditableRange().getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getEditableRangeEnd().getId());
// We can access the node types of each part like this. The editable range itself is not a node,
// but an entity which consists of a start, an end, and their enclosed contents.
Assert.assertEquals(NodeType.EDITABLE_RANGE_START, editableRangeStart.getNodeType());
Assert.assertEquals(NodeType.EDITABLE_RANGE_END, editableRangeEnd.getNodeType());
builder.writeln("This paragraph is outside the editable range, and cannot be edited.");
doc.save(getArtifactsDir() + "EditableRange.CreateAndRemove.docx");
// Remove an editable range. All the nodes that were inside the range will remain intact.
editableRange.remove();
value - The corresponding int value.public EditableRange getEditableRange()
Examples:
Shows how to work with an editable range.
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.");
// Editable ranges allow us to leave parts of protected documents open for editing.
EditableRangeStart editableRangeStart = builder.startEditableRange();
builder.writeln("This paragraph is inside an editable range, and can be edited.");
EditableRangeEnd editableRangeEnd = builder.endEditableRange();
// A well-formed editable range has a start node, and end node.
// These nodes have matching IDs and encompass editable nodes.
EditableRange editableRange = editableRangeStart.getEditableRange();
Assert.assertEquals(editableRangeStart.getId(), editableRange.getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getId());
// Different parts of the editable range link to each other.
Assert.assertEquals(editableRangeStart.getId(), editableRange.getEditableRangeStart().getId());
Assert.assertEquals(editableRangeStart.getId(), editableRangeEnd.getEditableRangeStart().getId());
Assert.assertEquals(editableRange.getId(), editableRangeStart.getEditableRange().getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getEditableRangeEnd().getId());
// We can access the node types of each part like this. The editable range itself is not a node,
// but an entity which consists of a start, an end, and their enclosed contents.
Assert.assertEquals(NodeType.EDITABLE_RANGE_START, editableRangeStart.getNodeType());
Assert.assertEquals(NodeType.EDITABLE_RANGE_END, editableRangeEnd.getNodeType());
builder.writeln("This paragraph is outside the editable range, and cannot be edited.");
doc.save(getArtifactsDir() + "EditableRange.CreateAndRemove.docx");
// Remove an editable range. All the nodes that were inside the range will remain intact.
editableRange.remove();
public int getNodeType()
NodeType.EDITABLE_RANGE_START.
Examples:
Shows how to work with an editable range.
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.");
// Editable ranges allow us to leave parts of protected documents open for editing.
EditableRangeStart editableRangeStart = builder.startEditableRange();
builder.writeln("This paragraph is inside an editable range, and can be edited.");
EditableRangeEnd editableRangeEnd = builder.endEditableRange();
// A well-formed editable range has a start node, and end node.
// These nodes have matching IDs and encompass editable nodes.
EditableRange editableRange = editableRangeStart.getEditableRange();
Assert.assertEquals(editableRangeStart.getId(), editableRange.getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getId());
// Different parts of the editable range link to each other.
Assert.assertEquals(editableRangeStart.getId(), editableRange.getEditableRangeStart().getId());
Assert.assertEquals(editableRangeStart.getId(), editableRangeEnd.getEditableRangeStart().getId());
Assert.assertEquals(editableRange.getId(), editableRangeStart.getEditableRange().getId());
Assert.assertEquals(editableRangeEnd.getId(), editableRange.getEditableRangeEnd().getId());
// We can access the node types of each part like this. The editable range itself is not a node,
// but an entity which consists of a start, an end, and their enclosed contents.
Assert.assertEquals(NodeType.EDITABLE_RANGE_START, editableRangeStart.getNodeType());
Assert.assertEquals(NodeType.EDITABLE_RANGE_END, editableRangeEnd.getNodeType());
builder.writeln("This paragraph is outside the editable range, and cannot be edited.");
doc.save(getArtifactsDir() + "EditableRange.CreateAndRemove.docx");
// Remove an editable range. All the nodes that were inside the range will remain intact.
editableRange.remove();
getNodeType in class NodeNodeType.EDITABLE_RANGE_START. The returned value is one of NodeType constants.public int getDisplacedByCustomXml()
public void setDisplacedByCustomXml(int value)
public int getIdInternal()
public void setIdInternal(int value)
public int getParentIdInternal()
public void setParentIdInternal(int value)