htmlunit-2.7

    }
    finally
    {
      ScriptRuntime.setRegExpProxy(cx, this);
    }
  }
  
  public Object compileRegExp(Context cx, String source, String flags)
  {
    try
    {
      return wrapped_.compileRegExp(cx, source, flags);
    }
    catch (Exception e)
    {
      LOG.warn("compileRegExp() threw for >" + source + "<, flags: >" + flags + "<. " + "Replacing with a '####shouldNotFindAnything###'");
    }
    return wrapped_.compileRegExp(cx, "####shouldNotFindAnything###", "");
  }
  
  public int find_split(Context cx, Scriptable scope, String target, String separator, Scriptable re, int[] ip, int[] matchlen, boolean[] matched, String[][] parensp)
  {
    return wrapped_.find_split(cx, scope, target, separator, re, ip, matchlen, matched, parensp);
  }
  
  public boolean isRegExp(Scriptable obj)
  {
    return wrapped_.isRegExp(obj);
  }
  
  public Scriptable wrapRegExp(Context cx, Scriptable scope, Object compiled)
  {
    return wrapped_.wrapRegExp(cx, scope, compiled);
  }
  
  private static class RegExpData
  {
    private final String jsSource_;
    private final String jsFlags_;
    
    RegExpData(NativeRegExp re)
    {
      String str = re.toString();
      jsSource_ = StringUtils.substringBeforeLast(str.substring(1), "/");
      jsFlags_ = StringUtils.substringAfterLast(str, "/");
    }
    
    public RegExpData(String string)
    {
      jsSource_ = string;
      jsFlags_ = "";
    }
    
    public int getJavaFlags()
    {
      int flags = 0;
      if (jsFlags_.contains("i")) {
        flags |= 0x2;
      }
      if (jsFlags_.contains("m")) {
        flags |= 0x8;
      }
      return flags;
    }
    
    public String getJavaPattern()
    {
      return HtmlUnitRegExpProxy.jsRegExpToJavaRegExp(jsSource_);
    }
    
    boolean hasFlag(char c)
    {
      return jsFlags_.indexOf(c) != -1;
    }
  }
  
  static String jsRegExpToJavaRegExp(String re)
  {
    re = re.replaceAll("\\[\\^\\\\\\d\\]", ".");
    re = re.replaceAll("\\[([^\\]]*)\\\\b([^\\]]*)\\]", "[$1\\\\cH$2]");
    re = re.replaceAll("(?<!\\\\)\\[([^((?<!\\\\)\\[)\\]]*)\\[", "[$1\\\\[");
    
    re = re.replaceAll("(?<!\\\\)\\[([^\\]]*)(?<!\\\\)\\\\\\d", "[$1");
    
    re = re.replaceAll("(?<!\\\\)\\\\([ACE-RT-VX-Zaeg-mpquyz])", "$1");
    
    re = escapeJSCurly(re);
    return re;
  }
  
  static String escapeJSCurly(String re)
  {
    re = re.replaceAll("(?<!\\\\)\\{(?!\\d)", "\\\\{");
    re = re.replaceAll("(?<!(\\d,?|\\\\))\\}", "\\\\}");
    return re;
  }
}

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

import java.lang.reflect.Method;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Function;
import net.sourceforge.htmlunit.corejs.javascript.FunctionObject;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import org.apache.commons.lang.ArrayUtils;

