Exemplo n.º 1
0
        public void OnTouchEnd(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            mouseDown = false;
        }
Exemplo n.º 2
0
        protected override void KeyDown(ElementEvent e)
        {
            switch (Status)
            {
            case ShooterStatus.Win:
                foreach (int handle in pendingTimers)
                {
                    Window.ClearTimeout(handle);
                }
                if (_practice)
                {
                    CurrentGame.ShowTitleScreen();
                }
                else
                {
                    CurrentGame.NextLevel();
                }
                break;

            case ShooterStatus.Fail:
                foreach (int handle in pendingTimers)
                {
                    Window.ClearTimeout(handle);
                }
                if (_practice)
                {
                    CurrentGame.ShowTitleScreen();
                }
                else
                {
                    CurrentGame.GameOver();
                }
                break;
            }
        }
Exemplo n.º 3
0
        public void MouseDown(ElementEvent e)
        {
            CanvasElement canvas = Document.GetElementById <CanvasElement>("graph");
            int           x      = Mouse.OffsetX(canvas, e);
            int           y      = Mouse.OffsetY(canvas, e);

            if ((Math.Abs(x - center) < 10) && Math.Abs(y - 75) < 10)
            {
                dragType = DragType.Center;
            }
            else if (Math.Abs(x - lowPosition) < 3)
            {
                dragType = DragType.Low;
            }
            else if (Math.Abs(x - highPosition) < 3)
            {
                dragType = DragType.High;
            }
            else
            {
                dragType     = DragType.Range;
                downPosition = Math.Min(255, Math.Max(0, x));

                Draw();
            }
            e.CancelBubble = true;
        }
