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#XSLTProcessor} class.</p>
028  * <p>This class enables you to transforms XML document nodes using XSLT stylesheets. 
029  * To use this class, create an object of it with the no-argument constructor of the 
030  * {@link JsClient#XSLTProcessor}:
031  * <pre>JsXSLTProcessor xsltp = Js.win().XSLTProcessor.create();</pre>
032  * and initialize it with an XSLT stylesheet with the {@link #importStyleSheet(JsNode)} 
033  * method. If your stylesheet uses parameters, you can set those with {@link #setParameter(String, String, String)}. 
034  * Finally, perform an actual XSL transformation with {@link #transformToDocument(JsNode)} 
035  * or {@link #transformToFragment(JsNode, JsDocument)}.</p>
036  * <p>IE does not implement this class. See IE-specific {@link JsNode#transformNode(JsDocument)} 
037  * and {@link JsNode#transformNodeToObject(JsDocument)} methods.</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  * @see JsNode#transformNode(JsDocument)
041  * @see JsNode#transformNodeToObject(JsDocument)
042  *
043  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
044  * generated into the target codes. Re-compilers must exit with error on the operations of
045  * accessing that kind of class objects.
046  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
047  * and <tt>instanceof</tt> to it always <tt>true</tt>.
048  */
049 public class JsXSLTProcessor extends JsClient.XSLTProcessor.Prototype
050 {
051     /**
052      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
053      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
054      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
055      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
056      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
057      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
058      * either circumstance, the field names must be exactly same as the member names, as 
059      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
060      * based on the field names.</p>
061      *
062      * @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>
063      * 
064      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
065      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
066      * of class objects.
067      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
068      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
069      * <pre>q.m</pre>
070      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
071      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
072      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
073      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
074      * <pre>m</pre>
075      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
076      * error on the access to <b>opaque</b> fields declared by this class under any other 
077      * circumstances.
078      */
079     public static class Member extends JsClient.XSLTProcessor.Prototype.Member
080     {
081         /**
082          * <p>Internally constructs a member based on a qualifying member.</p>
083          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
084          * or <b>internal</b> classes or class members.</p>
085          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
086          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
087          * declared in the declaring class of this constructor itself or its subclasses. 
088          * Under this circumstance, the field names must be exactly same as the member 
089          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
090          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
091          * to their names appending to the name resolved from the specified qualifying 
092          * member with a dot in between.</p>
093          * @param q A qualifying member
094          * @param mid The ID of the member to construct
095          * @since 1.0
096          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
097          */
098         public Member(JsObject.Member q, Mid mid) {
099             super(q, mid);
100         }
101         /**
102          * <p>Internally constructs a member without a qualifying member.</p>
103          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
104          * or <b>internal</b> classes or class members.</p>
105          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
106          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
107          * declared in <b>opaque</b> types other than the declaring class of this constructor 
108          * itself and its subclasses. Under this circumstance, the field names must be
109          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
110          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
111          * @param mid The ID of the member to construct
112          * @since 1.0
113          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
114          */
115         public Member(Mid mid) {
116             super(mid);
117         }
118         @Override
119         /**
120          * <p>Evaluates the property, represented by the current member instance, of the
121          * argument object.</p>
122          * @param o The argument object
123          * @return The value of the current member based on the object argument.
124          * @since 1.0
125          * @javascript Re-compilers must convert the instance invocation of this method into
126          * the JavaScript expression: 
127          * <pre>o.m</pre>
128          * where <tt>m</tt> is the identifier name resolved from the current member
129          * instance of the invocation.
130          */
131         public JsXSLTProcessor with(ObjectLike o) {
132             return new JsXSLTProcessor(super.with(o));
133         }
134         /**
135          * <p>Evaluates a property, represented by the current member instance, of the
136          * JavaScript global object, that is, evaluates the member to a global identifier.</p>
137          * @return The value of the current member based on the JavaScript global object.
138          * @since 1.0
139          * @javascript Re-compilers must convert the instance invocation of this method into
140          * the JavaScript expression: 
141          * <pre>m</pre>
142          * where <tt>m</tt> is the identifier name resolved from the current member
143          * instance of the invocation.
144          */
145         public JsXSLTProcessor with() {
146             return with(Js.win());
147         }
148     }
149 
150     /**
151      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
152      * with the wrapping constructor.</p>
153      * @param var The argument of an <b>opaque</b> object.
154      * @since 1.0
155      * @javascript Re-compilers must ignore the construction operation of this constructor,
156      * that is, replacing it with its only argument.
157      */
158     public JsXSLTProcessor(JsObject var) {
159         super(var);
160     }
161 
162     @Override
163     /**
164      * <p>Returns the primitive value associated with the current instance, if there is one.
165      * This invocation simply returns the instance itself for the current instance is an 
166      * object and there is no primitive value for it.</p>
167      * @return The current object itself.
168      * @since 1.0
169      * @javascript Re-compilers must convert the instance invocation of this method directly
170      * into a JavaScript invocation on its current object instance without changing the 
171      * method name, but expanding variable arguments, if any, into comma-separated values. 
172      */
173     public JsXSLTProcessor valueOf() {
174         return new JsXSLTProcessor((JsObject)var().valueOf());
175     }
176 
177     /**
178      * <p>Deletes any previously set parameters.</p>
179      * <p>This method erases any parameter values that have been specified with the {@link #setParameter(String, String, String)} 
180      * method. If a transformation is performed with no parameters set, the default values 
181      * specified by the stylesheet are used.</p>
182      * @since 1.0
183      * @javascript Re-compilers must convert the instance invocation of this method directly
184      * into a JavaScript invocation on its current object instance without changing the 
185      * method name, but expanding variable arguments, if any, into comma-separated values. 
186      */
187     public void clearParameters() {
188         call(clearParameters);
189     }
190     /**
191      * <p>Returns the value of a named parameter.</p>
192      * @param namespaceURI The name space of the parameter.
193      * @param localName The name of the parameter.
194      * @return The value of the parameter, or <tt>null</tt> if it has not been set. 
195      * @since 1.0
196      * @javascript Re-compilers must convert the instance invocation of this method directly
197      * into a JavaScript invocation on its current object instance without changing the 
198      * method name, but expanding variable arguments, if any, into comma-separated values. 
199      */
200     public String getParameter(String namespaceURI, String localName) {
201         return call(getParameter, new Vars<String>().add(namespaceURI).add(localName));
202     }
203     /**
204      * <p>Specifies the XSLT stylesheet to be used.</p>
205      * <p>This method specifies the XSLT stylesheet to be used by future calls to 
206      * {@link #transformToDocument(JsNode)} and {@link #transformToFragment(JsNode, JsDocument)}.</p>
207      * @param stylesheet The XSLT stylesheet to be used for transformations. This may be 
208      * a {@link JsDocument} object of its own, or an <tt>&lt;xsl:stylesheet&gt;</tt> or 
209      * <tt>&lt;xsl:transform&gt;</tt> {@link JsElement} node.
210      * @since 1.0
211      * @javascript Re-compilers must convert the instance invocation of this method directly
212      * into a JavaScript invocation on its current object instance without changing the 
213      * method name, but expanding variable arguments, if any, into comma-separated values. 
214      */
215     public void importStyleSheet(JsNode stylesheet) {
216         call(importStyleSheet, stylesheet);
217     }
218     /**
219      * <p>Removes a named parameter.</p>
220      * <p>This method deletes the value of the named parameter, if any such parameter 
221      * was previously set with the {@link #setParameter(String, String, String)} method. 
222      * Subsequent transformations use the default value of the parameter that is 
223      * specified in the stylesheet.</p>
224      * @param namespaceURI The name space of the parameter.
225      * @param localName The name of the parameter.
226      * @since 1.0
227      * @javascript Re-compilers must convert the instance invocation of this method directly
228      * into a JavaScript invocation on its current object instance without changing the 
229      * method name, but expanding variable arguments, if any, into comma-separated values. 
230      */
231     public void removeParameter(String namespaceURI, String localName) {
232         call(removeParameter, new Vars<String>().add(namespaceURI).add(localName));
233     }
234     /**
235      * <p>Resets the XSLTProcessor to its initial state, clearing all parameters and 
236      * stylesheets.</p>
237      * <p>This method restores a {@link JsXSLTProcessor} object to the state it was in 
238      * when it was first created. After calling this method, there is no stylesheet and 
239      * are no parameter values associated with the object.</p>
240      * @since 1.0
241      * @javascript Re-compilers must convert the instance invocation of this method directly
242      * into a JavaScript invocation on its current object instance without changing the 
243      * method name, but expanding variable arguments, if any, into comma-separated values. 
244      */
245     public void reset() {
246         call(reset);
247     }
248     /**
249      * <p>Sets a named parameter to a specified value.</p>
250      * @param namespaceURI The name space of the parameter.
251      * @param localName The name of the parameter.
252      * @param value The value of the parameter.
253      * @since 1.0
254      * @javascript Re-compilers must convert the instance invocation of this method directly
255      * into a JavaScript invocation on its current object instance without changing the 
256      * method name, but expanding variable arguments, if any, into comma-separated values. 
257      */
258     public void setParameter(String namespaceURI, String localName, String value) {
259         call(setParameter, new Vars<String>().add(namespaceURI).add(localName).add(value));
260     }
261     /**
262      * <p>Transforms the specified document or node using the stylesheet passed to 
263      * {@link #importStyleSheet(JsNode)} and parameters passed to {@link #setParameter(String, String, String)} 
264      * and returns the result as a new {@link JsDocument} object.</p>
265      * @param source The document or node that is to be transformed.
266      * @return A {@link JsDocument} object that holds the result of the transformation.
267      * @since 1.0
268      * @javascript Re-compilers must convert the instance invocation of this method directly
269      * into a JavaScript invocation on its current object instance without changing the 
270      * method name, but expanding variable arguments, if any, into comma-separated values. 
271      */
272     public JsDocument transformToDocument(JsNode source) {
273         return call(transformToDocument, source);
274     }
275     /**
276      * <p>Transforms the specified document or node, returning the result as a 
277      * {@link JsDocumentFragment} object.</p>
278      * <p>This method performs an XSLT transformation on the specified node, returning 
279      * the result as a {@link JsDocumentFragment} object. The transformation uses the 
280      * XSLT stylesheet specified by {@link #importStyleSheet(JsNode)} and the parameter 
281      * values specified with {@link #setParameter(String, String, String)}. The returned 
282      * fragment can be inserted into the specified <tt>owner</tt> document.</p>
283      * @param source The document or node that is to be transformed.
284      * @param owner The document through which the returned {@link JsDocumentFragment} 
285      * object is created. The {@link JsNode#ownerDocument} property of the returned 
286      * {@link JsDocumentFragment} object refers to this document.
287      * @return A {@link JsDocumentFragment} object that holds the result of the transformation.
288      * @since 1.0
289      * @javascript Re-compilers must convert the instance invocation of this method directly
290      * into a JavaScript invocation on its current object instance without changing the 
291      * method name, but expanding variable arguments, if any, into comma-separated values. 
292      */
293     public JsDocumentFragment transformToFragment(JsNode source, JsDocument owner) {
294         return call(transformToFragment,  new Vars<JsNode>().add(source).add(owner));
295     }
296 }