htmlunit-2.7

his instanceof SubmittableElement) ? this : null;
    ((HtmlPage)getPage()).setFocusedElement(elementToFocus);
    
    mouseUp(shiftKey, ctrlKey, altKey, 0);
    
    Event event = new MouseEvent(this, "click", shiftKey, ctrlKey, altKey, 0);
    
    return click(event);
  }
  
  public <P extends Page> P click(Event event)
    throws IOException
  {
    SgmlPage page = getPage();
    if (((this instanceof DisabledElement)) && (((DisabledElement)this).isDisabled())) {
      return page;
    }
    Page contentPage = page.getEnclosingWindow().getEnclosedPage();
    
    boolean stateUpdated = false;
    if (isStateUpdateFirst())
    {
      doClickAction();
      stateUpdated = true;
    }
    JavaScriptEngine jsEngine = page.getWebClient().getJavaScriptEngine();
    jsEngine.holdPosponedActions();
    ScriptResult scriptResult = fireEvent(event);
    
    boolean pageAlreadyChanged = contentPage != page.getEnclosingWindow().getEnclosedPage();
    if ((!pageAlreadyChanged) && (!stateUpdated) && (!event.isAborted(scriptResult))) {
      doClickAction();
    }
    jsEngine.processPostponedActions();
    
    return getPage().getWebClient().getCurrentWindow().getEnclosedPage();
  }
  
  public <P extends Page> P dblClick()
    throws IOException
  {
    return dblClick(false, false, false);
  }
  
  public <P extends Page> P dblClick(boolean shiftKey, boolean ctrlKey, boolean altKey)
    throws IOException
  {
    if (((this instanceof DisabledElement)) && (((DisabledElement)this).isDisabled())) {
      return getPage();
    }
    Page clickPage = click(shiftKey, ctrlKey, altKey);
    if (clickPage != getPage())
    {
      if (LOG.isDebugEnabled()) {
        LOG.debug("dblClick() is ignored, as click() loaded a different page.");
      }
      return clickPage;
    }
    Event event = new MouseEvent(this, "dblclick", shiftKey, ctrlKey, altKey, 0);
    
    ScriptResult scriptResult = fireEvent(event);
    if (scriptResult == null) {
      return clickPage;
    }
    return scriptResult.getNewPage();
  }
  
  protected void doClickAction()
    throws IOException
  {}
  
  public final String getLangAttribute()
  {
    return getAttribute("lang");
  }
  
  public final String getXmlLangAttribute()
  {
    return getAttribute("xml:lang");
  }
  
  public final String getTextDirectionAttribute()
  {
    return getAttribute("dir");
  }
  
  public final String getOnClickAttribute()
  {
    return getAttribute("onclick");
  }
  
  public final String getOnDblClickAttribute()
  {
    return getAttribute("ondblclick");
  }
  
  public final String getOnMouseDownAttribute()
  {
    return getAttribute("onmousedown");
  }
  
  public final String getOnMouseUpAttribute()
  {
    return getAttribute("onmouseup");
  }
  
  public final String getOnMouseOverAttribute()
  {
    return getAttribute("onmouseover");
  }
  
  public final String getOnMouseMoveAttribute()
  {
    return getAttribute("onmousemove");
  }
  
  public final String getOnMouseOutAttribute()
  {
    return getAttribute("onmouseout");
  }
  
  public final String getOnKeyPressAttribute()
  {
    return getAttribute("onkeypress");
  }
  
  public final String getOnKeyDownAttribute()
  {
    return getAttribute("onkeydown");
  }
  
  public final String getOnKeyUpAttribute()
  {
    return getAttribute("onkeyup");
  }
  
  protected boolean isStateUpdateFirst()
  {
    return false;
  }
  
  public String getCanonicalXPath()
  {
    DomNode parent = getParentNode();
    if (parent.getNodeType() == 9) {
      return "/" + getNodeName();
    }
    return parent.getCanonicalXPath() + '/' + getXPathToken();
  }
  
  private String getXPathToken()
  {
    DomNode parent = getParentNode();
    int total = 0;
    int nodeIndex = 0;
    for (DomNode child : parent.getChildren())
    {
      if ((child.getNodeType() == 1) && (child.getNodeName().equals(getNodeName()))) {
        total++;
      }
      if (child == this) {
        nodeIndex = total;
      }
    }
    if ((nodeIndex == 1) && (total == 1)) {
      return getNodeName();
    }
    return getNodeName() + '[' + nodeIndex + ']';
  }
}

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

import com.gargoylesoftware.htmlunit.SgmlPage;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringEscapeUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.TypeInfo;