public class MethodWrapper
  extends ScriptableObject
  implements Function
{
  private static final long serialVersionUID = 6106771000496895783L;
  private final Class<?> clazz_;
  private final Method method_;
  private final int[] jsTypeTags_;
  
  MethodWrapper(String methodName, Class<?> clazz)
    throws NoSuchMethodException
  {
    this(methodName, clazz, ArrayUtils.EMPTY_CLASS_ARRAY);
  }
  
  MethodWrapper(String methodName, Class<?> clazz, Class<?>[] parameterTypes)
    throws NoSuchMethodException
  {
    clazz_ = clazz;
    method_ = clazz.getMethod(methodName, parameterTypes);
    jsTypeTags_ = new int[parameterTypes.length];
    int i = 0;
    for (Class<?> klass : parameterTypes) {
      jsTypeTags_[(i++)] = FunctionObject.getTypeTag(klass);
    }
  }
  
  public String getClassName()
  {
    return "function " + method_.getName();
  }
  
  public Object call(Context context, Scriptable scope, Scriptable thisObj, Object[] args)
  {
    Object javaResp;
    if ((thisObj instanceof ScriptableWrapper))
    {
      ScriptableWrapper wrapper = (ScriptableWrapper)thisObj;
      Object wrappedObject = wrapper.getWrappedObject();
      if (clazz_.isInstance(wrappedObject))
      {
        Object[] javaArgs = convertJSArgsToJavaArgs(context, scope, args);
        try
        {
          javaResp = method_.invoke(wrappedObject, javaArgs);
        }
        catch (Exception e)
        {
          Object javaResp;
          throw Context.reportRuntimeError("Exception calling wrapped function " + method_.getName() + ": " + e.getMessage());
        }
      }
      else
      {
        throw buildInvalidCallException(thisObj);
      }
    }
    else
    {
      throw buildInvalidCallException(thisObj);
    }
    Object javaResp;
    Object jsResp = Context.javaToJS(javaResp, ScriptableObject.getTopLevelScope(scope));
    return jsResp;
  }
  
  private RuntimeException buildInvalidCallException(Scriptable thisObj)
  {
    return Context.reportRuntimeError("Function " + method_.getName() + " called on incompatible object: " + thisObj);
  }
  
  Object[] convertJSArgsToJavaArgs(Context context, Scriptable scope, Object[] jsArgs)
  {
    if (jsArgs.length != jsTypeTags_.length) {
      throw Context.reportRuntimeError("Bad number of parameters for function " + method_.getName() + ": expected " + jsTypeTags_.length + " got " + jsArgs.length);
    }
    Object[] javaArgs = new Object[jsArgs.length];
    int i = 0;
    for (Object object : jsArgs) {
      javaArgs[i] = FunctionObject.convertArg(context, scope, object, jsTypeTags_[(i++)]);
    }
    return javaArgs;
  }
  
  public Scriptable construct(Context context, Scriptable scope, Object[] args)
  {
    throw Context.reportRuntimeError("Function " + method_.getName() + " can't be used as a constructor");
  }
}

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

import java.io.Serializable;
import net.sourceforge.htmlunit.corejs.javascript.ErrorReporter;
import net.sourceforge.htmlunit.corejs.javascript.EvaluatorException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StrictErrorReporter
  implements ErrorReporter, Serializable
{
  private static final long serialVersionUID = 2165290829783324770L;
  private static final Log LOG = LogFactory.getLog(StrictErrorReporter.class);
  
  public void warning(String message, String sourceName, int line, String lineSource, int lineOffset)
  {
    LOG.warn(format("warning", message, sourceName, line, lineSource, lineOffset));
  }
  
  public void error(String message, String sourceName, int line, String lineSource, int lineOffset)
  {
    LOG.error(format("error", message, sourceName, line, lineSource, lineOffset));
    throw new EvaluatorException(message, sourceName, line, lineSource, lineOffset);
  }
  
  public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset)
  {
    LOG.error(format("runtimeError", message, sourceName, line, lineSource, lineOffset));
    return new EvaluatorException(message, sourceName, line, lineSource, lineOffset);
  }
  
  private String format(String prefix, String message, String sourceName, int line, String lineSource, int lineOffset)
  {
    return prefix + ": message=[" + message + "] sourceName=[" + sourceName + "] line=[" + line + "] lineSource=[" + lineSource + "] lineOffset=[" + lineOffset + "]";
  }
}

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

import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.debug.DebugFrame;
import net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableScript;
import net.sourceforge.htmlunit.corejs.javascript.debug.Debugger;

public class DebuggerAdapter
  implements Debugger
{
  public void handleCompilationDone(Context cx, DebuggableScript functionOrScript, String source) {}
  
  public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript)
  {
    return new DebugFrameAdapter();
  }
}

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

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.FunctionObject;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.ClassUtils;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;

