001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js.user;
021 
022 import js.*;
023 import js.core.*;
024 
025 /**
026  * <p>An <b>opaque</b> class representing JavaScript client-side objects of the global 
027  * {@link JsClient#DOMParser} class.</p>
028  * <p>A {@link JsDOMParser} object is used to parse XML text and return an XML {@link JsDocument} 
029  * node. To use a {@link JsDOMParser} object, instantiate one with the no-argument 
030  * {@link JsClient#DOMParser} class and then call its 
031  * {@link JsDOMParser#parseFromString(String, String)} method:
032  * <pre>JsDocument doc = Js.g().DOMParser.create().parseFromString(text);</pre>
033  * </p>
034  * <p>Note that a {@link JsXMLHttpRequest} object can also parse XML documents. See the 
035  * {@link JsXMLHttpRequest#responseXML} property.</p>
036  * <p>IE does not support this class. Instead, it supports XML parsing with 
037  * {@link JsDocument#loadXML(String)}.</p>
038  *
039  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
040  *
041  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
042  * generated into the target codes. Re-compilers must exit with error on the operations of
043  * accessing that kind of class objects.
044  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
045  * and <tt>instanceof</tt> to it always <tt>true</tt>.
046  */
047 public class JsDOMParser extends JsClient.DOMParser.Prototype
048 {
049     /**
050      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
051      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
052      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
053      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
054      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
055      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
056      * either circumstance, the field names must be exactly same as the member names, as 
057      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
058      * based on the field names.</p>
059      *
060      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
061      * 
062      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
063      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
064      * of class objects.
065      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
066      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
067      * <pre>q.m</pre>
068      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
069      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
070      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
071      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
072      * <pre>m</pre>
073      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
074      * error on the access to <b>opaque</b> fields declared by this class under any other 
075      * circumstances.
076      */
077     public static class Member extends JsClient.DOMParser.Prototype.Member
078     {
079         /**
080          * <p>Internally constructs a member based on a qualifying member.</p>
081          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
082          * or <b>internal</b> classes or class members.</p>
083          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
084          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
085          * declared in the declaring class of this constructor itself or its subclasses. 
086          * Under this circumstance, the field names must be exactly same as the member 
087          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
088          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
089          * to their names appending to the name resolved from the specified qualifying 
090          * member with a dot in between.</p>
091          * @param q A qualifying member
092          * @param mid The ID of the member to construct
093          * @since 1.0
094          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
095          */
096         public Member(JsObject.Member q, Mid mid) {
097             super(q, mid);
098         }
099         /**
100          * <p>Internally constructs a member without a qualifying member.</p>
101          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
102          * or <b>internal</b> classes or class members.</p>
103          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
104          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
105          * declared in <b>opaque</b> types other than the declaring class of this constructor 
106          * itself and its subclasses. Under this circumstance, the field names must be
107          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
108          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
109          * @param mid The ID of the member to construct
110          * @since 1.0
111          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
112          */
113         public Member(Mid mid) {
114             super(mid);
115         }
116         @Override
117         /**
118          * <p>Evaluates the property, represented by the current member instance, of the
119          * argument object.</p>
120          * @param o The argument object
121          * @return The value of the current member based on the object argument.
122          * @since 1.0
123          * @javascript Re-compilers must convert the instance invocation of this method into
124          * the JavaScript expression: 
125          * <pre>o.m</pre>
126          * where <tt>m</tt> is the identifier name resolved from the current member
127          * instance of the invocation.
128          */
129         public JsDOMParser with(ObjectLike o) {
130             return new JsDOMParser(super.with(o));
131         }
132     }
133 
134     /**
135      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
136      * with the wrapping constructor.</p>
137      * @param var The argument of an <b>opaque</b> object.
138      * @since 1.0
139      * @javascript Re-compilers must ignore the construction operation of this constructor,
140      * that is, replacing it with its only argument.
141      */
142     public JsDOMParser(JsObject var) {
143         super(var);
144     }
145 
146     @Override
147     /**
148      * <p>Returns the primitive value associated with the current instance, if there is one.
149      * This invocation simply returns the instance itself for the current instance is an 
150      * object and there is no primitive value for it.</p>
151      * @return The current object itself.
152      * @since 1.0
153      * @javascript Re-compilers must convert the instance invocation of this method directly
154      * into a JavaScript invocation on its current object instance without changing the 
155      * method name, but expanding variable arguments, if any, into comma-separated values. 
156      */
157     public JsDOMParser valueOf() {
158         return new JsDOMParser((JsObject)var().valueOf());
159     }
160     /**
161      * <p>Parses XML mark-up and returns a {@link JsDocument} node.</p>
162      * <p>See {@link JsDocument#loadXML(String)} for an IE-specific alternative to this 
163      * method.</p>
164      * @param text The XML mark-up to parse.
165      * @param contentType The content type of the text. This may be one of "text/xml", 
166      * "application/xml", or "application/xhtml+xml". Note that "text/html" is not 
167      * supported by this method.
168      * @return A {@link JsDocument} node that holds the parsed representation of <tt>text</tt>.
169      * @since 1.0
170      * @javascript Re-compilers must convert the instance invocation of this method directly
171      * into a JavaScript invocation on its current object instance without changing the 
172      * method name, but expanding variable arguments, if any, into comma-separated values. 
173      */
174     public final JsDocument parseFromString(String text, String contentType) {
175         return new JsDocument(call(parseFromString, new Vars<Object>().add(text).add(contentType)));
176     }
177 }