htmlunit-2.7

> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlSubscript
 * 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 java.util.Map;

public class HtmlOptionGroup
  extends HtmlElement
  implements DisabledElement
{
  private static final long serialVersionUID = 7854731553754432321L;
  public static final String TAG_NAME = "optgroup";
  
  HtmlOptionGroup(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final boolean isDisabled()
  {
    if (getPage().getWebClient().getBrowserVersion().isIE()) {
      return false;
    }
    return hasAttribute("disabled");
  }
  
  public final String getDisabledAttribute()
  {
    return getAttribute("disabled");
  }
  
  public final String getLabelAttribute()
  {
    return getAttribute("label");
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlOptionGroup
 * 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 HtmlDirectory
  extends HtmlElement
{
  private static final long serialVersionUID = 7234953475940770872L;
  public static final String TAG_NAME = "dir";
  
  HtmlDirectory(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlDirectory
 * 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 HtmlBlink
  extends HtmlElement
{
  private static final long serialVersionUID = 5968651790284866362L;
  public static final String TAG_NAME = "blink";
  
  HtmlBlink(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlBlink
 * 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.util.NameValuePair;
import java.util.Map;

public class HtmlIsIndex
  extends HtmlElement
  implements SubmittableElement
{
  private static final long serialVersionUID = -7566440323983487259L;
  public static final String TAG_NAME = "isindex";
  private String value_ = "";
  
  HtmlIsIndex(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public void setValue(String newValue)
  {
    WebAssert.notNull("newValue", newValue);
    value_ = newValue;
  }
  
  public String getValue()
  {
    return value_;
  }
  
  public NameValuePair[] getSubmitKeyValuePairs()
  {
    return new NameValuePair[] { new NameValuePair(getPromptAttribute(), getValue()) };
  }
  
  public void reset()
  {
    value_ = "";
  }
  
  public void setDefaultValue(String defaultValue) {}
  
  public String getDefaultValue()
  {
    return "";
  }
  
  public void setDefaultChecked(boolean defaultChecked) {}
  
  public boolean isDefaultChecked()
  {
    return false;
  }
  
  public final String getPromptAttribute()
  {
    return getAttribute("prompt");
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlIsIndex
 * 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 HtmlExample
  extends HtmlElement
{
  private static final long serialVersionUID = 7789806977925266910L;
  public static final String TAG_NAME = "xmp";
  
  HtmlExample(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlExample
 * 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.javascript.host.html.HTMLObjectElement;
import java.util.Map;

public class HtmlObject
  extends HtmlElement
{
  private static final long serialVersionUID = 1203763133530358990L;
  public static final String TAG_NAME = "object";
  
  HtmlObject(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
    if (attributes != null)
    {
      DomAttr classid = (DomAttr)attributes.get("classid");
      if (classid != null) {
        ((HTMLObjectElement)getScriptObject()).jsxSet_classid(classid.getValue());
      }
    }
  }
  
  public final String getDeclareAttribute()
  {
    return getAttribute("declare");
  }
  
  public final String getClassIdAttribute()
  {
    return getAttribute("classid");
  }
  
  public final String getCodebaseAttribute()
  {
    return getAttribute("codebase");
  }
  
  public final String getDataAttribute()
  {
    return getAttribute("data");
  }
  
  public final String getTypeAttribute()
  {
    return getAttribute("type");
  }
  
  public final String getCodeTypeAttribute()
  {
    return getAttribute("codetype");
  }
  
  public final String getArchiveAttribute()
  {
    return getAttribute("archive");
  }
  
  public final String getStandbyAttribute()
  {
    return getAttribute("standby");
  }
  
  public final String getHeightAttribute()
  {
    return getAttribute("height");
  }
  
  public final String getWidthAttribute()
  {
    return getAttribute("width");
  }
  
  public final String getUseMapAttribute()
  {
    return getAttribute("usemap");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getTabIndexAttribute()
  {
    return getAttribute("tabindex");
  }
  
  public final String getAlignAttribute()
  {
    return getAttribute("align");
  }
  
  public final String getBorderAttribute()
  {
    return getAttribute("border");
  }
  
  public final String getHspaceAttribute()
  {
    return getAttribute("hspace");
  }
  
  public final String getVspaceAttribute()
  {
    return getAttribute("vspace");
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlObject
 * 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 HtmlListItem
  extends HtmlElement
{
  private static final long serialVersionUID = -1649077723867505624L;
  public static final String TAG_NAME = "li";
  
  HtmlListItem(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getTypeAttribute()
  {
    return getAttribute("type");
  }
  
  public final String getValueAttribute()
  {
    return getAttribute("value");
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlListItem
 * 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 HtmlHeading5
  extends HtmlElement
{
  private static final long serialVersionUID = 2488902322765158768L;
  public static final String TAG_NAME = "h5";
  
  HtmlHeading5(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getAlignAttribute()
  {
    return getAttribute("align");
  }
  
  protected boolean isBlock()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlHeading5
 * 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 HtmlBold
  extends HtmlElement
{
  private static final long serialVersionUID = 7257383827767937681L;
  public static final String TAG_NAME = "b";
  
  HtmlBold(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlBold
 * 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 HtmlDefinition
  extends HtmlElement
{
  private static final long serialVersionUID = 4139591667031530755L;
  public static final String TAG_NAME = "dfn";
  
  HtmlDefinition(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlDefinition
 * 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.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.javascript.PostponedAction;

class HtmlScript$1
  extends PostponedAction
{
  HtmlScript$1(HtmlScript paramHtmlScript, Page x0)
  {
    super(x0);
  }
  
  public void execute()
  {
    boolean ie = this$0.getPage().getWebClient().getBrowserVersion().isIE();
    if (ie)
    {
      if (!this$0.isDeferred()) {
        if (!this$0.getSrcAttribute().equals("//:"))
        {
          this$0.setAndExecuteReadyState("loading");
          this$0.executeScriptIfNeeded(true);
          this$0.setAndExecuteReadyState("loaded");
        }
        else
        {
          this$0.setAndExecuteReadyState("complete");
          this$0.executeScriptIfNeeded(true);
        }
      }
    }
    else {
      this$0.executeScriptIfNeeded(true);
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlScript.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.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
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 com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.PostponedAction;
import com.gargoylesoftware.htmlunit.javascript.host.Event;
import com.gargoylesoftware.htmlunit.javascript.host.EventHandler;
import com.gargoylesoftware.htmlunit.javascript.host.Window;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLScriptElement;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import java.io.PrintWriter;
import java.net.URL;
import java.util.Map;
import net.sourceforge.htmlunit.corejs.javascript.BaseFunction;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HtmlScript
  extends HtmlElement
{
  private static final long serialVersionUID = 5736570536821513938L;
  private static final Log LOG = LogFactory.getLog(HtmlScript.class);
  public static final String TAG_NAME = "script";
  private static final String SLASH_SLASH_COLON = "//:";
  
  HtmlScript(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getCharsetAttribute()
  {
    return getAttribute("charset");
  }
  
  public final String getTypeAttribute()
  {
    return getAttribute("type");
  }
  
  public final String getLanguageAttribute()
  {
    return getAttribute("language");
  }
  
  public final String getSrcAttribute()
  {
    return getAttribute("src");
  }
  
  public final String getEventAttribute()
  {
    return getAttribute("event");
  }
  
  public final String getHtmlForAttribute()
  {
    return getAttribute("for");
  }
  
  public final String getDeferAttribute()
  {
    return getAttribute("defer");
  }
  
  protected boolean isDeferred()
  {
    return getDeferAttribute() != ATTRIBUTE_NOT_DEFINED;
  }
  
  public void setAttributeNS(String namespaceURI, String qualifiedName, String attributeValue)
  {
    String oldValue = getAttributeNS(namespaceURI, qualifiedName);
    super.setAttributeNS(namespaceURI, qualifiedName, attributeValue);
    
    boolean execute = false;
    if ((namespaceURI == null) && ("src".equals(qualifiedName)))
    {
      boolean ie = getPage().getWebClient().getBrowserVersion().isIE();
      if ((ie) || ((oldValue.length() == 0) && (getFirstChild() == null))) {
        execute = true;
      }
    }
    if (execute) {
      executeScriptIfNeeded(true);
    }
  }
  
  protected void onAllChildrenAddedToPage(boolean postponed)
  {
    if ((getOwnerDocument() instanceof XmlPage)) {
      return;
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Script node added: " + asXml());
    }
    PostponedAction action = new PostponedAction(getPage())
    {
      public void execute()
      {
        boolean ie = getPage().getWebClient().getBrowserVersion().isIE();
        if (ie)
        {
          if (!isDeferred()) {
            if (!getSrcAttribute().equals("//:"))
            {
              setAndExecuteReadyState("loading");
              executeScriptIfNeeded(true);
              setAndExecuteReadyState("loaded");
            }
            else
            {
              setAndExecuteReadyState("complete");
              executeScriptIfNeeded(true);
            }
          }
        }
        else {
          executeScriptIfNeeded(true);
        }
      }
    };
    if ((postponed) && (getTextContent().length() == 0))
    {
      JavaScriptEngine engine = getPage().getWebClient().getJavaScriptEngine();
      engine.addPostponedAction(action);
    }
    else
    {
      try
      {
        action.execute();
      }
      catch (Exception e)
      {
        if ((e instanceof RuntimeException)) {
          throw ((RuntimeException)e);
        }
        throw new RuntimeException(e);
      }
    }
  }
  
  private void executeInlineScriptIfNeeded(boolean executeIfDeferred)
  {
    if (!isExecutionNeeded()) {
      return;
    }
    boolean ie = getPage().getWebClient().getBrowserVersion().isIE();
    if ((!executeIfDeferred) && (isDeferred()) && (ie)) {
      return;
    }
    String src = getSrcAttribute();
    if (src != HtmlElement.ATTRIBUTE_NOT_DEFINED) {
      return;
    }
    DomCharacterData textNode = (DomCharacterData)getFirstChild();
    String forr = getHtmlForAttribute();
    String event = getEventAttribute();
    if (event.endsWith("()")) {
      event = event.substring(0, event.length() - 2);
    }
    String scriptCode = textNode.getData();
    if ((ie) && (event != ATTRIBUTE_NOT_DEFINED) && (forr != ATTRIBUTE_NOT_DEFINED))
    {
      if ("window".equals(forr))
      {
        Window window = (Window)getPage().getEnclosingWindow().getScriptObject();
        BaseFunction function = new EventHandler(this, event, scriptCode);
        window.jsxFunction_attachEvent(event, function);
      }
      else
      {
        try
        {
          HtmlElement elt = ((HtmlPage)getPage()).getHtmlElementById(forr);
          elt.setEventHandler(event, scriptCode);
        }
        catch (ElementNotFoundException e)
        {
          LOG.warn("<script for='" + forr + "' ...>: no element found with id \"" + forr + "\". Ignoring.");
        }
      }
    }
    else if ((forr == ATTRIBUTE_NOT_DEFINED) || ("onload".equals(event)))
    {
      String url = getPage().getWebResponse().getRequestSettings().getUrl().toExternalForm();
      int line1 = getStartLineNumber();
      int line2 = getEndLineNumber();
      int col1 = getStartColumnNumber();
      int col2 = getEndColumnNumber();
      String desc = "script in " + url + " from (" + line1 + ", " + col1 + ") to (" + line2 + ", " + col2 + ")";
      
      ((HtmlPage)getPage()).executeJavaScriptIfPossible(scriptCode, desc, line1);
    }
  }
  
  void executeScriptIfNeeded(boolean executeIfDeferred)
  {
    if (!isExecutionNeeded()) {
      return;
    }
    HtmlPage page = (HtmlPage)getPage();
    BrowserVersion browser = page.getWebClient().getBrowserVersion();
    boolean ie = browser.isIE();
    if ((!executeIfDeferred) && (isDeferred()) && (ie)) {
      return;
    }
    String src = getSrcAttribute();
    if (src.equals("//:")) {
      return;
    }
    if (src != ATTRIBUTE_NOT_DEFINED)
    {
      if (src.startsWith("javascript:"))
      {
        if ((!ie) || (browser.getBrowserVersionNumeric() != 7.0F))
        {
          String code = StringUtils.removeStart(src, "javascript:").trim();
          int len = code.length();
          if ((len > 2) && (
            ((code.charAt(0) == '\'') && (code.charAt(len - 1) == '\'')) || ((code.charAt(0) == '"') && (code.charAt(len - 1) == '"'))))
          {
            code = code.substring(1, len - 1);
            if (LOG.isDebugEnabled()) {
              LOG.debug("Executing JavaScript: " + code);
            }
            page.executeJavaScriptIfPossible(code, code, getStartLineNumber());
          }
        }
      }
      else
      {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Loading external JavaScript: " + src);
        }
        try
        {
          HtmlPage.JavaScriptLoadResult result = page.loadExternalJavaScriptFile(src, getCharsetAttribute());
          if (result == HtmlPage.JavaScriptLoadResult.SUCCESS) {
            executeEventIfNotIE("load");
          } else if (result == HtmlPage.JavaScriptLoadResult.DOWNLOAD_ERROR) {
            executeEventIfNotIE("error");
          }
        }
        catch (FailingHttpStatusCodeException e)
        {
          executeEventIfNotIE("error");
          throw e;
        }
      }
    }
    else if (getFirstChild() != null) {
      executeInlineScriptIfNeeded(executeIfDeferred);
    }
  }
  
  private void executeEventIfNotIE(String type)
  {
    if (!getPage().getWebClient().getBrowserVersion().isIE())
    {
      HTMLScriptElement script = (HTMLScriptElement)getScriptObject();
      Event event = new Event(this, type);
      script.executeEvent(event);
    }
  }
  
  private boolean isExecutionNeeded()
  {
    SgmlPage page = getPage();
    if (!page.getWebClient().isJavaScriptEnabled()) {
      return false;
    }
    if (((page instanceof HtmlPage)) && (((HtmlPage)page).isParsingHtmlSnippet())) {
      return false;
    }
    for (DomNode o = this; o != null; o = o.getParentNode()) {
      if (((o instanceof HtmlInlineFrame)) || ((o instanceof HtmlNoFrames)) || ((o instanceof HtmlNoScript))) {
        return false;
      }
    }
    if ((page.getEnclosingWindow() != null) && (page.getEnclosingWindow().getEnclosedPage() != page)) {
      return false;
    }
    if (!isJavaScript(getTypeAttribute(), getLanguageAttribute()))
    {
      String t = getTypeAttribute();
      String l = getLanguageAttribute();
      if (LOG.isWarnEnabled()) {
        LOG.warn("Script is not JavaScript (type: " + t + ", language: " + l + "). Skipping execution.");
      }
      return false;
    }
    DomNode root = this;
    while (root.getParentNode() != null) {
      root = root.getParentNode();
    }
    if (root != getPage()) {
      return false;
    }
    return true;
  }
  
  boolean isJavaScript(String typeAttribute, String languageAttribute)
  {
    boolean isJavaScript;
    boolean isJavaScript;
    if ((typeAttribute != null) && (typeAttribute.length() != 0))
    {
      isJavaScript = (typeAttribute.equalsIgnoreCase("text/javascript")) || ((typeAttribute.equalsIgnoreCase("application/javascript")) && (getPage().getWebClient().getBrowserVersion().isFirefox()));
    }
    else
    {
      boolean isJavaScript;
      if ((languageAttribute != null) && (languageAttribute.length() != 0)) {
        isJavaScript = TextUtil.startsWithIgnoreCase(languageAttribute, "javascript");
      } else {
        isJavaScript = true;
      }
    }
    return isJavaScript;
  }
  
  protected void setAndExecuteReadyState(String state)
  {
    if (getPage().getWebClient().getBrowserVersion().isIE())
    {
      setReadyState(state);
      HTMLScriptElement script = (HTMLScriptElement)getScriptObject();
      Event event = new Event(this, "readystatechange");
      script.executeEvent(event);
    }
  }
  
  public String asText()
  {
    return "";
  }
  
  protected boolean isEmptyXmlTagExpanded()
  {
    return true;
  }
  
  protected void printChildrenAsXml(String indent, PrintWriter printWriter)
  {
    DomCharacterData textNode = (DomCharacterData)getFirstChild();
    if (textNode != null)
    {
      printWriter.println("//<![CDATA[");
      printWriter.println(textNode.getData());
      printWriter.println("//]]>");
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlScript
 * 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;
import com.gargoylesoftware.htmlunit.javascript.host.Event;
import com.gargoylesoftware.htmlunit.javascript.host.Node;

class HtmlImage$1
  extends PostponedAction
{
  HtmlImage$1(HtmlImage paramHtmlImage, Page x0, Node paramNode, Event paramEvent)
  {
    super(x0);
  }
  
  public void execute()
    throws Exception
  {
    val$scriptObject.executeEvent(val$event);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlImage.1
 * 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.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.PostponedAction;
import com.gargoylesoftware.htmlunit.javascript.host.Event;
import com.gargoylesoftware.htmlunit.javascript.host.Node;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import net.sourceforge.htmlunit.corejs.javascript.Function;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HtmlImage
  extends HtmlElement
{
  private static final long serialVersionUID = -2304247017681577696L;
  private static final Log LOG = LogFactory.getLog(HtmlImage.class);
  public static final String TAG_NAME = "img";
  private int lastClickX_;
  private int lastClickY_;
  private WebResponse imageWebResponse_;
  private ImageReader imageReader_;
  private boolean downloaded_;
  private boolean onloadInvoked_;
  
  HtmlImage(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  protected void onAddedToPage()
  {
    doOnLoad();
    super.onAddedToPage();
  }
  
  public void doOnLoad()
  {
    if (!(getPage() instanceof HtmlPage)) {
      return;
    }
    if (onloadInvoked_) {
      return;
    }
    onloadInvoked_ = true;
    HtmlPage htmlPage = (HtmlPage)getPage();
    Function onload = getEventHandler("onload");
    if (onload != null)
    {
      boolean ok;
      try
      {
        downloadImageIfNeeded();
        int i = imageWebResponse_.getStatusCode();
        ok = ((i >= 200) && (i < 300)) || (i == 305);
      }
      catch (IOException e)
      {
        ok = false;
      }
      if (ok)
      {
        final Event event = new Event(this, "load");
        final Node scriptObject = (Node)getScriptObject();
        PostponedAction action = new PostponedAction(getPage())
        {
          public void execute()
            throws Exception
          {
            scriptObject.executeEvent(event);
          }
        };
        String readyState = htmlPage.getReadyState();
        if ("loading".equals(readyState)) {
          htmlPage.addAfterLoadAction(action);
        } else {
          htmlPage.getWebClient().getJavaScriptEngine().addPostponedAction(action);
        }
      }
      else
      {
        LOG.debug("Unable to download image for tag " + this + "; not firing onload event.");
      }
    }
  }
  
  public final String getSrcAttribute()
  {
    return getAttribute("src");
  }
  
  public final String getAltAttribute()
  {
    return getAttribute("alt");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getLongDescAttribute()
  {
    return getAttribute("longdesc");
  }
  
  public final String getHeightAttribute()
  {
    return getAttribute("height");
  }
  
  public final String getWidthAttribute()
  {
    return getAttribute("width");
  }
  
  public final String getUseMapAttribute()
  {
    return getAttribute("usemap");
  }
  
  public final String getIsmapAttribute()
  {
    return getAttribute("ismap");
  }
  
  public final String getAlignAttribute()
  {
    return getAttribute("align");
  }
  
  public final String getBorderAttribute()
  {
    return getAttribute("border");
  }
  
  public final String getHspaceAttribute()
  {
    return getAttribute("hspace");
  }
  
  public final String getVspaceAttribute()
  {
    return getAttribute("vspace");
  }
  
  public int getHeight()
    throws IOException
  {
    readImageIfNeeded();
    return imageReader_.getHeight(0);
  }
  
  public int getWidth()
    throws IOException
  {
    readImageIfNeeded();
    return imageReader_.getWidth(0);
  }
  
  public ImageReader getImageReader()
    throws IOException
  {
    readImageIfNeeded();
    return imageReader_;
  }
  
  public WebResponse getWebResponse(boolean downloadIfNeeded)
    throws IOException
  {
    if (downloadIfNeeded) {
      downloadImageIfNeeded();
    }
    return imageWebResponse_;
  }
  
  private void downloadImageIfNeeded()
    throws IOException
  {
    if (!downloaded_)
    {
      HtmlPage page = (HtmlPage)getPage();
      WebClient webclient = page.getWebClient();
      
      URL url = page.getFullyQualifiedUrl(getSrcAttribute());
      WebRequestSettings request = new WebRequestSettings(url);
      request.setAdditionalHeader("Referer", page.getWebResponse().getRequestSettings().getUrl().toExternalForm());
      
      imageWebResponse_ = webclient.loadWebResponse(request);
      downloaded_ = true;
    }
  }
  
  private void readImageIfNeeded()
    throws IOException
  {
    downloadImageIfNeeded();
    if (imageReader_ == null)
    {
      ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream());
      Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
      if (!iter.hasNext()) {
        throw new IOException("No image detected in response");
      }
      imageReader_ = ((ImageReader)iter.next());
      imageReader_.setInput(iis);
    }
  }
  
  public Page click(int x, int y)
    throws IOException
  {
    lastClickX_ = x;
    lastClickY_ = y;
    return super.click();
  }
  
  public Page click()
    throws IOException
  {
    return click(0, 0);
  }
  
  protected void doClickAction()
    throws IOException
  {
    if (getUseMapAttribute() != ATTRIBUTE_NOT_DEFINED)
    {
      String mapName = getUseMapAttribute().substring(1);
      HtmlElement doc = ((HtmlPage)getPage()).getDocumentElement();
      HtmlMap map = (HtmlMap)doc.getOneHtmlElementByAttribute("map", "name", mapName);
      for (HtmlElement element : map.getChildElements()) {
        if ((element instanceof HtmlArea))
        {
          HtmlArea area = (HtmlArea)element;
          if (area.containsPoint(lastClickX_, lastClickY_))
          {
            area.doClickAction();
            return;
          }
        }
      }
    }
    HtmlAnchor anchor = (HtmlAnchor)getEnclosingElement("a");
    if (anchor == null) {
      return;
    }
    if (getIsmapAttribute() != ATTRIBUTE_NOT_DEFINED)
    {
      String suffix = "?" + lastClickX_ + "," + lastClickY_;
      anchor.doClickAction(suffix);
      return;
    }
    anchor.doClickAction();
  }
  
  public void saveAs(File file)
    throws IOException
  {
    ImageReader reader = getImageReader();
    ImageIO.write(reader.read(0), reader.getFormatName(), file);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlImage
 * 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 HtmlStyle
  extends HtmlElement
{
  private static final long serialVersionUID = 8908548603811742885L;
  public static final String TAG_NAME = "style";
  
  HtmlStyle(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getTypeAttribute()
  {
    return getAttribute("type");
  }
  
  public final String getMediaAttribute()
  {
    return getAttribute("media");
  }
  
  public final String getTitleAttribute()
  {
    return getAttribute("title");
  }
  
  public String asText()
  {
    return "";
  }
  
  protected boolean isEmptyXmlTagExpanded()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlStyle
 * 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 HtmlSpacer
  extends HtmlElement
{
  private static final long serialVersionUID = -680661741943644813L;
  public static final String TAG_NAME = "spacer";
  
  HtmlSpacer(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlSpacer
 * 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 HtmlNoBreak
  extends HtmlElement
{
  private static final long serialVersionUID = -66463230199087310L;
  public static final String TAG_NAME = "nobr";
  
  HtmlNoBreak(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlNoBreak
 * 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 HtmlItalic
  extends HtmlElement
{
  private static final long serialVersionUID = -2658792144872361243L;
  public static final String TAG_NAME = "i";
  
  HtmlItalic(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlItalic
 * 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 HtmlMultiColumn
  extends HtmlElement
{
  private static final long serialVersionUID = 8652950102614375612L;
  public static final String TAG_NAME = "multicol";
  
  HtmlMultiColumn(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlMultiColumn
 * 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 HtmlNoEmbed
  extends HtmlElement
{
  private static final long serialVersionUID = 5022410958279401431L;
  public static final String TAG_NAME = "noembed";
  
  HtmlNoEmbed(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlNoEmbed
 * 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 HtmlTableColumn
  extends HtmlElement
{
  private static final long serialVersionUID = 1171825103356965818L;
  public static final String TAG_NAME = "col";
  
  HtmlTableColumn(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getSpanAttribute()
  {
    return getAttribute("span");
  }
  
  public final String getWidthAttribute()
  {
    return getAttribute("width");
  }
  
  public final String getAlignAttribute()
  {
    return getAttribute("align");
  }
  
  public final String getCharAttribute()
  {
    return getAttribute("char");
  }
  
  public final String getCharoffAttribute()
  {
    return getAttribute("charoff");
  }
  
  public final String getValignAttribute()
  {
    return getAttribute("valign");
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlTableColumn
 * 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 HtmlHiddenInput
  extends HtmlInput
{
  private static final long serialVersionUID = -8139303691659609858L;
  
  HtmlHiddenInput(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public String asText()
  {
    return "";
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlHiddenInput
 * 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 HtmlButtonInput
  extends HtmlInput
{
  private static final long serialVersionUID = 6218252462789212481L;
  
  HtmlButtonInput(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public void reset() {}
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlButtonInput
 * 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 HtmlBig
  extends HtmlElement
{
  private static final long serialVersionUID = -3803513740503023495L;
  public static final String TAG_NAME = "big";
  
  HtmlBig(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.html.HtmlBig
 * 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 HtmlSpan
  extends HtmlElement
{
  private static final long serialVersionUID = -625511251623194397L;
  public static final String TAG_NAME = "span";
  
  HtmlSpan(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  protected boolean isTrimmedText()
  {
    return false;
  }
  
  protected boolean isEmptyXmlTagExpanded()
  {
    return true;
  }
}

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

import com.gargoylesoftware.htmlunit.SgmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.applets.AppletClassLoader;
import com.gargoylesoftware.htmlunit.html.applets.AppletStubImpl;
import java.applet.Applet;
import java.io.IOException;
import java.net.URL;
import java.util.Map;

public class HtmlApplet
  extends HtmlElement
{
  private static final long serialVersionUID = -2868018454095564791L;
  public static final String TAG_NAME = "applet";
  private boolean downloaded_;
  private WebResponse appletWebResponse_;
  private Applet applet_;
  private AppletClassLoader appletClassLoader_;
  
  HtmlApplet(String namespaceURI, String qualifiedName, SgmlPage page, Map<String, DomAttr> attributes)
  {
    super(namespaceURI, qualifiedName, page, attributes);
  }
  
  public final String getCodebaseAttribute()
  {
    return getAttribute("codebase");
  }
  
  public final String getArchiveAttribute()
  {
    return getAttribute("archive");
  }
  
  public final String getCodeAttribute()
  {
    return getAttribute("code");
  }
  
  public final String getObjectAttribute()
  {
    return getAttribute("object");
  }
  
  public final String getAltAttribute()
  {
    return getAttribute("alt");
  }
  
  public final String getNameAttribute()
  {
    return getAttribute("name");
  }
  
  public final String getWidthAttribute()
  {
    return getAttribute("width");
  }
  
  public final String getHeightAttribute()
  {
    return getAttribute("height");
  }
  
  public final String getAlignAttribute()
  {
    return getAttribute("align");
  }
  
  public final String getHspaceAttribute()
  {
    return getAttribute("hspace");
  }
  
  public final String getVspaceAttribute()
  {
    return getAttribute("vspace");
  }
  
  public Applet getApplet()
    throws IOException
  {
    downloadContentIfNeeded();
    return applet_;
  }
  
  private void downloadContentIfNeeded()
    throws IOException
  {
    if (!downloaded_)
    {
      HtmlPage page = (HtmlPage)getPage();
      WebClient webclient = page.getWebClient();
      
      String src = getArchiveAttribute();
      URL url = p
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