public class ScriptableWrapper
  extends ScriptableObject
{
  private static final long serialVersionUID = 1736378450382368760L;
  private final Map<String, Method> properties_ = new HashMap();
  private Method getByIndexMethod_;
  private final Object javaObject_;
  private final String jsClassName_;
  private Method getByNameFallback_;
  
  public ScriptableWrapper(Scriptable scope, Object javaObject, Class<?> staticType)
  {
    javaObject_ = javaObject;
    setParentScope(scope);
    if ((NodeList.class.equals(staticType)) || (NamedNodeMap.class.equals(staticType))) {
      try
      {
        jsClassName_ = ClassUtils.getShortClassName(staticType);
        
        Method length = javaObject.getClass().getMethod("getLength", ArrayUtils.EMPTY_CLASS_ARRAY);
        
        properties_.put("length", length);
        
        Method item = javaObject.getClass().getMethod("item", new Class[] { Integer.TYPE });
        
        defineProperty("item", new MethodWrapper("item", staticType, new Class[] { Integer.TYPE }), 0);
        
        Method toString = getClass().getMethod("jsToString", ArrayUtils.EMPTY_CLASS_ARRAY);
        
        defineProperty("toString", new FunctionObject("toString", toString, this), 0);
        
        getByIndexMethod_ = item;
        if (NamedNodeMap.class.equals(staticType))
        {
          Method getNamedItem = javaObject.getClass().getMethod("getNamedItem", new Class[] { String.class });
          
          defineProperty("getNamedItem", new MethodWrapper("getNamedItem", staticType, new Class[] { String.class }), 0);
          
          getByNameFallback_ = getNamedItem;
        }
      }
      catch (Exception e)
      {
        throw new RuntimeException("Method not found", e);
      }
    } else {
      throw new RuntimeException("Unknown type: " + staticType.getName());
    }
  }
  
  public Object get(String name, Scriptable start)
  {
    Method propertyGetter = (Method)properties_.get(name);
    Object response;
    Object response;
    if (propertyGetter != null)
    {
      response = invoke(propertyGetter);
    }
    else
    {
      Object fromSuper = super.get(name, start);
      Object response;
      if (fromSuper != Scriptable.NOT_FOUND)
      {
        response = fromSuper;
      }
      else
      {
        Object byName = invoke(getByNameFallback_, new Object[] { name });
        Object response;
        if (byName != null) {
          response = byName;
        } else {
          response = Scriptable.NOT_FOUND;
        }
      }
    }
    return Context.javaToJS(response, ScriptableObject.getTopLevelScope(start));
  }
  
  public boolean has(String name, Scriptable start)
  {
    return (properties_.containsKey(name)) || (super.has(name, start));
  }
  
  protected Object invoke(Method method)
  {
    return invoke(method, ArrayUtils.EMPTY_OBJECT_ARRAY);
  }
  
  protected Object invoke(Method method, Object[] args)
  {
    try
    {
      return method.invoke(javaObject_, args);
    }
    catch (Exception e)
    {
      throw new RuntimeException("Invocation of method on java object failed", e);
    }
  }
  
  public Object get(int index, Scriptable start)
  {
    if (getByIndexMethod_ != null)
    {
      Object byIndex = invoke(getByIndexMethod_, new Object[] { new Integer(index) });
      
      return Context.javaToJS(byIndex, ScriptableObject.getTopLevelScope(start));
    }
    return super.get(index, start);
  }
  
  public Object getDefaultValue(Class<?> hint)
  {
    if ((String.class.equals(hint)) || (hint == null)) {
      return jsToString();
    }
    return super.getDefaultValue(hint);
  }
  
  public String jsToString()
  {
    return "[object " + getClassName() + "]";
  }
  
  public String getClassName()
  {
    return jsClassName_;
  }
  
  public Object getWrappedObject()
  {
    return javaObject_;
  }
}

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

import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import net.sourceforge.htmlunit.corejs.javascript.FunctionObject;
import net.sourceforge.htmlunit.corejs.javascript.NativeFunction;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import net.sourceforge.htmlunit.corejs.javascript.Undefined;

public final class ProxyAutoConfig
{
  public static String evaluate(String content, URL url)
  {
    Context cx = ContextFactory.getGlobal().enterContext();
    try
    {
      ProxyAutoConfig config = new ProxyAutoConfig();
      Scriptable scope = cx.initStandardObjects();
      
      config.defineMethod("isPlainHostName", scope);
      config.defineMethod("dnsDomainIs", scope);
      config.defineMethod("localHostOrDomainIs", scope);
      config.defineMethod("isResolvable", scope);
      config.defineMethod("isInNet", scope);
      config.defineMethod("dnsResolve", scope);
      config.defineMethod("myIpAddress", scope);
      config.defineMethod("dnsDomainLevels", scope);
      config.defineMethod("shExpMatch", scope);
      config.defineMethod("weekdayRange", scope);
      config.defineMethod("dateRange", scope);
      config.defineMethod("timeRange", scope);
      
      cx.evaluateString(scope, "var ProxyConfig = function() {}; ProxyConfig.bindings = {}", "<init>", 1, null);
      cx.evaluateString(scope, content, "<Proxy Auto-Config>", 1, null);
      Object[] functionArgs = { url.toExternalForm(), url.getHost() };
      Object fObj = scope.get("FindProxyForURL", scope);
      
      NativeFunction f = (NativeFunction)fObj;
      Object result = f.call(cx, scope, scope, functionArgs);
      return Context.toString(result);
    }
    finally
    {
      Context.exit();
    }
  }
  
  private void defineMethod(String methodName, Scriptable scope)
  {
    for (Method method : getClass().getMethods()) {
      if (method.getName().equals(methodName))
      {
        FunctionObject functionObject = new FunctionObject(methodName, method, scope);
        ((ScriptableObject)scope).defineProperty(methodName, functionObject, 0);
      }
    }
  }
  
  public static boolean isPlainHostName(String host)
  {
    return host.indexOf('.') == -1;
  }
  
  public static boolean dnsDomainIs(String host, String domain)
  {
    return host.endsWith(domain);
  }
  
  public static boolean localHostOrDomainIs(String host, String hostdom)
  {
    return ((host.length() > 1) && (host.equals(hostdom))) || ((host.indexOf('.') == -1) && (hostdom.startsWith(host)));
  }
  
  public static boolean isResolvable(String host)
  {
    return dnsResolve(host) != null;
  }
  
  public static boolean isInNet(String host, String pattern, String mask)
  {
    String[] hostTokens = dnsResolve(host).split("\\.");
    String[] patternTokens = pattern.split("\\.");
    String[] maskTokens = mask.split("\\.");
    for (int i = 0; i < hostTokens.length; i++) {
      if ((Integer.parseInt(maskTokens[i]) != 0) && (!hostTokens[i].equals(patternTokens[i]))) {
        return false;
      }
    }
    return true;
  }
  
  public static String dnsResolve(String host)
  {
    try
    {
      return InetAddress.getByName(host).getHostAddress();
    }
    catch (Exception e) {}
    return null;
  }
  
  public static String myIpAddress()
  {
    try
    {
      return InetAddress.getLocalHost().getHostAddress();
    }
    catch (Exception e)
    {
      throw Context.throwAsScriptRuntimeEx(e);
    }
  }
  
  public static int dnsDomainLevels(String host)
  {
    int levels = 0;
    for (int i = host.length() - 1; i >= 0; i--) {
      if (host.charAt(i) == '.') {
        levels++;
      }
    }
    return levels;
  }
  
  public static boolean shExpMatch(String str, String shexp)
  {
    String regexp = shexp.replace(".", "\\.").replace("*", ".*").replace("?", ".");
    return str.matches(regexp);
  }
  
  public static boolean weekdayRange(String wd1, Object wd2, Object gmt)
  {
    TimeZone timezone = TimeZone.getDefault();
    if (("GMT".equals(Context.toString(gmt))) || ("GMT".equals(Context.toString(wd2)))) {
      timezone = TimeZone.getTimeZone("GMT");
    }
    if ((wd2 == Undefined.instance) || ("GMT".equals(Context.toString(wd2)))) {
      wd2 = wd1;
    }
    Calendar calendar = Calendar.getInstance(timezone);
    for (int i = 0; i < 7; i++)
    {
      String day = new SimpleDateFormat("EEE").format(calendar.getTime()).toUpperCase();
      if (day.equals(wd2)) {
        return true;
      }
      if (day.equals(wd1)) {
        return i == 0;
      }
      calendar.add(7, 1);
    }
    return false;
  }
  
  public static boolean dateRange(String value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7)
  {
    Object[] values = { value1, value2, value3, value4, value5, value6, value7 };
    TimeZone timezone = TimeZone.getDefault();
    for (int length = values.length - 1; length >= 0; length--)
    {
      if (Context.toString(values[length]).equals("GMT"))
      {
        timezone = TimeZone.getTimeZone("GMT");
        break;
      }
      if (values[length] != Undefined.instance)
      {
        length++;
        break;
      }
    }
    Calendar cal1;
    Calendar cal2;
    int day1;
    int month1;
    int year1;
    int day2;
    int month2;
    int year2;
    int month1;
    int month2;
    Calendar cal1;
    Calendar cal2;
    switch (length)
    {
    case 1: 
      int day = getSmallInt(value1);
      int month = dateRange_getMonth(value1);
      int year = dateRange_getYear(value1);
      cal1 = dateRange_createCalendar(timezone, day, month, year);
      cal2 = (Calendar)cal1.clone();
      break;
    case 2: 
      day1 = getSmallInt(value1);
      month1 = dateRange_getMonth(value1);
      year1 = dateRange_getYear(value1);
      cal1 = dateRange_createCalendar(timezone, day1, month1, year1);
      day2 = getSmallInt(value2);
      month2 = dateRange_getMonth(value2);
      year2 = dateRange_getYear(value2);
      cal2 = dateRange_createCalendar(timezone, day2, month2, year2);
      break;
    case 4: 
      day1 = getSmallInt(value1);
      if (day1 != -1)
      {
        month1 = dateRange_getMonth(value2);
        day2 = getSmallInt(value3);
        month2 = dateRange_getMonth(value4);
        cal1 = dateRange_createCalendar(timezone, day1, month1, -1);
        cal2 = dateRange_createCalendar(timezone, day2, month2, -1);
      }
      else
      {
        month1 = dateRange_getMonth(value1);
        year1 = dateRange_getMonth(value2);
        month2 = getSmallInt(value3);
        year2 = dateRange_getMonth(value4);
        cal1 = dateRange_createCalendar(timezone, -1, month1, year1);
        cal2 = dateRange_createCalendar(timezone, -1, month2, year2);
      }
      break;
    case 3: 
    default: 
      day1 = getSmallInt(value1);
      month1 = dateRange_getMonth(value2);
      year1 = dateRange_getYear(value3);
      int day2 = getSmallInt(value4);
      month2 = dateRange_getMonth(value5);
      year2 = dateRange_getYear(value6);
      cal1 = dateRange_createCalendar(timezone, day1, month1, year1);
      cal2 = dateRange_createCalendar(timezone, day2, month2, year2);
    }
    Calendar today = Calendar.getInstance(timezone);
    today.set(14, 0);
    today.set(13, 0);
    cal1.set(14, 0);
    cal1.set(13, 0);
    cal2.set(14, 0);
    cal2.set(13, 0);
    return (today.equals(cal1)) || ((today.after(cal1)) && (today.before(cal2))) || (today.equals(cal2));
  }
  
