org.xwiki.gwt.dom.client
Class Document

java.lang.Object
  extended by com.google.gwt.core.client.JavaScriptObject
      extended by com.google.gwt.dom.client.Node
          extended by com.google.gwt.dom.client.Document
              extended by org.xwiki.gwt.dom.client.Document

public class Document
extends com.google.gwt.dom.client.Document

Extends the document implementation provided by GWT to add support for multi-window, selection and range.

Version:
$Id: Document.java 20042 2009-05-16 12:12:50Z sdumitriu $
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=2772, http://code.google.com/p/google-web-toolkit/issues/detail?id=3006, http://code.google.com/p/google-web-toolkit/issues/detail?id=3053

Field Summary
 
Fields inherited from class com.google.gwt.dom.client.Node
DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE
 
Constructor Summary
protected Document()
          Default constructor.
 
Method Summary
 void addInnerHTMLListener(InnerHTMLListener listener)
          Registers a new listener for changes to innerHTML property of element within this document.
 void close()
          Closes a document stream for writing.
 com.google.gwt.dom.client.Node createComment(java.lang.String data)
           
 DocumentFragment createDocumentFragment()
          Creates an empty document fragment.
A DocumentFragment is a minimal document object that has no parent.
 Range createRange()
          We've added this method because at the time of writing Document doesn't offer support for creating a range.
 boolean execCommand(java.lang.String command, java.lang.String parameter)
          When an HTML document has been switched to designMode, the document object exposes the execCommand method which allows one to run commands to manipulate the contents of the editable region.
 Element getDocumentElement()
           
 java.util.Iterator<com.google.gwt.dom.client.Node> getIterator(com.google.gwt.dom.client.Node startNode)
          Returns an iterator for the depth-first pre-order strategy, starting in startNode.
 Selection getSelection()
          We've added this method because at the time of writing Document doesn't offer support for retrieving the current selection.
 void open()
          Opens a document stream for writing.
 boolean queryCommandEnabled(java.lang.String command)
           
 boolean queryCommandState(java.lang.String command)
           
 boolean queryCommandSupported(java.lang.String command)
           
 java.lang.String queryCommandValue(java.lang.String command)
           
 void removeInnerHTMLListener(InnerHTMLListener listener)
          Stop sending notifications to the given listener when the innerHTML property, of some element included in this document, changes.
 void write(java.lang.String html)
          Writes a string of text to a document stream opened by open().
 com.google.gwt.dom.client.BaseElement xCreateBaseElement()
           
 com.google.gwt.dom.client.BRElement xCreateBRElement()
          Creates a <br> element.
 com.google.gwt.dom.client.ButtonElement xCreateButtonElement()
          Creates a <button> element.
 com.google.gwt.dom.client.DivElement xCreateDivElement()
          Creates a <div> element.
 Element xCreateElement(java.lang.String tagName)
          Creates a new element.
We've added this method because at the time of writing Document doesn't offer support for multi-window.
 com.google.gwt.dom.client.HRElement xCreateHRElement()
          Creates a <hr> element.
 com.google.gwt.dom.client.ImageElement xCreateImageElement()
          Creates a <img> element.
 com.google.gwt.dom.client.LIElement xCreateLIElement()
          Creates a <li> element.
 com.google.gwt.dom.client.LinkElement xCreateLinkElement()
          Creates a <link> element.
 com.google.gwt.dom.client.ParagraphElement xCreatePElement()
          Creates a <p> element.
 com.google.gwt.dom.client.ScriptElement xCreateScriptElement()
          Creates a <script> element.
 com.google.gwt.dom.client.SpanElement xCreateSpanElement()
          Creates a <span> element.
 com.google.gwt.dom.client.Node xImportNode(com.google.gwt.dom.client.Node externalNode, boolean deep)
          Creates a copy of a node from an external document that can be inserted into this document.
We've added this method because at time of writing Document.importNode(Node, boolean) is not well implemented.
 
Methods inherited from class com.google.gwt.dom.client.Document
createAnchorElement, createAreaElement, createBaseElement, createBlockQuoteElement, createBRElement, createButtonElement, createCaptionElement, createCheckInputElement, createColElement, createColGroupElement, createDelElement, createDivElement, createDLElement, createElement, createFieldSetElement, createFileInputElement, createFormElement, createFrameElement, createFrameSetElement, createHeadElement, createHElement, createHiddenInputElement, createHRElement, createIFrameElement, createImageElement, createImageInputElement, createInsElement, createLabelElement, createLegendElement, createLIElement, createLinkElement, createMapElement, createMetaElement, createObjectElement, createOLElement, createOptGroupElement, createOptionElement, createParamElement, createPasswordInputElement, createPElement, createPreElement, createQElement, createRadioInputElement, createScriptElement, createSelectElement, createSelectElement, createSpanElement, createStyleElement, createTableElement, createTBodyElement, createTDElement, createTextAreaElement, createTextInputElement, createTextNode, createTFootElement, createTHeadElement, createTHElement, createTitleElement, createTRElement, createULElement, createUniqueId, get, getBody, getBodyOffsetLeft, getBodyOffsetTop, getDomain, getElementById, getElementsByTagName, getReferrer, getTitle, getURL, importNode, setTitle
 
Methods inherited from class com.google.gwt.dom.client.Node
appendChild, cloneNode, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, hasChildNodes, insertBefore, removeChild, replaceChild, setNodeValue
 
Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createFunction, createObject, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Document

protected Document()
Default constructor. Needs to be protected because all instances are created from JavaScript.

Method Detail

xCreateElement

public final Element xCreateElement(java.lang.String tagName)
Creates a new element.
We've added this method because at the time of writing Document doesn't offer support for multi-window. This means that currently, using GWT's API we can create elements only within the document of the host page. Since com.google.gwt.user.client.ui.RichTextArea is based on an in-line frame which has its own window and document we have to be able to create elements within the edited document.

