htmlunit-2.7

esoftware.htmlunit.html;

import java.util.Iterator;

class DomNode$2
  implements Iterable<DomNode>
{
  DomNode$2(DomNode paramDomNode) {}
  
  public Iterator<DomNode> iterator()
  {
    return new DomNode.DescendantElementsIterator(this$0, DomNode.class);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomNode.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import java.util.Iterator;

class DomNode$3
  implements Iterable<HtmlElement>
{
  DomNode$3(DomNode paramDomNode) {}
  
  public Iterator<HtmlElement> iterator()
  {
    return new DomNode.DescendantElementsIterator(this$0, HtmlElement.class);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomNode.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebWindow;
import java.util.Iterator;

public class DomNode$DescendantElementsIterator<T extends DomNode>
  implements Iterator<T>
{
  private DomNode currentNode_;
  private DomNode nextNode_;
  private Class<T> type_;
  
  public DomNode$DescendantElementsIterator(Class<T> arg1)
  {
    type_ = type;
    nextNode_ = getFirstChildElement(???);
  }
  
  public boolean hasNext()
  {
    return nextNode_ != null;
  }
  
  public T next()
  {
    return nextNode();
  }
  
  public void remove()
  {
    if (currentNode_ == null) {
      throw new IllegalStateException("Unable to remove current node, because there is no current node.");
    }
    DomNode current = currentNode_;
    while ((nextNode_ != null) && (current.isAncestorOf(nextNode_))) {
      next();
    }
    current.remove();
  }
  
  public T nextNode()
  {
    currentNode_ = nextNode_;
    setNextElement();
    return currentNode_;
  }
  
  private void setNextElement()
  {
    DomNode next = getFirstChildElement(nextNode_);
    if (next == null) {
      next = getNextDomSibling(nextNode_);
    }
    if (next == null) {
      next = getNextElementUpwards(nextNode_);
    }
    nextNode_ = next;
  }
  
  private DomNode getNextElementUpwards(DomNode startingNode)
  {
    if (startingNode == this$0) {
      return null;
    }
    DomNode parent = startingNode.getParentNode();
    if (parent == this$0) {
      return null;
    }
    DomNode next = parent.getNextSibling();
    while ((next != null) && (!type_.isAssignableFrom(next.getClass()))) {
      next = next.getNextSibling();
    }
    if (next == null) {
      return getNextElementUpwards(parent);
    }
    return next;
  }
  
  private DomNode getFirstChildElement(DomNode parent)
  {
    if (((parent instanceof HtmlNoScript)) && (this$0.getPage().getEnclosingWindow().getWebClient().isJavaScriptEnabled())) {
      return null;
    }
    DomNode node = parent.getFirstChild();
    while ((node != null) && (!type_.isAssignableFrom(node.getClass()))) {
      node = node.getNextSibling();
    }
    return node;
  }
  
  private DomNode getNextDomSibling(DomNode element)
  {
    DomNode node = element.getNextSibling();
    while ((node != null) && (!type_.isAssignableFrom(node.getClass()))) {
      node = node.getNextSibling();
    }
    return node;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomNode.DescendantElementsIterator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.IncorrectnessListener;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.html.xpath.XPathUtils;
import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import org.apache.commons.lang.NotImplementedException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.UserDataHandler;

public abstract class DomNode
  implements Cloneable, Serializable, Node
{
  protected static final String AS_TEXT_BLOCK_SEPARATOR = "�bs�";
  protected static final String AS_TEXT_NEW_LINE = "�nl�";
  protected static final String AS_TEXT_BLANK = "�blank�";
  protected static final String AS_TEXT_TAB = "�tab�";
  private static final long serialVersionUID = -2013573303678006763L;
  public static final String READY_STATE_UNINITIALIZED = "uninitialized";
  public static final String READY_STATE_LOADING = "loading";
  public static final String READY_STATE_LOADED = "loaded";
  public static final String READY_STATE_INTERACTIVE = "interactive";
  public static final String READY_STATE_COMPLETE = "complete";
  public static final String PROPERTY_ELEMENT = "element";
  private SgmlPage page_;
  private DomNode parent_;
  private DomNode previousSibling_;
  private DomNode nextSibling_;
  private DomNode firstChild_;
  private ScriptableObject scriptObject_;
  private String readyState_;
  private int startLineNumber_ = -1;
  private int startColumnNumber_ = -1;
  private int endLineNumber_ = -1;
  private int endColumnNumber_ = -1;
  private List<DomChangeListener> domListeners_;
  private final Integer domListeners_lock_ = Integer.valueOf(0);
  
  @Deprecated
  protected DomNode()
  {
    this(null);
  }
  
  protected DomNode(SgmlPage page)
  {
    readyState_ = "loading";
    page_ = page;
  }
  
  void setStartLocation(int startLineNumber, int startColumnNumber)
  {
    startLineNumber_ = startLineNumber;
    startColumnNumber_ = startColumnNumber;
  }
  
  void setEndLocation(int endLineNumber, int endColumnNumber)
  {
    endLineNumber_ = endLineNumber;
    endColumnNumber_ = endColumnNumber;
  }
  
  public int getStartLineNumber()
  {
    return startLineNumber_;
  }
  
  public int getStartColumnNumber()
  {
    return startColumnNumber_;
  }
  
  public int getEndLineNumber()
  {
    return endLineNumber_;
  }
  
  public int getEndColumnNumber()
  {
    return endColumnNumber_;
  }
  
  public SgmlPage getPage()
  {
    return page_;
  }
  
  public Document getOwnerDocument()
  {
    return getPage();
  }
  
  public void setScriptObject(ScriptableObject scriptObject)
  {
    scriptObject_ = scriptObject;
  }
  
  public DomNode getLastChild()
  {
    if (firstChild_ != null) {
      return firstChild_.previousSibling_;
    }
    return null;
  }
  
  public DomNode getParentNode()
  {
    return parent_;
  }
  
  protected void setParentNode(DomNode parent)
  {
    parent_ = parent;
  }
  
  public int getIndex()
  {
    int index = 0;
    for (DomNode n = previousSibling_; (n != null) && (nextSibling_ != null); n = previousSibling_) {
      index++;
    }
    return index;
  }
  
  public DomNode getPreviousSibling()
  {
    if ((parent_ == null) || (this == parent_.firstChild_)) {
      return null;
    }
    return previousSibling_;
  }
  
  public DomNode getNextSibling()
  {
    return nextSibling_;
  }
  
  public DomNode getFirstChild()
  {
    return firstChild_;
  }
  
  public boolean isAncestorOf(DomNode node)
  {
    while (node != null)
    {
      if (node == this) {
        return true;
      }
      node = node.getParentNode();
    }
    return false;
  }
  
  public boolean isAncestorOfAny(DomNode... nodes)
  {
    for (DomNode node : nodes) {
      if (isAncestorOf(node)) {
        return true;
      }
    }
    return false;
  }
  
  protected void setPreviousSibling(DomNode previous)
  {
    previousSibling_ = previous;
  }
  
  protected void setNextSibling(DomNode next)
  {
    nextSibling_ = next;
  }
  
  public abstract short getNodeType();
  
  public abstract String getNodeName();
  
  public String getNamespaceURI()
  {
    return null;
  }
  
  public String getLocalName()
  {
    return null;
  }
  
  public String getPrefix()
  {
    return null;
  }
  
  public void setPrefix(String prefix) {}
  
  public boolean hasChildNodes()
  {
    return firstChild_ != null;
  }
  
  public DomNodeList<DomNode> getChildNodes()
  {
    return new SiblingDomNodeList(this);
  }
  
  public boolean isSupported(String namespace, String featureName)
  {
    throw new UnsupportedOperationException("DomNode.isSupported is not yet implemented.");
  }
  
  public void normalize()
  {
    for (DomNode child = getFirstChild(); child != null; child = child.getNextSibling()) {
      if ((child instanceof DomText))
      {
        boolean ie = getPage().getWebClient().getBrowserVersion().isIE();
        StringBuilder dataBuilder = new StringBuilder();
        DomNode toRemove = child;
        DomText firstText = null;
        while (((toRemove instanceof DomText)) && (!(toRemove instanceof DomCDataSection)))
        {
          DomNode nextChild = toRemove.getNextSibling();
          dataBuilder.append(toRemove.getTextContent());
          if ((ie) || (firstText != null)) {
            toRemove.remove();
          }
          if (firstText == null) {
            firstText = (DomText)toRemove;
          }
          toRemove = nextChild;
        }
        if (firstText != null) {
          if (ie)
          {
            DomText newText = new DomText(getPage(), dataBuilder.toString());
            insertBefore(newText, toRemove);
          }
          else
          {
            firstText.setData(dataBuilder.toString());
          }
        }
      }
    }
  }
  
  public String getBaseURI()
  {
    throw new UnsupportedOperationException("DomNode.getBaseURI is not yet implemented.");
  }
  
  public short compareDocumentPosition(Node other)
  {
    if (other == this) {
      return 0;
    }
    List<Node> myAncestors = getAncestors(true);
    List<Node> otherAncestors = ((DomNode)other).getAncestors(true);
    
    int max = Math.min(myAncestors.size(), otherAncestors.size());
    
    int i = 1;
    while ((i < max) && (myAncestors.get(i) == otherAncestors.get(i))) {
      i++;
    }
    if ((i != 1) && (i == max))
    {
      if (myAncestors.size() == max) {
        return 20;
      }
      return 10;
    }
    if (max == 1)
    {
      if (myAncestors.contains(other)) {
        return 8;
      }
      if (otherAncestors.contains(this)) {
        return 20;
      }
      return 33;
    }
    Node myAncestor = (Node)myAncestors.get(i);
    Node otherAncestor = (Node)otherAncestors.get(i);
    Node node = myAncestor;
    while ((node != otherAncestor) && (node != null)) {
      node = node.getPreviousSibling();
    }
    if (node == null) {
      return 4;
    }
    return 2;
  }
  
  protected List<Node> getAncestors(boolean includeSelf)
  {
    List<Node> list = new ArrayList();
    if (includeSelf) {
      list.add(this);
    }
    Node node = getParentNode();
    while (node != null)
    {
      list.add(0, node);
      node = node.getParentNode();
    }
    return list;
  }
  
  public String getTextContent()
  {
    switch (getNodeType())
    {
    case 1: 
    case 2: 
    case 5: 
    case 6: 
    case 11: 
      StringBuilder builder = new StringBuilder();
      for (DomNode child : getChildren())
      {
        short childType = child.getNodeType();
        if ((childType != 8) && (childType != 7)) {
          builder.append(child.getTextContent());
        }
      }
      return builder.toString();
    case 3: 
    case 4: 
    case 7: 
    case 8: 
      return getNodeValue();
    }
    return null;
  }
  
  public void setTextContent(String textContent)
  {
    removeAllChildren();
    if (textContent != null) {
      appendChild(new DomText(getPage(), textContent));
    }
  }
  
  public boolean isSameNode(Node other)
  {
    return other == this;
  }
  
  public String lookupPrefix(String namespaceURI)
  {
    throw new UnsupportedOperationException("DomNode.lookupPrefix is not yet implemented.");
  }
  
  public boolean isDefaultNamespace(String namespaceURI)
  {
    throw new UnsupportedOperationException("DomNode.isDefaultNamespace is not yet implemented.");
  }
  
  public String lookupNamespaceURI(String prefix)
  {
    throw new UnsupportedOperationException("DomNode.lookupNamespaceURI is not yet implemented.");
  }
  
  public boolean isEqualNode(Node arg)
  {
    throw new UnsupportedOperationException("DomNode.isEqualNode is not yet implemented.");
  }
  
  public Object getFeature(String feature, String version)
  {
    throw new UnsupportedOperationException("DomNode.getFeature is not yet implemented.");
  }
  
  public Object getUserData(String key)
  {
    throw new UnsupportedOperationException("DomNode.getUserData is not yet implemented.");
  }
  
  public Object setUserData(String key, Object data, UserDataHandler handler)
  {
    throw new UnsupportedOperationException("DomNode.setUserData is not yet implemented.");
  }
  
  public boolean hasAttributes()
  {
    return false;
  }
  
  protected boolean isTrimmedText()
  {
    return true;
  }
  
  public boolean isDisplayed()
  {
    Page page = getPage();
    if ((page instanceof HtmlPage))
    {
      for (Node node : getAncestors(true))
      {
        ScriptableObject scriptableObject = ((DomNode)node).getScriptObject();
        if ((scriptableObject instanceof HTMLElement))
        {
          CSSStyleDeclaration style = ((HTMLElement)scriptableObject).jsxGet_currentStyle();
          String display = style.jsxGet_display();
          if ("none".equals(display)) {
            return false;
          }
        }
      }
      boolean isNotIE = !((HtmlPage)page).getWebClient().getBrowserVersion().isIE();
      DomNode node = this;
      do
      {
        ScriptableObject scriptableObject = node.getScriptObject();
        if ((scriptableObject instanceof HTMLElement))
        {
          CSSStyleDeclaration style = ((HTMLElement)scriptableObject).jsxGet_currentStyle();
          String visibility = style.jsxGet_visibility();
          if (visibility.length() > 0)
          {
            if (visibility.equals("visible")) {
              return true;
            }
            if ((visibility.equals("hidden")) || ((isNotIE) && (visibility.equals("collapse")))) {
              return false;
            }
          }
        }
        node = node.getParentNode();
      } while (node != null);
    }
    return true;
  }
  
  public String asText()
  {
    HtmlSerializer ser = new HtmlSerializer();
    return ser.asText(this);
  }
  
  protected boolean isBlock()
  {
    return false;
  }
  
  public String asXml()
  {
    String charsetName = null;
    if ((getPage() instanceof HtmlPage)) {
      charsetName = ((HtmlPage)getPage()).getPageEncoding();
    }
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    if ((charsetName != null) && ((this instanceof HtmlHtml))) {
      printWriter.println("<?xml version=\"1.0\" encoding=\"" + charsetName + "\"?>");
    }
    printXml("", printWriter);
    printWriter.close();
    return stringWriter.toString();
  }
  
  protected void printXml(String indent, PrintWriter printWriter)
  {
    printWriter.println(indent + this);
    printChildrenAsXml(indent, printWriter);
  }
  
  protected void printChildrenAsXml(String indent, PrintWriter printWriter)
  {
    DomNode child = getFirstChild();
    while (child != null)
    {
      child.printXml(indent + "  ", printWriter);
      child = child.getNextSibling();
    }
  }
  
  public String getNodeValue()
  {
    return null;
  }
  
  public void setNodeValue(String value) {}
  
  public DomNode cloneNode(boolean deep)
  {
    DomNode newnode;
    try
    {
      newnode = (DomNode)clone();
    }
    catch (CloneNotSupportedException e)
    {
      throw new IllegalStateException("Clone not supported for node [" + this + "]");
    }
    parent_ = null;
    nextSibling_ = null;
    previousSibling_ = null;
    firstChild_ = null;
    scriptObject_ = null;
    if (deep) {
      for (DomNode child = firstChild_; child != null; child = nextSibling_) {
        newnode.appendChild(child.cloneNode(true));
      }
    }
    return newnode;
  }
  
  public ScriptableObject getScriptObject()
  {
    if (scriptObject_ == null)
    {
      if (this == getPage()) {
        throw new IllegalStateException("No script object associated with the Page");
      }
      scriptObject_ = ((SimpleScriptable)page_.getScriptObject()).makeScriptableFor(this);
    }
    return scriptObject_;
  }
  
  public DomNode appendChild(Node node)
  {
    DomNode domNode = (DomNode)node;
    if ((domNode instanceof DomDocumentFragment))
    {
      DomDocumentFragment fragment = (DomDocumentFragment)domNode;
      for (DomNode child : fragment.getChildren()) {
        appendChild(child);
      }
    }
    else
    {
      if ((domNode != this) && (domNode.getParentNode() != null)) {
        domNode.remove();
      }
      basicAppend(domNode);
      if (domNode.getStartLineNumber() == -1)
      {
        domNode.onAddedToPage();
        domNode.onAllChildrenAddedToPage(true);
      }
      if ((!(this instanceof DomDocumentFragment)) && ((getPage() instanceof HtmlPage))) {
        ((HtmlPage)getPage()).notifyNodeAdded(domNode);
      }
      fireNodeAdded(this, domNode);
    }
    return domNode;
  }
  
  void quietlyRemoveAndMoveChildrenTo(DomNode destination)
  {
    if (destination.getPage() != getPage()) {
      throw new RuntimeException("Cannot perform quiet move on nodes from different pages.");
    }
    for (DomNode child : getChildren())
    {
      child.basicRemove();
      destination.basicAppend(child);
    }
    basicRemove();
  }
  
  private void basicAppend(DomNode node)
  {
    node.setPage(getPage());
    if (firstChild_ == null)
    {
      firstChild_ = node;
      firstChild_.previousSibling_ = node;
    }
    else
    {
      DomNode last = getLastChild();
      nextSibling_ = node;
      previousSibling_ = last;
      nextSibling_ = null;
      firstChild_.previousSibling_ = node;
    }
    parent_ = this;
  }
  
  protected void checkChildHierarchy(Node newChild)
    throws DOMException
  {
    Node parentNode = this;
    while (parentNode != null)
    {
      if (parentNode == newChild) {
        throw new DOMException((short)3, "Child node is already a parent.");
      }
      parentNode = parentNode.getParentNode();
    }
    Document thisDocument = getOwnerDocument();
    Document childDocument = newChild.getOwnerDocument();
    if ((childDocument != thisDocument) && (childDocument != null)) {
      throw new DOMException((short)4, "Child node " + newChild.getNodeName() + " is not in the same Document as this " + getNodeName() + ".");
    }
  }
  
  public Node insertBefore(Node newChild, Node refChild)
  {
    if (refChild == null)
    {
      appendChild(newChild);
    }
    else
    {
      if (refChild.getParentNode() != this) {
        throw new DOMException((short)8, "Reference node is not a child of this node.");
      }
      ((DomNode)refChild).insertBefore((DomNode)newChild);
    }
    return null;
  }
  
  public void insertBefore(DomNode newNode)
    throws IllegalStateException
  {
    if (previousSibling_ == null) {
      throw new IllegalStateException("Previous sibling for " + this + " is null.");
    }
    if (newNode == this) {
      return;
    }
    DomNode exParent = newNode.getParentNode();
    newNode.basicRemove();
    if (parent_.firstChild_ == this) {
      parent_.firstChild_ = newNode;
    } else {
      previousSibling_.nextSibling_ = newNode;
    }
    previousSibling_ = previousSibling_;
    nextSibling_ = this;
    previousSibling_ = newNode;
    parent_ = parent_;
    newNode.setPage(page_);
    if (newNode.getStartLineNumber() == -1)
    {
      newNode.onAddedToPage();
      newNode.onAllChildrenAddedToPage(true);
    }
    if ((getPage() instanceof HtmlPage)) {
      ((HtmlPage)getPage()).notifyNodeAdded(newNode);
    }
    fireNodeAdded(this, newNode);
    if (exParent != null)
    {
      fireNodeDeleted(exParent, newNode);
      exParent.fireNodeDeleted(exParent, this);
    }
  }
  
  private void setPage(SgmlPage newPage)
  {
    if (page_ == newPage) {
      return;
    }
    page_ = newPage;
    for (DomNode node : getChildren()) {
      node.setPage(newPage);
    }
  }
  
  public NamedNodeMap getAttributes()
  {
    return NamedAttrNodeMapImpl.EMPTY_MAP;
  }
  
  public Node removeChild(Node child)
  {
    if (child.getParentNode() != this) {
      throw new DOMException((short)8, "Node is not a child of this node.");
    }
    ((DomNode)child).remove();
    return child;
  }
  
  public void remove()
  {
    DomNode exParent = parent_;
    basicRemove();
    if ((getPage() instanceof HtmlPage)) {
      ((HtmlPage)getPage()).notifyNodeRemoved(this);
    }
    if (exParent != null)
    {
      fireNodeDeleted(exParent, this);
      
      exParent.fireNodeDeleted(exParent, this);
    }
  }
  
  private void basicRemove()
  {
    if ((parent_ != null) && (parent_.firstChild_ == this)) {
      parent_.firstChild_ = nextSibling_;
    } else if ((previousSibling_ != null) && (previousSibling_.nextSibling_ == this)) {
      previousSibling_.nextSibling_ = nextSibling_;
    }
    if ((nextSibling_ != null) && (nextSibling_.previousSibling_ == this)) {
      nextSibling_.previousSibling_ = previousSibling_;
    }
    if ((parent_ != null) && (this == parent_.getLastChild())) {
      parent_.firstChild_.previousSibling_ = previousSibling_;
    }
    nextSibling_ = null;
    previousSibling_ = null;
    parent_ = null;
  }
  
  public Node replaceChild(Node newChild, Node oldChild)
  {
    if (oldChild.getParentNode() != this) {
      throw new DOMException((short)8, "Node is not a child of this node.");
    }
    ((DomNode)oldChild).replace((DomNode)newChild);
    return oldChild;
  }
  
  public void replace(DomNode newNode)
    throws IllegalStateException
  {
    if (newNode != this)
    {
      newNode.remove();
      insertBefore(newNode);
      remove();
    }
  }
  
  protected void onAddedToPage()
  {
    if (firstChild_ != null) {
      for (DomNode child : getChildren()) {
        child.onAddedToPage();
      }
    }
  }
  
  protected void onAllChildrenAddedToPage(boolean postponed) {}
  
  public final Iterable<DomNode> getChildren()
  {
    new Iterable()
    {
      public Iterator<DomNode> iterator()
      {
        return new DomNode.ChildIterator(DomNode.this);
      }
    };
  }
  
  protected class ChildIterator
    implements Iterator<DomNode>
  {
    private DomNode nextNode_ = firstChild_;
    private DomNode currentNode_ = null;
    
    protected ChildIterator() {}
    
    public boolean hasNext()
    {
      return nextNode_ != null;
    }
    
    public DomNode next()
    {
      if (nextNode_ != null)
      {
        currentNode_ = nextNode_;
        nextNode_ = nextNode_.nextSibling_;
        return currentNode_;
      }
      throw new NoSuchElementException();
    }
    
    public void remove()
    {
      if (currentNode_ == null) {
        throw new IllegalStateException();
      }
      currentNode_.remove();
    }
  }
  
  public final Iterable<DomNode> getDescendants()
  {
    new Iterable()
    {
      public Iterator<DomNode> iterator()
      {
        return new DomNode.DescendantElementsIterator(DomNode.this, DomNode.class);
      }
    };
  }
  
  public final Iterable<HtmlElement> getHtmlElementDescendants()
  {
    new Iterable()
    {
      public Iterator<HtmlElement> iterator()
      {
        return new DomNode.DescendantElementsIterator(DomNode.this, HtmlElement.class);
      }
    };
  }
  
  @Deprecated
  public final Iterable<HtmlElement> getAllHtmlChildElements()
  {
    return getHtmlElementDescendants();
  }
  
  protected class DescendantElementsIterator<T extends DomNode>
    implements Iterator<T>
  {
    private DomNode currentNode_;
    private DomNode nextNode_;
    private Class<T> type_;
    
    public DescendantElementsIterator()
    {
      type_ = type;
      nextNode_ = getFirstChildElement(DomNode.this);
    }
    
    public boolean hasNext()
    {
      return nextNode_ != null;
    }
    
    public T next()
    {
      return nextNode();
    }
    
    public void remove()
    {
      if (currentNode_ == null) {
        throw new IllegalStateException("Unable to remove current node, because there is no current node.");
      }
      DomNode current = currentNode_;
      while ((nextNode_ != null) && (current.isAncestorOf(nextNode_))) {
        next();
      }
      current.remove();
    }
    
    public T nextNode()
    {
      currentNode_ = nextNode_;
      setNextElement();
      return currentNode_;
    }
    
    private void setNextElement()
    {
      DomNode next = getFirstChildElement(nextNode_);
      if (next == null) {
        next = getNextDomSibling(nextNode_);
      }
      if (next == null) {
        next = getNextElementUpwards(nextNode_);
      }
      nextNode_ = next;
    }
    
    private DomNode getNextElementUpwards(DomNode startingNode)
    {
      if (startingNode == DomNode.this) {
        return null;
      }
      DomNode parent = startingNode.getParentNode();
      if (parent == DomNode.this) {
        return null;
      }
      DomNode next = parent.getNextSibling();
      while ((next != null) && (!type_.isAssignableFrom(next.getClass()))) {
        next = next.getNextSibling();
      }
      if (next == null) {
        return getNextElementUpwards(parent);
      }
      return next;
    }
    
    private DomNode getFirstChildElement(DomNode parent)
    {
      if (((parent instanceof HtmlNoScript)) && (getPage().getEnclosingWindow().getWebClient().isJavaScriptEnabled())) {
        return null;
      }
      DomNode node = parent.getFirstChild();
      while ((node != null) && (!type_.isAssignableFrom(node.getClass()))) {
        node = node.getNextSibling();
      }
      return node;
    }
    
    private DomNode getNextDomSibling(DomNode element)
    {
      DomNode node = element.getNextSibling();
      while ((node != null) && (!type_.isAssignableFrom(node.getClass()))) {
        node = node.getNextSibling();
      }
      return node;
    }
  }
  
  public String getReadyState()
  {
    return readyState_;
  }
  
  public void setReadyState(String state)
  {
    readyState_ = state;
  }
  
  public void removeAllChildren()
  {
    if (getFirstChild() == null) {
      return;
    }
    for (Iterator<DomNode> it = getChildren().iterator(); it.hasNext();)
    {
      ((DomNode)it.next()).removeAllChildren();
      it.remove();
    }
  }
  
  public List<?> getByXPath(String xpathExpr)
  {
    return XPathUtils.getByXPath(this, xpathExpr);
  }
  
  public <X> X getFirstByXPath(String xpathExpr)
  {
    List<?> results = getByXPath(xpathExpr);
    if (results.isEmpty()) {
      return null;
    }
    return (X)results.get(0);
  }
  
  public String getCanonicalXPath()
  {
    throw new NotImplementedException("Not implemented for nodes of type " + getNodeType());
  }
  
  protected void notifyIncorrectness(String message)
  {
    WebClient client = getPage().getEnclosingWindow().getWebClient();
    IncorrectnessListener incorrectnessListener = client.getIncorrectnessListener();
    incorrectnessListener.notify(message, this);
  }
  
  public void addDomChangeListener(DomChangeListener listener)
  {
    WebAssert.notNull("listener", listener);
    synchronized (domListeners_lock_)
    {
      if (domListeners_ == null) {
        domListeners_ = new ArrayList();
      }
      if (!domListeners_.contains(listener)) {
        domListeners_.add(listener);
      }
    }
  }
  
  public void removeDomChangeListener(DomChangeListener listener)
  {
    WebAssert.notNull("listener", listener);
    synchronized (domListeners_lock_)
    {
      if (domListeners_ != null) {
        domListeners_.remove(listener);
      }
    }
  }
  
  protected void fireNodeAdded(DomNode parentNode, DomNode addedNode)
  {
    List<DomChangeListener> listeners = safeGetDomListeners();
    DomChangeEvent event;
    if (listeners != null)
    {
      event = new DomChangeEvent(parentNode, addedNode);
      for (DomChangeListener listener : listeners) {
        listener.nodeAdded(event);
      }
    }
    if (parent_ != null) {
      parent_.fireNodeAdded(parentNode, addedNode);
    }
  }
  
  protected void fireNodeDeleted(DomNode parentNode, DomNode deletedNode)
  {
    List<DomChangeListener> listeners = safeGetDomListeners();
    DomChangeEvent event;
    if (listeners != null)
    {
      event = new DomChangeEvent(parentNode, deletedNode);
      for (DomChangeListener listener : listeners) {
        listener.nodeDeleted(event);
      }
    }
    if (parent_ != null) {
      parent_.fireNodeDeleted(parentNode, deletedNode);
    }
  }
  
  private List<DomChangeListener> safeGetDomListeners()
  {
    synchronized (domListeners_lock_)
    {
      if (domListeners_ != null) {
        return new ArrayList(domListeners_);
      }
      return null;
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomNode
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import java.io.Serializable;

public abstract interface HtmlAttributeChangeListener
  extends Serializable
{
  public abstract void attributeAdded(HtmlAttributeChangeEvent paramHtmlAttributeChangeEvent);
  
  public abstract void attributeRemoved(HtmlAttributeChangeEvent paramHtmlAttributeChangeEvent);
  
  public abstract void attributeReplaced(HtmlAttributeChangeEvent paramHtmlAttributeChangeEvent);
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import java.util.EventObject;

public class HtmlAttributeChangeEvent
  extends EventObject
{
  private static final long serialVersionUID = -7432080435641028075L;
  private final String name_;
  private final String value_;
  
  public HtmlAttributeChangeEvent(HtmlElement element, String name, String value)
  {
    super(element);
    name_ = name;
    value_ = value;
  }
  
  public HtmlElement getHtmlElement()
  {
    return (HtmlElement)getSource();
  }
  
  public String getName()
  {
    return name_;
  }
  
  public String getValue()
  {
    return value_;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import java.util.List;
import org.w3c.dom.NodeList;

public abstract interface DomNodeList<E extends DomNode>
  extends NodeList, List<E>
{}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomNodeList
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import java.io.Serializable;

public abstract interface DomChangeListener
  extends Serializable
{
  public abstract void nodeAdded(DomChangeEvent paramDomChangeEvent);
  
  public abstract void nodeDeleted(DomChangeEvent paramDomChangeEvent);
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomChangeListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import com.gargoylesoftware.htmlunit.SgmlPage;
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;

public class DomDocumentType
  extends DomNode
  implements DocumentType
{
  private static final long serialVersionUID = -5089258626822609432L;
  private final String name_;
  private final String publicId_;
  private final String systemId_;
  
  public DomDocumentType(SgmlPage page, String name, String publicId, String systemId)
  {
    super(page);
    name_ = name;
    publicId_ = publicId;
    systemId_ = systemId;
  }
  
  public String getNodeName()
  {
    return name_;
  }
  
  public short getNodeType()
  {
    return 10;
  }
  
  public NamedNodeMap getEntities()
  {
    return null;
  }
  
  public String getInternalSubset()
  {
    return "";
  }
  
  public String getName()
  {
    return name_;
  }
  
  public NamedNodeMap getNotations()
  {
    return null;
  }
  
  public String getPublicId()
  {
    return publicId_;
  }
  
  public String getSystemId()
  {
    return systemId_;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomDocumentType
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import com.gargoylesoftware.htmlunit.SgmlPage;
import org.w3c.dom.DocumentFragment;

public class DomDocumentFragment
  extends DomNode
  implements DocumentFragment
{
  private static final long serialVersionUID = 7073670645099705230L;
  public static final String NODE_NAME = "#document-fragment";
  
  public DomDocumentFragment(SgmlPage page)
  {
    super(page);
  }
  
  public String getNodeName()
  {
    return "#document-fragment";
  }
  
  public short getNodeType()
  {
    return 11;
  }
  
  public String asXml()
  {
    return getFirstChild().asXml();
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomDocumentFragment
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

import com.gargoylesoftware.htmlunit.util.NameValuePair;

public abstract interface SubmittableElement
{
  public abstract NameValuePair[] getSubmitKeyValuePairs();
  
  public abstract void reset();
  
  public abstract void setDefaultValue(String paramString);
  
  public abstract String getDefaultValue();
  
  public abstract void setDefaultChecked(boolean paramBoolean);
  
  public abstract boolean isDefaultChecked();
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.SubmittableElement
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html;

public abstract interface DisabledElement
{
  public abstract boolean isDisabled();
  
  public abstract String getDisabledAttribute();
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DisabledElement
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html.impl;

import com.gargoylesoftware.htmlunit.Page;
import org.w3c.dom.Node;

public abstract interface SelectableTextInput
  extends Node
{
  public abstract Page getPage();
  
  public abstract void focus();
  
  public abstract void select();
  
  public abstract String getText();
  
  public abstract void setText(String paramString);
  
  public abstract String getSelectedText();
  
  public abstract int getSelectionStart();
  
  public abstract void setSelectionStart(int paramInt);
  
  public abstract int getSelectionEnd();
  
  public abstract void setSelectionEnd(int paramInt);
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.impl.SelectableTextInput
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html.impl;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.Serializable;
import org.w3c.dom.ranges.Range;

public class SelectionDelegate
  implements Serializable
{
  private static final long serialVersionUID = -5611492671640559880L;
  private final SelectableTextInput element_;
  private final Range selection_;
  
  public SelectionDelegate(SelectableTextInput element)
  {
    element_ = element;
    selection_ = new SimpleRange(element, element.getText().length());
  }
  
  public void select()
  {
    element_.focus();
    setSelectionStart(0);
    setSelectionEnd(element_.getText().length());
  }
  
  public String getSelectedText()
  {
    return selection_.toString();
  }
  
  public int getSelectionStart()
  {
    return selection_.getStartOffset();
  }
  
  public void setSelectionStart(int selectionStart)
  {
    int length = element_.getText().length();
    selectionStart = Math.max(0, Math.min(selectionStart, length));
    selection_.setStart(element_, selectionStart);
    if (selection_.getEndOffset() < selectionStart) {
      selection_.setEnd(element_, selectionStart);
    }
    makeThisTheOnlySelectionIfEmulatingIE();
  }
  
  public int getSelectionEnd()
  {
    return selection_.getEndOffset();
  }
  
  public void setSelectionEnd(int selectionEnd)
  {
    int length = element_.getText().length();
    selectionEnd = Math.min(length, Math.max(selectionEnd, 0));
    selection_.setEnd(element_, selectionEnd);
    if (selection_.getStartOffset() > selectionEnd) {
      selection_.setStart(element_, selectionEnd);
    }
    makeThisTheOnlySelectionIfEmulatingIE();
  }
  
  private void makeThisTheOnlySelectionIfEmulatingIE()
  {
    Page page = element_.getPage();
    if ((page instanceof HtmlPage))
    {
      HtmlPage htmlPage = (HtmlPage)page;
      if (htmlPage.getWebClient().getBrowserVersion().isIE()) {
        htmlPage.setSelectionRange(selection_);
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.impl.SelectionDelegate
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit.html.impl;

import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.html.DomDocumentFragment;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.DomText;
import java.io.Serializable;
import java.util.Iterator;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ranges.Range;
import org.w3c.dom.ranges.RangeException;

public class SimpleRange
  implements Range, Serializable
{
  private static final long serialVersionUID = 5779974839466976193L;
  private Node startContainer_;
  private Node endContainer_;
  private int startOffset_;
  private int endOffset_;
  
  public SimpleRange() {}
  
  public SimpleRange(Node node)
  {
    startContainer_ = node;
    endContainer_ = node;
    startOffset_ = 0;
    endOffset_ = getMaxOffset(node);
  }
  
  public SimpleRange(Node node, int offset)
  {
    startContainer_ = node;
    endContainer_ = node;
    startOffset_ = offset;
    endOffset_ = offset;
  }
  
  public SimpleRange(Node startNode, int startOffset, Node endNode, int endOffset)
  {
    startContainer_ = startNode;
    endContainer_ = endNode;
    startOffset_ = startOffset;
    endOffset_ = endOffset;
  }
  
  public DocumentFragment cloneContents()
    throws DOMException
  {
    throw new RuntimeException("Not implemented!");
  }
  
  public Range cloneRange()
    throws DOMException
  {
    return new SimpleRange(startContainer_, startOffset_, endContainer_, endOffset_);
  }
  
  public void collapse(boolean toStart)
    throws DOMException
  {
    if (toStart)
    {
      endContainer_ = startContainer_;
      endOffset_ = startOffset_;
    }
    else
    {
      startContainer_ = endContainer_;
      
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd