Exemplo n.º 1
0
        public XMLList (XMLLib lib, object inputObject)
            : this (lib)
        {
            string frag;
            if (inputObject == null || inputObject is Undefined) {
                frag = "";
            }
            else if (inputObject is XML) {
                XML xml = (XML)inputObject;
                Add (xml);
            }
            else if (inputObject is XMLList) {
                XMLList xmll = (XMLList)inputObject;
                AddRange (xmll);
            }
            else {
                frag = ScriptConvert.ToString (inputObject).Trim ();
                if (!frag.StartsWith ("<>")) {
                    frag = "<>" + frag + "</>";
                }
                frag = "<fragment>" + frag.Substring (2);
                if (!frag.EndsWith ("</>")) {
                    throw ScriptRuntime.TypeError ("XML with anonymous tag missing end anonymous tag");
                }
                frag = frag.Substring (0, frag.Length - 3) + "</fragment>";

                XML orgXML = XML.CreateFromJS (lib, frag);

                // Now orphan the children and add them to our XMLList.
                XMLList children = (XMLList)orgXML.Children ();
                AddRange (children);
            }
        }
Exemplo n.º 2
0
        internal static Namespace Parse(XMLLib lib, Context cx, Object uriValue)
        {
            String prefix;
            String uri;

            if (uriValue is Namespace)
            {
                Namespace ns = (Namespace)uriValue;
                prefix = ns.Prefix;
                uri    = ns.Uri;
            }
            else if (uriValue is QName)
            {
                QName qname = (QName)uriValue;
                uri = qname.Uri;
                if (uri != null)
                {
                    prefix = qname.Prefix;
                }
                else
                {
                    uri    = qname.ToString();
                    prefix = null;
                }
            }
            else
            {
                uri    = ScriptConvert.ToString(uriValue);
                prefix = (uri.Length == 0) ? "" : null;
            }

            return(new Namespace(lib, prefix, uri));
        }
Exemplo n.º 3
0
        internal static XMLName Parse(XMLLib lib, Context cx, string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            int l = name.Length;

            if (l != 0)
            {
                char firstChar = name [0];
                if (firstChar == '*')
                {
                    if (l == 1)
                    {
                        return(FormStar());
                    }
                }
                else if (firstChar == '@')
                {
                    XMLName xmlName = FormProperty("", name.Substring(1));
                    xmlName.IsAttributeName = true;
                    return(xmlName);
                }
            }

            String uri = lib.GetDefaultNamespaceURI(cx);

            return(XMLName.FormProperty(uri, name));
        }
Exemplo n.º 4
0
        public Namespace(XMLLib lib, string uri)
            : base(lib.GlobalScope, lib.namespacePrototype)
        {
            if (uri == null)
                throw new System.ArgumentException ();

            this.lib = lib;
            this.prefix = (uri.Length == 0) ? "" : null;
            this.uri = uri;
        }
Exemplo n.º 5
0
 internal QName (XMLLib lib, string uri, string localName, string prefix)
     : base (lib.GlobalScope, lib.qnamePrototype)
 {
     if (localName == null)
         throw new System.ArgumentException ();
     this.lib = lib;
     this.uri = uri;
     this.prefix = prefix;
     this.localName = localName;
 }
Exemplo n.º 6
0
        internal static QName Parse(XMLLib lib, Context cx, object namespaceValue, object nameValue)
        {
            String uri;
            String localName;
            String prefix;

            if (nameValue is QName)
            {
                QName qname = (QName)nameValue;
                localName = qname.LocalName;
            }
            else
            {
                localName = ScriptConvert.ToString(nameValue);
            }

            Namespace ns;

            if (namespaceValue == Undefined.Value)
            {
                if ("*".Equals(localName))
                {
                    ns = null;
                }
                else
                {
                    ns = lib.GetDefaultNamespace(cx);
                }
            }
            else if (namespaceValue == null)
            {
                ns = null;
            }
            else if (namespaceValue is Namespace)
            {
                ns = (Namespace)namespaceValue;
            }
            else
            {
                ns = Namespace.Parse(lib, cx, namespaceValue);
            }

            if (ns == null)
            {
                uri    = null;
                prefix = null;
            }
            else
            {
                uri    = ns.Uri;
                prefix = ns.Prefix;
            }

            return(new QName(lib, uri, localName, prefix));
        }
Exemplo n.º 7
0
        public Namespace(XMLLib lib, string uri)
            : base(lib.GlobalScope, lib.namespacePrototype)
        {
            if (uri == null)
            {
                throw new System.ArgumentException();
            }

            this.lib    = lib;
            this.prefix = (uri.Length == 0) ? "" : null;
            this.uri    = uri;
        }
Exemplo n.º 8
0
 internal QName(XMLLib lib, string uri, string localName, string prefix)
     : base(lib.GlobalScope, lib.qnamePrototype)
 {
     if (localName == null)
     {
         throw new System.ArgumentException();
     }
     this.lib       = lib;
     this.uri       = uri;
     this.prefix    = prefix;
     this.localName = localName;
 }
Exemplo n.º 9
0
        public static XMLLib ExtractFromScope(IScriptable scope)
        {
            XMLLib lib = ExtractFromScopeOrNull(scope);

            if (lib != null)
            {
                return(lib);
            }
            string msg = ScriptRuntime.GetMessage("msg.XML.not.available");

            throw Context.ReportRuntimeError(msg);
        }
Exemplo n.º 10
0
        public static Namespace Parse(XMLLib lib, Context cx, Object prefixValue,
                                      Object uriValue)
        {
            String prefix;
            String uri;

            if (uriValue is QName)
            {
                QName qname = (QName)uriValue;
                uri = qname.Uri;
                if (uri == null)
                {
                    uri = qname.ToString();
                }
            }
            else
            {
                uri = ScriptConvert.ToString(uriValue);
            }

            if (uri.Length == 0)
            {
                if (prefixValue == Undefined.Value)
                {
                    prefix = "";
                }
                else
                {
                    prefix = ScriptConvert.ToString(prefixValue);
                    if (prefix.Length != 0)
                    {
                        throw ScriptRuntime.TypeError(
                                  "Illegal prefix '" + prefix + "' for 'no namespace'.");
                    }
                }
            }
            else if (prefixValue == Undefined.Value)
            {
                prefix = "";
            }
            else if (!lib.IsXMLName(cx, prefixValue))
            {
                prefix = "";
            }
            else
            {
                prefix = ScriptConvert.ToString(prefixValue);
            }

            return(new Namespace(lib, prefix, uri));
        }
Exemplo n.º 11
0
        public Namespace(XMLLib lib, string prefix, string uri)
            : base(lib.GlobalScope, lib.namespacePrototype)
        {
            if (uri == null)
                throw new System.ArgumentException ();
            if (uri.Length == 0) {
                // prefix should be "" for empty uri
                if (prefix == null)
                    throw new System.ArgumentException ();
                if (prefix.Length != 0)
                    throw new System.ArgumentException ();
            }

            this.lib = lib;
            this.prefix = prefix;
            this.uri = uri;
        }
Exemplo n.º 12
0
        internal static QName Parse(XMLLib lib, Context cx, object value)
        {
            QName result;

            if (value is QName)
            {
                QName qname = (QName)value;
                result = new QName(lib, qname.Uri, qname.LocalName,
                                   qname.Prefix);
            }
            else
            {
                result = Parse(lib, cx, ScriptConvert.ToString(value));
            }

            return(result);
        }
Exemplo n.º 13
0
        public static void Init(IScriptable scope, bool zealed)
        {
            XMLLib impl = new XMLLib(scope);

            impl.SetDefaultSettings();
            impl.BindToScope(scope);

            impl.xmlPrototype = XML.CreateEmptyXml(impl);
            impl.xmlPrototype.ExportAsJSClass(zealed);

            impl.xmlListPrototype = new XMLList(impl);
            impl.xmlListPrototype.ExportAsJSClass(zealed);


            impl.qnamePrototype = new QName(impl);
            impl.qnamePrototype.ExportAsJSClass(zealed);

            impl.namespacePrototype = new Namespace(impl);
            impl.namespacePrototype.ExportAsJSClass(zealed);
        }
