htmlunit-2.7

Context;

public class Selection
  extends SimpleScriptable
{
  private static final long serialVersionUID = 3712755502782559551L;
  private String type_ = "None";
  
  public Object getDefaultValue(Class<?> hint)
  {
    boolean ff = getBrowserVersion().isFirefox();
    if ((ff) && ((String.class.equals(hint)) || (hint == null)))
    {
      StringBuilder sb = new StringBuilder();
      for (org.w3c.dom.ranges.Range r : getRanges()) {
        sb.append(r.toString());
      }
      return sb.toString();
    }
    return super.getDefaultValue(hint);
  }
  
  public Node jsxGet_anchorNode()
  {
    org.w3c.dom.ranges.Range last = getLastRange();
    if (last == null) {
      return null;
    }
    return (Node)getScriptableNullSafe(last.getStartContainer());
  }
  
  public int jsxGet_anchorOffset()
  {
    org.w3c.dom.ranges.Range last = getLastRange();
    if (last == null) {
      return 0;
    }
    return last.getStartOffset();
  }
  
  public Node jsxGet_focusNode()
  {
    org.w3c.dom.ranges.Range last = getLastRange();
    if (last == null) {
      return null;
    }
    return (Node)getScriptableNullSafe(last.getEndContainer());
  }
  
  public int jsxGet_focusOffset()
  {
    org.w3c.dom.ranges.Range last = getLastRange();
    if (last == null) {
      return 0;
    }
    return last.getEndOffset();
  }
  
  public boolean jsxGet_isCollapsed()
  {
    List<org.w3c.dom.ranges.Range> ranges = getRanges();
    return (ranges.isEmpty()) || ((ranges.size() == 1) && (((org.w3c.dom.ranges.Range)ranges.get(0)).getCollapsed()));
  }
  
  public int jsxGet_rangeCount()
  {
    return getRanges().size();
  }
  
  public String jsxGet_type()
  {
    return type_;
  }
  
  public TextRange jsxFunction_createRange()
  {
    org.w3c.dom.ranges.Range first = getFirstRange();
    TextRange range;
    TextRange range;
    if (first != null) {
      range = new TextRange(first);
    } else {
      range = new TextRange(new SimpleRange());
    }
    range.setParentScope(getParentScope());
    range.setPrototype(getPrototype(range.getClass()));
    return range;
  }
  
  public void jsxFunction_addRange(Range range)
  {
    getRanges().add(range.toW3C());
  }
  
  public void jsxFunction_removeRange(Range range)
  {
    getRanges().remove(range.toW3C());
  }
  
  public void jsxFunction_removeAllRanges()
  {
    getRanges().clear();
  }
  
  public Range jsxFunction_getRangeAt(int index)
  {
    List<org.w3c.dom.ranges.Range> ranges = getRanges();
    if ((index < 0) || (index >= ranges.size())) {
      throw Context.reportRuntimeError("Invalid range index: " + index);
    }
    org.w3c.dom.ranges.Range range = (org.w3c.dom.ranges.Range)ranges.get(index);
    Range jsRange = new Range(range);
    
    jsRange.setParentScope(getWindow());
    jsRange.setPrototype(getPrototype(Range.class));
    
    return jsRange;
  }
  
  public void jsxFunction_collapse(Node parentNode, int offset)
  {
    List<org.w3c.dom.ranges.Range> ranges = getRanges();
    ranges.clear();
    ranges.add(new SimpleRange(parentNode.getDomNodeOrDie(), offset));
  }
  
  public void jsxFunction_collapseToEnd()
  {
    org.w3c.dom.ranges.Range last = getLastRange();
    if (last != null)
    {
      List<org.w3c.dom.ranges.Range> ranges = getRanges();
      ranges.clear();
      ranges.add(last);
      last.collapse(false);
    }
  }
  
  public void jsxFunction_collapseToStart()
  {
    org.w3c.dom.ranges.Range first = getFirstRange();
    if (first != null)
    {
      List<org.w3c.dom.ranges.Range> ranges = getRanges();
      ranges.clear();
      ranges.add(first);
      first.collapse(true);
    }
  }
  
  public void jsxFunction_empty()
  {
    type_ = "None";
  }
  
  public void jsxFunction_extend(Node parentNode, int offset)
  {
    org.w3c.dom.ranges.Range last = getLastRange();
    if (last != null) {
      last.setEnd(parentNode.getDomNodeOrDie(), offset);
    }
  }
  
  public void jsxFunction_selectAllChildren(Node parentNode)
  {
    List<org.w3c.dom.ranges.Range> ranges = getRanges();
    ranges.clear();
    ranges.add(new SimpleRange(parentNode.getDomNodeOrDie()));
  }
  
  private List<org.w3c.dom.ranges.Range> getRanges()
  {
    HtmlPage page = (HtmlPage)getWindow().getDomNodeOrDie();
    return page.getSelectionRanges();
  }
  
  private org.w3c.dom.ranges.Range getFirstRange()
  {
    org.w3c.dom.ranges.Range first = null;
    for (org.w3c.dom.ranges.Range range : getRanges()) {
      if (first == null)
      {
        first = range;
      }
      else
      {
        org.w3c.dom.Node firstStart = first.getStartContainer();
        org.w3c.dom.Node rangeStart = range.getStartContainer();
        if ((firstStart.compareDocumentPosition(rangeStart) & 0x2) != 0) {
          first = range;
        }
      }
    }
    return first;
  }
  
  private org.w3c.dom.ranges.Range getLastRange()
  {
    org.w3c.dom.ranges.Range last = null;
    for (org.w3c.dom.ranges.Range range : getRanges()) {
      if (last == null)
      {
        last = range;
      }
      else
      {
        org.w3c.dom.Node lastStart = last.getStartContainer();
        org.w3c.dom.Node rangeStart = range.getStartContainer();
        if ((lastStart.compareDocumentPosition(rangeStart) & 0x4) != 0) {
          last = range;
        }
      }
    }
    return last;
  }
  
  private SimpleScriptable getScriptableNullSafe(Object object)
  {
    SimpleScriptable scriptable;
    SimpleScriptable scriptable;
    if (object != null) {
      scriptable = getScriptableFor(object);
    } else {
      scriptable = null;
    }
    return scriptable;
  }
}

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

import com.gargoylesoftware.htmlunit.html.DomChangeEvent;
import com.gargoylesoftware.htmlunit.html.DomChangeListener;
import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent;
import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeListener;

class HTMLCollection$DomHtmlAttributeChangeListenerImpl
  implements DomChangeListener, HtmlAttributeChangeListener
{
  private static final long serialVersionUID = -6690451155079053212L;
  
  private HTMLCollection$DomHtmlAttributeChangeListenerImpl(HTMLCollection paramHTMLCollection) {}
  
  public void nodeAdded(DomChangeEvent event)
  {
    HTMLCollection.access$102(this$0, null);
  }
  
  public void nodeDeleted(DomChangeEvent event)
  {
    HTMLCollection.access$102(this$0, null);
  }
  
  public void attributeAdded(HtmlAttributeChangeEvent event)
  {
    HTMLCollection.access$102(this$0, null);
  }
  
  public void attributeRemoved(HtmlAttributeChangeEvent event)
  {
    HTMLCollection.access$102(this$0, null);
  }
  
  public void attributeReplaced(HtmlAttributeChangeEvent event)
  {
    HTMLCollection.access$102(this$0, null);
  }
}

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

class HTMLCollection$1 {}

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

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.html.BaseFrame;
import com.gargoylesoftware.htmlunit.html.DomChangeEvent;
import com.gargoylesoftware.htmlunit.html.DomChangeListener;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.DomText;
import com.gargoylesoftware.htmlunit.html.FrameWindow;
import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent;
import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeListener;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlNoScript;
import com.gargoylesoftware.htmlunit.html.xpath.XPathUtils;
import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
import com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration;
import com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration;
import com.gargoylesoftware.htmlunit.javascript.host.WindowProxy;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Function;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.functors.NOPTransformer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class HTMLCollection
  extends SimpleScriptable
  implements Function, NodeList
{
  private static final long serialVersionUID = 4049916048017011764L;
  private static final Log LOG = LogFactory.getLog(HTMLCollection.class);
  private String xpath_;
  private DomNode node_;
  private boolean avoidObjectDetection_ = false;
  private Transformer transformer_;
  private List<Object> cachedElements_;
  private int currentIndex_ = 0;
  
  @Deprecated
  public HTMLCollection() {}
  
  public HTMLCollection(DomNode parentScope)
  {
    this(parentScope.getScriptObject());
  }
  
  public HTMLCollection(ScriptableObject parentScope)
  {
    setParentScope(parentScope);
    setPrototype(getPrototype(getClass()));
  }
  
  public boolean avoidObjectDetection()
  {
    return avoidObjectDetection_;
  }
  
  public void setAvoidObjectDetection(boolean newValue)
  {
    avoidObjectDetection_ = newValue;
  }
  
  public void init(DomNode node, String xpath)
  {
    init(node, xpath, NOPTransformer.INSTANCE);
  }
  
  public void init(DomNode node, String xpath, Transformer transformer)
  {
    if (node != null)
    {
      node_ = node;
      xpath_ = xpath;
      transformer_ = transformer;
      DomHtmlAttributeChangeListenerImpl listener = new DomHtmlAttributeChangeListenerImpl(null);
      node_.addDomChangeListener(listener);
      if ((node_ instanceof HtmlElement))
      {
        ((HtmlElement)node_).addHtmlAttributeChangeListener(listener);
        cachedElements_ = null;
      }
    }
  }
  
  public void initFromChildren(DomNode node)
  {
    if (node != null)
    {
      node_ = node;
      DomHtmlAttributeChangeListenerImpl listener = new DomHtmlAttributeChangeListenerImpl(null);
      node_.addDomChangeListener(listener);
      if ((node_ instanceof HtmlElement))
      {
        ((HtmlElement)node_).addHtmlAttributeChangeListener(listener);
        cachedElements_ = null;
      }
    }
    transformer_ = NOPTransformer.INSTANCE;
  }
  
  public final Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
  {
    if (args.length == 0) {
      throw Context.reportRuntimeError("Zero arguments; need an index or a key.");
    }
    return nullIfNotFound(getIt(args[0]));
  }
  
  public final Scriptable construct(Context cx, Scriptable scope, Object[] args)
  {
    return null;
  }
  
  private Object getIt(Object o)
  {
    if ((o instanceof Number))
    {
      Number n = (Number)o;
      int i = n.intValue();
      return get(i, this);
    }
    String key = String.valueOf(o);
    return get(key, this);
  }
  
  public final Object get(int index, Scriptable start)
  {
    HTMLCollection array = (HTMLCollection)start;
    List<Object> elements = array.getElements();
    if ((index >= 0) && (index < elements.size())) {
      return getScriptableForElement(transformer_.transform(elements.get(index)));
    }
    return NOT_FOUND;
  }
  
  protected List<Object> getElements()
  {
    if (cachedElements_ == null) {
      cachedElements_ = computeElements();
    }
    return cachedElements_;
  }
  
  protected List<Object> computeElements()
  {
    List<Object> response;
    if (node_ != null)
    {
      List<Object> response;
      if (xpath_ != null)
      {
        response = XPathUtils.getByXPath(node_, xpath_);
      }
      else
      {
        List<Object> response = new ArrayList();
        Node node = node_.getFirstChild();
        while (node != null)
        {
          response.add(node);
          node = node.getNextSibling();
        }
      }
    }
    else
    {
      response = new ArrayList();
    }
    boolean isXmlPage = (node_ != null) && ((node_.getOwnerDocument() instanceof XmlPage));
    
    boolean isIE = getBrowserVersion().isIE();
    for (int i = 0; i < response.size(); i++)
    {
      DomNode element = (DomNode)response.get(i);
      if ((isIE) && (isXmlPage) && ((element instanceof DomText)) && (((DomText)element).getNodeValue().trim().length() == 0))
      {
        Boolean xmlSpaceDefault = isXMLSpaceDefault(element.getParentNode());
        if (xmlSpaceDefault != Boolean.FALSE)
        {
          response.remove(i--);
          continue;
        }
      }
      for (DomNode parent = element.getParentNode(); parent != null; parent = parent.getParentNode()) {
        if ((parent instanceof HtmlNoScript))
        {
          response.remove(i--);
          break;
        }
      }
    }
    return response;
  }
  
  private static Boolean isXMLSpaceDefault(DomNode node)
  {
    for (; (node instanceof DomElement); node = node.getParentNode())
    {
      String value = ((DomElement)node).getAttribute("xml:space");
      if (value.length() != 0)
      {
        if (value.equals("default")) {
          return Boolean.TRUE;
        }
        return Boolean.FALSE;
      }
    }
    return null;
  }
  
  protected Object getWithPreemption(String name)
  {
    if ((xpath_ == null) || ("length".equals(name))) {
      return NOT_FOUND;
    }
    List<Object> elements = getElements();
    CollectionUtils.transform(elements, transformer_);
    for (Object next : elements) {
      if ((next instanceof DomElement))
      {
        String id = ((DomElement)next).getAttribute("id");
        if ((id != null) && (id.equals(name)))
        {
          if ((getBrowserVersion().isIE()) || ("FF3".equals(getBrowserVersion().getNickname())))
          {
            int totalIDs = 0;
            for (Object o : elements) {
              if (((o instanceof DomElement)) && (name.equals(((DomElement)o).getAttribute("id")))) {
                totalIDs++;
              }
            }
            if (totalIDs > 1)
            {
              HTMLCollectionTags collection = new HTMLCollectionTags((SimpleScriptable)getParentScope());
              
              collection.setAvoidObjectDetection(!getBrowserVersion().isIE());
              collection.init(node_, ".//*[@id='" + id + "']");
              return collection;
            }
          }
          LOG.debug("Property \"" + name + "\" evaluated (by id) to " + next);
          return getScriptableForElement(next);
        }
      }
      else if ((next instanceof WebWindow))
      {
        WebWindow window = (WebWindow)next;
        String windowName = window.getName();
        if ((windowName != null) && (windowName.equals(name)))
        {
          LOG.debug("Property \"" + name + "\" evaluated (by name) to " + window);
          return getScriptableForElement(window);
        }
        if ((getBrowserVersion().isIE()) && ((window instanceof FrameWindow)) && (((FrameWindow)window).getFrameElement().getAttribute("id").equals(name)))
        {
          LOG.debug("Property \"" + name + "\" evaluated (by id) to " + window);
          return getScriptableForElement(window);
        }
      }
      else
      {
        LOG.warn("Unrecognized type in collection: " + next + " (" + next.getClass().getName() + ")");
      }
    }
    HTMLCollection array = new HTMLCollection(this);
    String newCondition = "@name = '" + name.replaceAll("\\$", "\\\\\\$") + "'";
    String xpathExpr;
    String xpathExpr;
    if (xpath_.endsWith("]")) {
      xpathExpr = xpath_.replaceAll("\\[([^\\]]*)\\]$", "[($1) and " + newCondition + "]");
    } else {
      xpathExpr = xpath_ + "[" + newCondition + "]";
    }
    array.init(node_, xpathExpr);
    
    List<Object> subElements = array.getElements();
    if (subElements.size() > 1)
    {
      LOG.debug("Property \"" + name + "\" evaluated (by name) to " + array + " with " + subElements.size() + " elements");
      
      return array;
    }
    if (subElements.size() == 1)
    {
      Scriptable singleResult = getScriptableForElement(subElements.get(0));
      LOG.debug("Property \"" + name + "\" evaluated (by name) to " + singleResult);
      return singleResult;
    }
    return NOT_FOUND;
  }
  
  public final int jsxGet_length()
  {
    return getElements().size();
  }
  
  public final Object jsxFunction_item(Object index)
  {
    return nullIfNotFound(getIt(index));
  }
  
  private Object nullIfNotFound(Object object)
  {
    if (object == NOT_FOUND)
    {
      if (getBrowserVersion().isIE()) {
        return null;
      }
      return Context.getUndefinedValue();
    }
    return object;
  }
  
  public final Object jsxFunction_namedItem(String name)
  {
    return nullIfNotFound(getIt(name));
  }
  
  public Object jsxFunction_nextNode()
  {
    List<Object> elements = getElements();
    Object nextNode;
    Object nextNode;
    if ((currentIndex_ >= 0) && (currentIndex_ < elements.size())) {
      nextNode = elements.get(currentIndex_);
    } else {
      nextNode = null;
    }
    currentIndex_ += 1;
    return nextNode;
  }
  
  public void jsxFunction_reset()
  {
    currentIndex_ = 0;
  }
  
  public Object jsxFunction_tags(String tagName)
  {
    HTMLCollection array = new HTMLCollection(this);
    array.init(node_, xpath_ + "[name() = '" + tagName.toLowerCase() + "']");
    return array;
  }
  
  public String toString()
  {
    if (xpath_ != null) {
      return super.toString() + '<' + xpath_ + '>';
    }
    return super.toString();
  }
  
  protected Object equivalentValues(Object other)
  {
    if (other == this) {
      return Boolean.TRUE;
    }
    if ((other instanceof HTMLCollection))
    {
      HTMLCollection otherArray = (HTMLCollection)other;
      if ((node_ == node_) && (xpath_.toString().equals(xpath_.toString())) && (transformer_.equals(transformer_))) {
        return Boolean.TRUE;
      }
      return NOT_FOUND;
    }
    return super.equivalentValues(other);
  }
  
  public boolean has(String name, Scriptable start)
  {
    try
    {
      int index = Integer.parseInt(name);
      List<Object> elements = getElements();
      CollectionUtils.transform(elements, transformer_);
      if ((index >= 0) && (index < elements.size())) {
        return true;
      }
    }
    catch (NumberFormatException e) {}
    if (name.equals("length")) {
      return true;
    }
    if (!getBrowserVersion().isIE())
    {
      JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(BrowserVersion.FIREFOX_2);
      for (String functionName : jsConfig.getClassConfiguration(getClassName()).functionKeys()) {
        if (name.equals(functionName)) {
          return true;
        }
      }
      return false;
    }
    return getWithPreemption(name) != NOT_FOUND;
  }
  
  public Object[] getIds()
  {
    List<String> idList = new ArrayList();
    
    List<Object> elements = getElements();
    CollectionUtils.transform(elements, transformer_);
    int index;
    if (!getBrowserVersion().isIE())
    {
      int length = getElements().size();
      for (int i = 0; i < length; i++) {
        idList.add(Integer.toString(i));
      }
      idList.add("length");
      JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(BrowserVersion.FIREFOX_2);
      for (String name : jsConfig.getClassConfiguration(getClassName()).functionKeys()) {
        idList.add(name);
      }
    }
    else
    {
      idList.add("length");
      
      index = 0;
      for (Object next : elements) {
        if ((next instanceof HtmlElement))
        {
          HtmlElement element = (HtmlElement)next;
          String name = element.getAttribute("name");
          if (name != HtmlElement.ATTRIBUTE_NOT_DEFINED)
          {
            idList.add(name);
          }
          else
          {
            String id = element.getId();
            if (id != HtmlElement.ATTRIBUTE_NOT_DEFINED) {
              idList.add(id);
            } else {
              idList.add(Integer.toString(index));
            }
          }
          index++;
        }
        else if ((next instanceof WebWindow))
        {
          WebWindow window = (WebWindow)next;
          String windowName = window.getName();
          if (windowName != null) {
            idList.add(windowName);
          }
        }
        else
        {
          LOG.debug("Unrecognized type in array: \"" + next.getClass().getName() + "\"");
        }
      }
    }
    return idList.toArray();
  }
  
  private class DomHtmlAttributeChangeListenerImpl
    implements DomChangeListener, HtmlAttributeChangeListener
  {
    private static final long serialVersionUID = -6690451155079053212L;
    
    private DomHtmlAttributeChangeListenerImpl() {}
    
    public void nodeAdded(DomChangeEvent event)
    {
      cachedElements_ = null;
    }
    
    public void nodeDeleted(DomChangeEvent event)
    {
      cachedElements_ = null;
    }
    
    public void attributeAdded(HtmlAttributeChangeEvent event)
    {
      cachedElements_ = null;
    }
    
    public void attributeRemoved(HtmlAttributeChangeEvent event)
    {
      cachedElements_ = null;
    }
    
    public void attributeReplaced(HtmlAttributeChangeEvent event)
    {
      cachedElements_ = null;
    }
  }
  
  public int getLength()
  {
    return jsxGet_length();
  }
  
  public Node item(int index)
  {
    return (DomNode)transformer_.transform(getElements().get(index));
  }
  
  public Object getDefaultValue(Class<?> hint)
  {
    if ((String.class.equals(hint)) || (hint == null))
    {
      if (getBrowserVersion().isIE()) {
        return "[object]";
      }
      return "[object HTMLCollection]";
    }
    return super.getDefaultValue(hint);
  }
  
  protected Scriptable getScriptableForElement(Object object)
  {
    if ((object instanceof Scriptable)) {
      return (Scriptable)object;
    }
    if ((object instanceof WebWindow)) {
      return new WindowProxy((WebWindow)object);
    }
    return getScriptableFor(object);
  }
}

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

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.html.DomText;
import com.gargoylesoftware.htmlunit.html.HTMLParser;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
import com.gargoylesoftware.htmlunit.html.IElementFactory;
import com.gargoylesoftware.htmlunit.javascript.ScriptableWithFallbackGetter;
import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;

