DhDocument Class

DhDocument Class

This Package | All Packages

DhElement
  |
  +--DhBaseContainer
    |
    +--DhDocument
public class DhDocument
extends DhBaseContainer
implements DhIFilterableObject

Represents an HTML document. You can use it to bind to an existing HTML page and traverse the elements on that page. Alternatively, you can create new elements and add them to the page through this class.

Objects in this class cannot be created directly; instead, you acquire a reference to it through a DhModule class.

Also see wfc.html.DhStyle, wfc.html.DhText, wfc.html.DhElement, wfc.html.DhSection, DhPane

Constructors
Name Description
DhDocument( DhModule module, IHTMLDocument2 document, IHTMLWindow2 window ) Creates a document object.
DhDocument() Creates a document object.

Methods
Name Description
add(DhElement element) Adds an element into this container.
add(DhElement element, int insertFlag ) Adds an element into this container.
add( DhElement element, DhElement relativeTo, int insertFlag ) Adds an element into this container.
add( DhStyle newStyle ) Explicitly adds a DhStyle style object to this document.

Note that this is done automatically for you whenever you call the setStyle method on any element.

addFilter(DhFilter filter) Topic under construction.
addFilter(DhFilter filter, boolean bApply) Adds a filter to this element.
addFilter(DhFilter filter, boolean bApply, boolean bFlush) Adds a filter to this element.
addText( String text ) Appends a text string to the current document.
addTransition(DhFilter trans) Adds a transition effect to this element.
applyFilters() Applies filters that were previously deferred.
enumerate( int type ) Returns an enumerator that represents the collection of elements.
findElement( String id ) Searches for an element in the document.
findFilter(Class filterClass) Retrieves the current filter with the specified filter class.
findStyle(String style) Retrieves a DHStyle object with the named style for this document.
getAllElements() Recursively retrieves all child elements and their children.
getDomain() Returns the host name of the server the page is from.
getElement( IHTMLElement peer ) Returns the corresponding derivation of DhElement given the underlying HTML element peer.
getElements() Retrieves the child elements of this element.
getFixed() Determines whether the default placement of elements uses fixed x-y coordinate positioning or traditional HTML text flow layout positioning.
getHTML() Returns the representative HTML of this document (also known as the page).
getLastModified() Retrieves the last modified date of the current document in the form
MM/DD/YY HH:MM:SS

Return Value:

Returns the document's last modified date, or returns a null string if it is unavailable.

getLocation() Retrieves the current location of the document.
getMatchingChildElements( String strQuery, boolean fRecursive ) Retrieves the matching child elements according to the parameters in strQuery.
getModule() Returns the DhModule associated with this document.
getPeer() Return the underlying HTML peer element for this class.
getProtocol() Retrieves the long name of the protocol.
getReferrer() Retrieves the referring document.
getSize() Retrieves the current size of the document.
getStyles() Retrieves all styles in this document.
getTitle() Retrieves the title of the document.
getWindow() Retrieves the window object of this document.
getWindowPeer() Retrieves the window peer of this document.
importHTML(String html) Topic under construction.
importHTMLFromFile(String file) throws IOException Imports the HTML code from the specified file.
MessageBox( String s ) Displays a modal user message box.
moveElement( DhElement element, int newOrder ) Moves an element to a new numeric order in the layout flow.
newLine() Appends a new line to the current document.
recreateElement( String html ) Deserializes HTML text generated by generateHTML.
recreateElement( String html, boolean fHonorIDs ) Deserializes HTML text generated by generateHTML.
remove(DhElement element) Removes an element from this container.
removeAll() Removes all child elements from this container.
removeAllFilters() Automatically removes all filters from this element immediately.
removeAllFilters(boolean bApply) Removes all filters from this element.
removeFilter(DhFilter filter) Removes the specified filter from this element.
removeFilter(DhFilter filter, boolean bApply) Removes the specified filter from this element.
replaceFilter(DhFilter filter1, DhFilter filter2) Replaces filters currently applied to the document.
replaceFilter(DhFilter filter1, DhFilter filter2, boolean bApply) Replaces filters currently applied to the document.
setDomain( String strDomain ) Sets the host domain for the page.
setFixed( boolean isFixed ) Determines whether the default placement of elements uses fixed x-y coordinate positioning or traditional HTML text flow layout positioning.
setFixed() Sets the default placement of elements to fixed x-y coordinate positioning in contrast to traditional HTML text flow layout.
setGenerateTags( boolean fGenerate ) Determines whether HEAD and TITLE tags are generated by the generateHTML() method.
setTitle( String newTitle ) Sets the title of the document.

Constructors

DhDocument.DhDocument

Syntax 1
public DhDocument( DhModule module, IHTMLDocument2 document, IHTMLWindow2 window );
Description

Creates a document object.



Syntax 2
public DhDocument();
Description

Creates a document object. This is a blank document with no object model binding.

Methods

DhDocument.add

Syntax 1
public void add( DhElement element );
Parameters
element
The DhElement to add to the end of the flow of this container.
Description

Adds an element into this container. This method adds the element following all other elements.



Syntax 2
public void add( DhElement element, int insertFlag );
Parameters
element
The DhElement to add to this container.
insertFlag
One of the applicable insert constants from DhInsertEnum. The valid values for insertFlag are:
  • INSERT_END
  • INSERT_BEGINNING
Description

Adds an element into this container. This method adds the element either at the beginning or at the end of this container depending on the insertFlag parameter.



Syntax 3
public void add( DhElement element, DhElement relativeTo, int insertFlag );
Parameters
element
The element to be added.
relativeTo
An element to which the insertFlags parameter relates (this can be null depending on the value of insertFlags).
insertFlags
One of the INSERT_ constants in DhInsertEnum.
Description

Adds an element into this container. This method adds the specified element either at the end or at the beginning of the document, or before or after another element.

For details of this method and other available add methods, see DhSection.add.



Syntax 4
public synchronized void add( DhStyle newStyle );
Parameters
newStyle
The DhStyle object to add to this document.
Description

Explicitly adds a DhStyle style object to this document.

Note that this is done automatically for you whenever you call the setStyle method on any element.

DhDocument.addFilter

Syntax 1
public void addFilter( DhFilter filter );
Description

Topic under construction.



Syntax 2
public void addFilter( DhFilter filter, boolean bApply );
Parameters
filter
The DhFilter object to apply.
bApply
Set to true to apply the filter directly; set to false to delay the application.
Description

Adds a filter to this element. You can apply the filter immediately or delay application. Delaying application is useful if you are applying more than one filter to this element. Filters added this way are combined with other filters that were previously added and not explicity flushed or removed.

Exceptions

wfc.html.DhCantAddElementException thrown if this type of filter already exists on this element.

See Also
applyFilters, replaceFilter



Syntax 3
public void addFilter( DhFilter filter, boolean bApply, boolean bFlush );
Parameters
filter
The DhFilter object to apply.
bApply
Set to true to apply the filter directly; set to false to delay applying the filter.
bFlush
Set to true to flush the previously applied filters; set to false to combine filter with those already present.
Description

Adds a filter to this element. You can apply the filter immediately or delay application. Delaying application is useful if you are applying more than one filter to this element. You can also specify whether you want to flush filters that were previously applied to this element or whether you want this filter to be combined with those already present.

Exceptions

wfc.html.DhCantAddElementException thrown if this type of filter already exists on this element.

See Also
applyFilters, replaceFilter

DhDocument.addText

Syntax
public void addText( String text );
Parameters
text
The text string.
Description

Appends a text string to the current document.

DhDocument.addTransition

Syntax
public void addTransition( DhFilter trans );
Parameters
trans
The transition effect you will run.
Description

Adds a transition effect to this element. You must call this method before you can run the effect. Note that this functionality is provided for extension only (see the sample classes). This package does provide transition effects.