Exemplo n.º 14
0
        public XMLList(XMLLib lib, object inputObject)
            : this(lib)
        {
            string frag;
            if (inputObject == null || inputObject is Undefined)
            {
                frag = "";
            }
            else if (inputObject is XML)
            {
                XML xml = (XML)inputObject;
                Add(xml);
            }
            else if (inputObject is XMLList)
            {
                XMLList xmll = (XMLList)inputObject;
                AddRange(xmll);
            }
            else
            {
                frag = ScriptConvert.ToString(inputObject).Trim();
                if (!frag.StartsWith("<>"))
                {
                    frag = "<>" + frag + "</>";
                }
                frag = "<fragment>" + frag.Substring(2);
                if (!frag.EndsWith("</>"))
                {
                    throw ScriptRuntime.TypeError("XML with anonymous tag missing end anonymous tag");
                }
                frag = frag.Substring(0, frag.Length - 3) + "</fragment>";

                XML orgXML = XML.CreateFromJS(lib, frag);

                // Now orphan the children and add them to our XMLList.
                XMLList children = (XMLList)orgXML.Children();
                AddRange(children);
            }
        }
Exemplo n.º 15
0
        public Namespace(XMLLib lib, string prefix, string uri)
            : base(lib.GlobalScope, lib.namespacePrototype)
        {
            if (uri == null)
            {
                throw new System.ArgumentException();
            }
            if (uri.Length == 0)
            {
                // prefix should be "" for empty uri
                if (prefix == null)
                {
                    throw new System.ArgumentException();
                }
                if (prefix.Length != 0)
                {
                    throw new System.ArgumentException();
                }
            }

            this.lib    = lib;
            this.prefix = prefix;
            this.uri    = uri;
        }
Exemplo n.º 16
0
        internal static QName Parse(XMLLib lib, Context cx, string localName)
        {
            if (localName == null)
            {
                throw new ArgumentNullException("localName");
            }

            String uri;
            String prefix;

            if ("*".Equals(localName))
            {
                uri    = null;
                prefix = null;
            }
            else
            {
                Namespace ns = lib.GetDefaultNamespace(cx);
                uri    = ns.Uri;
                prefix = ns.Prefix;
            }

            return(new QName(lib, uri, localName, prefix));
        }
Exemplo n.º 17
0
 protected internal XMLObject (XMLLib lib, XMLObject prototype)
     : base (lib.GlobalScope, prototype)
 {
     this.lib = lib;
 }
Exemplo n.º 18
0
 internal QName(XMLLib lib)
     : base(lib.GlobalScope, lib.qnamePrototype)
 {
     this.lib = lib;
 }
Exemplo n.º 19
0
 internal static Namespace Parse(XMLLib lib, Context cx)
 {
     return(new Namespace(lib, "", ""));
 }
Exemplo n.º 20
0
 public XML(XMLLib lib, XmlNode underlyingNode)
     : base(lib, lib.xmlPrototype)
 {
     this.lib = lib;
     this.underlyingNode = underlyingNode;
 }
Exemplo n.º 21
0
        internal static XMLName Parse(XMLLib lib, Context cx, string name)
        {
            if (name == null)
                throw new ArgumentNullException ("name");

            int l = name.Length;
            if (l != 0) {
                char firstChar = name [0];
                if (firstChar == '*') {
                    if (l == 1) {
                        return FormStar ();
                    }
                }
                else if (firstChar == '@') {
                    XMLName xmlName = FormProperty ("", name.Substring (1));
                    xmlName.IsAttributeName = true;
                    return xmlName;
                }
            }

            String uri = lib.GetDefaultNamespaceURI (cx);

            return XMLName.FormProperty (uri, name);
        }
Exemplo n.º 22
0
 internal QName(XMLLib lib, QName qname)
     :
     this(lib, qname.Uri, qname.LocalName, qname.Prefix)
 {
     ;
 }