public class HTMLOptionsCollection
  extends SimpleScriptable
  implements ScriptableWithFallbackGetter
{
  private static final long serialVersionUID = -4790255174217201235L;
  private HtmlSelect htmlSelect_;
  
  public HTMLOptionsCollection() {}
  
  public HTMLOptionsCollection(SimpleScriptable parentScope)
  {
    setParentScope(parentScope);
    setPrototype(getPrototype(getClass()));
  }
  
  public void initialize(HtmlSelect select)
  {
    WebAssert.notNull("select", select);
    htmlSelect_ = select;
  }
  
  public Object get(int index, Scriptable start)
  {
    if (index < 0) {
      throw Context.reportRuntimeError("Index or size is negative");
    }
    Object response;
    Object response;
    if (index >= htmlSelect_.getOptionSize()) {
      response = Context.getUndefinedValue();
    } else {
      response = getScriptableFor(htmlSelect_.getOption(index));
    }
    return response;
  }
  
  public void put(String name, Scriptable start, Object value)
  {
    if (htmlSelect_ == null)
    {
      super.put(name, start, value);
      return;
    }
    HTMLSelectElement parent = (HTMLSelectElement)htmlSelect_.getScriptObject();
    if ((!has(name, start)) && (ScriptableObject.hasProperty(parent, name))) {
      ScriptableObject.putProperty(parent, name, value);
    } else {
      super.put(name, start, value);
    }
  }
  
  public Object getWithFallback(String name)
  {
    if ((!getBrowserVersion().isIE()) && (name.equals("childNodes"))) {
      return NOT_FOUND;
    }
    HTMLSelectElement select = (HTMLSelectElement)htmlSelect_.getScriptObject();
    return ScriptableObject.getProperty(select, name);
  }
  
  public Object jsxFunction_item(int index)
  {
    return get(index, null);
  }
  
  public void put(int index, Scriptable start, Object newValue)
  {
    if (newValue == null)
    {
      htmlSelect_.removeOption(index);
    }
    else
    {
      HTMLOptionElement option = (HTMLOptionElement)newValue;
      HtmlOption htmlOption = option.getDomNodeOrNull();
      if (index >= jsxGet_length()) {
        htmlSelect_.appendOption(htmlOption);
      } else {
        htmlSelect_.replaceOption(index, htmlOption);
      }
    }
    if ((jsxGet_length() == 1) && (!htmlSelect_.isMultipleSelectEnabled())) {
      ((HTMLSelectElement)htmlSelect_.getScriptObject()).jsxSet_selectedIndex(0);
    }
  }
  
  public int jsxGet_length()
  {
    return htmlSelect_.getOptionSize();
  }
  
  public void jsxSet_length(int newLength)
  {
    int currentLength = htmlSelect_.getOptionSize();
    if (currentLength > newLength) {
      htmlSelect_.setOptionSize(newLength);
    } else {
      for (int i = currentLength; i < newLength; i++)
      {
        HtmlOption option = (HtmlOption)HTMLParser.getFactory("option").createElement(htmlSelect_.getPage(), "option", null);
        
        htmlSelect_.appendOption(option);
        if (!getBrowserVersion().isIE()) {
          option.appendChild(new DomText(option.getPage(), ""));
        }
      }
    }
  }
  
  public void jsxFunction_add(Object newOptionObject, Object newIndex)
  {
    int index = jsxGet_length();
    if ((newIndex instanceof Number)) {
      index = ((Number)newIndex).intValue();
    }
    put(index, null, newOptionObject);
  }
}

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