  private static Calendar dateRange_createCalendar(TimeZone timezone, int day, int month, int year)
  {
    Calendar calendar = Calendar.getInstance(timezone);
    if (day != -1) {
      calendar.set(5, day);
    }
    if (month != -1) {
      calendar.set(2, month);
    }
    if (year != -1) {
      calendar.set(1, year);
    }
    return calendar;
  }
  
  private static int getSmallInt(Object object)
  {
    String s = Context.toString(object);
    if (Character.isDigit(s.charAt(0)))
    {
      int i = Integer.parseInt(s);
      if (i < 70) {
        return i;
      }
    }
    return -1;
  }
  
  private static int dateRange_getMonth(Object object)
  {
    String s = Context.toString(object);
    if (Character.isLetter(s.charAt(0))) {
      try
      {
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.setTime(new SimpleDateFormat("MMM").parse(s));
        return cal.get(2);
      }
      catch (Exception e) {}
    }
    return -1;
  }
  
  private static int dateRange_getYear(Object object)
  {
    String s = Context.toString(object);
    if (Character.isDigit(s.charAt(0)))
    {
      int i = Integer.parseInt(s);
      if (i > 1000) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean timeRange(String value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7)
  {
    Object[] values = { value1, value2, value3, value4, value5, value6, value7 };
    TimeZone timezone = TimeZone.getDefault();
    for (int length = values.length - 1; length >= 0; length--)
    {
      if (Context.toString(values[length]).equals("GMT"))
      {
        timezone = TimeZone.getTimeZone("GMT");
        break;
      }
      if (values[length] != Undefined.instance)
      {
        length++;
        break;
      }
    }
    int hour1;
    Calendar cal1;
    Calendar cal2;
    int hour2;
    int min1;
    int min2;
    switch (length)
    {
    case 1: 
      hour1 = getSmallInt(value1);
      cal1 = timeRange_createCalendar(timezone, hour1, -1, -1);
      cal2 = (Calendar)cal1.clone();
      cal2.add(11, 1);
      break;
    case 2: 
      hour1 = getSmallInt(value1);
      cal1 = timeRange_createCalendar(timezone, hour1, -1, -1);
      hour2 = getSmallInt(value2);
      cal2 = timeRange_createCalendar(timezone, hour2, -1, -1);
      break;
    case 4: 
      hour1 = getSmallInt(value1);
      min1 = getSmallInt(value2);
      hour2 = getSmallInt(value3);
      min2 = getSmallInt(value4);
      cal1 = dateRange_createCalendar(timezone, hour1, min1, -1);
      cal2 = dateRange_createCalendar(timezone, hour2, min2, -1);
      break;
    case 3: 
    default: 
      hour1 = getSmallInt(value1);
      min1 = getSmallInt(value2);
      int second1 = getSmallInt(value3);
      hour2 = getSmallInt(value4);
      min2 = getSmallInt(value5);
      int second2 = getSmallInt(value6);
      cal1 = dateRange_createCalendar(timezone, hour1, min1, second1);
      cal2 = dateRange_createCalendar(timezone, hour2, min2, second2);
    }
    Calendar now = Calendar.getInstance(timezone);
    return (now.equals(cal1)) || ((now.after(cal1)) && (now.before(cal2))) || (now.equals(cal2));
  }
  
  private static Calendar timeRange_createCalendar(TimeZone timezone, int hour, int minute, int second)
  {
    Calendar calendar = Calendar.getInstance(timezone);
    if (hour != -1) {
      calendar.set(11, hour);
    }
    if (minute != -1) {
      calendar.set(12, minute);
    }
    if (second != -1) {
      calendar.set(13, second);
    }
    return calendar;
  }
}

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

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.ScriptPreProcessor;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.ArrayUtils;

public class IEConditionalCompilationScriptPreProcessor
  implements ScriptPreProcessor
{
  private static final String CC_VARIABLE_PREFIX = "htmlunit_cc_variable_";
  private final Set<String> setVariables_ = new HashSet();
  
  public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, HtmlElement htmlElement)
  {
    int startPos = StringScriptPreProcessor.indexOf(sourceCode, "/*@cc_on", 0);
    if (startPos == -1) {
      return sourceCode;
    }
    int endPos = StringScriptPreProcessor.indexOf(sourceCode, "@*/", startPos);
    if (endPos == -1) {
      return sourceCode;
    }
    StringBuilder sb = new StringBuilder();
    if (startPos > 0) {
      sb.append(sourceCode.substring(0, startPos));
    }
    BrowserVersion browserVersion = htmlPage.getWebClient().getBrowserVersion();
    String body = sourceCode.substring(startPos + 8, endPos);
    sb.append(processConditionalCompilation(body, browserVersion));
    if (endPos < sourceCode.length() - 3)
    {
      String remaining = sourceCode.substring(endPos + 3);
      int nextStart = remaining.indexOf("/*@");
      int nextEnd = remaining.indexOf("@*/", nextStart + 3);
      while ((nextStart >= 0) && (nextEnd > 0))
      {
        sb.append(remaining.substring(0, nextStart));
        String nextBody = remaining.substring(nextStart + 3, nextEnd);
        sb.append(processConditionalCompilation(nextBody, browserVersion));
        remaining = remaining.substring(nextEnd + 3);
        nextStart = remaining.indexOf("/*@");
        nextEnd = remaining.indexOf("@*/", nextStart + 3);
      }
      sb.append(remaining);
    }
    return sb.toString();
  }
  
  private String processConditionalCompilation(String precompilationBody, BrowserVersion browserVersion)
  {
    String body = precompilationBody;
    if (body.startsWith("cc_on")) {
      body = body.substring(5);
    }
    body = body.replaceAll("/\\*@end", "");
    body = processIfs(body);
    body = replaceCompilationVariables(body, browserVersion);
    body = processSet(body);
    body = replaceCustomCompilationVariables(body);
    return body;
  }
  
  private String replaceCustomCompilationVariables(String body)
  {
    Pattern p = Pattern.compile("@\\w+|'[^']*'|\"[^\"]*\"");
    Matcher m = p.matcher(body);
    StringBuffer sb = new StringBuffer();
    while (m.find())
    {
      String match = m.group();
      if (match.startsWith("@")) {
        m.appendReplacement(sb, replaceOneCustomCompilationVariable(match));
      } else {
        m.appendReplacement(sb, match);
      }
    }
    m.appendTail(sb);
    return sb.toString();
  }
  
  private String replaceOneCustomCompilationVariable(String variable)
  {
    if (setVariables_.contains(variable)) {
      return "htmlunit_cc_variable_" + variable.substring(1);
    }
    return "NaN";
  }
  
  private String processSet(String body)
  {
    Pattern p = Pattern.compile("@set\\s+(@\\w+)(\\s*=\\s*[\\d\\.]+)");
    Matcher m = p.matcher(body);
    StringBuffer sb = new StringBuffer();
    while (m.find())
    {
      setVariables_.add(m.group(1));
      m.appendReplacement(sb, "htmlunit_cc_variable_" + m.group(1).substring(1) + m.group(2) + ";");
    }
    m.appendTail(sb);
    return sb.toString();
  }
  
  private static String processIfs(String code)
  {
    code = code.replaceAll("@if\\s*\\(([^\\)]+)\\)", "if ($1) {");
    code = code.replaceAll("@elif\\s*\\(([^\\)]+)\\)", "} else if ($1) {");
    code = code.replaceAll("@else", "} else {");
    code = code.replaceAll("@end", "}");
    return code;
  }
  
  String replaceCompilationVariables(String source, BrowserVersion browserVersion)
  {
    Pattern p = Pattern.compile("(@_\\w+)|'[^']*'|\"[^\"]*\"");
    Matcher m = p.matcher(source);
    StringBuffer sb = new StringBuffer();
    while (m.find())
    {
      String match = m.group();
      if (match.startsWith("@")) {
        m.appendReplacement(sb, replaceOneVariable(match, browserVersion));
      } else {
        m.appendReplacement(sb, match);
      }
    }
    m.appendTail(sb);
    return sb.toString();
  }
  
  private static String replaceOneVariable(String variable, BrowserVersion browserVersion)
  {
    String[] varNaN = { "@_win16", "@_mac", "@_alpha", "@_mc680x0", "@_PowerPC", "@_debug", "@_fast" };
    String[] varTrue = { "@_win32", "@_x86", "@_jscript" };
    if (ArrayUtils.contains(varTrue, variable)) {
      return "true";
    }
    if ("@_jscript_version".equals(variable))
    {
      if (browserVersion.getBrowserVersionNumeric() <= 6.0F) {
        return "5.6";
      }
      if (browserVersion.getBrowserVersionNumeric() == 7.0F) {
        return "5.7";
      }
      return "5.8";
    }
    if ("@_jscript_build".equals(variable))
    {
      if (browserVersion.getBrowserVersionNumeric() <= 6.0F) {
        return "6626";
      }
      if (browserVersion.getBrowserVersionNumeric() == 7.0F) {
        return "5730";
      }
      return "18702";
    }
    if (ArrayUtils.contains(varNaN, variable)) {
      return "NaN";
    }
    return variable;
  }
}

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

public class TimeoutError
  extends Error
{
  private static final long serialVersionUID = 2637882768887747478L;
  
  TimeoutError(long allowedTimeout, long executionTime)
  {
    super("Javascript execution takes too long (allowed: " + allowedTimeout + ", already elapsed: " + executionTime + ")");
  }
}

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

import java.io.Serializable;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.WrapFactory;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;

public class HtmlUnitWrapFactory
  extends WrapFactory
  implements Serializable
{
  private static final long serialVersionUID = 1779982280511278636L;
  
  public HtmlUnitWrapFactory()
  {
    setJavaPrimitiveWrap(false);
  }
  
  public Scriptable wrapAsJavaObject(Context context, Scriptable scope, Object javaObject, Class<?> staticType)
  {
    Scriptable resp;
    Scriptable resp;
    if ((NodeList.class.equals(staticType)) || (NamedNodeMap.class.equals(staticType))) {
      resp = new ScriptableWrapper(scope, javaObject, staticType);
    } else {
      resp = super.wrapAsJavaObject(context, scope, javaObject, staticType);
    }
    return resp;
  }
}

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

import com.gargoylesoftware.htmlunit.ScriptPreProcessor;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IEWeirdSyntaxScriptPreProcessor
  implements ScriptPreProcessor
{
  private static final IEWeirdSyntaxScriptPreProcessor instance_ = new IEWeirdSyntaxScriptPreProcessor();
  private static final Pattern patternFinally_ = Pattern.compile("(\\}(?:\\s*(?://.*\\n)?)*);((?:\\s*(?://.*\\n)?)*finally)");
  private static final Pattern patternCatch_ = Pattern.compile("(\\}(?:\\s*(?://.*\\n)?)*);((?:\\s*(?://.*\\n)?)*catch)");
  
  public static IEWeirdSyntaxScriptPreProcessor getInstance()
  {
    return instance_;
  }
  
  public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, HtmlElement htmlElement)
  {
    if (sourceCode.contains("catch")) {
      sourceCode = patternCatch_.matcher(sourceCode).replaceAll("$1 $2");
    }
    if (sourceCode.contains("finally")) {
      sourceCode = patternFinally_.matcher(sourceCode).replaceAll("$1 $2");
    }
    return sourceCode;
  }
}

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