Exemplo n.º 23
0
        internal static XML CreateFromJS(XMLLib lib, Object inputObject)
        {
            string frag = "";

            if (inputObject == null || inputObject == Undefined.Value) {
                frag = "";
            }
            else if (inputObject is XMLObject) {
                frag = ((XMLObject)inputObject).ToXMLString ();
            }
            else {
                frag = ScriptConvert.ToString (inputObject);
            }

            if (frag.Trim ().StartsWith ("<>")) {
                throw ScriptRuntime.TypeError ("Invalid use of XML object anonymous tags <></>.");
            }

            XmlDocument doc = null;
            if (frag.IndexOf ("<") == -1) {
                // Must be solo text node
                doc = new XmlDocument ();
                XmlNode node = doc.CreateTextNode (frag);
                return new XML (lib, node);
            }

            doc = new XmlDocument ();
            try {
                using (StringReader sr = new StringReader (frag)) {
                    XmlTextReader xr = new XMLTextReader (lib, sr);
                    doc.Load (xr);

                }
            }
            catch (XmlException e) {
                throw ScriptRuntime.TypeError (e.Message);
            }

            return new XML (lib, doc);
        }
Exemplo n.º 24
0
        public static Namespace Parse (XMLLib lib, Context cx, Object prefixValue,
            Object uriValue)
        {
            String prefix;
            String uri;

            if (uriValue is QName) {
                QName qname = (QName)uriValue;
                uri = qname.Uri;
                if (uri == null) {
                    uri = qname.ToString ();
                }
            }
            else {
                uri = ScriptConvert.ToString (uriValue);
            }

            if (uri.Length == 0) {
                if (prefixValue == Undefined.Value) {
                    prefix = "";
                }
                else {
                    prefix = ScriptConvert.ToString (prefixValue);
                    if (prefix.Length != 0) {
                        throw ScriptRuntime.TypeError (
                            "Illegal prefix '" + prefix + "' for 'no namespace'.");
                    }
                }
            }
            else if (prefixValue == Undefined.Value) {
                prefix = "";
            }
            else if (!lib.IsXMLName (cx, prefixValue)) {
                prefix = "";
            }
            else {
                prefix = ScriptConvert.ToString (prefixValue);
            }

            return new Namespace (lib, prefix, uri);
        }
Exemplo n.º 25
0
        internal static Namespace Parse (XMLLib lib, Context cx, Object uriValue)
        {
            String prefix;
            String uri;

            if (uriValue is Namespace) {
                Namespace ns = (Namespace)uriValue;
                prefix = ns.Prefix;
                uri = ns.Uri;
            }
            else if (uriValue is QName) {
                QName qname = (QName)uriValue;
                uri = qname.Uri;
                if (uri != null) {
                    prefix = qname.Prefix;
                }
                else {
                    uri = qname.ToString ();
                    prefix = null;
                }
            }
            else {
                uri = ScriptConvert.ToString (uriValue);
                prefix = (uri.Length == 0) ? "" : null;
            }

            return new Namespace (lib, prefix, uri);
        }
