com.ephox.editlive.java2.editor
Class DocumentModifier

java.lang.Object
  extended by com.ephox.editlive.java2.editor.DocumentModifier

public abstract class DocumentModifier
extends Object

Methods that modify the document while maintaining compatibility with Track Changes

NOTE: Eventually this class will move into com.ephox.editlive.model


Constructor Summary
DocumentModifier()
           
 
Method Summary
abstract  void adjustCharacterAttributes(int startOffset, int endOffset, AttributeSet add, Collection<?> remove)
          Changes the attributes of all content level elements within the specified range.
abstract  void adjustCharacterAttributesForElementSelection(Collection<Element> selectedElements, AttributeSet add, Collection<?> remove)
          Changes the attributes of all content level elements that are children of the elements in selectedElements.
abstract  void changeListItemIndent(int startOffset, int endOffset, int depthFromContent, int indentAmount, HTML.Tag targetListTag)
          Changes the indent level of list items in the specified range.
abstract  void endElementPropertiesTransaction()
          End a properties transaction and add the operation to the manager.
abstract  String excludeRemovedWords(int offset, String text)
          A simple wrapper to OperationManager.excludeRemovedWords(int, String)
abstract  OperationManager getOperationManager()
          Returns the operation manager that this modifier's operations are tracked in.
abstract  void insertHtml(int offset, String html)
          Inserts a HTML fragment into the document.
abstract  void insertHtml(int offset, String html, HTML.Tag firstTagToInsert, Element insertIntoElement)
          Insert a HTML fragment into the document.
abstract  void insertString(int offset, AttributeSet attributes, String insert)
          Inserts a plain text string into the document with the specified formatting applied.
abstract  void pauseTracking()
          Pause tracking operations.
abstract  void remove(Element element)
          Remove the specified element and all its content from the document.
abstract  boolean remove(int startOffset, int endOffset)
          Remove the specified range from the document.
abstract  void resumeTracking()
          Unpause tracking operations.
abstract  void setElementAttributes(Element element, AttributeSet add, Collection<?> remove)
          Modify an elements attributes.
abstract  void setListType(int startOffset, int endOffset, int depthFromContent, HTML.Tag targetListTag, String targetListType, String targetListStart)
          Changes the list type in a given range.
abstract  void setOverrideContentEditable(boolean override)
          Allows developers to override the content editable attribute and modify uneditable sections.
abstract  void startElementPropertiesTransaction()
          Begin a new element properties transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentModifier

public DocumentModifier()
Method Detail

insertHtml

public abstract void insertHtml(int offset,
                                String html)
                         throws BadLocationException
Inserts a HTML fragment into the document. The HTML must be a well-formed HTML fragment.

Parameters:
offset - the offset in the document to perform at.
html - the HTML to insert.
Throws:
BadLocationException - if offset is invalid.

insertHtml

public abstract void insertHtml(int offset,
                                String html,
                                HTML.Tag firstTagToInsert,
                                Element insertIntoElement)
                         throws BadLocationException
Insert a HTML fragment into the document. The HTML must be a well-formed HTML fragment. When inserting, the parser will ignore any content before firstTagToInsert is encountered, allowing HTML which isn't necessarily well-formed to be inserted. The insertIntoElement indicates the depth at which the insert will occur. This allows operations such as inserting new list items or table rows because the HTML fragment can be inserted part-way up the element tree instead of just at the content level.

Parameters:
offset - the offset to insert at.
html - the HTML fragment to insert.
firstTagToInsert - the tag which indicates the start of the content to actually insert.
insertIntoElement - the element that the fragment should be inserted into.
Throws:
BadLocationException - if offset or insertIntoElement is invalid.

insertString

public abstract void insertString(int offset,
                                  AttributeSet attributes,
                                  String insert)
                           throws BadLocationException
Inserts a plain text string into the document with the specified formatting applied.

Parameters:
offset - the offset to insert the string at.
attributes - the attributes to apply to the content. This must include at a minimum a HTML.Tag instance specified as the value for AttributeSet.NameAttribute. For normal text content, use HTML.Tag.CONTENT.
insert - the content to insert.
Throws:
BadLocationException - if the specified offset is invalid.

remove

public abstract boolean remove(int startOffset,
                               int endOffset)
                        throws BadLocationException
Remove the specified range from the document.

Parameters:
startOffset - the start of the range to remove.
endOffset - the end of the range to remove.
Returns:
true if the changes were applied to the document, false if they were deferred until the operation is accepted.
Throws:
BadLocationException - if the specified range is invalid.

remove

