com.ephox.editlive.java2.editor
Class DocumentModifier

java.lang.Object
  extended bycom.ephox.editlive.java2.editor.DocumentModifier

public class DocumentModifier
extends Object


Method Summary
 void adjustCharacterAttributes(int startOffset, int endOffset, AttributeSet add, Collection remove)
          Changes the attributes of all content level elements within the specified range.
 void adjustCharacterAttributesForElementSelection(Collection selectedElements, AttributeSet add, Collection remove)
          Changes the attributes of all content level elements that are children of the elements in selectedElements.
 void changeListItemIndent(int startOffset, int endOffset, int depthFromContent, int indentAmount, HTML.Tag targetListTag)
          Changes the indent level of list items in the specified range.
 void endElementPropertiesTransaction()
          End a properties transaction and add the operation to the manager.
 OperationManager getOperationManager()
          Returns the operation manager that this modifier's operations are tracked in.
 void insertHtml(int offset, String html)
          Inserts a HTML fragment into the document.
 void insertHtml(int offset, String html, HTML.Tag firstTagToInsert, Element insertIntoElement)
          Insert a HTML fragment into the document.
 void insertString(int offset, AttributeSet attributes, String insert)
          Inserts a plain text string into the document with the specified formatting applied.
 void pauseTracking()
          Pause tracking operations.
 void remove(Element element)
          Remove the specified element and all its content from the document.
 boolean remove(int startOffset, int endOffset)
          Remove the specified range from the document.
 void resumeTracking()
          Unpause tracking operations.
 void setElementAttributes(Element element, AttributeSet add, Collection remove)
          Modify an elements attributes.
 void setListType(int startOffset, int endOffset, int depthFromContent, HTML.Tag targetListTag, String targetListType, String targetListStart)
          Changes the list type in a given range.
 void setOverrideContentEditable(boolean override)
          Allows developers to override the content editable attribute and modify uneditable sections.
 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
 

Method Detail

insertHtml

public 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 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 nessecarily 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 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 as the tag.
insert - the content to insert.
Throws:
BadLocationException - if the specified offset is invalid.

remove

public 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 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 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 void endElementPropertiesTransaction()
End a properties transaction and add the operation to the manager.


setElementAttributes

public 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 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 void adjustCharacterAttributesForElementSelection(Collection 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 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 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 void pauseTracking()
Pause tracking operations. This is used to temporarily disable track changes while performing operations that shouldn't be tracked.


resumeTracking

public void resumeTracking()
Unpause tracking operations.


getOperationManager

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

Returns:
the operation manager.

setOverrideContentEditable

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

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