Parameters:
tagName - the tag name of the element to be created
Returns:
the newly created element
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=2772

createComment

public final com.google.gwt.dom.client.Node createComment(java.lang.String data)
Parameters:
data - contains the data to be added to the comment.
Returns:
the created comment node.

xCreateLinkElement

public final com.google.gwt.dom.client.LinkElement xCreateLinkElement()
Creates a <link> element.

Returns:
the newly created element

xCreateScriptElement

public final com.google.gwt.dom.client.ScriptElement xCreateScriptElement()
Creates a <script> element.

Returns:
the newly created element

xCreateBRElement

public final com.google.gwt.dom.client.BRElement xCreateBRElement()
Creates a <br> element.

Returns:
the newly created element

xCreatePElement

public final com.google.gwt.dom.client.ParagraphElement xCreatePElement()
Creates a <p> element.

Returns:
the newly created element

xCreateDivElement

public final com.google.gwt.dom.client.DivElement xCreateDivElement()
Creates a <div> element.

Returns:
the newly created element.

xCreateSpanElement

public final com.google.gwt.dom.client.SpanElement xCreateSpanElement()
Creates a <span> element.

Returns:
the newly created element.

xCreateBaseElement

public final com.google.gwt.dom.client.BaseElement xCreateBaseElement()
Returns:
a new base element

xCreateHRElement

public final com.google.gwt.dom.client.HRElement xCreateHRElement()
Creates a <hr> element.

Returns:
the newly create element.

xCreateImageElement

public final com.google.gwt.dom.client.ImageElement xCreateImageElement()
Creates a <img> element.

Returns:
the newly create element.

xCreateLIElement

public final com.google.gwt.dom.client.LIElement xCreateLIElement()
Creates a <li> element.

Returns:
the newly created element.

xCreateButtonElement

public final com.google.gwt.dom.client.ButtonElement xCreateButtonElement()
Creates a <button> element.

Returns:
the newly create element.

getSelection

public final Selection getSelection()
We've added this method because at the time of writing Document doesn't offer support for retrieving the current selection.

Returns:
The selection object associated with this document.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3053

createRange

public final Range createRange()
We've added this method because at the time of writing Document doesn't offer support for creating a range.

Returns:
A new range for this document.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3053

xImportNode

public final com.google.gwt.dom.client.Node xImportNode(com.google.gwt.dom.client.Node externalNode,
                                                        boolean deep)
Creates a copy of a node from an external document that can be inserted into this document.
We've added this method because at time of writing Document.importNode(Node, boolean) is not well implemented.

Parameters:
externalNode - The node from another document to be imported.
deep - Indicates whether the children of the given node need to be imported.
Returns:
a copy of the given node that can be inserted into this document.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3006

getIterator

public final java.util.Iterator<com.google.gwt.dom.client.Node> getIterator(com.google.gwt.dom.client.Node startNode)
Returns an iterator for the depth-first pre-order strategy, starting in startNode.

Parameters:
startNode - node to start iteration from
Returns:
the depth-first pre-order iterator
See Also:
DepthFirstPreOrderIterator}, http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html#Traversal-Document

execCommand

public final boolean execCommand(java.lang.String command,
                                 java.lang.String parameter)
When an HTML document has been switched to designMode, the document object exposes the execCommand method which allows one to run commands to manipulate the contents of the editable region. Most commands affect the document's selection (bold, italics, etc), while others insert new elements (adding a link) or affect an entire line (indenting). When using contentEditable, calling execCommand will affect the currently active editable element.

Parameters:
command - The name of the command.
parameter - Some commands (such as insertimage) require an extra value argument (the image's url). Pass an argument of null if no argument is needed.
Returns:
true if the specified command has been successfully executed.

queryCommandValue

public final java.lang.String queryCommandValue(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
The current value of the current range for the given command. If a command value has not been explicitly set then it returns null.

queryCommandEnabled

public final boolean queryCommandEnabled(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
true if the given command can be executed on the current range.

queryCommandState

public final boolean queryCommandState(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
true if the given command has been executed on the current range.

queryCommandSupported

public final boolean queryCommandSupported(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
true if the given command is supported by the current browser.

getDocumentElement

public final Element getDocumentElement()
Returns:
the document element.

createDocumentFragment

public final DocumentFragment createDocumentFragment()
Creates an empty document fragment.
A DocumentFragment is a minimal document object that has no parent. It supports the following DOM 2 methods: appendChild, cloneNode, hasAttributes, hasChildNodes, insertBefore, normalize, removeChild, replaceChild.
It also supports the following DOM 2 properties: attributes, childNodes, firstChild, lastChild, localName, namespaceURI, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentNode, prefix, previousSibling, textContent.
Various other methods can take a document fragment as an argument (e.g. Node interface methods such as appendChild and insertBefore), in which case the children of the fragment are appended or inserted, not the fragment itself.

Returns:
The newly created document fragment.

open

public final void open()
Opens a document stream for writing.


close

public final void close()
Closes a document stream for writing.


write

public final void write(java.lang.String html)
Writes a string of text to a document stream opened by open().

Parameters:
html - a string containing the HTML to be written to the document.

addInnerHTMLListener

public final void addInnerHTMLListener(InnerHTMLListener listener)
Registers a new listener for changes to innerHTML property of element within this document.

Parameters:
listener - The listener to be registered.

removeInnerHTMLListener

public final void removeInnerHTMLListener(InnerHTMLListener listener)
Stop sending notifications to the given listener when the innerHTML property, of some element included in this document, changes.

Parameters:
listener - The listener to be unregistered.


Copyright © 2004-2009 XWiki. All Rights Reserved.