public abstract void remove(Element element)
                     throws BadLocationException
Remove the specified element and all its content from the document.

Parameters:
element - the element to remove.
Throws:
BadLocationException - if the element is not from this document or is no longer valid for this document.

startElementPropertiesTransaction

public abstract void startElementPropertiesTransaction()
Begin a new element properties transaction. This allows multiple changes to element properties to be tracked as a single change to the document.


endElementPropertiesTransaction

public abstract void endElementPropertiesTransaction()
End a properties transaction and add the operation to the manager.


setElementAttributes

public abstract void setElementAttributes(Element element,
                                          AttributeSet add,
                                          Collection<?> remove)
Modify an elements attributes. The attributes from remove are first removed from the element's attributes, then the attributes specified in add are added. If the element already has an attribute which is being added, the value is changed to the value specified in add.

Parameters:
element - the element to change the attributes of.
add - the attributes to add.
remove - the attributes to remove.

adjustCharacterAttributes

public abstract void adjustCharacterAttributes(int startOffset,
                                               int endOffset,
                                               AttributeSet add,
                                               Collection<?> remove)
                                        throws BadLocationException
Changes the attributes of all content level elements within the specified range. The add and remove parameters work the same as for setElementAttributes(Element, AttributeSet, Collection).

Parameters:
startOffset - the start of the range to change character attributes within.
endOffset - the end of the range to change character attributes within.
add - the attributes to add.
remove - the attributes to remove.
Throws:
BadLocationException
See Also:
setElementAttributes(Element, AttributeSet, Collection)

adjustCharacterAttributesForElementSelection

public abstract void adjustCharacterAttributesForElementSelection(Collection<Element> selectedElements,
                                                                  AttributeSet add,
                                                                  Collection<?> remove)
                                                           throws BadLocationException
Changes the attributes of all content level elements that are children of the elements in selectedElements. The add and remove parameters work the same as for setElementAttributes(Element, AttributeSet, Collection).

Parameters:
selectedElements - a collection of Element instances to change the character attributes within.
add - the attributes to add.
remove - the attributes to remove.
Throws:
BadLocationException
See Also:
setElementAttributes(Element, AttributeSet, Collection)

setListType

public abstract void setListType(int startOffset,
                                 int endOffset,
                                 int depthFromContent,
                                 HTML.Tag targetListTag,
                                 String targetListType,
                                 String targetListStart)
                          throws BadLocationException
Changes the list type in a given range. This method allows changing from OL to UL or changing the type attribute of lists.

Parameters:
startOffset - the start of the range to modify.
endOffset - the end of the range to modify.
depthFromContent - how many elements down from the content is the list tag to modify. This allows nested lists to be handled correctly.
targetListTag - the list tag to change to. Either HTML.Tag.OL or HTML.Tag.UL.
targetListType - the list type to change to.
targetListStart - the list number to start at.
Throws:
BadLocationException - if the offsets are invalid.

changeListItemIndent

public abstract void changeListItemIndent(int startOffset,
                                          int endOffset,
                                          int depthFromContent,
                                          int indentAmount,
                                          HTML.Tag targetListTag)
                                   throws BadLocationException
Changes the indent level of list items in the specified range.

Parameters:
startOffset - the start of the range to modify.
endOffset - the end of the range to modify.
depthFromContent - how many elements down from the content is the list tag to modify. This allows nested lists to be handled correctly.
indentAmount - how much to increase the indent level by. Negative numbers reduce the indent level.
targetListTag - the list tag to apply to the modified list items. Either HTML.Tag.OL or HTML.Tag.UL.
Throws:
BadLocationException - of the specified offsets are invalid.

pauseTracking

public abstract void pauseTracking()
Pause tracking operations. This is used to temporarily disable track changes while performing operations that shouldn't be tracked.


resumeTracking

public abstract void resumeTracking()
Unpause tracking operations.


getOperationManager

public abstract OperationManager getOperationManager()
Returns the operation manager that this modifier's operations are tracked in.

Returns:
the operation manager.

setOverrideContentEditable

public abstract void setOverrideContentEditable(boolean override)
Allows developers to override the content editable attribute and modify uneditable sections. Note that this is a temporary effect and should be set immediately before performing changes as events like changing the caret position can cause this to be reset.

Parameters:
override - whether or not content editable attributes should be ignored.

excludeRemovedWords

public abstract String excludeRemovedWords(int offset,
                                           String text)
A simple wrapper to OperationManager.excludeRemovedWords(int, String)


Copyright (c) 2005-2012 Ephox Pty Ltd. All rights reserved.