import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;

public class HTMLCollectionTags
  extends HTMLCollection
{
  private static final long serialVersionUID = -1772897974886997756L;
  
  @Deprecated
  public HTMLCollectionTags() {}
  
  public HTMLCollectionTags(SimpleScriptable parentScope)
  {
    super(parentScope);
  }
  
  protected Object equivalentValues(Object other)
  {
    if (!(other instanceof HTMLCollectionTags)) {
      return Boolean.FALSE;
    }
    return super.equivalentValues(other);
  }
}

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

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.javascript.PostponedAction;

class HTMLDocument$1
  extends PostponedAction
{
  HTMLDocument$1(HTMLDocument paramHTMLDocument, Page x0)
  {
    super(x0);
  }
  
  public void execute()
    throws Exception
  {
    if (HTMLDocument.access$000(this$0).length() > 0) {
      this$0.jsxFunction_close();
    }
    HTMLDocument.access$102(this$0, false);
  }
}

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

 enum HTMLDocument$PARSING_STATUS
{
  OUTSIDE,  START,  IN_NAME,  INSIDE,  IN_STRING;
  
  private HTMLDocument$PARSING_STATUS() {}
}

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

import com.gargoylesoftware.htmlunit.javascript.host.Node;
import com.gargoylesoftware.htmlunit.javascript.host.NodeFilter;
import net.sourceforge.htmlunit.corejs.javascript.Callable;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;