import java.lang.reflect.Method;
import net.sourceforge.htmlunit.corejs.javascript.Callable;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Function;
import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;

public abstract class SimpleScriptableProxy
  extends ScriptableObject
  implements ScriptableWithFallbackGetter, Function
{
  private static final long serialVersionUID = -3836061858668746684L;
  
  public abstract SimpleScriptable getWrappedScriptable();
  
  public void delete(int index)
  {
    getWrappedScriptable().delete(index);
  }
  
  public void delete(String name)
  {
    getWrappedScriptable().delete(name);
  }
  
  public Object get(int index, Scriptable start)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    return getWrappedScriptable().get(index, start);
  }
  
  public Object get(String name, Scriptable start)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    return getWrappedScriptable().get(name, start);
  }
  
  public Object getWithFallback(String name)
  {
    SimpleScriptable wrapped = getWrappedScriptable();
    if ((wrapped instanceof ScriptableWithFallbackGetter)) {
      return ((ScriptableWithFallbackGetter)wrapped).getWithFallback(name);
    }
    return NOT_FOUND;
  }
  
  public String getClassName()
  {
    return getWrappedScriptable().getClassName();
  }
  
  public Object getDefaultValue(Class<?> hint)
  {
    return getWrappedScriptable().getDefaultValue(hint);
  }
  
  public Object[] getIds()
  {
    return getWrappedScriptable().getIds();
  }
  
  public Scriptable getParentScope()
  {
    return getWrappedScriptable().getParentScope();
  }
  
  public Scriptable getPrototype()
  {
    return getWrappedScriptable().getPrototype();
  }
  
  public boolean has(int index, Scriptable start)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    return getWrappedScriptable().has(index, start);
  }
  
  public boolean has(String name, Scriptable start)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    return getWrappedScriptable().has(name, start);
  }
  
  public boolean hasInstance(Scriptable instance)
  {
    if ((instance instanceof SimpleScriptableProxy)) {
      instance = ((SimpleScriptableProxy)instance).getWrappedScriptable();
    }
    return getWrappedScriptable().hasInstance(instance);
  }
  
  public void put(int index, Scriptable start, Object value)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    getWrappedScriptable().put(index, start, value);
  }
  
  public void put(String name, Scriptable start, Object value)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    getWrappedScriptable().put(name, start, value);
  }
  
  public void setParentScope(Scriptable parent)
  {
    getWrappedScriptable().setParentScope(parent);
  }
  
  public void setPrototype(Scriptable prototype)
  {
    getWrappedScriptable().setPrototype(prototype);
  }
  
  public boolean avoidObjectDetection()
  {
    return getWrappedScriptable().avoidObjectDetection();
  }
  
  public void defineConst(String name, Scriptable start)
  {
    if ((start instanceof SimpleScriptableProxy)) {
      start = ((SimpleScriptableProxy)start).getWrappedScriptable();
    }
    getWrappedScriptable().defineConst(name, start);
  }
  
  public void defineFunctionProperties(String[] names, Class<?> clazz, int attributes)
  {
    getWrappedScriptable().defineFunctionProperties(names, clazz, attributes);
  }
  
  public void defineProperty(String propertyName, Class<?> clazz, int attributes)
  {
    getWrappedScriptable().defineProperty(propertyName, clazz, attributes);
  }
  
  public void defineProperty(String propertyName, Object value, int attributes)
  {
    getWrappedScriptable().defineProperty(propertyName, value, attributes);
  }
  
  public void defineProperty(String propertyName, Object delegateTo, Method getter, Method setter, int attributes)
  {
    getWrappedScriptable().defineProperty(propertyName, delegateTo, getter, setter, attributes);
  }
  
  public boolean equals(Object obj)
  {
    return getWrappedScriptable().equals(obj);
  }
  
  public Object[] getAllIds()
  {
    return getWrappedScriptable().getAllIds();
  }
  
  public int getAttributes(int index)
  {
    return getWrappedScriptable().getAttributes(index);
  }
  
  public int getAttributes(String name)
  {
    return getWrappedScriptable().getAttributes(name);
  }
  
  public Object getGetterOrSetter(String name, int index, boolean isSetter)
  {
    return getWrappedScriptable().getGetterOrSetter(name, index, isSetter);
  }
  
  public int hashCode()
  {
    return getWrappedScriptable().hashCode();
  }
  
  public boolean isConst(String name)
  {
    return getWrappedScriptable().isConst(name);
  }
  
  public void putConst(String name, Scriptable start, Object value)
  {
    getWrappedScriptable().putConst(name, start, value);
  }
  
  public synchronized void sealObject()
  {
    getWrappedScriptable().sealObject();
  }
  
  public void setAttributes(int index, int attributes)
  {
    getWrappedScriptable().setAttributes(index, attributes);
  }
  
  @Deprecated
  public void setAttributes(int index, Scriptable start, int attributes)
  {
    getWrappedScriptable().setAttributes(index, start, attributes);
  }
  
  public void setAttributes(String name, int attributes)
  {
    getWrappedScriptable().setAttributes(name, attributes);
  }
  
  public void setGetterOrSetter(String name, int index, Callable getterOrSetter, boolean isSetter)
  {
    getWrappedScriptable().setGetterOrSetter(name, index, getterOrSetter, isSetter);
  }
  
  public String toString()
  {
    return getWrappedScriptable().toString();
  }
  
  protected Object equivalentValues(Object value)
  {
    return Boolean.valueOf(ScriptRuntime.eq(getWrappedScriptable(), value));
  }
  
  public Object call(Context cx, Scriptable scope, Scriptable thisObj, Obje
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