Exceptions

wfc.html.DhCantAddElementException thrown if this type of transition effect already exists on this element.

See Also
replaceFilter

DhDocument.applyFilters

Syntax
public void applyFilters();
Description

Applies filters that were previously deferred. Use this method if you called addFilter(DhFilter,boolean) with false as the second parameter. This function applies every filter that was added to this element.

See Also
addFilter(DhFilter,boolean), addFilter

DhDocument.enumerate

Syntax
public DhEnumeration enumerate( int type );
Parameters
type
One of the types enumerated by the DhEnumeration class.
Return Value

Returns a DhEnumeration enumerator that represents the collection of elements of the types defined by the type parameter. This can be one of the following:

Description

Returns an enumerator that represents the collection of elements.

DhDocument.findElement

Syntax
public DhElement findElement( String id );
Parameters
id
The HTML ID attribute of the element to search for. For example,
ID="Caption1"

this argument would be: "Caption1".

Return Value

Returns the DhElement representing the element in the document. This element can then be cast to the actual element type (for example, DhText).

Description

Searches for an element in the document. This method can be used to find any element in the document by the HTML ID attribute.

DhDocument.findFilter

Syntax
public DhFilter findFilter( Class filterClass );
Parameters
filterClass
The class of the filter you are looking for, for example, wfc.html.DhDropShadowFilter.
Return Value

Returns the DhFilter object (if found) that is of type filterClass.

Description

Retrieves the current filter with the specified filter class.

DhDocument.findStyle

Syntax
public DhStyle findStyle( String style );
Parameters
style
The string name of the style you are looking for (for example, ".myClass").
Return Value

Returns the style object that corresponds to the style parameter, or returns null if no such style exists in this document.

Description

Retrieves a DHStyle object with the named style for this document.

Note This method is not used in the normal course of programming this package.

DhDocument.getAllElements

Syntax
public DhElement[] getAllElements();
Return Value

Returns an array of all child elements.

Description

Recursively retrieves all child elements and their children.

Overrides

getAllElements() in DhBaseContainer.

DhDocument.getDomain

Syntax
public String getDomain();
Return Value

Returns the current host server domain, or returns a null string if it is unavailable.

Description

Returns the host name of the server the page is from.

DhDocument.getElement

Syntax
public synchronized DhElement getElement( IHTMLElement peer );
Parameters
peer
The underlying HTML element peer. This peer may have been acquired using DhElement.getPeer.
Return Value

Returns the specific derivation that corresponds to the peer parameter.

Description

Returns the corresponding derivation of DhElement given the underlying HTML element peer.

Note Calling this method represents a very advanced usage scenario. Typically, you would never use this method.

DhDocument.getElements

Syntax
public DhElement[] getElements();
Return Value

Returns an array of direct child elements.

Description

Retrieves the child elements of this element.

Overrides

getElements() in DhBaseContainer.

DhDocument.getFixed

Syntax
public synchronized boolean getFixed();
Return Value

Returns true if this document uses fixed positioning; otherwise, returns false, which is the default.

Description

Determines whether the default placement of elements uses fixed x-y coordinate positioning or traditional HTML text flow layout positioning. Rather than use this property, it is much more useful to create DhSections and/or DhPanels to control the placement of elements.

DhDocument.getHTML

Syntax
public synchronized String getHTML();
Return Value

Returns the generated or bound HTML text.

Description

Returns the representative HTML of this document (also known as the page).

DhDocument.getLastModified

Syntax
public String getLastModified();
Return Value

Returns the document's last modified date, or returns a null string if it is unavailable.

Description

Retrieves the last modified date of the current document in the form

MM/DD/YY HH:MM:SS

DhDocument.getLocation

Syntax
public Point getLocation();
Return Value

Returns a Point object holding the document's location.

Description

Retrieves the current location of the document.

DhDocument.getMatchingChildElements

