View Javadoc
1   /*
2    * Copyright (c) 2002-2025 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   * A JavaScript object for {@code XMLHttpRequestEventTarget}.
28   *
29   * @author Ahmed Ashour
30   * @author Ronald Brill
31   * @author Thorsten Wendelmuth
32   * @author Atsushi Nakagawa
33   */
34  @JsxClass
35  public class XMLHttpRequestEventTarget extends EventTarget {
36  
37      /**
38       * JavaScript constructor.
39       */
40      @Override
41      @JsxConstructor
42      public void jsConstructor() {
43          throw JavaScriptEngine.typeErrorIllegalConstructor();
44      }
45  
46      /**
47       * Returns the event handler that fires on load.
48       * @return the event handler that fires on load
49       */
50      @JsxGetter
51      public Function getOnload() {
52          return getEventHandler(Event.TYPE_LOAD);
53      }
54  
55      /**
56       * Sets the event handler that fires on load.
57       * @param loadHandler the event handler that fires on load
58       */
59      @JsxSetter
60      public void setOnload(final Function loadHandler) {
61          setEventHandler(Event.TYPE_LOAD, loadHandler);
62      }
63  
64      /**
65       * Returns the event handler that fires on error.
66       * @return the event handler that fires on error
67       */
68      @JsxGetter
69      public Function getOnerror() {
70          return getEventHandler(Event.TYPE_ERROR);
71      }
72  
73      /**
74       * Sets the event handler that fires on error.
75       * @param errorHandler the event handler that fires on error
76       */
77      @JsxSetter
78      public void setOnerror(final Function errorHandler) {
79          setEventHandler(Event.TYPE_ERROR, errorHandler);
80      }
81  
82      /**
83       * Returns the event handler that fires on load start.
84       * @return the event handler that fires on load start
85       */
86      @JsxGetter
87      public Function getOnloadstart() {
88          return getEventHandler(Event.TYPE_LOAD_START);
89      }
90  
91      /**
92       * Sets the event handler that fires on load start.
93       * @param loadstartHandler the event handler that fires on load start
94       */
95      @JsxSetter
96      public void setOnloadstart(final Function loadstartHandler) {
97          setEventHandler(Event.TYPE_LOAD_START, loadstartHandler);
98      }
99  
100     /**
101      * Returns the event handler that fires on load end.
102      * @return the event handler that fires on load end
103      */
104     @JsxGetter
105     public Function getOnloadend() {
106         return getEventHandler(Event.TYPE_LOAD_END);
107     }
108 
109     /**
110      * Sets the event handler that fires on load end.
111      * @param loadendHandler the event handler that fires on load end
112      */
113     @JsxSetter
114     public void setOnloadend(final Function loadendHandler) {
115         setEventHandler(Event.TYPE_LOAD_END, loadendHandler);
116     }
117 
118     /**
119      * Returns the event handler that fires on progress.
120      * @return the event handler that fires on progress
121      */
122     @JsxGetter
123     public Function getOnprogress() {
124         return getEventHandler(Event.TYPE_PROGRESS);
125     }
126 
127     /**
128      * Sets the event handler that fires on progress.
129      * @param progressHandler the event handler that fires on progress
130      */
131     @JsxSetter
132     public void setOnprogress(final Function progressHandler) {
133         setEventHandler(Event.TYPE_PROGRESS, progressHandler);
134     }
135 
136     /**
137      * Returns the event handler that fires on timeout.
138      * @return the event handler that fires on timeout
139      */
140     @JsxGetter
141     public Function getOntimeout() {
142         return getEventHandler(Event.TYPE_TIMEOUT);
143     }
144 
145     /**
146      * Sets the event handler that fires on timeout.
147      * @param timeoutHandler the event handler that fires on timeout
148      */
149     @JsxSetter
150     public void setOntimeout(final Function timeoutHandler) {
151         setEventHandler(Event.TYPE_TIMEOUT, timeoutHandler);
152     }
153 
154     /**
155      * Returns the event handler that fires on ready state change.
156      * @return the event handler that fires on ready state change
157      */
158     public Function getOnreadystatechange() {
159         return getEventHandler(Event.TYPE_READY_STATE_CHANGE);
160     }
161 
162     /**
163      * Sets the event handler that fires on ready state change.
164      * @param readyStateChangeHandler the event handler that fires on ready state change
165      */
166     public void setOnreadystatechange(final Function readyStateChangeHandler) {
167         setEventHandler(Event.TYPE_READY_STATE_CHANGE, readyStateChangeHandler);
168     }
169 
170     /**
171      * Returns the event handler that fires on abort.
172      * @return the event handler that fires on abort
173      */
174     @JsxGetter
175     public Function getOnabort() {
176         return getEventHandler(Event.TYPE_ABORT);
177     }
178 
179     /**
180      * Sets the event handler that fires on abort.
181      * @param abortHandler the event handler that fires on abort
182      */
183     @JsxSetter
184     public void setOnabort(final Function abortHandler) {
185         setEventHandler(Event.TYPE_ABORT, abortHandler);
186     }
187 }