Exemplo n.º 26
0
        internal static XMLName Parse(XMLLib lib, Context cx, Object value)
        {
            XMLName result;

            if (value is XMLName)
            {
                result = (XMLName)value;
            }
            else if (value is String)
            {
                String str  = (String)value;
                long   test = ScriptRuntime.testUint32String(str);
                if (test >= 0)
                {
                    ScriptRuntime.storeUint32Result(cx, test);
                    result = null;
                }
                else
                {
                    result = Parse(lib, cx, str);
                }
            }
            else if (CliHelper.IsNumber(value))
            {
                double d = ScriptConvert.ToNumber(value);
                long   l = (long)d;
                if (l == d && 0 <= l && l <= 0xFFFFFFFFL)
                {
                    ScriptRuntime.storeUint32Result(cx, l);
                    result = null;
                }
                else
                {
                    throw XMLLib.BadXMLName(value);
                }
            }
            else if (value is QName)
            {
                QName  qname  = (QName)value;
                String uri    = qname.Uri;
                bool   number = false;
                result = null;
                if (uri != null && uri.Length == 0)
                {
                    // Only in this case qname.toString() can resemble uint32
                    long test = ScriptRuntime.testUint32String(uri);
                    if (test >= 0)
                    {
                        ScriptRuntime.storeUint32Result(cx, test);
                        number = true;
                    }
                }
                if (!number)
                {
                    result = XMLName.FormProperty(uri, qname.LocalName);
                }
            }
            else if (value is Boolean ||
                     value == Undefined.Value ||
                     value == null)
            {
                throw XMLLib.BadXMLName(value);
            }
            else
            {
                String str  = ScriptConvert.ToString(value);
                long   test = ScriptRuntime.testUint32String(str);
                if (test >= 0)
                {
                    ScriptRuntime.storeUint32Result(cx, test);
                    result = null;
                }
                else
                {
                    result = Parse(lib, cx, str);
                }
            }

            return(result);
        }
Exemplo n.º 27
0
 internal XMLCtor(XML xml, object tag, int id, int arity)
     : base(xml, tag, id, arity)
 {
     _lib = xml.lib;
     ActivatePrototypeMap(MaxFunctionId);
 }
Exemplo n.º 28
0
        public static void Init (IScriptable scope, bool zealed)
        {
            XMLLib impl = new XMLLib (scope);
            impl.SetDefaultSettings ();
            impl.BindToScope (scope);

            impl.xmlPrototype = XML.CreateEmptyXml (impl);
            impl.xmlPrototype.ExportAsJSClass (zealed);

            impl.xmlListPrototype = new XMLList (impl);
            impl.xmlListPrototype.ExportAsJSClass (zealed);


            impl.qnamePrototype = new QName (impl);
            impl.qnamePrototype.ExportAsJSClass (zealed);

            impl.namespacePrototype = new Namespace (impl);
            impl.namespacePrototype.ExportAsJSClass (zealed);
        }
Exemplo n.º 29
0
 public XMLTextReader(XMLLib lib, StringReader sr)
     : base(sr)
 {
     this.lib = lib;
 }
Exemplo n.º 30
0
        internal static QName Parse (XMLLib lib, Context cx, object value)
        {
            QName result;

            if (value is QName) {
                QName qname = (QName)value;
                result = new QName (lib, qname.Uri, qname.LocalName,
                    qname.Prefix);
            }
            else {
                result = Parse (lib, cx, ScriptConvert.ToString (value));
            }

            return result;
        }
Exemplo n.º 31
0
 internal static XML CreateEmptyXml(XMLLib impl)
 {
     return new XML (impl);
 }
Exemplo n.º 32
0
        internal static QName Parse (XMLLib lib, Context cx, string localName)
        {
            if (localName == null)
                throw new ArgumentNullException ("localName");

            String uri;
            String prefix;

            if ("*".Equals (localName)) {
                uri = null;
                prefix = null;
            }
            else {
                Namespace ns = lib.GetDefaultNamespace (cx);
                uri = ns.Uri;
                prefix = ns.Prefix;
            }

            return new QName (lib, uri, localName, prefix);
        }
Exemplo n.º 33
0
 public XML(XMLLib lib)
     : base(lib, lib.xmlPrototype)
 {
     this.lib = lib;
 }
Exemplo n.º 34
0
        internal static QName Parse (XMLLib lib, Context cx, object namespaceValue, object nameValue)
        {
            String uri;
            String localName;
            String prefix;

            if (nameValue is QName) {
                QName qname = (QName)nameValue;
                localName = qname.LocalName;
            }
            else {
                localName = ScriptConvert.ToString (nameValue);
            }

            Namespace ns;
            if (namespaceValue == Undefined.Value) {
                if ("*".Equals (localName)) {
                    ns = null;
                }
                else {
                    ns = lib.GetDefaultNamespace (cx);
                }
            }
            else if (namespaceValue == null) {
                ns = null;
            }
            else if (namespaceValue is Namespace) {
                ns = (Namespace)namespaceValue;
            }
            else {
                ns = Namespace.Parse (lib, cx, namespaceValue);
            }

            if (ns == null) {
                uri = null;
                prefix = null;
            }
            else {
                uri = ns.Uri;
                prefix = ns.Prefix;
            }

            return new QName (lib, uri, localName, prefix);
        }
