htmlunit-2.7

 com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Node;

public class HtmlSelect
  extends HtmlElement
  implements DisabledElement, SubmittableElement
{
  private static final long serialVersionUID = 7893240015923163203L;
  public static final String TAG_NAME = "select";
  
  HtmlSelect(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  protected void onAllChildrenAddedToPage(boolean postponed)
  {
    int size;
    try
    {
      size = Integer.parseInt(getSizeAttribute());
      if (size < 0)
      {
        removeAttribute("size");
        size = 0;
      }
    }
    catch (NumberFormatException e)
    {
      removeAttribute("size");
      size = 0;
    }
    if ((getSelectedOptions().isEmpty()) && (size <= 1) && (!isMultipleSelectEnabled()))
    {
      List<HtmlOption> options = getOptions();
      if (!options.isEmpty())
      {
        HtmlOption first = (HtmlOption)options.get(0);
        first.setSelectedInternal(true);
      }
    }
  }
  
  public List<HtmlOption> getSelectedOptions()
  {
    List<HtmlOption> result;
    List<HtmlOption> result;
    if (isMultipleSelectEnabled())
    {
      result = new ArrayList();
      for (HtmlElement element : getHtmlElementDescendants()) {
        if (((element instanceof HtmlOption)) && (((HtmlOption)element).isSelected())) {
          result.add((HtmlOption)element);
        }
      }
    }
    else
    {
      result = new ArrayList(1);
      HtmlOption lastSelected = null;
      for (HtmlElement element : getHtmlElementDescendants()) {
        if ((element instanceof HtmlOption))
        {
          HtmlOption option = (HtmlOption)element;
          if (option.isSelected()) {
            lastSelected = option;
          }
        }
      }
      if (lastSelected != null) {
        result.add(lastSelected);
      }
    }
    return Collections.unmodifiableList(result);
  }
  
  public List<HtmlOption> getOptions()
  {
    return Collections.unmodifiableList(getHtmlElementsByTagName("option"));
  }
  
  public HtmlOption getOption(int index)
  {
    return (HtmlOption)getHtmlElementsByTagName("option").get(index);
  }
  
  public int getOptionSize()
  {
    return getHtmlElementsByTagName("option").size();
  }
  
  public void setOptionSize(int newLength)
  {
    List<HtmlElement> elementList = getHtmlElementsByTagName("option");
    for (int i = elementList.size() - 1; i >= newLength; i--) {
      ((HtmlElement)elementList.get(i)).remove();
    }
  }
  
  public void removeOption(int index)
  {
    HtmlElement.ChildElementsIterator iterator = new HtmlElement.ChildElementsIterator(this);
    for (int i = 0; iterator.hasNext();)
    {
      HtmlElement element = iterator.nextElement();
      if ((element instanceof HtmlOption))
      {
        if (i == index)
        {
          element.remove();
          return;
        }
        i++;
      }
    }
  }
  
  public void replaceOption(int index, HtmlOption newOption)
  {
    HtmlElement.ChildElementsIterator iterator = new HtmlElement.ChildElementsIterator(this);
    for (int i = 0; iterator.hasNext();)
    {
      HtmlElement element = iterator.nextElement();
      if ((element instanceof HtmlOption))
      {
        if (i == index)
        {
          element.replace(newOption);
          return;
        }
        i++;
      }
    }
    if (newOption.isSelected()) {
      setSelectedAttribute(newOption, true);
    }
  }
  
  public void appendOption(HtmlOption newOption)
  {
    appendChild(newOption);
  }
  
  public DomNode appendChild(Node node)
  {
    DomNode response = super.appendChild(node);
    if ((node instanceof HtmlOption))
    {
      HtmlOption option = (HtmlOption)node;
      if (option.isSelected()) {
        doSelectOption(option, true);
      }
    }
    return response;
  }
  
  public Page setSelectedAttribute(String optionValue, boolean isSelected)
  {
    try
    {
      return setSelectedAttribute(getOptionByValue(optionValue), isSelected);
    }
    catch (ElementNotFoundException e)
    {
      if (getPage().getWebClient().getBrowserVersion().isIE()) {
        for (HtmlOption o : getSelectedOptions()) {
          o.setSelected(false);
        }
      }
    }
    return getPage();
  }
  
  public Page setSelectedAttribute(HtmlOption selectedOption, boolean isSelected)
  {
    return setSelectedAttribute(selectedOption, isSelected, true);
  }
  
  public Page setSelectedAttribute(HtmlOption selectedOption, boolean isSelected, boolean invokeOnFocus)
  {
    if ((isSelected) && (invokeOnFocus)) {
      ((HtmlPage)getPage()).setFocusedElement(this);
    }
    boolean changeSelectedState = selectedOption.isSelected() != isSelected;
    if (changeSelectedState)
    {
      doSelectOption(selectedOption, isSelected);
      return HtmlInput.executeOnChangeHandlerIfAppropriate(this);
    }
    return getPage();
  }
  
  private void doSelectOption(HtmlOption selectedOption, boolean isSelected)
  {
    if (isMultipleSelectEnabled()) {
      selectedOption.setSelectedInternal(isSelected);
    } else {
      for (HtmlOption option : getOptions()) {
        option.setSelectedInternal((option == selectedOption) && (isSelected));
      }
    }
  }
  
  public NameValuePair[] getSubmitKeyValuePairs()
  {
    String name = getNameAttribute();
    
    List<HtmlOption> selectedOptions = getSelectedOptions();
    
    NameValuePair[] pairs = new NameValuePair[selectedOptions.size()];
    
    int i = 0;
    for (HtmlOption option : selectedOptions) {
      pairs[(i++)] = new NameValuePair(name, option.getValueAttribute());
    }
    return pairs;
  }
  
  boolean isValidForSubmission()
  {
    return getOptionSize() > 0;
  }
  
  public void reset()
  {
    for (HtmlOption option : getOptions()) {
      option.reset();
    }
  }
  
  public void setDefaultValue(String defaultValue)
  {
    setSelectedAttribute(defaultValue, true);
  }
  
  public String getDefaultValue()
  {
    List<HtmlOption> options = getSelectedOptions();
    if (options.size() > 0) {
      return ((HtmlOption)options.get(0)).getValueAttribute();
    }
    return "";
  }
  
  public void setDefaultChecked(boolean defaultChecked) {}
  
  public boolean isDefaultChecked()
  {
    return false;
  }
  
  public boolean isMultipleSelectEnabled()
  {
    return getAttribute("multiple") != ATTRIBUTE_NOT_DEFINED;
  }
  
  public HtmlOption getOptionByValue(String value)
    throws ElementNotFoundException
  {
    WebAssert.notNull("value", value);
    for (HtmlOption option : getOptions()) {
      if (option.getValueAttribute().equals(value)) {
        return option;
      }
    }
    throw new ElementNotFoundException("option", "value", value);
  }
  
  public HtmlOption getOptionByText(String text)
    throws ElementNotFoundException
  {
    WebAssert.notNull("text", text);
    for (HtmlOption option : getOptions()) {
      if (option.getText().equals(text)) {
        return option;
      }
    }
    throw new ElementNotFoundException("option", "text", text);
  }
  
  public String asText()
  {
    List<HtmlOption> options;
    List<HtmlOption> options;
    if (isMultipleSelectEnabled()) {
      options = getOptions();
    } else {
      options = getSelectedOptions();
    }
    StringBuilder buffer = new StringBuilder();
    for (Iterator<HtmlOption> i = options.iterator(); i.hasNext();)
    {
      HtmlOption currentOption = (HtmlOption)i.next();
      if (currentOption != null) {
        buffer.append(currentOption.asText());
      }
      if (i.hasNext()) {
        buffer.append("\n");
      }
    }
    return buffer.toString();
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getSizeAttribute()
  {
    return getAttribute("size");
  }
  
  public final String getMultipleAttribute()
  {
    return getAttribute("multiple");
  }
  
  public final String getDisabledAttribute()
  {
    return getAttribute("disabled");
  }
  
  public final boolean isDisabled()
  {
    return hasAttribute("disabled");
  }
  
  public final String getTabIndexAttribute()
  {
    return getAttribute("tabindex");
  }
  
  public final String getOnFocusAttribute()
  {
    return getAttribute("onfocus");
  }
  
  public final String getOnBlurAttribute()
  {
    return getAttribute("onblur");
  }
  
  public final String getOnChangeAttribute()
  {
    return getAttribute("onchange");
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlSelect
 * 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.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HtmlButton
  extends HtmlElement
  implements DisabledElement, SubmittableElement
{
  private static final long serialVersionUID = 4828725767615187345L;
  private static final Log LOG = LogFactory.getLog(HtmlButton.class);
  public static final String TAG_NAME = "button";
  
  HtmlButton(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public void setValueAttribute(String newValue)
  {
    setAttribute("value", newValue);
  }
  
  protected void doClickAction()
    throws IOException
  {
    String type = getTypeAttribute().toLowerCase();
    
    HtmlForm form = getEnclosingForm();
    if (form != null) {
      if (type.equals("submit")) {
        form.submit(this);
      } else if (type.equals("reset")) {
        form.reset();
      }
    }
  }
  
  public final boolean isDisabled()
  {
    return hasAttribute("disabled");
  }
  
  public NameValuePair[] getSubmitKeyValuePairs()
  {
    return new NameValuePair[] { new NameValuePair(getNameAttribute(), getValueAttribute()) };
  }
  
  public void reset()
  {
    if (LOG.isDebugEnabled()) {
      LOG.debug("reset() not implemented for this element");
    }
  }
  
  public void setDefaultValue(String defaultValue)
  {
    if (LOG.isDebugEnabled()) {
      LOG.debug("setDefaultValue() not implemented for this element");
    }
  }
  
  public String getDefaultValue()
  {
    if (LOG.isDebugEnabled()) {
      LOG.debug("getDefaultValue() not implemented for this element");
    }
    return "";
  }
  
  public void setDefaultChecked(boolean defaultChecked) {}
  
  public boolean isDefaultChecked()
  {
    return false;
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getValueAttribute()
  {
    return getAttribute("value");
  }
  
  public final String getTypeAttribute()
  {
    String type = getAttribute("type");
    if (type == HtmlElement.ATTRIBUTE_NOT_DEFINED)
    {
      BrowserVersion browser = getPage().getWebClient().getBrowserVersion();
      if (browser.isIE()) {
        type = "button";
      } else {
        type = "submit";
      }
    }
    return type;
  }
  
  public final String getDisabledAttribute()
  {
    return getAttribute("disabled");
  }
  
  public final String getTabIndexAttribute()
  {
    return getAttribute("tabindex");
  }
  
  public final String getAccessKeyAttribute()
  {
    return getAttribute("accesskey");
  }
  
  public final String getOnFocusAttribute()
  {
    return getAttribute("onfocus");
  }
  
  public final String getOnBlurAttribute()
  {
    return getAttribute("onblur");
  }
}

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

class HtmlTextArea$1
  extends DoTypeProcessor
{
  private static final long serialVersionUID = 2906652041039202266L;
  
  HtmlTextArea$1(HtmlTextArea paramHtmlTextArea) {}
  
  void typeDone(String newValue, int newCursorPosition)
  {
    HtmlTextArea.access$000(this$0, newValue);
    this$0.setSelectionStart(newCursorPosition);
    this$0.setSelectionEnd(newCursorPosition);
  }
  
  protected boolean acceptChar(char c)
  {
    return (super.acceptChar(c)) || (c == '\n') || (c == '\r');
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlTextArea.1
 * 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.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.impl.SelectableTextInput;
import com.gargoylesoftware.htmlunit.html.impl.SelectionDelegate;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.io.PrintWriter;
import java.util.Map;

public class HtmlTextArea
  extends HtmlElement
  implements DisabledElement, SubmittableElement, SelectableTextInput
{
  private static final long serialVersionUID = 4572856255042499634L;
  public static final String TAG_NAME = "textarea";
  private String defaultValue_;
  private String valueAtFocus_;
  private final SelectionDelegate selectionDelegate_ = new SelectionDelegate(this);
  private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor()
  {
    private static final long serialVersionUID = 2906652041039202266L;
    
    void typeDone(String newValue, int newCursorPosition)
    {
      HtmlTextArea.this.setTextInternal(newValue);
      setSelectionStart(newCursorPosition);
      setSelectionEnd(newCursorPosition);
    }
    
    protected boolean acceptChar(char c)
    {
      return (super.acceptChar(c)) || (c == '\n') || (c == '\r');
    }
  };
  
  HtmlTextArea(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  private void initDefaultValue()
  {
    if (defaultValue_ == null) {
      defaultValue_ = readValue();
    }
  }
  
  public final String getText()
  {
    return readValue();
  }
  
  private String readValue()
  {
    StringBuilder buffer = new StringBuilder();
    for (DomNode node : getChildren()) {
      if ((node instanceof DomText)) {
        buffer.append(((DomText)node).getData());
      }
    }
    if ((buffer.length() > 0) && (buffer.charAt(0) == '\n')) {
      buffer.deleteCharAt(0);
    }
    return buffer.toString();
  }
  
  public final void setText(String newValue)
  {
    initDefaultValue();
    setTextInternal(newValue);
    
    HtmlInput.executeOnChangeHandlerIfAppropriate(this);
  }
  
  private void setTextInternal(String newValue)
  {
    initDefaultValue();
    DomText child = (DomText)getFirstChild();
    if (child == null)
    {
      DomText newChild = new DomText(getPage(), newValue);
      appendChild(newChild);
    }
    else
    {
      child.setData(newValue);
    }
    setSelectionStart(newValue.length());
    setSelectionEnd(newValue.length());
  }
  
  public NameValuePair[] getSubmitKeyValuePairs()
  {
    String text = getText();
    text = text.replace("\r\n", "\n").replace("\n", "\r\n");
    
    return new NameValuePair[] { new NameValuePair(getNameAttribute(), text) };
  }
  
  public void reset()
  {
    initDefaultValue();
    setText(defaultValue_);
  }
  
  public void setDefaultValue(String defaultValue)
  {
    initDefaultValue();
    if (defaultValue == null) {
      defaultValue = "";
    }
    if ((getPage().getWebClient().getBrowserVersion().isFirefox()) && (getText().equals(getDefaultValue()))) {
      setTextInternal(defaultValue);
    }
    defaultValue_ = defaultValue;
  }
  
  public String getDefaultValue()
  {
    initDefaultValue();
    return defaultValue_;
  }
  
  public void setDefaultChecked(boolean defaultChecked) {}
  
  public boolean isDefaultChecked()
  {
    return false;
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getRowsAttribute()
  {
    return getAttribute("rows");
  }
  
  public final String getColumnsAttribute()
  {
    return getAttribute("cols");
  }
  
  public final boolean isDisabled()
  {
    return hasAttribute("disabled");
  }
  
  public final String getDisabledAttribute()
  {
    return getAttribute("disabled");
  }
  
  public final String getReadOnlyAttribute()
  {
    return getAttribute("readonly");
  }
  
  public final String getTabIndexAttribute()
  {
    return getAttribute("tabindex");
  }
  
  public final String getAccessKeyAttribute()
  {
    return getAttribute("accesskey");
  }
  
  public final String getOnFocusAttribute()
  {
    return getAttribute("onfocus");
  }
  
  public final String getOnBlurAttribute()
  {
    return getAttribute("onblur");
  }
  
  public final String getOnSelectAttribute()
  {
    return getAttribute("onselect");
  }
  
  public final String getOnChangeAttribute()
  {
    return getAttribute("onchange");
  }
  
  public void select()
  {
    selectionDelegate_.select();
  }
  
  public String getSelectedText()
  {
    return selectionDelegate_.getSelectedText();
  }
  
  public int getSelectionStart()
  {
    return selectionDelegate_.getSelectionStart();
  }
  
  public void setSelectionStart(int selectionStart)
  {
    selectionDelegate_.setSelectionStart(selectionStart);
  }
  
  public int getSelectionEnd()
  {
    return selectionDelegate_.getSelectionEnd();
  }
  
  public void setSelectionEnd(int selectionEnd)
  {
    selectionDelegate_.setSelectionEnd(selectionEnd);
  }
  
  protected void printXml(String indent, PrintWriter printWriter)
  {
    printWriter.print(indent + "<");
    printOpeningTagContentAsXml(printWriter);
    
    printWriter.print(">");
    printWriter.print(getText());
    printWriter.print(indent + "</textarea>");
  }
  
  protected void doType(char c, boolean shiftKey, boolean ctrlKey, boolean altKey)
  {
    doTypeProcessor_.doType(getText(), getSelectionStart(), getSelectionEnd(), c, shiftKey, ctrlKey, altKey);
  }
  
  public void focus()
  {
    super.focus();
    valueAtFocus_ = getText();
  }
  
  void removeFocus()
  {
    super.removeFocus();
    if (!valueAtFocus_.equals(getText())) {
      HtmlInput.executeOnChangeHandlerIfAppropriate(this);
    }
    valueAtFocus_ = null;
  }
  
  public void setReadOnly(boolean isReadOnly)
  {
    if (isReadOnly) {
      setAttribute("readOnly", "readOnly");
    } else {
      removeAttribute("readOnly");
    }
  }
  
  public boolean isReadOnly()
  {
    return hasAttribute("readOnly");
  }
  
  protected Object clone()
    throws CloneNotSupportedException
  {
    return new HtmlTextArea(getNamespaceURI(), getQualifiedName(), getPage(), getAttributesMap());
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlTextArea
 * 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.Page;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import java.io.IOException;
import java.util.Map;

public class HtmlRadioButtonInput
  extends HtmlInput
{
  private static final long serialVersionUID = 425993174633373218L;
  private boolean defaultCheckedState_;
  
  HtmlRadioButtonInput(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
    if (getAttribute("value") == ATTRIBUTE_NOT_DEFINED) {
      setAttribute("value", "on");
    }
    defaultCheckedState_ = hasAttribute("checked");
  }
  
  public void reset()
  {
    if (defaultCheckedState_) {
      setAttribute("checked", "checked");
    } else {
      removeAttribute("checked");
    }
  }
  
  public Page setChecked(boolean isChecked)
  {
    HtmlForm form = getEnclosingForm();
    boolean changed = isChecked() != isChecked;
    if (isChecked)
    {
      if (form != null) {
        form.setCheckedRadioButton(this);
      } else {
        ((HtmlPage)getPage()).setCheckedRadioButton(this);
      }
    }
    else {
      removeAttribute("checked");
    }
    Page page = getPage();
    if (changed)
    {
      ScriptResult scriptResult = fireEvent("change");
      if (scriptResult != null) {
        page = scriptResult.getNewPage();
      }
    }
    return page;
  }
  
  public String asText()
  {
    if (isChecked()) {
      return "checked";
    }
    return "unchecked";
  }
  
  protected void doClickAction()
    throws IOException
  {
    setChecked(true);
  }
  
  public void setDefaultValue(String defaultValue)
  {
    super.setDefaultValue(defaultValue);
    setValueAttribute(defaultValue);
  }
  
  public void setDefaultChecked(boolean defaultChecked)
  {
    defaultCheckedState_ = defaultChecked;
    if (getPage().getWebClient().getBrowserVersion().isFirefox()) {
      setChecked(defaultChecked);
    }
  }
  
  public boolean isDefaultChecked()
  {
    return defaultCheckedState_;
  }
  
  protected boolean isStateUpdateFirst()
  {
    return true;
  }
  
  protected void onAddedToPage()
  {
    if (getPage().getWebClient().getBrowserVersion().isIE()) {
      setChecked(isDefaultChecked());
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput
 * 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.BrowserVersionFeatures;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

public class HtmlOption
  extends HtmlElement
  implements DisabledElement
{
  private static final long serialVersionUID = 8995198439134305753L;
  public static final String TAG_NAME = "option";
  private final boolean initialSelectedState_;
  private boolean selected_;
  
  HtmlOption(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
    initialSelectedState_ = hasAttribute("selected");
  }
  
  public boolean isSelected()
  {
    return (hasAttribute("selected")) || (selected_);
  }
  
  public Page setSelected(boolean selected)
  {
    if (selected == isSelected()) {
      return getPage();
    }
    HtmlSelect select = getEnclosingSelect();
    if (select != null)
    {
      if ((!select.isMultipleSelectEnabled()) && (select.getOptionSize() == 1)) {
        selected = true;
      }
      return select.setSelectedAttribute(this, selected);
    }
    setSelectedInternal(selected);
    return getPage();
  }
  
  public void insertBefore(DomNode newNode)
    throws IllegalStateException
  {
    super.insertBefore(newNode);
    if ((newNode instanceof HtmlOption))
    {
      HtmlOption option = (HtmlOption)newNode;
      if (option.isSelected()) {
        getEnclosingSelect().setSelectedAttribute(option, true);
      }
    }
  }
  
  public HtmlSelect getEnclosingSelect()
  {
    return (HtmlSelect)getEnclosingElement("select");
  }
  
  public void reset()
  {
    setSelectedInternal(initialSelectedState_);
  }
  
  public final String getSelectedAttribute()
  {
    return getAttribute("selected");
  }
  
  public final boolean isDefaultSelected()
  {
    return initialSelectedState_;
  }
  
  public final boolean isDisabled()
  {
    if (getPage().getWebClient().getBrowserVersion().hasFeature(BrowserVersionFeatures.HTMLOPTION_PREVENT_DISABLED)) {
      return false;
    }
    return hasAttribute("disabled");
  }
  
  public final String getDisabledAttribute()
  {
    return getAttribute("disabled");
  }
  
  public final String getLabelAttribute()
  {
    return getAttribute("label");
  }
  
  public final void setLabelAttribute(String newLabel)
  {
    setAttribute("label", newLabel);
  }
  
  public final String getValueAttribute()
  {
    String value = getAttribute("value");
    if (value == ATTRIBUTE_NOT_DEFINED) {
      value = getText();
    }
    return value;
  }
  
  public final void setValueAttribute(String newValue)
  {
    setAttribute("value", newValue);
  }
  
  protected void doClickAction()
    throws IOException
  {
    if (!isSelected()) {
      setSelected(true);
    }
  }
  
  protected void printOpeningTagContentAsXml(PrintWriter printWriter)
  {
    super.printOpeningTagContentAsXml(printWriter);
    if ((selected_) && (getAttribute("selected") == ATTRIBUTE_NOT_DEFINED)) {
      printWriter.print(" selected=\"selected\"");
    }
  }
  
  void setSelectedInternal(boolean selected)
  {
    selected_ = selected;
    if (!selected) {
      removeAttribute("selected");
    }
  }
  
  public String asText()
  {
    return super.asText();
  }
  
  public void setText(String text)
  {
    if ((getPage().getWebClient().getBrowserVersion().isIE()) && ((text == null) || (text.length() == 0)))
    {
      removeAllChildren();
    }
    else
    {
      DomNode child = getFirstChild();
      if (child == null) {
        appendChild(new DomText(getPage(), text));
      } else {
        child.setNodeValue(text);
      }
    }
  }
  
  public String getText()
  {
    HtmlSerializer ser = new HtmlSerializer();
    ser.setIgnoreMaskedElements(false);
    return ser.asText(this);
  }
}

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

import com.gargoylesoftware.htmlunit.SgmlPage;
import java.util.Map;

public class HtmlBase
  extends HtmlElement
{
  private static final long serialVersionUID = 1763844738357920208L;
  public static final String TAG_NAME = "base";
  
  HtmlBase(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getHrefAttribute()
  {
    return getAttribute("href");
  }
  
  public final String getTargetAttribute()
  {
    return getAttribute("target");
  }
}

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

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.TextUtil;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HtmlAnchor
  extends HtmlElement
{
  private static final long serialVersionUID = 7968778206454737178L;
  private static final Log LOG = LogFactory.getLog(HtmlAnchor.class);
  public static final String TAG_NAME = "a";
  
  HtmlAnchor(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  protected void doClickAction(String hrefSuffix)
    throws IOException
  {
    String href = getHrefAttribute() + hrefSuffix;
    if (LOG.isDebugEnabled())
    {
      String w = getPage().getEnclosingWindow().getName();
      LOG.debug("do click action in window '" + w + "', using href '" + href + "'");
    }
    if (href.length() == 0) {
      return;
    }
    HtmlPage page = (HtmlPage)getPage();
    if (TextUtil.startsWithIgnoreCase(href, "javascript:"))
    {
      StringBuilder builder = new StringBuilder(href.length());
      for (int i = 0; i < href.length(); i++)
      {
        char ch = href.charAt(i);
        if ((ch == '%') && (i + 2 < href.length()))
        {
          char ch1 = Character.toUpperCase(href.charAt(i + 1));
          char ch2 = Character.toUpperCase(href.charAt(i + 2));
          if (((Character.isDigit(ch1)) || ((ch1 >= 'A') && (ch1 <= 'F'))) && ((Character.isDigit(ch2)) || ((ch2 >= 'A') && (ch2 <= 'F'))))
          {
            builder.append((char)Integer.parseInt(href.substring(i + 1, i + 3), 16));
            i += 2;
            continue;
          }
        }
        builder.append(ch);
      }
      page.executeJavaScriptIfPossible(builder.toString(), "javascript url", getStartLineNumber());
      return;
    }
    URL url = page.getFullyQualifiedUrl(href);
    WebRequestSettings wrs = new WebRequestSettings(url);
    wrs.setAdditionalHeader("Referer", page.getWebResponse().getRequestSettings().getUrl().toExternalForm());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Getting page for " + url.toExternalForm() + ", derived from href '" + href + "', using the originating URL " + page.getWebResponse().getRequestSettings().getUrl());
    }
    page.getWebClient().download(page.getEnclosingWindow(), page.getResolvedTarget(getTargetAttribute()), wrs, "Link click");
  }
  
  protected void doClickAction()
    throws IOException
  {
    doClickAction("");
  }
  
  public final String getCharsetAttribute()
  {
    return getAttribute("charset");
  }
  
  public final String getTypeAttribute()
  {
    return getAttribute("type");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getHrefAttribute()
  {
    return getAttribute("href").trim();
  }
  
  public final String getHrefLangAttribute()
  {
    return getAttribute("hreflang");
  }
  
  public final String getRelAttribute()
  {
    return getAttribute("rel");
  }
  
  public final String getRevAttribute()
  {
    return getAttribute("rev");
  }
  
  public final String getAccessKeyAttribute()
  {
    return getAttribute("accesskey");
  }
  
  public final String getShapeAttribute()
  {
    return getAttribute("shape");
  }
  
  public final String getCoordsAttribute()
  {
    return getAttribute("coords");
  }
  
  public final String getTabIndexAttribute()
  {
    return getAttribute("tabindex");
  }
  
  public final String getOnFocusAttribute()
  {
    return getAttribute("onfocus");
  }
  
  public final String getOnBlurAttribute()
  {
    return getAttribute("onblur");
  }
  
  public final String getTargetAttribute()
  {
    return getAttribute("target");
  }
  
  public final Page openLinkInNewWindow()
    throws MalformedURLException
  {
    URL target = ((HtmlPage)getPage()).getFullyQualifiedUrl(getHrefAttribute());
    String windowName = "HtmlAnchor.openLinkInNewWindow() target";
    WebWindow newWindow = getPage().getWebClient().openWindow(target, "HtmlAnchor.openLinkInNewWindow() target");
    return newWindow.getEnclosedPage();
  }
}

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

import com.gargoylesoftware.htmlunit.SgmlPage;
import java.util.Map;

public class HtmlTitle
  extends HtmlElement
{
  private static final long serialVersionUID = 5463879100333678376L;
  public static final String TAG_NAME = "title";
  
  HtmlTitle(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public void setNodeValue(String message)
  {
    DomNode child = getFirstChild();
    if (child == null)
    {
      DomNode textNode = new DomText(getPage(), message);
      appendChild(textNode);
    }
    else if ((child instanceof DomText))
    {
      ((DomText)child).setData(message);
    }
    else
    {
      throw new IllegalStateException("For title tag, this should be a text node");
    }
  }
  
  protected boolean isEmptyXmlTagExpanded()
  {
    return true;
  }
}

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

import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.util.Cookie;
import java.net.URL;
import java.util.Date;
import java.util.Map;

public class HtmlMeta
  extends HtmlElement
{
  private static final long serialVersionUID = 7408601325303605790L;
  public static final String TAG_NAME = "meta";
  
  HtmlMeta(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
    if ("set-cookie".equalsIgnoreCase(getHttpEquivAttribute())) {
      performSetCookie();
    }
  }
  
  protected void performSetCookie()
  {
    String[] parts = getContentAttribute().split("\\s*;\\s*");
    String name = org.apache.commons.lang.StringUtils.substringBefore(parts[0], "=");
    String value = org.apache.commons.lang.StringUtils.substringAfter(parts[0], "=");
    URL url = getPage().getWebResponse().getRequestSettings().getUrl();
    String host = url.getHost();
    boolean secure = "https".equals(url.getProtocol());
    String path = null;
    Date expires = null;
    for (int i = 1; i < parts.length; i++)
    {
      String partName = org.apache.commons.lang.StringUtils.substringBefore(parts[i], "=").trim().toLowerCase();
      String partValue = org.apache.commons.lang.StringUtils.substringAfter(parts[i], "=").trim();
      if ("path".equals(partName)) {
        path = partValue;
      } else if ("expires".equals(partName)) {
        expires = com.gargoylesoftware.htmlunit.util.StringUtils.parseHttpDate(partValue);
      } else {
        notifyIncorrectness("set-cookie http-equiv meta tag: unknown attribute '" + partName + "'.");
      }
    }
    Cookie cookie = new Cookie(host, name, value, path, expires, secure);
    getPage().getWebClient().getCookieManager().addCookie(cookie);
  }
  
  public final String getHttpEquivAttribute()
  {
    return getAttribute("http-equiv");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getContentAttribute()
  {
    return getAttribute("content");
  }
  
  public final String getSchemeAttribute()
  {
    return getAttribute("scheme");
  }
}

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

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

class BaseFrame$1
  extends PostponedAction
{
  BaseFrame$1(BaseFrame paramBaseFrame, Page x0, String paramString)
  {
    super(x0);
  }
  
  public void execute()
    throws Exception
  {
    if (this$0.getSrcAttribute().equals(val$src)) {
      this$0.loadInnerPage();
    }
  }
}

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

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.PostponedAction;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class BaseFrame
  extends HtmlElement
{
  private static final long serialVersionUID = -7658106924909626296L;
  private static final Log LOG = LogFactory.getLog(BaseFrame.class);
  private final WebWindow enclosedWindow_ = new FrameWindow(this);
  private boolean contentLoaded_ = false;
  
  protected BaseFrame(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
    try
    {
      WebClient webClient = getPage().getEnclosingWindow().getWebClient();
      HtmlPage temporaryPage = (HtmlPage)webClient.getPage(enclosedWindow_, new WebRequestSettings(WebClient.URL_ABOUT_BLANK));
      
      temporaryPage.setReadyState("loading");
    }
    catch (FailingHttpStatusCodeException e) {}catch (IOException e) {}
  }
  
  void loadInnerPage()
    throws FailingHttpStatusCodeException
  {
    String source = getSrcAttribute();
    if (source.length() == 0) {
      source = "about:blank";
    }
    loadInnerPageIfPossible(source);
    
    Page enclosedPage = getEnclosedPage();
    if ((enclosedPage instanceof HtmlPage)) {
      ((HtmlPage)enclosedPage).setReadyState("complete");
    }
  }
  
  boolean isContentLoaded()
  {
    return contentLoaded_;
  }
  
  private void loadInnerPageIfPossible(String src)
    throws FailingHttpStatusCodeException
  {
    contentLoaded_ = true;
    if (src.length() != 0)
    {
      URL url;
      try
      {
        url = ((HtmlPage)getPage()).getFullyQualifiedUrl(src);
      }
      catch (MalformedURLException e)
      {
        notifyIncorrectness("Invalid src attribute of " + getTagName() + ": url=[" + src + "]. Ignored.");
        return;
      }
      if (isAlreadyLoadedByAncestor(url))
      {
        notifyIncorrectness("Recursive src attribute of " + getTagName() + ": url=[" + src + "]. Ignored.");
        return;
      }
      try
      {
        WebRequestSettings settings = new WebRequestSettings(url);
        settings.setAdditionalHeader("Referer", getPage().getWebResponse().getRequestSettings().getUrl().toExternalForm());
        
        getPage().getEnclosingWindow().getWebClient().getPage(enclosedWindow_, settings);
      }
      catch (IOException e)
      {
        if (LOG.isErrorEnabled()) {
          LOG.error("IOException when getting content for " + getTagName() + ": url=[" + url + "]", e);
        }
      }
    }
  }
  
  private boolean isAlreadyLoadedByAncestor(URL url)
  {
    WebWindow window = getPage().getEnclosingWindow();
    while (window != null)
    {
      if (url.sameFile(window.getEnclosedPage().getWebResponse().getRequestSettings().getUrl())) {
        return true;
      }
      if (window == window.getParentWindow()) {
        window = null;
      } else {
        window = window.getParentWindow();
      }
    }
    return false;
  }
  
  public final String getLongDescAttribute()
  {
    return getAttribute("longdesc");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final void setNameAttribute(String name)
  {
    setAttribute("name", name);
  }
  
  public final String getSrcAttribute()
  {
    return getAttribute("src");
  }
  
  public final String getFrameBorderAttribute()
  {
    return getAttribute("frameborder");
  }
  
  public final String getMarginWidthAttribute()
  {
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