View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.xml;
16  
17  import org.htmlunit.corejs.javascript.Function;
18  import org.htmlunit.javascript.JavaScriptEngine;
19  import org.htmlunit.javascript.configuration.JsxClass;
20  import org.htmlunit.javascript.configuration.JsxConstructor;
21  import org.htmlunit.javascript.configuration.JsxGetter;
22  import org.htmlunit.javascript.configuration.JsxSetter;
23  import org.htmlunit.javascript.host.event.Event;
24  import org.htmlunit.javascript.host.event.EventTarget;
25  
26  /**
27   * JavaScript host object for {@code XMLHttpRequestEventTarget}.
28   *
29   * @author Ahmed Ashour
30   * @author Ronald Brill
31   * @author Thorsten Wendelmuth
32   * @author Atsushi Nakagawa
33   *
34   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget">MDN Documentation</a>
35   */
36  @JsxClass
37  public class XMLHttpRequestEventTarget extends EventTarget {
38  
39      /**
40       * Creates an instance of this object.
41       */
42      @Override
43      @JsxConstructor
44      public void jsConstructor() {
45          throw JavaScriptEngine.typeErrorIllegalConstructor();
46      }
47  
48      /**
49       * Returns the event handler that fires on load.
50       *
51       * @return the event handler that fires on load
52       */
53      @JsxGetter
54      public Function getOnload() {
55          return getEventHandler(Event.TYPE_LOAD);
56      }
57  
58      /**
59       * Sets the event handler that fires on load.
60       *
61       * @param loadHandler the event handler that fires on load
62       */
63      @JsxSetter
64      public void setOnload(final Function loadHandler) {
65          setEventHandler(Event.TYPE_LOAD, loadHandler);
66      }
67  
68      /**
69       * Returns the event handler that fires on error.
70       *
71       * @return the event handler that fires on error
72       */
73      @JsxGetter
74      public Function getOnerror() {
75          return getEventHandler(Event.TYPE_ERROR);
76      }
77  
78      /**
79       * Sets the event handler that fires on error.
80       *
81       * @param errorHandler the event handler that fires on error
82       */
83      @JsxSetter
84      public void setOnerror(final Function errorHandler) {
85          setEventHandler(Event.TYPE_ERROR, errorHandler);
86      }
87  
88      /**
89       * Returns the event handler that fires on load start.
90       *
91       * @return the event handler that fires on load start
92       */
93      @JsxGetter
94      public Function getOnloadstart() {
95          return getEventHandler(Event.TYPE_LOAD_START);
96      }
97  
98      /**
99       * Sets the event handler that fires on load start.
100      *
101      * @param loadstartHandler the event handler that fires on load start
102      */
103     @JsxSetter
104     public void setOnloadstart(final Function loadstartHandler) {
105         setEventHandler(Event.TYPE_LOAD_START, loadstartHandler);
106     }
107 
108     /**
109      * Returns the event handler that fires on load end.
110      *
111      * @return the event handler that fires on load end
112      */
113     @JsxGetter
114     public Function getOnloadend() {
115         return getEventHandler(Event.TYPE_LOAD_END);
116     }
117 
118     /**
119      * Sets the event handler that fires on load end.
120      *
121      * @param loadendHandler the event handler that fires on load end
122      */
123     @JsxSetter
124     public void setOnloadend(final Function loadendHandler) {
125         setEventHandler(Event.TYPE_LOAD_END, loadendHandler);
126     }
127 
128     /**
129      * Returns the event handler that fires on progress.
130      *
131      * @return the event handler that fires on progress
132      */
133     @JsxGetter
134     public Function getOnprogress() {
135         return getEventHandler(Event.TYPE_PROGRESS);
136     }
137 
138     /**
139      * Sets the event handler that fires on progress.
140      *
141      * @param progressHandler the event handler that fires on progress
142      */
143     @JsxSetter
144     public void setOnprogress(final Function progressHandler) {
145         setEventHandler(Event.TYPE_PROGRESS, progressHandler);
146     }
147 
148     /**
149      * Returns the event handler that fires on timeout.
150      *
151      * @return the event handler that fires on timeout
152      */
153     @JsxGetter
154     public Function getOntimeout() {
155         return getEventHandler(Event.TYPE_TIMEOUT);
156     }
157 
158     /**
159      * Sets the event handler that fires on timeout.
160      *
161      * @param timeoutHandler the event handler that fires on timeout
162      */
163     @JsxSetter
164     public void setOntimeout(final Function timeoutHandler) {
165         setEventHandler(Event.TYPE_TIMEOUT, timeoutHandler);
166     }
167 
168     /**
169      * Returns the event handler that fires on ready state change.
170      *
171      * @return the event handler that fires on ready state change
172      */
173     public Function getOnreadystatechange() {
174         return getEventHandler(Event.TYPE_READY_STATE_CHANGE);
175     }
176 
177     /**
178      * Sets the event handler that fires on ready state change.
179      *
180      * @param readyStateChangeHandler the event handler that fires on ready state change
181      */
182     public void setOnreadystatechange(final Function readyStateChangeHandler) {
183         setEventHandler(Event.TYPE_READY_STATE_CHANGE, readyStateChangeHandler);
184     }
185 
186     /**
187      * Returns the event handler that fires on abort.
188      *
189      * @return the event handler that fires on abort
190      */
191     @JsxGetter
192     public Function getOnabort() {
193         return getEventHandler(Event.TYPE_ABORT);
194     }
195 
196     /**
197      * Sets the event handler that fires on abort.
198      *
199      * @param abortHandler the event handler that fires on abort
200      */
201     @JsxSetter
202     public void setOnabort(final Function abortHandler) {
203         setEventHandler(Event.TYPE_ABORT, abortHandler);
204     }
205 }