Exemplo n.º 35
0
        internal static XMLName Parse(XMLLib lib, Context cx, Object value)
        {
            XMLName result;

            if (value is XMLName) {
                result = (XMLName)value;
            }
            else if (value is String) {
                String str = (String)value;
                long test = ScriptRuntime.testUint32String (str);
                if (test >= 0) {
                    ScriptRuntime.storeUint32Result (cx, test);
                    result = null;
                }
                else {
                    result = Parse (lib, cx, str);
                }
            }
            else if (CliHelper.IsNumber (value)) {
                double d = ScriptConvert.ToNumber (value);
                long l = (long)d;
                if (l == d && 0 <= l && l <= 0xFFFFFFFFL) {
                    ScriptRuntime.storeUint32Result (cx, l);
                    result = null;
                }
                else {
                    throw XMLLib.BadXMLName (value);
                }
            }
            else if (value is QName) {
                QName qname = (QName)value;
                String uri = qname.Uri;
                bool number = false;
                result = null;
                if (uri != null && uri.Length == 0) {
                    // Only in this case qname.toString() can resemble uint32
                    long test = ScriptRuntime.testUint32String (uri);
                    if (test >= 0) {
                        ScriptRuntime.storeUint32Result (cx, test);
                        number = true;
                    }
                }
                if (!number) {
                    result = XMLName.FormProperty (uri, qname.LocalName);
                }
            }
            else if (value is Boolean
                     || value == Undefined.Value
                     || value == null) {
                throw XMLLib.BadXMLName (value);
            }
            else {
                String str = ScriptConvert.ToString (value);
                long test = ScriptRuntime.testUint32String (str);
                if (test >= 0) {
                    ScriptRuntime.storeUint32Result (cx, test);
                    result = null;
                }
                else {
                    result = Parse (lib, cx, str);
                }
            }

            return result;
        }
Exemplo n.º 36
0
 internal XMLCtor(XML xml, object tag, int id, int arity)
     : base(xml, tag, id, arity)
 {
     this.lib = xml.lib;
     ActivatePrototypeMap(MAX_FUNCTION_ID);
 }
Exemplo n.º 37
0
 internal XMLCtor(XML xml, object tag, int id, int arity)
     : base(xml, tag, id, arity)
 {
     this.lib = xml.lib;
     ActivatePrototypeMap (MAX_FUNCTION_ID);
 }
Exemplo n.º 38
0
 internal QName (XMLLib lib, QName qname)
     :
     this (lib, qname.Uri, qname.LocalName, qname.Prefix)
 {
     ;
 }
Exemplo n.º 39
0
 internal QName (XMLLib lib)
     : base (lib.GlobalScope, lib.qnamePrototype)
 {
     this.lib = lib;
 }
Exemplo n.º 40
0
 internal Namespace(XMLLib lib)
     : base(lib.GlobalScope, lib.namespacePrototype)
 {
     this.lib = lib;
 }
Exemplo n.º 41
0
 internal static Namespace Parse (XMLLib lib, Context cx)
 {
     return new Namespace (lib, "", "");
 }
Exemplo n.º 42
0
 public XMLList(XMLLib lib)
     : base(lib, lib.xmlListPrototype)
 {
     this.lib = lib;
 }
Exemplo n.º 43
0
 internal Namespace (XMLLib lib)
     : base (lib.GlobalScope, lib.namespacePrototype)
 {
     this.lib = lib;
 }
Exemplo n.º 44
0
 protected internal XMLObject(XMLLib lib, XMLObject prototype)
     : base(lib.GlobalScope, prototype)
 {
     this.lib = lib;
 }