~etherpad/etherpad/ubuntu-lucid-backport

« back to all changes in this revision

Viewing changes to infrastructure/rhino1_7R1/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java

  • Committer: James Page
  • Date: 2011-04-13 08:00:43 UTC
  • Revision ID: james.page@canonical.com-20110413080043-eee2nq7y1v7cv2mp
* Refactoring to use native Ubuntu Java libraries. 
* debian/control:
  - use openjdk instead of sun's java
  - update maintainer
* debian/etherpad.init.orig, debian/etherpad.upstart:
  - move the init script out of the way
  - create a basic upstart script
  - note that the open office document conversion daemon was dropped
    from the upstart configuration; if this behavior is desired, please
    create a separate upstart job for it
* debian/rules:
  - just use basic dh_installinit, as it will pick up the new upstart job
* New release
* Changed maintainer to Packaging
* Fixed installation scripts
* Initial Release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public License Version
 
7
 * 1.1 (the "License"); you may not use this file except in compliance with
 
8
 * the License. You may obtain a copy of the License at
 
9
 * http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the License is distributed on an "AS IS" basis,
 
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
 * for the specific language governing rights and limitations under the
 
14
 * License.
 
15
 *
 
16
 * The Original Code is Rhino code, released
 
17
 * May 6, 1999.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Netscape Communications Corporation.
 
21
 * Portions created by the Initial Developer are Copyright (C) 1997-1999
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *   Norris Boyd
 
26
 *   Ethan Hugg
 
27
 *   Terry Lucas
 
28
 *   Milen Nankov
 
29
 *
 
30
 * Alternatively, the contents of this file may be used under the terms of
 
31
 * the GNU General Public License Version 2 or later (the "GPL"), in which
 
32
 * case the provisions of the GPL are applicable instead of those above. If
 
33
 * you wish to allow use of your version of this file only under the terms of
 
34
 * the GPL and not to allow others to use your version of this file under the
 
35
 * MPL, indicate your decision by deleting the provisions above and replacing
 
36
 * them with the notice and other provisions required by the GPL. If you do
 
37
 * not delete the provisions above, a recipient may use your version of this
 
38
 * file under either the MPL or the GPL.
 
39
 *
 
40
 * ***** END LICENSE BLOCK ***** */
 
41
 
 
42
package org.mozilla.javascript.xmlimpl;
 
43
 
 
44
import org.mozilla.javascript.*;
 
45
import org.mozilla.javascript.xml.*;
 
46
 
 
47
final class XMLWithScope extends NativeWith
 
48
{
 
49
    private static final long serialVersionUID = -696429282095170887L;
 
50
 
 
51
    private XMLLibImpl lib;
 
52
    private int         _currIndex;
 
53
    private XMLList     _xmlList;
 
54
    private XMLObject   _dqPrototype;
 
55
 
 
56
    XMLWithScope(XMLLibImpl lib, Scriptable parent, XMLObject prototype)
 
57
    {
 
58
        super(parent, prototype);
 
59
        this.lib = lib;
 
60
    }
 
61
 
 
62
    void initAsDotQuery()
 
63
    {
 
64
        XMLObject prototype = (XMLObject)getPrototype();
 
65
        // XMLWithScope also handles the .(xxx) DotQuery for XML
 
66
        // basically DotQuery is a for/in/with statement and in
 
67
        // the following 3 statements we setup to signal it's
 
68
        // DotQuery,
 
69
        // the index and the object being looped over.  The
 
70
        // xws.setPrototype is the scope of the object which is
 
71
        // is a element of the lhs (XMLList).
 
72
        _currIndex = 0;
 
73
        _dqPrototype = prototype;
 
74
        if (prototype instanceof XMLList) {
 
75
            XMLList xl = (XMLList)prototype;
 
76
            if (xl.length() > 0) {
 
77
                setPrototype((Scriptable)(xl.get(0, null)));
 
78
            }
 
79
        }
 
80
        // Always return the outer-most type of XML lValue of
 
81
        // XML to left of dotQuery.
 
82
        _xmlList = lib.newXMLList();
 
83
    }
 
84
 
 
85
    protected Object updateDotQuery(boolean value)
 
86
    {
 
87
        // Return null to continue looping
 
88
 
 
89
        XMLObject seed = _dqPrototype;
 
90
        XMLList xmlL = _xmlList;
 
91
 
 
92
        if (seed instanceof XMLList) {
 
93
            // We're a list so keep testing each element of the list if the
 
94
            // result on the top of stack is true then that element is added
 
95
            // to our result list.  If false, we try the next element.
 
96
            XMLList orgXmlL = (XMLList)seed;
 
97
 
 
98
            int idx = _currIndex;
 
99
 
 
100
            if (value) {
 
101
                xmlL.addToList(orgXmlL.get(idx, null));
 
102
            }
 
103
 
 
104
            // More elements to test?
 
105
            if (++idx < orgXmlL.length()) {
 
106
                // Yes, set our new index, get the next element and
 
107
                // reset the expression to run with this object as
 
108
                // the WITH selector.
 
109
                _currIndex = idx;
 
110
                setPrototype((Scriptable)(orgXmlL.get(idx, null)));
 
111
 
 
112
                // continue looping
 
113
                return null;
 
114
            }
 
115
        } else {
 
116
            // If we're not a XMLList then there's no looping
 
117
            // just return DQPrototype if the result is true.
 
118
            if (value) {
 
119
              xmlL.addToList(seed);
 
120
            }
 
121
        }
 
122
 
 
123
        return xmlL;
 
124
    }
 
125
}