class HTMLDocument$2
  extends NodeFilter
{
  private static final long serialVersionUID = -7572357836681155579L;
  
  HTMLDocument$2(HTMLDocument paramHTMLDocument, Scriptable paramScriptable) {}
  
  public short acceptNode(Node n)
  {
    Object[] args = { n };
    Object response;
    Object response;
    if ((val$filter instanceof Callable)) {
      response = ((Callable)val$filter).call(Context.getCurrentContext(), val$filter, val$filter, args);
    } else {
      response = ScriptableObject.callMethod(val$filter, "acceptNode", args);
    }
    return (short)(int)Context.toNumber(response);
  }
}

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

class HTMLDocument$3 {}

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

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.BrowserVersionFeatures;
import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.StringWebResponse;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.html.BaseFrame;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.FrameWindow;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlScript;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.PostponedAction;
import com.gargoylesoftware.htmlunit.javascript.ScriptableWithFallbackGetter;
import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
import com.gargoylesoftware.htmlunit.javascript.host.Document;
import com.gargoylesoftware.htmlunit.javascript.host.Event;
import com.gargoylesoftware.htmlunit.javascript.host.KeyboardEvent;
import com.gargoylesoftware.htmlunit.javascript.host.MouseEvent;
import com.gargoylesoftware.htmlunit.javascript.host.MutationEvent;
import com.gargoylesoftware.htmlunit.javascript.host.NamespaceCollection;
import com.gargoylesoftware.htmlunit.javascript.host.Node;
import com.gargoylesoftware.htmlunit.javascript.host.NodeFilter;
import com.gargoylesoftware.htmlunit.javascript.host.Range;
import com.gargoylesoftware.htmlunit.javascript.host.Selection;
import com.gargoylesoftware.htmlunit.javascript.host.StyleSheetList;
import com.gargoylesoftware.htmlunit.javascript.host.Stylesheet;
import com.gargoylesoftware.htmlunit.javascript.host.TreeWalker;
import com.gargoylesoftware.htmlunit.javascript.host.UIEvent;
import com.gargoylesoftware.htmlunit.javascript.host.Window;
import com.gargoylesoftware.htmlunit.util.Cookie;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.htmlunit.corejs.javascript.Callable;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Function;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import net.sourceforge.htmlunit.corejs.javascript.UniqueTag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentType;