Syntax
public IEnumerator getMatchingChildElements( String strQuery, boolean fRecursive );
Parameters
strQuery
The query criteria string.
fRecursive
Set to true to apply to all children; set to false to apply to only direct children.
Return Value

Returns an enumeration of matching elements, or returns null if there are none.

Description

Retrieves the matching child elements according to the parameters in strQuery.

Some query examples are as follows:

Overrides

getMatchingChildElements(String,boolean) in DhBaseContainer.

DhDocument.getModule

Syntax
public DhModule getModule();
Return Value

Returns the DhModule associated with this document.

Description

Returns the DhModule associated with this document. DhDocument cannot be created directly; instead, you acquire a reference to it through a DhModule object.

DhDocument.getPeer

Syntax
public IUnknown getPeer();
Return Value

Returns the element peer underlying the HTML peer for this class.

Description

Return the underlying HTML peer element for this class. This method may return null if the document is not bound to this class. Java code that is running in a trusted environment can freely cast the resulting reference to a specific element peer type (such as wfc.html.om.IHTMLDocument2). This method always returns null if the code is running in a Web server environment.

Note Calling this method represents a very advanced usage scenario. Typically, you would never use this method.

DhDocument.getProtocol

Syntax
public String getProtocol();
Return Value

Returns the name of the protocol.

Description

Retrieves the long name of the protocol.

Examples:

"Hypertext Transfer Protocol"

"File Protocol"

See Also
getDocumentUrl

DhDocument.getReferrer

Syntax
public String getReferrer();
Return Value

Returns the URL of the referring document, or returns a null string if it is unavailable.

Description

Retrieves the referring document. This is the document that contains the hyperlink to the current document.

DhDocument.getSize

Syntax
public Point getSize();
Return Value

Returns a Point object holding the document's size.

Description

Retrieves the current size of the document.

DhDocument.getStyles

Syntax
public DhStyle[] getStyles();
Return Value

Returns an array of DhStyle objects found on this document.

Description

Retrieves all styles in this document. Style objects can be applied to any element using the setStyle method.

DhDocument.getTitle

Syntax
public String getTitle();
Return Value

Returns the title of document.

Description

Retrieves the title of the document. For a browser, the title appears in the caption of the browser window.

DhDocument.getWindow

Syntax
final public DhWindow getWindow();
Return Value

Returns the window object of the document.

Description

Retrieves the window object of this document.

DhDocument.getWindowPeer

Syntax
protected IHTMLWindow2 getWindowPeer();
Return Value

Returns the WindowPeer object related to this the document.

Description

Retrieves the window peer of this document.

DhDocument.importHTML

Syntax
public void importHTML( String html );
Description

Topic under construction.

DhDocument.importHTMLFromFile

Syntax
public void importHTMLFromFile( String file ) throws IOException;
Parameters
file
The file to import from.
Description

Imports the HTML code from the specified file.

Exceptions

IOException thrown if file cannot be read or opened.

DhDocument.MessageBox

Syntax
final public void MessageBox( String s );
Parameters
s
The message string to display.
Description

Displays a modal user message box.

DhDocument.moveElement

Syntax
public void moveElement( DhElement element, int newOrder );
Parameters
element
The element to move.
newOrder
The new numeric order in the flow of this container.
Description

Moves an element to a new numeric order in the layout flow.

DhDocument.newLine

Syntax
public void newLine();
Description

Appends a new line to the current document. All elements added after this call will be on a new line.

DhDocument.recreateElement

Syntax 1
public DhElement recreateElement( String html );
Parameters
html
The text that was generated by calling generateHTML on a given DhElement.
Return Value

Returns the corresponding tree of derivations of DhElements that originally created the text in the html parameter.

Description

Deserializes HTML text generated by generateHTML. The default case of calling this method ignores the ID attributes of the HTML and overrides those attributes with IDs that are unique to this document. To control this behavior, see recreateElement(String,boolean).



Syntax 2
public DhElement recreateElement( String html, boolean fHonorIDs );
Parameters
html
The text that was generated by calling generateHTML() on a given DhElement.
fHonorIDs
Set to true to prevent destruction of ID attributes.
Return Value