public class DomElement
  extends DomNamespaceNode
  implements Element
{
  private static final long serialVersionUID = 8573853996234946066L;
  public static final String ATTRIBUTE_NOT_DEFINED = new String("");
  public static final String ATTRIBUTE_VALUE_EMPTY = new String("");
  private NamedAttrNodeMapImpl attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive());
  private Map<String, String> namespaces_ = new HashMap();
  
  public DomElement(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page);
    if ((attributes != null) && (!attributes.isEmpty()))
    {
      attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive(), attributes);
      for (DomAttr entry : attributes_.values())
      {
        entry.setParentNode(this);
        String attrNamespaceURI = entry.getNamespaceURI();
        if (attrNamespaceURI != null) {
          namespaces_.put(attrNamespaceURI, entry.getPrefix());
        }
      }
    }
  }
  
  public String getNodeName()
  {
    return getQualifiedName();
  }
  
  public final short getNodeType()
  {
    return 1;
  }
  
  protected Map<String, String> namespaces()
  {
    return namespaces_;
  }
  
  public final String getTagName()
  {
    return getNodeName();
  }
  
  public final boolean hasAttributes()
  {
    return !attributes_.isEmpty();
  }
  
  public boolean hasAttribute(String attributeName)
  {
    return attributes_.containsKey(attributeName);
  }
  
  protected void printOpeningTagContentAsXml(PrintWriter printWriter)
  {
    printWriter.print(getTagName());
    for (String name : attributes_.keySet())
    {
      printWriter.print(" ");
      printWriter.print(name);
      printWriter.print("=\"");
      printWriter.print(StringEscapeUtils.escapeXml(attributes_.get(name).getNodeValue()));
      printWriter.print("\"");
    }
  }
  
  protected void printXml(String indent, PrintWriter printWriter)
  {
    boolean hasChildren = getFirstChild() != null;
    printWriter.print(indent + "<");
    printOpeningTagContentAsXml(printWriter);
    if ((!hasChildren) && (!isEmptyXmlTagExpanded()))
    {
      printWriter.println("/>");
    }
    else
    {
      printWriter.println(">");
      printChildrenAsXml(indent, printWriter);
      printWriter.println(indent + "</" + getTagName() + ">");
    }
  }
  
  protected boolean isEmptyXmlTagExpanded()
  {
    return false;
  }
  
  String getQualifiedName(String namespaceURI, String localName)
  {
    String qualifiedName;
    String qualifiedName;
    if (namespaceURI != null)
    {
      String prefix = (String)namespaces().get(namespaceURI);
      String qualifiedName;
      if (prefix != null) {
        qualifiedName = prefix + ':' + localName;
      } else {
        qualifiedName = null;
      }
    }
    else
    {
      qualifiedName = localName;
    }
    return qualifiedName;
  }
  
  public String getAttribute(String attributeName)
  {
    DomAttr attr = attributes_.get(attributeName);
    if (attr != null) {
      return attr.getNodeValue();
    }
    return ATTRIBUTE_NOT_DEFINED;
  }
  
  public void removeAttribute(String attributeName)
  {
    attributes_.remove(attributeName.toLowerCase());
  }
  
  public final void removeAttributeNS(String namespaceURI, String localName)
  {
    String qualifiedName = getQualifiedName(namespaceURI, localName);
    if (qualifiedName != null) {
      removeAttribute(qualifiedName);
    }
  }
  
  public final Attr removeAttributeNode(Attr attribute)
  {
    throw new UnsupportedOperationException("DomElement.removeAttributeNode is not yet implemented.");
  }
  
  public final boolean hasAttributeNS(String namespaceURI, String localName)
  {
    String qualifiedName = getQualifiedName(namespaceURI, localName);
    if (qualifiedName != null) {
      return attributes_.get(qualifiedName) != null;
    }
    return false;
  }
  
  public final Map<String, DomAttr> getAttributesMap()
  {
    return attributes_;
  }
  
  public NamedNodeMap getAttributes()
  {
    return attributes_;
  }
  
  public final void setAttribute(String attributeName, String attributeValue)
  {
    setAttributeNS(null, attributeName, attributeValue);
  }
  
  public void setAttributeNS(String namespaceURI, String qualifiedName, String attributeValue)
  {
    String value = attributeValue;
    DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value, true);
    newAttr.setParentNode(this);
    attributes_.put(qualifiedName, newAttr);
    if (namespaceURI != null) {
      namespaces().put(namespaceURI, newAttr.getPrefix());
    }
  }
  
  protected boolean isAttributeCaseSensitive()
  {
    return true;
  }
  
  public final String getAttributeNS(String namespaceURI, String localName)
  {
    String qualifiedName = getQualifiedName(namespaceURI, localName);
    if (qualifiedName != null) {
      return getAttribute(qualifiedName);
    }
    return ATTRIBUTE_NOT_DEFINED;
  }
  
  public DomAttr getAttributeNode(String name)
  {
    return attributes_.get(name);
  }
  
  public DomAttr getAttributeNodeNS(String namespaceURI, String localName)
  {
    String qualifiedName = getQualifiedName(namespaceURI, localName);
    if (qualifiedName != null) {
      return attributes_.get(qualifiedName);
    }
    return null;
  }
  
  public DomNodeList<HtmlElement> getElementsByTagName(String tagName)
  {
    return new XPathDomNodeList(this, ".//*[local-name()='" + tagName + "']");
  }
  
  public DomNodeList<HtmlElement> getElementsByTagNameNS(String namespace, String localName)
  {
    throw new UnsupportedOperationException("DomElement.getElementsByTagNameNS is not yet implemented.");
  }
  
  public TypeInfo getSchemaTypeInfo()
  {
    throw new UnsupportedOperationException("DomElement.getSchemaTypeInfo is not yet implemented.");
  }
  
  public void setIdAttribute(String name, boolean isId)
  {
    throw new UnsupportedOperationException("DomElement.setIdAttribute is not yet implemented.");
  }
  
  public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
  {
    throw new UnsupportedOperationException("DomElement.setIdAttributeNS is not yet implemented.");
  }
  
  public Attr setAttributeNode(Attr attribute)
  {
    attributes_.setNamedItem(attribute);
    return null;
  }
  
  public Attr setAttributeNodeNS(Attr attribute)
  {
    throw new UnsupportedOperationException("DomElement.setAttributeNodeNS is not yet implemented.");
  }
  
  public final void setIdAttributeNode(Attr idAttr, boolean isId)
  {
    throw new UnsupportedOperationException("DomElement.setIdAttributeNode is not yet implemented.");
  }
  
  public DomNode cloneNode(boolean deep)
  {
    DomElement clone = (DomElement)super.cloneNode(deep);
    attributes_ = new NamedAttrNodeMapImpl(clone, isAttributeCaseSensitive());
    attributes_.putAll(attributes_);
    return clone;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomElement
 * 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.WebAssert;
import com.gargoylesoftware.htmlunit.html.xpath.XPathUtils;

public abstract class DomNamespaceNode
  extends DomNode
{
  private static final long serialVersionUID = 4121331154432606647L;
  private final String namespaceURI_;
  private String qualifiedName_;
  private final String localName_;
  private String prefix_;
  
  protected DomNamespaceNode(String namespaceURI, String qualifiedName, SgmlPage page)
  {
    super(page);
    WebAssert.notNull("qualifiedName", qualifiedName);
    qualifiedName_ = qualifiedName;
    if (qualifiedName.indexOf(':') != -1)
    {
      namespaceURI_ = namespaceURI;
      int colonPosition = qualifiedName_.indexOf(':');
      localName_ = qualifiedName_.substring(colonPosition + 1);
      prefix_ = qualifiedName_.substring(0, colonPosition);
    }
    else
    {
      namespaceURI_ = namespaceURI;
      localName_ = qualifiedName_;
      prefix_ = null;
    }
  }
  
  public String getNamespaceURI()
  {
    return namespaceURI_;
  }
  
  public String getLocalName()
  {
    boolean caseSensitive = getPage().hasCaseSensitiveTagNames();
    if ((!caseSensitive) && (XPathUtils.isProcessingXPath())) {
      return localName_.toLowerCase();
    }
    return localName_;
  }
  
  public String getPrefix()
  {
    return prefix_;
  }
  
  public void setPrefix(String prefix)
  {
    prefix_ = prefix;
    if ((prefix_ != null) && (localName_ != null)) {
      qualifiedName_ = (prefix_ + ":" + localName_);
    }
  }
  
  public String getQualifiedName()
  {
    return qualifiedName_;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomNamespaceNode
 * 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.Attr;
import org.w3c.dom.TypeInfo;

public class DomAttr
  extends DomNamespaceNode
  implements Attr
{
  private static final long serialVersionUID = 4832218455328064213L;
  private String value_;
  private boolean specified_;
  
  public DomAttr(SgmlPage page, String namespaceURI, String qualifiedName, String value, boolean specified)
  {
    super(namespaceURI, qualifiedName, page);
    value_ = value;
    specified_ = specified;
  }
  
  public short getNodeType()
  {
    return 2;
  }
  
  public String getNodeName()
  {
    return getName();
  }
  
  public String getNodeValue()
  {
    return getValue();
  }
  
  public String getName()
  {
    return getQualifiedName();
  }
  
  public String getValue()
  {
    return value_;
  }
  
  public void setNodeValue(String value)
  {
    setValue(value);
  }
  
  public void setValue(String value)
  {
    value_ = value;
    specified_ = true;
  }
  
  public DomElement getOwnerElement()
  {
    return (DomElement)getParentNode();
  }
  
  public boolean getSpecified()
  {
    return specified_;
  }
  
  public TypeInfo getSchemaTypeInfo()
  {
    throw new UnsupportedOperationException("DomAttr.getSchemaTypeInfo is not yet implemented.");
  }
  
  public boolean isId()
  {
    return "id".equals(getNodeName());
  }
  
  public String toString()
  {
    return getClass().getSimpleName() + "[name=" + getNodeName() + " value=" + getNodeValue() + "]";
  }
  
  public String getCanonicalXPath()
  {
    return getParentNode().getCanonicalXPath() + "/@" + getName();
  }
  
  public String getTextContent()
  {
    return getNodeValue();
  }
  
  public void setTextContent(String textContent)
  {
    boolean mappedElement = HtmlPage.isMappedElement(getOwnerDocument(), getName());
    if (mappedElement) {
      ((HtmlPage)getPage()).removeMappedElement((HtmlElement)getOwnerElement());
    }
    setValue(textContent);
    if (mappedElement) {
      ((HtmlPage)getPage()).addMappedElement((HtmlElement)getOwnerElement());
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.DomAttr
 * 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.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.FormEncodingType;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.TextUtil;
import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.util.EncodingUtil;
import org.apache.commons.lang.StringUtils;

public class HtmlForm
  extends HtmlElement
{
  private static final long serialVersionUID = 5338964478788825866L;
  public static final String TAG_NAME = "form";
  private static final Collection<String> SUBMITTABLE_ELEMENT_NAMES = Arrays.asList(new String[] { "input", "button", "select", "textarea", "isindex" });
  private final List<HtmlElement> lostChildren_ = new ArrayList();
  private boolean isPreventDefault_;
  
  HtmlForm(String namespaceURI, String qualifiedName, SgmlPage htmlPage, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, htmlPage, attributes);
  }
  
  Page submit(SubmittableElement submitElement)
    throws IOException
  {
    HtmlPage htmlPage = (HtmlPage)getPage();
    WebClient webClient = htmlPage.getWebClient();
    if (webClient.isJavaScriptEnabled())
    {
      if (submitElement != null)
      {
        isPreventDefault_ = false;
        ScriptResult scriptResult = fireEvent("submit");
        if (isPreventDefault_) {
          return scriptResult.getNewPage();
        }
      }
      String action = getActionAttribute();
      if (TextUtil.startsWithIgnoreCase(action, "javascript:")) {
        return htmlPage.executeJavaScriptIfPossible(action, "Form action", getStartLineNumber()).getNewPage();
      }
    }
    else if (TextUtil.startsWithIgnoreCase(getActionAttribute(), "javascript:"))
    {
      return htmlPage;
    }
    WebRequestSettings settings = getWebRequestSettings(submitElement);
    String target = htmlPage.getResolvedTarget(getTargetAttribute());
    
    WebWindow webWindow = htmlPage.getEnclosingWindow();
    webClient.download(webWindow, target, settings, "JS form.submit()");
    return htmlPage;
  }
  
  public WebRequestSettings getWebRequestSettings(SubmittableElement submitElement)
  {
    HtmlPage htmlPage = (HtmlPage)getPage();
    List<NameValuePair> parameters = getParameterListForSubmit(submitElement);
    
    String methodAttribute = getMethodAttribute();
    HttpMethod method;
    HttpMethod method;
    if ("post".equalsIgnoreCase(methodAttribute))
    {
      method = HttpMethod.POST;
    }
    else
    {
      if ((!"get".equalsIgnoreCase(methodAttribute)) && (methodAttribute.trim().length() > 0)) {
        notifyIncorrectness("Incorrect submit method >" + getMethodAttribute() + "<. Using >GET<.");
      }
      method = HttpMethod.GET;
    }
    String actionUrl = getActionAttribute();
    if (HttpMethod.GET == method)
    {
      String anchor = StringUtils.substringAfter(actionUrl, "#");
      String enc = getPage().getPageEncoding();
      String queryFromFields = EncodingUtil.formUrlEncode(NameValuePair.toHttpClient(parameters), enc);
      
      actionUrl = StringUtils.substringBefore(actionUrl, "#");
      actionUrl = StringUtils.substringBefore(actionUrl, "?");
      BrowserVersion browser = getPage().getWebClient().getBrowserVersion();
      if ((!browser.isIE()) || (browser.getBrowserVersionNumeric() < 7.0F) || (queryFromFields.length() > 0)) {
        actionUrl = actionUrl + "?" + queryFromFields;
      }
      if (anchor.length() > 0) {
        actionUrl = actionUrl + "#" + anchor;
      }
      parameters.clear();
    }
    URL url;
    try
    {
      URL url;
      if (actionUrl.length() == 0)
      {
        url = htmlPage.getWebResponse().getRequestSettings().getUrl();
      }
      else
      {
        URL url;
        if (actionUrl.startsWith("?"))
        {
          String urlString = htmlPage.getWebResponse().getRequestSettings().getUrl().toExternalForm();
          if (urlString.indexOf('?') != -1) {
            urlString = urlString.substring(0, urlString.indexOf('?'));
          }
          url = new URL(urlString + actionUrl);
        }
        else
        {
          url = htmlPage.getFullyQualifiedUrl(actionUrl);
        }
      }
    }
    catch (MalformedURLException e)
    {
      throw new IllegalArgumentException("Not a valid url: " + actionUrl);
    }
    WebRequestSettings settings = new WebRequestSettings(url, method);
    settings.setRequestParameters(parameters);
    if (HttpMethod.POST == method) {
      settings.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute()));
    }
    settings.setCharset(getSubmitCharset());
    settings.setAdditionalHeader("Referer", htmlPage.getWebResponse().getRequestSettings().getUrl().toExternalForm());
    
    return settings;
  }
  
  private String getSubmitCharset()
  {
    if (getAcceptCharsetAttribute().length() > 0) {
      return getAcceptCharsetAttribute().trim().replaceAll("[ ,].*", "");
    }
    return getPage().getPageEncoding();
  }
  
  private List<NameValuePair> getParameterListForSubmit(SubmittableElement submitElement)
  {
    Collection<SubmittableElement> submittableElements = getSubmittableElements(submitElement);
    
    List<NameValuePair> parameterList = new ArrayList(submittableElements.size());
    for (SubmittableElement element : submittableElements) {
      for (NameValuePair pair : element.getSubmitKeyValuePairs()) {
        parameterList.add(pair);
      }
    }
    return parameterList;
  }
  
  public Page reset()
  {
    SgmlPage htmlPage = getPage();
    ScriptResult scriptResult = fireEvent("reset");
    if (ScriptResult.isFalse(scriptResult)) {
      return scriptResult.getNewPage();
    }
    for (HtmlElement next : getHtmlElementDescendants()) {
      if ((next instanceof SubmittableElement)) {
        ((SubmittableElement)next).reset();
      }
    }
    return htmlPage;
  }
  
  Collection<SubmittableElement> getSubmittableElements(SubmittableElement submitElement)
  {
    List<SubmittableElement> submittableElements = new ArrayList();
    for (HtmlElement element : getHtmlElementDescendants()) {
      if (isSubmittable(element, submitElement)) {
        submittableElements.add((SubmittableElement)element);
      }
    }
    for (HtmlElement element : lostChildren_) {
      if (isSubmittable(element, submitElement)) {
        submittableElements.add((SubmittableElement)element);
      }
    }
    return submittableElements;
  }
  
  private boolean isValidForSubmission(HtmlElement element, SubmittableElement submitElement)
  {
    String tagName = element.getTagName();
    if (!SUBMITTABLE_ELEMENT_NAMES.contains(tagName)) {
      return false;
    }
    if (element.hasAttribute("disabled")) {
      return false;
    }
    if ((element == submitElement) && ((element instanceof HtmlImageInput))) {
      return true;
    }
    if ((!tagName.equals("isindex")) && (!element.hasAttribute("name"))) {
      return false;
    }
    if ((!tagName.equals("isindex")) && (element.getAttribute("name").equals(""))) {
      return false;
    }
    if ((element instanceof HtmlInput))
    {
      String type = element.getAttribute("type").toLowerCase();
      if ((type.equals("radio")) || (type.equals("checkbox"))) {
        return element.hasAttribute("checked");
      }
    }
    if (tagName.equals("select")) {
      return ((HtmlSelect)element).isValidForSubmission();
    }
    return true;
  }
  
  private boolean isSubmittable(HtmlElement element, SubmittableElement submitElement)
  {
    String tagName = element.getTagName();
    if (!isValidForSubmission(element, submitElement)) {
      return false;
    }
    if (element == submitElement) {
      return true;
    }
    if ((element instanceof HtmlInput))
    {
      HtmlInput input = (HtmlInput)element;
      String type = input.getTypeAttribute().toLowerCase();
      if ((type.equals("submit")) || (type.equals("image")) || (type.equals("reset")) || (type.equals("button"))) {
        return false;
      }
    }
    if (tagName.equals("button")) {
      return false;
    }
    return true;
  }
  
  public List<HtmlInput> getInputsByName(String name)
  {
    List<HtmlInput> list = getElementsByAttribute("input", "name", name);
    for (HtmlElement elt : getLostChildren()) {
      if (((elt instanceof HtmlInput)) && (name.equals(elt.getAttribute("name")))) {
        list.add((HtmlInput)elt);
      }
    }
    return list;
  }
  
  public final <I extends HtmlInput> I getInputByName(String name)
    throws ElementNotFoundException
  {
    List<HtmlInput> inputs = getInputsByName(name);
    if (inputs.isEmpty()) {
      throw new ElementNotFoundException("input", "name", name);
    }
    return (HtmlInput)inputs.get(0);
  }
  
  public List<HtmlSelect> getSelectsByName(String name)
  {
    List<HtmlSelect> list = getElementsByAttribute("select", "name", name);
    for (HtmlElement elt : getLostChildren()) {
      if (((elt instanceof HtmlSelect)) && (name.equals(elt.getAttribute("name")))) {
        list.add((HtmlSelect)elt);
      }
    }
    return list;
  }
  
  public HtmlSelect getSelectByName(String name)
    throws ElementNotFoundException
  {
    List<HtmlSelect> list = getSelectsByName(name);
    if (list.isEmpty()) {
      throw new ElementNotFoundException("select", "name", name);
    }
    return (HtmlSelect)list.get(0);
  }
  
  public List<HtmlButton> getButtonsByName(String name)
  {
    List<HtmlButton> list = getElementsByAttribute("button", "name", name);
    for (HtmlElement elt : getLostChildren()) {
      if (((elt instanceof HtmlButton)) && (name.equals(elt.getAttribute("name")))) {
        list.add((HtmlButton)elt);
      }
    }
    return list;
  }
  
  public HtmlButton getButtonByName(String name)
    throws ElementNotFoundException
  {
    List<HtmlButton> list = getButtonsByName(name);
    if (list.isEmpty()) {
      throw new ElementNotFoundException("button", "name", name);
    }
    return (HtmlButton)list.get(0);
  }
  
  public List<HtmlTextArea> getTextAreasByName(String name)
  {
    List<HtmlTextArea> list = getElementsByAttribute("textarea", "name", name);
    for (HtmlElement elt : getLostChildren()) {
      if (((elt instanceof HtmlTextArea)) && (name.equals(elt.getAttribute("name")))) {
        list.add((HtmlTextArea)elt);
      }
    }
    return list;
  }
  
  public HtmlTextArea getTextAreaByName(String name)
    throws ElementNotFoundException
  {
    List<HtmlTextArea> list = getTextAreasByName(name);
    if (list.isEmpty()) {
      throw new ElementNotFoundException("textarea", "name", name);
    }
    return (HtmlTextArea)list.get(0);
  }
  
  public List<HtmlRadioButtonInput> getRadioButtonsByName(String name)
  {
    WebAssert.notNull("name", name);
    
    List<HtmlRadioButtonInput> results = new ArrayList();
    for (HtmlElement element : getInputsByName(name)) {
      if ((element instanceof HtmlRadioButtonInput)) {
        results.add((HtmlRadioButtonInput)element);
      }
    }
    return results;
  }
  
  void setCheckedRadioButton(HtmlRadioButtonInput radioButtonInput)
  {
    if ((!isAncestorOf(radioButtonInput)) && (!lostChildren_.contains(radioButtonInput))) {
      throw new IllegalArgumentException("HtmlRadioButtonInput is not child of this HtmlForm");
    }
    List<HtmlRadioButtonInput> radios = getRadioButtonsByName(radioButtonInput.getNameAttribute());
    for (HtmlRadioButtonInput input : radios) {
      if (input == radioButtonInput) {
        input.setAttribute("checked", "checked");
      } else {
        input.removeAttribute("checked");
      }
    }
  }
  
  public HtmlRadioButtonInput getCheckedRadioButton(String name)
  {
    WebAssert.notNull("name", name);
    for (HtmlRadioButtonInput input : getRadioButtonsByName(name)) {
      if (input.isChecked()) {
        return input;
      }
    }
    return null;
  }
  
  public final String getActionAttribute()
  {
    return getAttribute("action");
  }
  
  public final void setActionAttribute(String action)
  {
    setAttribute("action", action);
  }
  
  public final String getMethodAttribute()
  {
    return getAttribute("method");
  }
  
  public final void setMethodAttribute(String method)
  {
    setAttribute("method", method);
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final void setNameAttribute(String name)
  {
    setAttribute("name", name);
  }
  
  public final String getEnctypeAttribute()
  {
    return getAttribute("enctype");
  }
  
  public final void setEnctypeAttribute(String encoding)
  {
    setAttribute("enctype", encoding);
  }
  
  public final String getOnSubmitAttribute()
  {
    return getAttribute("onsubmit");
  }
  
  public final String getOnResetAttribute()
  {
    return getAttribute("onreset");
  }
  
  public final String getAcceptAttribute()
  {
    return getAttribute("accept");
  }
  
  public final String getAcceptCharsetAttribute()
  {
    return getAttribute("accept-charset");
  }
  
  public final String getTargetAttribute()
  {
    return getAttribute("target");
  }
  
  public final void setTargetAttribute(String target)
  {
    setAttribute("target", target);
  }
  
  public <I extends HtmlInput> I getInputByValue(String value)
    throws ElementNotFoundException
  {
    List<HtmlInput> list = getInputsByValue(value);
    if (list.isEmpty()) {
      throw new ElementNotFoundException("input", "value", value);
    }
    return (HtmlInput)list.get(0);
  }
  
  public List<HtmlInput> getInputsByValue(String value)
  {
    List<HtmlInput> results = getElementsByAttribute("input", "value", value);
    for (HtmlElement element : getLostChildren()) {
      if (((element instanceof HtmlInput)) && (value.equals(element.getAttribute("value")))) {
        results.add((HtmlInput)element);
      }
    }
    return results;
  }
  
  void addLostChild(HtmlElement field)
  {
    lostChildren_.add(field);
    field.setOwningForm(this);
  }
  
  public List<HtmlElement> getLostChildren()
  {
    return lostChildren_;
  }
  
  protected void preventDefault()
  {
    isPreventDefault_ = true;
  }
}

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

import com.gargoylesoftware.htmlunit.util.MapWrapper;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

class NamedAttrNodeMapImpl
  extends MapWrapper<String, DomAttr>
  implements NamedNodeMap, Serializable
{
  private static final long serialVersionUID = -450637965125944616L;
  private final List<String> attrPositions_ = new ArrayList();
  private final DomElement domNode_;
  public static final NamedAttrNodeMapImpl EMPTY_MAP = new NamedAttrNodeMapImpl();
  private final boolean caseSensitive_;
  
  private NamedAttrNodeMapImpl()
  {
    super(new HashMap());
    domNode_ = null;
    caseSensitive_ = true;
  }
  
  NamedAttrNodeMapImpl(DomElement domNode, boolean caseSensitive, Map<String, DomAttr> attributes)
  {
    super(attributes);
    if (domNode == null) {
      throw new IllegalArgumentException();
    }
    domNode_ = domNode;
    caseSensitive_ = caseSensitive;
    for (String name : keySet()) {
      attrPositions_.add(name);
    }
  }
  
  NamedAttrNodeMapImpl(DomElement domElement, boolean caseSensitive)
  {
    this(domElement, caseSensitive, new HashMap());
  }
  
  public int getLength()
  {
    return size();
  }
  
  public DomAttr getNamedItem(String name)
  {
    return get(fixName(name));
  }
  
  private String fixName(String name)
  {
    if (caseSensitive_) {
      return name;
    }
    return name.toLowerCase();
  }
  
  public Node getNamedItemNS(String namespaceURI, String localName)
  {
    if (domNode_ == null) {
      return null;
    }
    return get(domNode_.getQualifiedName(namespaceURI, fixName(localName)));
  }
  
  public Node item(int index)
  {
    if ((index < 0) || (index >= attrPositions_.size())) {
      return null;
    }
    return get(attrPositions_.get(index));
  }
  
  public Node removeNamedItem(String name)
    throws DOMException
  {
    return remove(fixName(name));
  }
  
  public Node removeNamedItemNS(String namespaceURI, String localName)
  {
    if (domNode_ == null) {
      return null;
    }
    return remove(domNode_.getQualifiedName(namespaceURI, fixName(localName)));
  }
  
  public DomAttr setNamedItem(Node node)
  {
    return put(fixName(node.getLocalName()), (DomAttr)node);
  }
  
  public Node setNamedItemNS(Node node)
    throws DOMException
  {
    return put(fixName(node.getNodeName()), (DomAttr)node);
  }
  
  public DomAttr put(String key, DomAttr value)
  {
    key = fixName(key);
    if (!containsKey(key)) {
      attrPositions_.add(key);
    }
    return (DomAttr)super.put(key, value);
  }
  
  public DomAttr remove(Object key)
  {
    if (!(key instanceof String)) {
      return null;
    }
    String name = fixName((String)key);
    attrPositions_.remove(name);
    return (DomAttr)super.remove(name);
  }
  
  public void clear()
  {
    attrPositions_.clear();
    super.clear();
  }
  
  public void putAll(Map<? extends String, ? extends DomAttr> t)
  {
    for (Map.Entry<? extends String, ? extends DomAttr> entry : t.entrySet()) {
      put((String)entry.getKey(), (DomAttr)entry.getValue());
    }
  }
  
  public boolean containsKey(Object key)
  {
    if (!(key instanceof String)) {
      return false;
    }
    String name = fixName((String)key);
    return super.containsKey(name);
  }
  
  public DomAttr get(Object key)
  {
    if (!(key instanceof String)) {
      return null;
    }
    String name = fixName((String)key);
    return (DomAttr)super.get(name);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.NamedAttrNodeMapImpl
 * 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.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public abstract class HtmlInput
  extends HtmlElement
  implements DisabledElement, SubmittableElement
{
  private static final long serialVersionUID = 3602129443357463947L;
  public static final String TAG_NAME = "input";
  private String defaultValue_;
  
  public HtmlInput(SgmlPage page, Map<String, DomAttr> attributes)
  {
    this(null, "input", page, attributes);
  }
  
  public HtmlInput(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
    defaultValue_ = getValueAttribute();
  }
  
  public Page setValueAttribute(String newValue)
  {
    WebAssert.notNull("newValue", newValue);
    setAttribute("value", newValue);
    
    return executeOnChangeHandlerIfAppropriate(this);
  }
  
  public NameValuePair[] getSubmitKeyValuePairs()
  {
    return new NameValuePair[] { new NameValuePair(getNameAttribute(), getValueAttribute()) };
  }
  
  public final String getTypeAttribute()
  {
    return getAttribute("type");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getValueAttribute()
  {
    return getAttribute("value");
  }
  
  public final String getCheckedAttribute()
  {
    return getAttribute("checked");
  }
  
  public final String getDisabledAttribute()
  {
    return getAttribute("disabled");
  }
  
  public final boolean isDisabled()
  {
    return hasAttribute("disabled");
  }
  
  public final String getReadOnlyAttribute()
  {
    return getAttribute("readonly");
  }
  
  public final String getSizeAttribute()
  {
    return getAttribute("size");
  }
  
  public final String getMaxLengthAttribute()
  {
    return getAttribute("maxlength");
  }
  
  public final String getSrcAttribute()
  {
    return getAttribute("src");
  }
  
  public final String getAltAttribute()
  {
    return getAttribute("alt");
  }
  
  public final String getUseMapAttribute()
  {
    return getAttribute("usemap");
  }
  
  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 final String getAcceptAttribute()
  {
    return getAttribute("accept");
  }
  
  public final String getAlignAttribute()
  {
    return getAttribute("align");
  }
  
  public void reset()
  {
    setValueAttribute(defaultValue_);
  }
  
  public void setDefaultValue(String defaultValue)
  {
    boolean modifyValue = getPage().getWebClient().getBrowserVersion().isFirefox();
    setDefaultValue(defaultValue, modifyValue);
  }
  
  protected void setDefaultValue(String defaultValue, boolean modifyValue)
  {
    defaultValue_ = defaultValue;
    if (modifyValue) {
      setValueAttribute(defaultValue);
    }
  }
  
  public String getDefaultValue()
  {
    return defaultValue_;
  }
  
  public void setDefaultChecked(boolean defaultChecked) {}
  
  public boolean isDefaultChecked()
  {
    return false;
  }
  
  public Page setChecked(boolean isChecked)
  {
    return getPage();
  }
  
  public void setReadOnly(boolean isReadOnly)
  {
    if (isReadOnly) {
      setAttribute("readOnly", "readOnly");
    } else {
      removeAttribute("readOnly");
    }
  }
  
  public boolean isChecked()
  {
    return hasAttribute("checked");
  }
  
  public boolean isReadOnly()
  {
    return hasAttribute("readOnly");
  }
  
  public <P extends Page> P click(int x, int y)
    throws IOException, ElementNotFoundException
  {
    return click();
  }
  
  static Page executeOnChangeHandlerIfAppropriate(HtmlElement htmlElement)
  {
    SgmlPage page = htmlElement.getPage();
    
    JavaScriptEngine engine = htmlElement.getPage().getWebClient().getJavaScriptEngine();
    if (engine.isScriptRunning()) {
      return page;
    }
    ScriptResult scriptResult = htmlElement.fireEvent("change");
    if (page.getWebClient().getWebWindows().contains(page.getEnclosingWindow())) {
      return page.getEnclosingWindow().getEnclosedPage();
    }
    if (scriptResult != null) {
      return scriptResult.getNewPage();
    }
    return page;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlInput
 * 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.ElementNotFoundException;
import
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