public class HTMLDocument
  extends Document
  implements ScriptableWithFallbackGetter
{
  private static final long serialVersionUID = -7646789903352066465L;
  private static final Log LOG = LogFactory.getLog(HTMLDocument.class);
  public static final String EMPTY_COOKIE_NAME = "HTMLUNIT_EMPTY_COOKIE";
  private static final String LAST_MODIFIED_DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
  private static final Map<String, Class<? extends Event>> SUPPORTED_EVENT_TYPE_MAP;
  private static final List<String> EXECUTE_CMDS_IE = Arrays.asList(new String[] { "2D-Position", "AbsolutePosition", "BackColor", "BackgroundImageCache", "BlockDirLTR", "BlockDirRTL", "Bold", "BrowseMode", "ClearAuthenticationCache", "Copy", "CreateBookmark", "CreateLink", "Cut", "Delete", "DirLTR", "DirRTL", "EditMode", "FontName", "FontSize", "ForeColor", "FormatBlock", "Indent", "InlineDirLTR", "InlineDirRTL", "InsertButton", "InsertFieldset", "InsertHorizontalRule", "InsertIFrame", "InsertImage", "InsertInputButton", "InsertInputCheckbox", "InsertInputFileUpload", "InsertInputHidden", "InsertInputImage", "InsertInputPassword", "InsertInputRadio", "InsertInputReset", "InsertInputSubmit", "InsertInputText", "InsertMarquee", "InsertOrderedList", "InsertParagraph", "InsertSelectDropdown", "InsertSelectListbox", "InsertTextArea", "InsertUnorderedList", "Italic", "JustifyCenter", "JustifyFull", "JustifyLeft", "JustifyNone", "JustifyRight", "LiveResize", "MultipleSelection", "Open", "Outdent", "OverWrite", "Paste", "PlayImage", "Print", "Redo", "Refresh", "RemoveFormat", "RemoveParaFormat", "SaveAs", "SelectAll", "SizeToControl", "SizeToControlHeight", "SizeToControlWidth", "Stop", "StopImage", "StrikeThrough", "Subscript", "Superscript", "UnBookmark", "Underline", "Undo", "Unlink", "Unselect" });
  private static final List<String> EXECUTE_CMDS_FF = Arrays.asList(new String[] { "backColor", "bold", "contentReadOnly", "copy", "createLink", "cut", "decreaseFontSize", "delete", "fontName", "fontSize", "foreColor", "formatBlock", "heading", "hiliteColor", "increaseFontSize", "indent", "insertHorizontalRule", "insertHTML", "insertImage", "insertOrderedList", "insertUnorderedList", "insertParagraph", "italic", "justifyCenter", "justifyLeft", "justifyRight", "outdent", "paste", "redo", "removeFormat", "selectAll", "strikeThrough", "subscript", "superscript", "underline", "undo", "unlink", "useCSS", "styleWithCSS" });
  private static int UniqueID_Counter_ = 1;
  private HTMLCollection all_;
  private HTMLCollection forms_;
  private HTMLCollection links_;
  private HTMLCollection images_;
  private HTMLCollection scripts_;
  private HTMLCollection anchors_;
  private HTMLCollection applets_;
  private StyleSheetList styleSheets_;
  private NamespaceCollection namespaces_;
  private HTMLElement activeElement_;
  private final StringBuilder writeBuffer_ = new StringBuilder();
  private boolean writeInCurrentDocument_ = true;
  private String domain_;
  private String uniqueID_;
  private String lastModified_;
  private boolean closePostponedAction_;
  
  static
  {
    Map<String, Class<? extends Event>> eventMap = new HashMap();
    eventMap.put("Event", Event.class);
    eventMap.put("Events", Event.class);
    eventMap.put("KeyboardEvent", KeyboardEvent.class);
    eventMap.put("KeyEvents", KeyboardEvent.class);
    eventMap.put("HTMLEvents", Event.class);
    eventMap.put("MouseEvent", MouseEvent.class);
    eventMap.put("MouseEvents", MouseEvent.class);
    eventMap.put("MutationEvent", MutationEvent.class);
    eventMap.put("MutationEvents", MutationEvent.class);
    eventMap.put("UIEvent", UIEvent.class);
    eventMap.put("UIEvents", UIEvent.class);
    SUPPORTED_EVENT_TYPE_MAP = Collections.unmodifiableMap(eventMap);
  }
  
  public <N extends DomNode> N getDomNodeOrDie()
    throws IllegalStateException
  {
    try
    {
      return super.getDomNodeOrDie();
    }
    catch (IllegalStateException e)
    {
      DomNode node = getDomNodeOrNullFromRealDocument();
      if (node != null) {
        return node;
      }
      throw Context.reportRuntimeError("No node attached to this object");
    }
  }
  
  public DomNode getDomNodeOrNull()
  {
    DomNode node = super.getDomNodeOrNull();
    if (node == null) {
      node = getDomNodeOrNullFromRealDocument();
    }
    return node;
  }
  
  private DomNode getDomNodeOrNullFromRealDocument()
  {
    DomNode node = null;
    boolean ie = getWindow().getWebWindow().getWebClient().getBrowserVersion().isIE();
    if (ie)
    {
      Scriptable scope = getParentScope();
      if ((scope instanceof Window))
      {
        Window w = (Window)scope;
        HTMLDocument realDocument = w.jsxGet_document();
        if (realDocument != this) {
          node = realDocument.getDomNodeOrDie();
        }
      }
    }
    return node;
  }
  
  public HtmlPage getHtmlPage()
  {
    return (HtmlPage)getDomNodeOrDie();
  }
  
  public HtmlPage getHtmlPageOrNull()
  {
    return (HtmlPage)getDomNodeOrNull();
  }
  
  public Object jsxGet_forms()
  {
    if (forms_ == null)
    {
      forms_ = new HTMLCollection(this);
      forms_.init(getDomNodeOrDie(), ".//form");
    }
    return forms_;
  }
  
  public Object jsxGet_links()
  {
    if (links_ == null)
    {
      links_ = new HTMLCollection(this);
      links_.init(getDomNodeOrDie(), ".//a[@href] | .//area[@href]");
    }
    return links_;
  }
  
  public String jsxGet_lastModified()
  {
    if (lastModified_ == null)
    {
      WebResponse webResponse = getPage().getWebResponse();
      String stringDate = webResponse.getResponseHeaderValue("Last-Modified");
      if (stringDate == null) {
        stringDate = webResponse.getResponseHeaderValue("Date");
      }
      Date lastModified = parseDateOrNow(stringDate);
      lastModified_ = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(lastModified);
    }
    return lastModified_;
  }
  
  private static Date parseDateOrNow(String stringDate)
  {
    Date date = com.gargoylesoftware.htmlunit.util.StringUtils.parseHttpDate(stringDate);
    if (date == null) {
      return new Date();
    }
    return date;
  }
  
  public Object jsxGet_namespaces()
  {
    if (namespaces_ == null) {
      namesp
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