Exemplo n.º 4
0
        public bool MouseDown(object sender, ElementEvent e)
        {
            // todo enable links
            Vector2d location;

            location = PointToView(Vector2d.Create(e.OffsetX, e.OffsetY));

            if (tour == null || tour.CurrentTourStop == null)
            {
                return(false);
            }

            for (int i = tour.CurrentTourStop.Overlays.Count - 1; i >= 0; i--)
            {
                if (tour.CurrentTourStop.Overlays[i].HitTest(location))
                {
                    if (!string.IsNullOrEmpty(tour.CurrentTourStop.Overlays[i].Url))
                    {
                        Overlay linkItem = tour.CurrentTourStop.Overlays[i];
                        Util.OpenUrl(linkItem.Url);
                        return(true);
                    }

                    if (!string.IsNullOrEmpty(tour.CurrentTourStop.Overlays[i].LinkID))
                    {
                        callStack.Push(tour.CurrentTourstopIndex);
                        PlayFromTourstop(tour.TourStops[tour.GetTourStopIndexByID(tour.CurrentTourStop.Overlays[i].LinkID)]);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        private void OnKeyDown(ElementEvent e)
        {
            switch (e.KeyCode)
            {
            case 37:
                Left = true;
                break;

            case 38:
                Up = true;
                break;

            case 39:
                Right = true;
                break;

            case 40:
                Down = true;
                break;

            case 32:
                Fire = true;
                break;

            default:
                KeyDown(e);
                break;
            }
        }
Exemplo n.º 6
0
        public bool MouseMove(object sender, ElementEvent e)
        {
            // todo enable links
            Vector2d location;

            try
            {
                location = PointToView(Vector2d.Create(e.OffsetX, e.OffsetY));
            }
            catch
            {
                return(false);
            }

            if (tour == null || tour.CurrentTourStop == null)
            {
                return(false);
            }

            for (int i = tour.CurrentTourStop.Overlays.Count - 1; i >= 0; i--)
            {
                if (tour.CurrentTourStop.Overlays[i].HitTest(location) && (!string.IsNullOrEmpty(tour.CurrentTourStop.Overlays[i].Url) || !string.IsNullOrEmpty(tour.CurrentTourStop.Overlays[i].LinkID)))
                {
                    //todo change cursor to hand
                    return(true);
                }
            }

            //todo set cursor to default
            //Viewer.MasterView.Cursor = null;
            return(false);
        }
Exemplo n.º 7
0
        private void OnKeyUp(ElementEvent e)
        {
            switch (e.KeyCode)
            {
            case 37:
                Left = false;
                break;

            case 38:
                Up = false;
                break;

            case 39:
                Right = false;
                break;

            case 40:
                Down = false;
                break;

            case 32:
                Fire = false;
                break;

            default:
                KeyUp(e);
                break;
            }
        }
Exemplo n.º 8
0
 public void CurveStyleSelected(ElementEvent e)
 {
     SelectedCurveStyle = dropDown.SelectedIndex;
     SetUpdateTimer();
     Draw();
     ignoreNextClick = true;
 }
Exemplo n.º 9
0
 public void OnMouseWheel(ElementEvent e)
 {
     WheelEvent ev = (WheelEvent)(object)e;
     //firefox
     //    double delta = event.detail ? event.detail * (-120) : event.wheelDelta;
     double delta = ev.WheelDelta;
 }
Exemplo n.º 10
0
 public void CurveStyleSelected(ElementEvent e)
 {
     SelectedCurveStyle = dropDown.SelectedIndex;
     SetUpdateTimer();
     layer.ImageSet.FitsProperties.ScaleType = (ScaleTypes)SelectedCurveStyle;
     Draw();
     ignoreNextClick = true;
 }
 public void OkClicked(ElementEvent e)
 {
     Close();
     if (okCallback != null)
     {
         okCallback();
     }
 }
 public void NonMenuClick(ElementEvent e)
 {
     if (!ignoreNextClick)
     {
         Close();
     }
     ignoreNextClick = false;
 }
        internal void MenuItemClicked(ElementEvent e)
        {
            TagMe me = (TagMe)(Object)e.CurrentTarget;



            me.ItemTag.Click(me.ItemTag, new EventArgs());
        }
Exemplo n.º 14
0
 private void OnBlur(ElementEvent e)
 {
     if (Document.HasFocus())
     {
         return;
     }
     Pause();
 }
Exemplo n.º 15
0
 protected override void KeyDown(ElementEvent e)
 {
     _keyPressed = true;
     if (_finished)
     {
         _game.NextLevel();
     }
 }
Exemplo n.º 16
0
        public void NonMenuClick(ElementEvent e)
        {
            //DivElement menu = Document.GetElementById<DivElement>("colorpicker");
            //menu.Style.Display = "none";
            //Window.RemoveEventListener("click", NonMenuClick, true);

            //ImageElement image = Document.GetElementById<ImageElement>("colorhex");
            //image.RemoveEventListener("click", PickColor, false);
        }
Exemplo n.º 17
0
        private void HandleButtonClicked(ElementEvent e)
        {
            if (ButtonPressed == null)
            {
                return;
            }

            Script.SetTimeout(ButtonPressed, 0);
        }
Exemplo n.º 18
0
        public void OnGestureChange(ElementEvent e)
        {
            GestureEvent g = (GestureEvent)e;

            mouseDown = false;
            double delta = g.Scale;

            //      if (delta > 1 && Math.Abs(delta - 1) > .05)
        }
Exemplo n.º 19
0
        public void OnTouchStart(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            mouseDown = true;
            lastX     = ev.TargetTouches[0].PageX;
            lastY     = ev.TargetTouches[0].PageY;
        }
Exemplo n.º 20
0
 public void mouseup(ElementEvent e)
 {
     if (dragType != DragType.None)
     {
         dragType = DragType.None;
         SetUpdateTimer();
         ignoreNextClick = true;
     }
     e.CancelBubble = true;
 }
Exemplo n.º 21
0
        public void OnMouseMove(ElementEvent e)
        {
            if (mouseDown)
            {
                Move(e.OffsetX - lastX, e.OffsetY - lastY);

                lastX = e.OffsetX;
                lastY = e.OffsetY;
            }
        }
Exemplo n.º 22
0
        private void OnLocateMeClick(ElementEvent e)
        {
            GeoLocationProvider geoLocationProvider = new GeoLocationProvider(_map);

            GeoLocationOptions options = new GeoLocationOptions();

            options.UpdateMapView = true;

            geoLocationProvider.GetCurrentPosition(options);
        }
Exemplo n.º 23
0
        public void OnTouchStart(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            mouseDown = true;
            lastX     = ev.TargetTouches[0].PageX;
            lastY     = ev.TargetTouches[0].PageY;

            indexTouchDown = GetItemIndexFromCursor(Vector2d.Create(ev.TargetTouches[0].PageX, ev.TargetTouches[0].PageY));
        }
Exemplo n.º 24
0
 public void OnPointerUp(ElementEvent e)
 {
     Script.Literal("{0}.releasePointerCapture({1}.pointerId)", e.SrcElement, e);
     if (dragType != DragType.None)
     {
         dragType = DragType.None;
         SetUpdateTimer();
         ignoreNextClick = true;
     }
     e.CancelBubble = true;
 }
Exemplo n.º 25
0
        private void SoundLoaded(ElementEvent e)
        {
            _engine.RemoveEventListener("canplaythrough", _playThroughListener, false);
            _engine.AddEventListener("timeupdate", _timeUpdatedListener, false);

            _engineStatus = EngineStatus.Low;
            // _engine.CurrentTime = EngineLowStart;

            _engine.Volume = 0.5f;
            _engine.Play();
        }
Exemplo n.º 26
0
        private void OnWindowResize(ElementEvent e)
        {
            _width  = Document.Body.OffsetWidth;
            _height = Document.Body.OffsetHeight;

            _tankCanvas.Width    = _width;
            _tankCanvas.Height   = _height;
            _fishesCanvas.Width  = _width;
            _fishesCanvas.Height = _height;

            Draw();
        }
Exemplo n.º 27
0
        public BxEventArgs FireEvent(Int32 eventID, object target, object trigger)
        {
            if (ElementEvent == null)
            {
                return(null);
            }

            BxEventArgs e = new BxEventArgs(eventID, target, trigger);

            ElementEvent.Invoke(e);
            return(e);
        }
Exemplo n.º 28
0
 public void OnClick(ElementEvent e)
 {
     if (!ignoreClick)
     {
         int index = GetItemIndexFromCursor(Vector2d.Create(e.OffsetX, e.OffsetY));
         HandleClick(index);
     }
     else
     {
         ignoreClick = false;
     }
 }
Exemplo n.º 29
0
        public void OnTouchMove(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            if (mouseDown)
            {
                double curX = ev.TargetTouches[0].PageX - lastX;

                double curY = ev.TargetTouches[0].PageY - lastY;
                if (mouseDown)
                {
                    dragging = true;
                }

                if (!dragging)
                {
                    int newHover = GetItemIndexFromCursor(Vector2d.Create(ev.TargetTouches[0].PageX, ev.TargetTouches[0].PageY));
                    if (hoverItem != newHover)
                    {
                        hoverItem = newHover;
                        //if (ItemHover != null)
                        //{
                        //    if (hoverItem > -1)
                        //    {
                        //        ItemHover.Invoke(this, items[hoverItem]);
                        //    }
                        //    else
                        //    {
                        //        ItemHover.Invoke(this, null);
                        //    }
                        //}
                    }
                }
                else
                {
                    int tiles  = (int)Math.Round(((ev.TargetTouches[0].PageX - lastX) + startOffset) / HorzSpacing);
                    int offset = (int)Math.Round(((ev.TargetTouches[0].PageX - lastX) + startOffset) - (tiles * HorzSpacing));

                    startOffset = offset;
                    startIndex -= tiles;
                    if (startIndex < 0)
                    {
                        startOffset -= (HorzSpacing * startIndex);
                        startIndex   = 0;
                    }
                    lastX = ev.TargetTouches[0].PageX;
                    lastY = ev.TargetTouches[0].PageY;
                }
                Refresh();
            }
        }
Exemplo n.º 30
0
        public bool MouseUp(object sender, ElementEvent e)
        {
            if (leftDown || rightDown || middleDown)
            {
                leftDown   = false;
                rightDown  = false;
                middleDown = false;
                return(true);
            }


            return(false);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Implementation of the RDF/XML Grammar Production 'RDF'
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <param name="element">RDF Element to apply Production to</param>
        private void GrammarProductionRDF(RdfXmlParserContext context, ElementEvent element)
        {
            //Tracing
            if (this._traceparsing)
            {
                this.ProductionTrace("RDF", element);
            }

            //Check Uri is correct
            String localName = element.LocalName;
            String prefix = element.Namespace;
            if (localName.Equals("RDF") ||
                ((context.Namespaces.HasNamespace(prefix) && context.Namespaces.GetNamespaceUri(prefix).ToString().Equals(NamespaceMapper.RDF))
                 || element.NamespaceAttributes.Any(ns => ns.Prefix.Equals(prefix) && ns.Uri.Equals(NamespaceMapper.RDF))))
            {
                //This is OK
            }
            else
            {
                throw ParserHelper.Error("Unexpected Node '" + element.QName + "', an 'rdf:RDF' node was expected", "RDF", element);
            }
            //Check has no Attributes
            if (element.Attributes.Count > 0)
            {
                throw ParserHelper.Error("Root Node should not contain any attributes other than XML Namespace Declarations", "RDF", element);
            }

            //Apply Namespaces
            this.ApplyNamespaces(context, element);

            //Build a Sublist of all Nodes up to the matching EndElement
            IEventQueue<IRdfXmlEvent> subevents = new EventQueue<IRdfXmlEvent>();
            IRdfXmlEvent next;

            //Make sure we discard the current ElementEvent which will be at the front of the queue
            context.Events.Dequeue();

            //Gather the Sublist
            while (context.Events.Count > 1)
            {
                subevents.Enqueue(context.Events.Dequeue());
            }

            //Call the NodeElementList Grammer Production
            this.GrammarProductionNodeElementList(context, subevents);

            //Next Event in queue should be an EndElementEvent or we Error
            next = context.Events.Dequeue();
            if (!(next is EndElementEvent))
            {
                throw ParserHelper.Error("Unexpected Event '" + next.GetType().ToString() + "', an EndElementEvent was expected", "RDF", element);
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Implementation of the RDF/XML Grammar Production 'RDF'
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <param name="element">RDF Element to apply Production to</param>
        private void GrammarProductionRDF(RdfXmlParserContext context, ElementEvent element)
        {
            //Tracing
            if (this._traceparsing)
            {
                this.ProductionTrace("RDF");
            }

            //Check Uri is correct (using the QName for simplicity)
            if (!element.QName.Equals("rdf:RDF") && !element.QName.Equals(":RDF"))
            {
                throw ParserHelper.Error("Unexpected Node '" + element.QName + "', an 'rdf:RDF' node was expected", "RDF", element);
            }
            //Check has no Attributes
            if (element.Attributes.Count > 0)
            {
                throw ParserHelper.Error("Root Node should not contain any attributes other than XML Namespace Declarations", "RDF", element);
            }

            //Apply Namespaces
            this.ApplyNamespaces(context, element);

            //Build a Sublist of all Nodes up to the matching EndElement
            IEventQueue<IRdfXmlEvent> subevents = new EventQueue<IRdfXmlEvent>();
            IRdfXmlEvent next;

            //Make sure we discard the current ElementEvent which will be at the front of the queue
            context.Events.Dequeue();

            //Gather the Sublist
            while (context.Events.Count > 1)
            {
                subevents.Enqueue(context.Events.Dequeue());
            }

            //Call the NodeElementList Grammer Production
            this.GrammarProductionNodeElementList(context, subevents);

            //Next Event in queue should be an EndElementEvent or we Error
            next = context.Events.Dequeue();
            if (!(next is EndElementEvent))
            {
                throw ParserHelper.Error("Unexpected Event '" + next.GetType().ToString() + "', an EndElementEvent was expected", "RDF", element);
            }
        }
Exemplo n.º 33
0
        /// <summary>
        /// Implementation of the RDF/XML Grammar Production 'parseTypeResourcePropertyElt'
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <param name="eventlist">Queue of Events that make up the Resource Parse Type Property Element and its Children</param>
        /// <param name="parent">Parent Event (ie. Node) of the Property Element</param>
        private void GrammarProductionParseTypeResourcePropertyElement(RdfXmlParserContext context, IEventQueue<IRdfXmlEvent> eventlist, IRdfXmlEvent parent)
        {
            //Tracing
            if (this._traceparsing)
            {
                this.ProductionTracePartial("Parse Type Resource Property Element");
            }

            //Get the first Event, should be an ElementEvent
            //Type checking is done by the Parent Production
            IRdfXmlEvent first = eventlist.Dequeue();
            ElementEvent element = (ElementEvent)first;
            if (this._traceparsing) this.ProductionTracePartial(element);

            //Apply Namespaces
            this.ApplyNamespaces(context, element);

            //Validate Attributes
            String ID = String.Empty;
            if (element.Attributes.Count > 2)
            {
                //Can't be more than 2 Attributes, only allowed an optional rdf:ID and a required rdf:parseType
                throw ParserHelper.Error("An Property Element with Parse Type 'Resource' was encountered with too many Attributes.  Only rdf:ID and rdf:parseType are allowed on Property Elements with Parse Type 'Resource'", "Parse Type Resource Property Element", element);
            }
            else
            {
                //Check the attributes that do exist
                foreach (AttributeEvent a in element.Attributes)
                {
                    if (RdfXmlSpecsHelper.IsIDAttribute(a))
                    {
                        ID = "#" + a.Value;
                    }
                    else if (a.QName.Equals("rdf:parseType"))
                    {
                        //OK
                    }
                    else
                    {
                        //Invalid Attribute
                        throw ParserHelper.Error("Unexpected Attribute '" + a.QName + "' was encountered on a Property Element with Parse Type 'Resource'.  Only rdf:ID and rdf:parseType are allowed on Property Elements with Parse Type 'Resource'", "Parse Type Resource Property Element", element);
                    }
                }
            }

            //Add a Triple about this
            INode subj, pred, obj;

            //Get the Subject from the Parent
            ElementEvent parentEvent = (ElementEvent)parent;
            subj = parentEvent.SubjectNode;

            //Validate the ID (if any)
            if (!ID.Equals(String.Empty))
            {
                this.ValidateID(context, ID.Substring(1), subj);
            }

            //Create the Predicate from the Element
            pred = this.Resolve(context, element);//context.Handler.CreateUriNode(element.QName);

            //Generate a Blank Node ID for the Object
            obj = context.Handler.CreateBlankNode();

            //Assert
            if (!context.Handler.HandleTriple(new Triple(subj, pred, obj))) ParserHelper.Stop();

            //Reify if applicable
            if (!ID.Equals(String.Empty))
            {
                //Resolve the Uri
                UriReferenceEvent uriref = new UriReferenceEvent(ID, String.Empty);
                IUriNode uri = this.Resolve(context, uriref,element.BaseUri);

                this.Reify(context, uri, subj, pred, obj);
            }

            //Get the next event in the Queue which should be either an Element Event or a End Element Event
            //Validate this
            IRdfXmlEvent next = eventlist.Dequeue();
            if (next is EndElementEvent)
            {
                //Content is Empty so nothing else to do
            }
            else if (next is ElementEvent)
            {
                //Non-Empty Content so need to build a sequence of new events
                IEventQueue<IRdfXmlEvent> subEvents = new EventQueue<IRdfXmlEvent>();

                //Create an rdf:Description event as the container
                ElementEvent descrip = new ElementEvent("rdf:Description", element.BaseUri, String.Empty);
                descrip.Subject = new BlankNodeIDEvent(String.Empty);
                descrip.SubjectNode = obj;
                subEvents.Enqueue(descrip);

                //Add the current element we were looking at
                subEvents.Enqueue(next);

                //Add rest of events in list (exceot the last)
                while (eventlist.Count > 1)
                {
                    subEvents.Enqueue(eventlist.Dequeue());
                }

                //Terminate with an EndElement Event
                subEvents.Enqueue(new EndElementEvent());

                //Process with Node Element Production
                this.GrammarProductionNodeElement(context, subEvents);

                //Get the last thing in the List
                next = eventlist.Dequeue();
            }
            else
            {
                throw ParserHelper.Error("Unexpected Event '" + next.GetType().ToString() + "', expected an ElementEvent or EndElementEvent after a Parse Type Resource Property Element!", "Parse Type Resource Property Element", next);
            }

            //Check for the last thing being an EndElement Event
            if (!(next is EndElementEvent))
            {
                throw ParserHelper.Error("Unexpected Event '" + next.GetType().ToString() + "', expected an EndElementEvent to terminate a Parse Type Resource Property Element!", "Parse Type Resource Property Element", next);
            }
        }
Exemplo n.º 34
0
 /// <summary>
 /// Tracing function used when Parse Tracing is enabled
 /// </summary>
 /// <param name="production">Production</param>
 /// <param name="evt"></param>
 private void ProductionTrace(String production, ElementEvent evt)
 {
     Console.WriteLine("Production '" + production + "' called on element <" + evt.QName + ">" + (evt.Position != null ? " at Line " + evt.Position.StartLine + " Column " + evt.Position.StartPosition : String.Empty));
 }
Exemplo n.º 35
0
 private void ProductionTracePartial(ElementEvent evt)
 {
     Console.WriteLine(" on element <" + evt.QName + ">" + (evt.Position != null ? " at Line " + evt.Position.StartLine + " Column " + evt.Position.StartPosition : String.Empty));
 }
Exemplo n.º 36
0
        /// <summary>
        /// Implementation of the RDF/XML Grammar Production 'emptyPropertyElt'
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <param name="element">Element Event for the Empty Property Element</param>
        /// <param name="parent">Parent Event (ie. Node) of the Property Element</param>
        private void GrammarProductionEmptyPropertyElement(RdfXmlParserContext context, ElementEvent element, IRdfXmlEvent parent)
        {
            //Tracing
            if (this._traceparsing)
            {
                this.ProductionTrace("Empty Property Element");
            }

            //Apply Namespaces
            this.ApplyNamespaces(context, element);

            INode subj, pred, obj;
            ElementEvent parentEl;

            //Are there any attributes OR Only a rdf:ID attribute?
            if (element.Attributes.Count == 0 || (element.Attributes.Count == 1 && RdfXmlSpecsHelper.IsIDAttribute(element.Attributes[0])))
            {
                //No Attributes/Only rdf:ID

                //Get the Subject Node from the Parent
                parentEl = (ElementEvent)parent;
                subj = parentEl.SubjectNode;

                //Create the Predicate from the Element
                pred = this.Resolve(context, element);//context.Handler.CreateUriNode(element.QName);

                //Create the Object
                if (!element.Language.Equals(String.Empty))
                {
                    obj = context.Handler.CreateLiteralNode(String.Empty, element.Language);
                }
                else
                {
                    obj = context.Handler.CreateLiteralNode(String.Empty);
                }

                //Make the Assertion
                if (!context.Handler.HandleTriple(new Triple(subj, pred, obj))) ParserHelper.Stop();

                //Reifiy if applicable
                if (element.Attributes.Count == 1)
                {
                    //Validate the ID
                    this.ValidateID(context, element.Attributes[0].Value, subj);

                    //Resolve the Uri
                    UriReferenceEvent uriref = new UriReferenceEvent("#" + element.Attributes[0].Value, String.Empty);
                    IUriNode uri = this.Resolve(context, uriref, element.BaseUri);

                    this.Reify(context, uri, subj, pred, obj);
                }

            }
            else if (element.Attributes.Count > 0 && element.Attributes.Where(a => RdfXmlSpecsHelper.IsDataTypeAttribute(a)).Count() == 1)
            {
                //Should be processed as a Typed Literal Event instead
                EventQueue<IRdfXmlEvent> temp = new EventQueue<IRdfXmlEvent>();
                temp.Enqueue(element);
                temp.Enqueue(new TextEvent(String.Empty, String.Empty));
                temp.Enqueue(new EndElementEvent());
                this.GrammarProductionLiteralPropertyElement(context, temp, parent);
                return;
            }
            else
            {

                //Check through attributes
                IRdfXmlEvent res = null;

                //Check through attributes to decide the Subject of the Triple(s)
                String ID = String.Empty;
                int limitedAttributes = 0;
                foreach (AttributeEvent a in element.Attributes)
                {
                    if (RdfXmlSpecsHelper.IsResourceAttribute(a))
                    {
                        //An rdf:resource attribute so a Uri Reference
                        res = new UriReferenceEvent(a.Value, a.SourceXml);
                        limitedAttributes++;
                    }
                    else if (RdfXmlSpecsHelper.IsNodeIDAttribute(a))
                    {
                        //An rdf:nodeID attribute so a Blank Node

                        //Validate the Node ID
                        if (!XmlSpecsHelper.IsName(a.Value))
                        {
                            //Invalid nodeID
                            throw ParserHelper.Error("The value '" + a.Value + "' for rdf:nodeID is not valid, RDF Node IDs can only be valid Names as defined by the W3C XML Specification", "Empty Property Element", a);
                        }
                        res = new BlankNodeIDEvent(a.Value, a.SourceXml);
                        limitedAttributes++;
                    }
                    else if (RdfXmlSpecsHelper.IsIDAttribute(a))
                    {
                        //Set the ID for later use in reification
                        ID = "#" + a.Value;
                    }

                    //Check we haven't got more than 1 of the Limited Attributes
                    if (limitedAttributes > 1)
                    {
                        throw ParserHelper.Error("A Property Element can only have 1 of the following attributes: rdf:nodeID or rdf:resource", "Empty Property Element", element);
                    }
                }
                if (res == null)
                {
                    //No relevant attributes so an anonymous Blank Node
                    res = new BlankNodeIDEvent(String.Empty);
                }

                //Now create the actual Subject Node
                if (res is UriReferenceEvent)
                {
                    //Resolve the Uri Reference
                    UriReferenceEvent uriref = (UriReferenceEvent)res;
                    subj = this.Resolve(context, uriref, element.BaseUri);
                }
                else if (res is BlankNodeIDEvent)
                {
                    BlankNodeIDEvent blank = (BlankNodeIDEvent)res;
                    if (blank.Identifier.Equals(String.Empty))
                    {
                        //Have the Graph generate a Blank Node ID
                        subj = context.Handler.CreateBlankNode();
                    }
                    else
                    {
                        //Use the supplied Blank Node ID
                        subj = context.Handler.CreateBlankNode(blank.Identifier);
                    }
                }
                else
                {
                    //Should never hit this case but required to get the Code to Compile
                    //Have the Graph generate a Blank Node ID
                    subj = context.Handler.CreateBlankNode();
                }

                //Validate the ID (if any)
                if (!ID.Equals(String.Empty))
                {
                    this.ValidateID(context, ID.Substring(1), subj);
                }

                //Relate the Property element to its parent
                parentEl = (ElementEvent)parent;
                pred = this.Resolve(context, element);//context.Handler.CreateUriNode(element.QName);
                if (!context.Handler.HandleTriple(new Triple(parentEl.SubjectNode, pred, subj))) ParserHelper.Stop();

                //Reify if applicable
                if (!ID.Equals(String.Empty))
                {
                    //Resolve the Uri
                    UriReferenceEvent uriref = new UriReferenceEvent(ID, String.Empty);
                    IUriNode uri = this.Resolve(context, uriref, element.BaseUri);

                    this.Reify(context, uri, parentEl.SubjectNode, pred, subj);
                }

                //Process the rest of the Attributes
                foreach (AttributeEvent a in element.Attributes)
                {
                    if (a.QName.Equals("rdf:type"))
                    {
                        //A Property Attribute giving a Type

                        //Assert a Type Triple
                        UriReferenceEvent type = new UriReferenceEvent(a.Value, a.SourceXml);
                        pred = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfType));
                        obj = this.Resolve(context, type, element.BaseUri);

                        if (!context.Handler.HandleTriple(new Triple(parentEl.SubjectNode, pred, obj))) ParserHelper.Stop();
                    }
                    else if (RdfXmlSpecsHelper.IsPropertyAttribute(a))
                    {
                        //A Property Attribute

                        //Validate the Normalization of the Attribute Value
            #if !NO_NORM
                        if (!a.Value.IsNormalized())
                        {
                            throw ParserHelper.Error("Encountered a Property Attribute '" + a.QName + "' whose value was not correctly normalized in Unicode Normal Form C", "Empty Property Element", a);
                        }
                        else
                        {
            #endif
                            //Create the Predicate from the Attribute QName
                            pred = context.Handler.CreateUriNode(UriFactory.Create(Tools.ResolveQName(a.QName, context.Namespaces, context.BaseUri)));

                            //Create the Object from the Attribute Value
                            if (element.Language.Equals(String.Empty))
                            {
                                obj = context.Handler.CreateLiteralNode(a.Value);
                            }
                            else
                            {
                                obj = context.Handler.CreateLiteralNode(a.Value, element.Language);
                            }

                            //Assert the Property Triple
                            if (!context.Handler.HandleTriple(new Triple(subj, pred, obj))) ParserHelper.Stop();
            #if !NO_NORM
                        }
            #endif
                    }
                    else if (RdfXmlSpecsHelper.IsIDAttribute(a) || RdfXmlSpecsHelper.IsNodeIDAttribute(a) || RdfXmlSpecsHelper.IsResourceAttribute(a))
                    {
                        //These have already been processed
                        //We test for them so that we can then throw ParserHelper.Errors in the final case for unexpected attributes
                    }
                    else
                    {
                        //Unexpected Attribute
                        throw ParserHelper.Error("Unexpected Attribute '" + a.QName + "' encountered on a Property Element!  Only rdf:ID, rdf:resource, rdf:nodeID and Property Attributes are permitted on Property Elements", "Empty Property Element", element);
                    }
                }
            }
        }
Exemplo n.º 37
0
 /// <summary>
 /// Applies the Namespace Attributes of an Element Event to the Namespace Map
 /// </summary>
 /// <param name="context">Parser Context</param>
 /// <param name="evt">Element Event</param>
 private void ApplyNamespaces(RdfXmlParserContext context, ElementEvent evt)
 {
     if (!evt.BaseUri.Equals(String.Empty))
     {
         Uri baseUri = UriFactory.Create(Tools.ResolveUri(evt.BaseUri, context.BaseUri.ToSafeString()));
         context.BaseUri = baseUri;
         if (!context.Handler.HandleBaseUri(baseUri)) ParserHelper.Stop();
     }
     foreach (NamespaceAttributeEvent ns in evt.NamespaceAttributes)
     {
         if (!context.Namespaces.HasNamespace(ns.Prefix) || !context.Namespaces.GetNamespaceUri(ns.Prefix).ToString().Equals(ns.Uri))
         {
             context.Namespaces.AddNamespace(ns.Prefix, UriFactory.Create(ns.Uri));
             if (!context.Handler.HandleNamespace(ns.Prefix, UriFactory.Create(ns.Uri))) ParserHelper.Stop();
         }
     }
 }
Exemplo n.º 38
0
 private IUriNode Resolve(RdfXmlParserContext context, ElementEvent el)
 {
     try
     {
         IUriNode u = context.Handler.CreateUriNode(UriFactory.Create(Tools.ResolveQName(el.QName, context.Namespaces, context.BaseUri)));
         return u;
     }
     catch (Exception ex)
     {
         throw ParserHelper.Error(ex.Message, el);
     }
 }