Returns the corresponding tree of derivations of DhElements that originally created the text in the html parameter.

Description

Deserializes HTML text generated by generateHTML. Passing true to fHonorIDs tells this method not to overwrite the ID attributes of the HTML tags in the html parameter. This is a very advanced usage of this method. If ID attributes conflict with elements already on the page, the resulting behavior is undefined in the rest of the package.

See Also
recreateElement

DhDocument.remove

Syntax
public int remove( DhElement element );
Parameters
element
The element to remove from this container.
Description

Removes an element from this container. If the element was visible prior to this call, it will not be visible after the call.

DhDocument.removeAll

Syntax
public void removeAll();
Description

Removes all child elements from this container. If the elements were visible prior to this call, they will not be visible after the call.

DhDocument.removeAllFilters

Syntax 1
public void removeAllFilters();
Description

Automatically removes all filters from this element immediately.



Syntax 2
public void removeAllFilters( boolean bApply );
Description

Removes all filters from this element. You can clear all filters on this element or delay removal.

DhDocument.removeFilter

Syntax 1
public void removeFilter( DhFilter filter );
Parameters
filter
The filter to remove.
Description

Removes the specified filter from this element. This method automatically reapplies filters that may be left after this method is called.

See Also
findFilter.



Syntax 2
public void removeFilter( DhFilter filter, boolean bApply );
Parameters
filter
A reference to the filter to remove.
bApply
Set to true to reapply other filters left on this element; set to false to delay reapplying the filters.
Description

Removes the specified filter from this element. You can reapply other filters that may be left after this method is called, or you can delay if you are removing more than one filter.

See Also
findFilter.

DhDocument.replaceFilter

Syntax 1
public void replaceFilter( DhFilter filter1, DhFilter filter2 );
Parameters
filter1
The filter to be replaced.
filter2
The filter that is to replace filter1
Description

Replaces filters currently applied to the document. This method provides an easy way to swap filters. It automatically applies all the changes immediately.



Syntax 2
public void replaceFilter( DhFilter filter1, DhFilter filter2, boolean bApply );
Parameters
filter1
The filter to be replaced.
filter2
The filter that is to replace filter1
bApply
Set to true to apply visual changes now; set to false to delay making changes.
Description

Replaces filters currently applied to the document. This method provides an easy way to swap filters. You can specify whether to apply all the changes immediately or to delay making changes until later.

See Also
applyFilters

DhDocument.setDomain

Syntax
public void setDomain( String strDomain );
Parameters
strDomain
The domain to set.
Description

Sets the host domain for the page. Pages on different frames can have their domains set to the same host to allow communication between frames.

DhDocument.setFixed

Syntax 1
public synchronized void setFixed( boolean isFixed );
Parameters
isFixed
Set to true to enable x-y coordinate placement by default; set to false to use traditional HTML text flow layout.
Description

Determines whether the default placement of elements uses fixed x-y coordinate positioning or traditional HTML text flow layout positioning. Rather than use this method, it is much more useful to create DhSection objects and/or DhPanel objects to control the placement of elements.

See Also
isFixed



Syntax 2
public void setFixed();
Description

Sets the default placement of elements to fixed x-y coordinate positioning in contrast to traditional HTML text flow layout. Rather than use this method, it is much more useful to create DhSections and/or DhPanels to control the placement of elements.

See Also
isFixed

DhDocument.setGenerateTags

Syntax
public void setGenerateTags( boolean fGenerate );
Parameters
fGenerate
Set to true to generate <HEAD> and <TITLE> tags in a call to generateHTML(); otherwise, set to false.
Description

Determines whether HEAD and TITLE tags are generated by the generateHTML() method.

DhDocument.setTitle

Syntax
public void setTitle( String newTitle );
Parameters
newTitle
The text that goes into the caption of the host.
Description

Sets the title of the document. For a browser, the title appears in the caption of the browser window.