// Token: 0x06007854 RID: 30804 RVA: 0x002243FC File Offset: 0x002225FC
        public static void UpdateAnnotation(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            AnnotationService annotationService = null;
            bool autoFlush = false;

            try
            {
                annotationService = AnnotationService.GetService(((IAnnotationComponent)snc).AnnotatedElement);
                if (annotationService != null && annotationService.Store != null)
                {
                    autoFlush = annotationService.Store.AutoFlush;
                    annotationService.Store.AutoFlush = false;
                }
                if ((token & XmlToken.Ink) != (XmlToken)0 && snc.Content.Type == StickyNoteType.Ink)
                {
                    sncAnnotation.UpdateContent(snc, true, XmlToken.Ink);
                }
                if ((token & XmlToken.Text) != (XmlToken)0 && snc.Content.Type == StickyNoteType.Text)
                {
                    sncAnnotation.UpdateContent(snc, true, XmlToken.Text);
                }
                if ((token & (XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset | XmlToken.Width | XmlToken.Height | XmlToken.IsExpanded | XmlToken.Author | XmlToken.ZOrder)) != (XmlToken)0)
                {
                    SNCAnnotation.UpdateMetaData(token, snc, sncAnnotation);
                }
            }
            finally
            {
                if (annotationService != null && annotationService.Store != null)
                {
                    annotationService.Store.AutoFlush = autoFlush;
                }
            }
        }
        // Token: 0x0600785B RID: 30811 RVA: 0x002248A0 File Offset: 0x00222AA0
        private static void GetCargoAndRoot(SNCAnnotation annotation, XmlToken token, out AnnotationResource cargo, out XmlElement root, out bool newCargo, out bool newRoot)
        {
            Invariant.Assert(annotation != null, "Annotation is null.");
            Invariant.Assert((token & (XmlToken.MetaData | XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset | XmlToken.Width | XmlToken.Height | XmlToken.IsExpanded | XmlToken.Author | XmlToken.Text | XmlToken.Ink | XmlToken.ZOrder)) > (XmlToken)0, "No token specified.");
            string cargoName = SNCAnnotation.GetCargoName(token);

            newRoot  = false;
            newCargo = false;
            cargo    = annotation.FindCargo(cargoName);
            if (cargo != null)
            {
                root = SNCAnnotation.FindRootXmlElement(token, cargo);
                if (root == null)
                {
                    newRoot = true;
                    XmlDocument xmlDocument = new XmlDocument();
                    root = xmlDocument.CreateElement(SNCAnnotation.GetXmlName(token), "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                    return;
                }
            }
            else
            {
                newCargo = true;
                cargo    = new AnnotationResource(cargoName);
                XmlDocument xmlDocument2 = new XmlDocument();
                root = xmlDocument2.CreateElement(SNCAnnotation.GetXmlName(token), "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                cargo.Contents.Add(root);
            }
        }
示例#3
0
        public IXmlAttributeValue Parse(IXmlAttributeValue xmlAttributeValue)
        {
            ReferenceNameAttributeValue attributeValue = new ReferenceNameAttributeValue();

            CompositeElement result = null;

            string rawValue = xmlAttributeValue.UnquotedValue;

            try
            {
                result = ParseTypeNameOrAttributeValue(rawValue);
            }
            catch (SyntaxError syntaxError)
            {
                result = (CompositeElement)syntaxError.ParsingResult;
                result = handleError(result, syntaxError);
            }

            attributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));
            attributeValue.AddChild(result);
            int resultLegth = result.GetText().Length;
            if(resultLegth < rawValue.Length)
            {
                string suffix = rawValue.Substring(resultLegth);
                StringBuffer sb = new StringBuffer(suffix);
                XmlToken suffixToken = new XmlToken(L4NTokenNodeType.TEXT , sb, 0, suffix.Length);
                attributeValue.AddChild(suffixToken);
            }
            attributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));

            return attributeValue;
        }
示例#4
0
        /// <summary>
        /// Before any doctype - still in the prolog. No declaration
        /// allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        private void BeforeDoctype(XmlToken token)
        {
            switch (token.Type)
            {
            case XmlTokenType.Doctype:
            {
                var doctypeToken = (XmlDoctypeToken)token;
                var doctypeNode  = new DocumentType(_document, doctypeToken.Name)
                {
                    SystemIdentifier = doctypeToken.SystemIdentifier,
                    PublicIdentifier = doctypeToken.PublicIdentifier
                };
                _document.AppendChild(doctypeNode);
                _currentMode = XmlTreeMode.Misc;

                break;
            }

            default:
            {
                InMisc(token);
                break;
            }
            }
        }
示例#5
0
        /// <summary>
        /// Consumes a token and processes it.
        /// </summary>
        /// <param name="token">The token to consume.</param>
        private void Consume(XmlToken token)
        {
            switch (_currentMode)
            {
            case XmlTreeMode.Initial:
                Initial(token);
                break;

            case XmlTreeMode.Prolog:
                BeforeDoctype(token);
                break;

            case XmlTreeMode.Misc:
                InMisc(token);
                break;

            case XmlTreeMode.Body:
                InBody(token);
                break;

            case XmlTreeMode.After:
                AfterBody(token);
                break;
            }
        }
示例#6
0
            public override void Write(XmlNodeType nodeType, QName name, string value)
            {
                lock (this)
                {
                    Debug.Assert(ReadEndPos <= WritePos && WritePos <= ReadStartPos + Buffer.Length);
                    if (WritePos == ReadStartPos + Buffer.Length)
                    {
                        if (WritePos == ReadEndPos)
                        {
                            ExpandBuffer();
                        }
                        else
                        {
                            Monitor.Wait(this);
                        }
                    }

                    Debug.Assert(WritePos < ReadStartPos + Buffer.Length);
                    XmlToken.Set(ref Buffer[WritePos & Mask], nodeType, name, value);

                    WritePos++;
                    if (ReadStartPos + Buffer.Length <= WritePos)
                    {
                        // This "if" is some heuristics, it may wrk or may not:
                        // To minimize task switching we wakeup reader ony if we wrote enouph tokens.
                        // So if reader already waits, let it sleep before we fill up the buffer.
                        Monitor.Pulse(this);
                    }
                }
            }
示例#7
0
        /// <summary>
        /// After the body state - nothing except Comment PI S allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        private void AfterBody(XmlToken token)
        {
            switch (token.Type)
            {
            case XmlTokenType.ProcessingInstruction:
            case XmlTokenType.Comment:
            {
                InMisc(token);
                break;
            }

            case XmlTokenType.EndOfFile:
            {
                break;
            }

            default:
            {
                if (!token.IsIgnorable && !_options.IsSuppressingErrors)
                {
                    throw XmlParseError.XmlMissingRoot.At(token.Position);
                }

                break;
            }
            }
        }
        // Token: 0x0600785C RID: 30812 RVA: 0x0022494C File Offset: 0x00222B4C
        private void UpdateAttribute(XmlElement root, XmlToken token, string value)
        {
            string  xmlName       = SNCAnnotation.GetXmlName(token);
            XmlNode attributeNode = root.GetAttributeNode(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base");

            if (attributeNode == null)
            {
                if (value == null)
                {
                    return;
                }
                root.SetAttribute(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base", value);
                return;
            }
            else
            {
                if (value == null)
                {
                    root.RemoveAttribute(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                    return;
                }
                if (attributeNode.Value != value)
                {
                    root.SetAttribute(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base", value);
                }
                return;
            }
        }
 // Token: 0x06007851 RID: 30801 RVA: 0x0022435C File Offset: 0x0022255C
 static SNCAnnotation()
 {
     foreach (object obj in Enum.GetValues(typeof(XmlToken)))
     {
         XmlToken token = (XmlToken)obj;
         SNCAnnotation.AddXmlTokenNames(token);
     }
 }
        // Token: 0x06007863 RID: 30819 RVA: 0x00224D80 File Offset: 0x00222F80
        private static void UpdateMetaData(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            AnnotationResource annotationResource;
            XmlElement         xmlElement;
            bool flag;
            bool flag2;

            SNCAnnotation.GetCargoAndRoot(sncAnnotation, XmlToken.MetaData, out annotationResource, out xmlElement, out flag, out flag2);
            if ((token & XmlToken.IsExpanded) != (XmlToken)0)
            {
                bool isExpanded = snc.IsExpanded;
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.IsExpanded, isExpanded.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Height) != (XmlToken)0)
            {
                double num = (double)snc.GetValue(FrameworkElement.HeightProperty);
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Height, num.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Width) != (XmlToken)0)
            {
                double num2 = (double)snc.GetValue(FrameworkElement.WidthProperty);
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Width, num2.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Left) != (XmlToken)0)
            {
                double num3 = snc.PositionTransform.X;
                if (snc.FlipBothOrigins)
                {
                    num3 = -(num3 + snc.Width);
                }
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Left, num3.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Top) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Top, snc.PositionTransform.Y.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.XOffset) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.XOffset, snc.XOffset.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.YOffset) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.YOffset, snc.YOffset.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.ZOrder) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.ZOrder, ((IAnnotationComponent)snc).ZOrder.ToString(CultureInfo.InvariantCulture));
            }
            if (flag2)
            {
                annotationResource.Contents.Add(xmlElement);
            }
            if (flag)
            {
                sncAnnotation._annotation.Cargos.Add(annotationResource);
            }
        }
示例#11
0
            public override void GetToken(int attNum, out QName name, out string value)
            {
                Debug.Assert(0 <= attNum && attNum < ReadEndPos - ReadStartPos - 1);
                XmlNodeType nodeType;

                XmlToken.Get(ref Buffer[(ReadStartPos + attNum) & Mask], out nodeType, out name, out value);
                Debug.Assert(nodeType == (attNum == 0 ? XmlNodeType.Element : XmlNodeType.Attribute),
                             "We use GetToken() only to access parts of start element tag.");
            }
示例#12
0
        private TreeElement ParseIdentifier()
        {
            if (lexer.TokenType != CSharpTokenType.IDENTIFIER)
            {
                throw new UnexpectedToken("Expected identifier");
            }

            TreeElement result = new XmlToken(L4NTokenNodeType.IDENTIFIER, lexer.Buffer, lexer.TokenStart, lexer.TokenEnd);
            lexer.Advance();
            return result;
        }
示例#13
0
        DtdToken Rework(XmlToken xmlToken)
        {
            if (xmlToken is XmlPIToken)
                return new DtdPIToken((XmlPIToken)xmlToken);
            else if (xmlToken is XmlCommentToken)
                return new DtdCommentToken((XmlCommentToken)xmlToken);
            else if (xmlToken is XmlEndOfFileToken)
                return DtdToken.EOF;

            throw new ArgumentException("The received token is not valid for a DTD.");
        }
示例#14
0
 public virtual void Write(XmlNodeType nodeType, QName name, string value)
 {
     Debug.Assert(WritePos <= Buffer.Length);
     if (WritePos == Buffer.Length)
     {
         var temp = new XmlToken[Buffer.Length * 2];
         Buffer.CopyTo(temp, 0);
         Buffer = temp;
     }
     Debug.Assert(WritePos < Buffer.Length);
     XmlToken.Set(ref Buffer[WritePos], nodeType, name, value);
     WritePos++;
 }
        // Token: 0x06007860 RID: 30816 RVA: 0x00224AE8 File Offset: 0x00222CE8
        private static XmlElement FindRootXmlElement(XmlToken token, AnnotationResource cargo)
        {
            XmlElement result = null;
            string     value  = string.Empty;

            if (token <= XmlToken.YOffset)
            {
                if (token <= XmlToken.Left)
                {
                    if (token != XmlToken.MetaData && token != XmlToken.Left)
                    {
                        goto IL_77;
                    }
                }
                else if (token != XmlToken.Top && token != XmlToken.XOffset && token != XmlToken.YOffset)
                {
                    goto IL_77;
                }
            }
            else if (token <= XmlToken.IsExpanded)
            {
                if (token != XmlToken.Width && token != XmlToken.Height && token != XmlToken.IsExpanded)
                {
                    goto IL_77;
                }
            }
            else
            {
                if (token == XmlToken.Text || token == XmlToken.Ink)
                {
                    value = SNCAnnotation.GetXmlName(token);
                    goto IL_77;
                }
                if (token != XmlToken.ZOrder)
                {
                    goto IL_77;
                }
            }
            value = SNCAnnotation.GetXmlName(XmlToken.MetaData);
IL_77:
            foreach (XmlElement xmlElement in cargo.Contents)
            {
                if (xmlElement.Name.Equals(value))
                {
                    result = xmlElement;
                    break;
                }
            }
            return(result);
        }
示例#16
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            if (!Highlighting.IsValid())
            {
                return(null);
            }

            var node             = Highlighting.Node;
            var badWordTextRange = Highlighting.Range.TextRange;

            var newText = StringUtil.ReplaceSection(
                node.GetText(),
                Suggestion,
                badWordTextRange.StartOffset - node.GetDocumentRange().TextRange.StartOffset,
                badWordTextRange.Length
                );

            if (node is XmlValueToken)
            {
                var newElm = new XmlValueToken(
                    (node as XmlValueToken).GetTokenType(),
                    new StringBuffer(newText),
                    new TreeOffset(0),
                    new TreeOffset(newText.Length)
                    );
                ModificationUtil.ReplaceChild(node, newElm);
                return(null);
            }
            if (node is XmlFloatingTextToken)
            {
                var newElm = new XmlFloatingTextToken(
                    (node as XmlFloatingTextToken).GetTokenType(),
                    newText
                    );
                ModificationUtil.ReplaceChild(node, newElm);
                return(null);
            }
            if (node is XmlToken)
            {
                var newElm = new XmlToken(
                    (node as XmlToken).GetTokenType(),
                    new StringBuffer(newText),
                    new TreeOffset(0),
                    new TreeOffset(newText.Length)
                    );
                ModificationUtil.ReplaceChild(node, newElm);
                return(null);
            }
            return(null);
        }
        static Color ColorForToken(XmlToken token, string tokenText)
        {
            Color color = Color.FromRgb(0, 0, 0);

            switch (token.Kind)
            {
            case XmlTokenKind.Open:
            case XmlTokenKind.OpenClose:
            case XmlTokenKind.Close:
            case XmlTokenKind.SelfClose:
            case XmlTokenKind.CommentBegin:
            case XmlTokenKind.CommentEnd:
            case XmlTokenKind.CDataBegin:
            case XmlTokenKind.CDataEnd:
            case XmlTokenKind.Equals:
            case XmlTokenKind.OpenProcessingInstruction:
            case XmlTokenKind.CloseProcessingInstruction:
            case XmlTokenKind.AttributeValue:
                color = Color.FromRgb(0, 0, 255);
                // color = "blue";
                break;

            case XmlTokenKind.ElementName:
                color = Color.FromRgb(163, 21, 21);
                // color = "brown";
                break;

            case XmlTokenKind.TextContent:
                // color = "black";
                break;

            case XmlTokenKind.AttributeName:
            case XmlTokenKind.Entity:
                color = Color.FromRgb(255, 0, 0);
                // color = "red";
                break;

            case XmlTokenKind.CommentText:
                color = Color.FromRgb(0, 128, 0);
                // color = "green";
                break;
            }
            if (token.Kind == XmlTokenKind.ElementWhitespace ||
                (token.Kind == XmlTokenKind.TextContent && tokenText.Trim() == ""))
            {
                // color = null;
            }
            return(color);
        }
        // Token: 0x0600785E RID: 30814 RVA: 0x002249BC File Offset: 0x00222BBC
        private static void AddXmlTokenNames(XmlToken token)
        {
            string text = token.ToString();

            if (token <= XmlToken.YOffset)
            {
                if (token <= XmlToken.Left)
                {
                    if (token != XmlToken.MetaData)
                    {
                        if (token != XmlToken.Left)
                        {
                            goto IL_84;
                        }
                        goto IL_84;
                    }
                }
                else
                {
                    if (token != XmlToken.Top && token != XmlToken.XOffset && token != XmlToken.YOffset)
                    {
                        goto IL_84;
                    }
                    goto IL_84;
                }
            }
            else if (token <= XmlToken.IsExpanded)
            {
                if (token != XmlToken.Width && token != XmlToken.Height && token != XmlToken.IsExpanded)
                {
                    goto IL_84;
                }
                goto IL_84;
            }
            else if (token != XmlToken.Text && token != XmlToken.Ink)
            {
                if (token != XmlToken.ZOrder)
                {
                    goto IL_84;
                }
                goto IL_84;
            }
            SNCAnnotation.s_xmlTokeFullNames.Add(token, "anb:" + text);
            return;

IL_84:
            SNCAnnotation.s_xmlTokeFullNames.Add(token, text);
        }
示例#19
0
            private void ExpandBuffer()
            {
                // Buffer is too smal for this amount of attributes.
                Debug.Assert(WritePos == ReadStartPos + Buffer.Length, "no space to write next token");
                Debug.Assert(WritePos == ReadEndPos, "all tokens ware read");
                var newMask   = (Mask << 1) | 1;
                var newBuffer = new XmlToken[newMask + 1];

                for (var i = ReadStartPos; i < WritePos; i++)
                {
                    newBuffer[i & newMask] = Buffer[i & Mask];
                }
                Buffer = newBuffer;
                Mask   = newMask;
                Debug.Assert(WritePos < ReadStartPos + Buffer.Length, "we should have now space to next write token");
            }
        // Token: 0x06007861 RID: 30817 RVA: 0x00224BB8 File Offset: 0x00222DB8
        private static object FindContent(XmlToken token, AnnotationResource cargo)
        {
            object     result     = null;
            XmlElement xmlElement = SNCAnnotation.FindRootXmlElement(token, cargo);

            if (xmlElement != null)
            {
                if (token <= XmlToken.Width)
                {
                    if (token <= XmlToken.Top)
                    {
                        if (token != XmlToken.Left && token != XmlToken.Top)
                        {
                            return(result);
                        }
                    }
                    else if (token != XmlToken.XOffset && token != XmlToken.YOffset && token != XmlToken.Width)
                    {
                        return(result);
                    }
                }
                else if (token <= XmlToken.IsExpanded)
                {
                    if (token != XmlToken.Height && token != XmlToken.IsExpanded)
                    {
                        return(result);
                    }
                }
                else
                {
                    if (token == XmlToken.Text || token == XmlToken.Ink)
                    {
                        return(xmlElement);
                    }
                    if (token != XmlToken.ZOrder)
                    {
                        return(result);
                    }
                }
                return(xmlElement.GetAttributeNode(SNCAnnotation.GetXmlName(token), "http://schemas.microsoft.com/windows/annotations/2003/11/base"));
            }
            return(result);
        }
        // Token: 0x0600785F RID: 30815 RVA: 0x00224A5C File Offset: 0x00222C5C
        private static string GetCargoName(XmlToken token)
        {
            if (token <= XmlToken.YOffset)
            {
                if (token <= XmlToken.Left)
                {
                    if (token != XmlToken.MetaData && token != XmlToken.Left)
                    {
                        goto IL_75;
                    }
                }
                else if (token != XmlToken.Top && token != XmlToken.XOffset && token != XmlToken.YOffset)
                {
                    goto IL_75;
                }
            }
            else if (token <= XmlToken.IsExpanded)
            {
                if (token != XmlToken.Width && token != XmlToken.Height && token != XmlToken.IsExpanded)
                {
                    goto IL_75;
                }
            }
            else
            {
                if (token == XmlToken.Text)
                {
                    return("Text Data");
                }
                if (token == XmlToken.Ink)
                {
                    return("Ink Data");
                }
                if (token != XmlToken.ZOrder)
                {
                    goto IL_75;
                }
            }
            return("Meta Data");

IL_75:
            return(string.Empty);
        }
        // Token: 0x0600785A RID: 30810 RVA: 0x00224848 File Offset: 0x00222A48
        private object FindData(XmlToken token)
        {
            object obj = null;

            if (this._cachedXmlElements.ContainsKey(token))
            {
                obj = this._cachedXmlElements[token];
            }
            else
            {
                AnnotationResource annotationResource = this.FindCargo(SNCAnnotation.GetCargoName(token));
                if (annotationResource != null)
                {
                    obj = SNCAnnotation.FindContent(token, annotationResource);
                    if (obj != null)
                    {
                        this._cachedXmlElements.Add(token, obj);
                    }
                }
            }
            return(obj);
        }
示例#23
0
        /// <summary>
        /// In the body state - no doctypes and declarations allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        private void InMisc(XmlToken token)
        {
            switch (token.Type)
            {
            case XmlTokenType.Comment:
            {
                var commenToken = (XmlCommentToken)token;
                var commentNode = _document.CreateComment(commenToken.Data);
                CurrentNode.AppendChild(commentNode);
                break;
            }

            case XmlTokenType.ProcessingInstruction:
            {
                var piToken = (XmlPIToken)token;
                var piNode  = _document.CreateProcessingInstruction(piToken.Target, piToken.Content);
                CurrentNode.AppendChild(piNode);
                break;
            }

            case XmlTokenType.StartTag:
            {
                _currentMode = XmlTreeMode.Body;
                InBody(token);
                break;
            }

            default:
            {
                if (!token.IsIgnorable && !_options.IsSuppressingErrors)
                {
                    throw XmlParseError.XmlMissingRoot.At(token.Position);
                }

                break;
            }
            }
        }
示例#24
0
 public override void Read(out XmlNodeType nodeType, out QName name, out string value)
 {
     lock (this)
     {
         Debug.Assert(ReadEndPos <= WritePos && WritePos <= ReadStartPos + Buffer.Length);
         if (ReadEndPos == WritePos)
         {
             if (ReadEndPos == ReadStartPos + Buffer.Length)
             {
                 ExpandBuffer();
                 Monitor.Pulse(this);
             }
             Monitor.Wait(this);
         }
         if (_exception != null)
         {
             throw new XsltException("Exception happened during transformation. See inner exception for details:\n", _exception);
         }
     }
     Debug.Assert(ReadEndPos < WritePos);
     XmlToken.Get(ref Buffer[ReadEndPos & Mask], out nodeType, out name, out value);
     ReadEndPos++;
 }
示例#25
0
        /// <summary>
        /// The initial state. Expects an XML declaration.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        private void Initial(XmlToken token)
        {
            if (token.Type == XmlTokenType.Declaration)
            {
                var declarationToken = (XmlDeclarationToken)token;
                _standalone = declarationToken.Standalone;

                if (!declarationToken.IsEncodingMissing)
                {
                    SetEncoding(declarationToken.Encoding);
                }

                if (!CheckVersion(declarationToken.Version) && !_options.IsSuppressingErrors)
                {
                    throw XmlParseError.XmlDeclarationVersionUnsupported.At(token.Position);
                }
            }
            else
            {
                _currentMode = XmlTreeMode.Prolog;
                BeforeDoctype(token);
            }
        }
示例#26
0
        /// <summary>
        /// After the body state - nothing except Comment PI S allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        void AfterBody(XmlToken token)
        {
            switch (token.Type)
            {
                case XmlTokenType.ProcessingInstruction:
                case XmlTokenType.Comment:
                {
                    InMisc(token);
                    break;
                }
                case XmlTokenType.EndOfFile:
                {
                    break;
                }
                default:
                {
                    if (!token.IsIgnorable && !_options.IsSuppressingErrors)
                    {
                        throw XmlParseError.XmlMissingRoot.At(token.Position);
                    }

                    break;
                }
            }
        }
示例#27
0
        /// <summary>
        /// In the body state - no doctypes and declarations allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        void InBody(XmlToken token)
        {
            switch (token.Type)
            {
                case XmlTokenType.StartTag:
                {
                    var tagToken = (XmlTagToken)token;
                    var element = new XmlElement(_document, tagToken.Name);
                    CurrentNode.AppendChild(element);

                    if (!tagToken.IsSelfClosing)
                    {
                        _openElements.Add(element);
                    }
                    else if (_openElements.Count == 0)
                    {
                        _currentMode = XmlTreeMode.After;
                    }

                    for (var i = 0; i < tagToken.Attributes.Count; i++)
                    {
                        var name = tagToken.Attributes[i].Key;
                        var value = tagToken.Attributes[i].Value.Trim();
                        element.SetAttribute(name, value);
                    }

                    break;
                }
                case XmlTokenType.EndTag:
                {
                    var tagToken = (XmlTagToken)token;

                    if (!CurrentNode.NodeName.Is(tagToken.Name))
                    {
                        if (_options.IsSuppressingErrors)
                        {
                            break;
                        }

                        throw XmlParseError.TagClosingMismatch.At(token.Position);
                    }

                    _openElements.RemoveAt(_openElements.Count - 1);

                    if (_openElements.Count == 0)
                    {
                        _currentMode = XmlTreeMode.After;
                    }

                    break;
                }
                case XmlTokenType.ProcessingInstruction:
                case XmlTokenType.Comment:
                {
                    InMisc(token);
                    break;
                }
                case XmlTokenType.CData:
                {
                    var cdataToken = (XmlCDataToken)token;
                    CurrentNode.AppendText(cdataToken.Data);
                    break;
                }
                case XmlTokenType.Character:
                {
                    var charToken = (XmlCharacterToken)token;
                    CurrentNode.AppendText(charToken.Data);
                    break;
                }
                case XmlTokenType.EndOfFile:
                {
                    if (_options.IsSuppressingErrors)
                    {
                        break;
                    }

                    throw XmlParseError.EOF.At(token.Position);
                }
                case XmlTokenType.Doctype:
                {
                    if (_options.IsSuppressingErrors)
                    {
                        break;
                    }

                    throw XmlParseError.XmlDoctypeAfterContent.At(token.Position);
                }
                case XmlTokenType.Declaration:
                {
                    if (_options.IsSuppressingErrors)
                    {
                        break;
                    }

                    throw XmlParseError.XmlDeclarationMisplaced.At(token.Position);
                }
            }
        }
示例#28
0
        /// <summary>
        /// In the body state - no doctypes and declarations allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        void InMisc(XmlToken token)
        {
            switch (token.Type)
            {
                case XmlTokenType.Comment:
                {
                    var commenToken = (XmlCommentToken)token;
                    var commentNode = _document.CreateComment(commenToken.Data);
                    CurrentNode.AppendChild(commentNode);
                    break;
                }
                case XmlTokenType.ProcessingInstruction:
                {
                    var piToken = (XmlPIToken)token;
                    var piNode = _document.CreateProcessingInstruction(piToken.Target, piToken.Content);
                    CurrentNode.AppendChild(piNode);
                    break;
                }
                case XmlTokenType.StartTag:
                {
                    _currentMode = XmlTreeMode.Body;
                    InBody(token);
                    break;
                }
                default:
                {
                    if (!token.IsIgnorable && !_options.IsSuppressingErrors)
                    {
                        throw XmlParseError.XmlMissingRoot.At(token.Position);
                    }

                    break;
                }
            }
        }
示例#29
0
        /// <summary>
        /// Before any doctype - still in the prolog. No declaration
        /// allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        void BeforeDoctype(XmlToken token)
        {
            switch (token.Type)
            {
                case XmlTokenType.Doctype:
                {
                    var doctypeToken = (XmlDoctypeToken)token;
                    var doctypeNode = new DocumentType(_document, doctypeToken.Name)
                    {
                        SystemIdentifier = doctypeToken.SystemIdentifier,
                        PublicIdentifier = doctypeToken.PublicIdentifier
                    };
                    _document.AppendChild(doctypeNode);
                    _currentMode = XmlTreeMode.Misc;

                    break;
                }
                default:
                {
                    InMisc(token);
                    break;
                }
            }
        }
示例#30
0
文件: XmlReader.cs 项目: noear/Snacks
        //------------------------
        public bool Read()
        {
            Token = XmlToken.None;
            Value = null;
            int buffer_char = 0;
            int buffer_peek = 0;

            while (true)
            {
                buffer_char = text_read();

                if (buffer_char < 0)
                {
                    Token = XmlToken.End;
                    return true;
                }

                if (buffer_char == '<')
                {
                    buffer_peek = text_peek();

                    if (buffer_peek == '/')
                    {
                        Token = XmlToken.TargetEnd;
                        ReadName();
                        return true;
                    }
                    else if (buffer_peek == '!')
                    {
                        text_read();
                        buffer_peek = text_peek();
                        if (buffer_peek == '-')//<!-- 注释
                            text_jump('>');
                        else //<![CDATA[
                        {
                            text_jump(6);
                            Token = XmlToken.CDATA;
                            ReadCDATA();
                            return true;
                        }
                    }
                    else if (buffer_peek == '?')
                        text_jump('>');
                    else
                    {
                        Token = XmlToken.TargetStart;
                        ReadName();
                        return true;
                    }
                }
                else
                {
                    if (Token == XmlToken.None && buffer_char > 32)
                    {
                        Token = XmlToken.Value;
                        ReadValue();
                        return true;
                    }
                }
            }
        }
示例#31
0
    /// <summary>
    /// Iterate over characters one by one to tokenize the Xml string.
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    private static List <XmlToken> LoopTokenize(string str)
    {
        //  Temp variables to build up the current token
        List <char> currentTokenText = new List <char>();

        //  Represents the list of tokens to be returned
        List <XmlToken> tokens = new List <XmlToken>();

        //  Represents the index of the first character in the token
        int tokenIndex = 0;

        bool isStartTag  = false;
        bool isComment   = false;
        bool isQuote     = false;
        bool isAttribute = false;

        for (int i = 0; i < str.Length; i++)
        {
            //  Get the current character
            char c = str[i];

            //  Skip the "ZERO WIDTH NO-BREAK SPACE" character resulting from encoding
            if (c == 65279)
            {
                continue;
            }

            //  Handle the escape sequence case
            if (c == '&')
            {
                if (currentTokenText.Count > 0)
                {
                    XmlToken token = new XmlToken();
                    token.Index = tokenIndex;
                    token.Text  = new string(currentTokenText.ToArray());
                    tokens.Add(token);
                    currentTokenText.Clear();

                    //  Determine token type
                    if (isQuote)
                    {
                        token.Type = XmlTokenType.Value;
                    }
                    else if (isComment)
                    {
                        token.Type = XmlTokenType.Comment;
                    }
                    else if (isStartTag)
                    {
                        if (isAttribute)
                        {
                            token.Type = XmlTokenType.Attribute;
                        }
                        else
                        {
                            token.Type = XmlTokenType.Element;
                        }
                    }
                    else
                    {
                        token.Type = XmlTokenType.None;
                    }
                }

                currentTokenText.Add('&');

                XmlToken escapeToken = new XmlToken();
                escapeToken.Type  = XmlTokenType.Escape;
                escapeToken.Index = i;
                i++;

                while (i < str.Length && char.IsLetterOrDigit(str[i]))
                {
                    currentTokenText.Add(str[i]);
                    i++;
                }

                if (i < str.Length && c == ';')
                {
                    currentTokenText.Add(';');
                    i++;
                }

                escapeToken.Text = new string(currentTokenText.ToArray());
                currentTokenText.Clear();
                tokens.Add(escapeToken);
                continue;
            }

            //  Only if the character is not between "" that is in a tag
            if (!isQuote)
            {
                //  Only if the character is not in a comment
                if (!isComment)
                {
                    //  Only if we already have a start tag
                    if (isStartTag)
                    {
                        if (char.IsLetterOrDigit(c))
                        {
                            //  We're starting to build up a token, so save its index
                            if (currentTokenText.Count == 0)
                            {
                                tokenIndex = i;
                            }

                            currentTokenText.Add(c);
                        }
                        else
                        {
                            //  Add the previous token that could be an element or an attribute
                            if (currentTokenText.Count > 0)
                            {
                                XmlToken token = new XmlToken();
                                token.Text = new string(currentTokenText.ToArray());
                                currentTokenText.Clear();
                                token.Index = tokenIndex;

                                if (isAttribute)
                                {
                                    token.Type = XmlTokenType.Attribute;
                                }
                                else
                                {
                                    token.Type = XmlTokenType.Element;
                                }

                                tokens.Add(token);
                            }

                            //  Check if we have something like <!-- to flag that we have a comment
                            if (c == '-')
                            {
                                if (i - 2 >= 0 && i + 1 < str.Length)
                                {
                                    if (str[i - 2] == '<' && str[i - 1] == '!' && str[i + 1] == '-')
                                    {
                                        isStartTag = false;
                                        isComment  = true;
                                        i         += 1;
                                    }
                                }
                            }
                            //  Check if our start tag is now closed
                            else if (c == '>')
                            {
                                isStartTag  = false;
                                isAttribute = false;
                            }
                            //  We hit another start tag
                            else if (c == '<')
                            {
                                isAttribute = false;
                            }
                            //  We're starting a quote
                            else if (c == '"')
                            {
                                isQuote = true;
                            }

                            //  Check if we now have an attribute
                            if (char.IsWhiteSpace(c))
                            {
                                isAttribute = true;
                            }
                            else
                            {
                                tokens.Add(new XmlToken(c.ToString(), i, XmlTokenType.SpecialChar));
                            }
                        }
                    }
                    //  If we didn't have a start tag, check if we now have one
                    else
                    {
                        if (c == '<')
                        {
                            if (currentTokenText.Count > 0)
                            {
                                XmlToken token = new XmlToken();
                                token.Index = tokenIndex;
                                token.Text  = new string(currentTokenText.ToArray());
                                token.Type  = XmlTokenType.None;
                                tokens.Add(token);
                                currentTokenText.Clear();
                            }

                            isStartTag = true;
                            tokens.Add(new XmlToken("<", i, XmlTokenType.SpecialChar));
                        }
                        else
                        {
                            if (currentTokenText.Count == 0)
                            {
                                tokenIndex = i;
                            }

                            currentTokenText.Add(c);
                        }
                    }
                }
                //  In case we have a comment
                else
                {
                    //  We're starting to build up a token, so save its index
                    if (currentTokenText.Count == 0)
                    {
                        tokenIndex = i;
                    }

                    currentTokenText.Add(c);

                    //  Check if we have something like --> to see if we're closing a comment
                    //  or if we're at the end
                    if (i + 2 < str.Length)
                    {
                        if (c == '-')
                        {
                            if (str[i + 1] == '-' && str[i + 2] == '>')
                            {
                                isComment = false;
                                i        += 2;
                            }
                        }
                    }
                    else
                    {
                        isComment = false;
                    }

                    if (!isComment)
                    {
                        XmlToken token = new XmlToken();
                        token.Type  = XmlTokenType.Comment;
                        token.Index = tokenIndex;
                        token.Text  = new string(currentTokenText.ToArray());
                        tokens.Add(token);
                        currentTokenText.Clear();
                    }
                }
            }
            //  In case we have a quote
            else
            {
                //  We're starting to build up a token, so save its index
                if (currentTokenText.Count == 0)
                {
                    tokenIndex = i;
                }

                //  Check if we no longer have a quote
                if (c == '"')
                {
                    isQuote = false;
                    XmlToken token = new XmlToken();
                    token.Type  = XmlTokenType.Value;
                    token.Index = tokenIndex;
                    token.Text  = new string(currentTokenText.ToArray());
                    tokens.Add(token);
                    currentTokenText.Clear();
                }
                else
                {
                    currentTokenText.Add(c);
                }
            }
        }

        //  Handle the last element
        if (currentTokenText.Count > 0)
        {
            XmlToken token = new XmlToken();
            token.Index = tokenIndex;
            token.Text  = new string(currentTokenText.ToArray());
            tokens.Add(token);
            currentTokenText.Clear();

            //  Determine token type
            if (isQuote)
            {
                token.Type = XmlTokenType.Value;
            }
            else if (isComment)
            {
                token.Type = XmlTokenType.Comment;
            }
            else if (isStartTag)
            {
                if (isAttribute)
                {
                    token.Type = XmlTokenType.Attribute;
                }
                else
                {
                    token.Type = XmlTokenType.Element;
                }
            }
            else
            {
                token.Type = XmlTokenType.None;
            }
        }

        return(tokens);
    }
示例#32
0
        private IXmlAttributeValue ParseAttributeValueAspect(IXmlAttributeValue xmlAttributeValue, CompositeElement newAttributeValue, StringParse stringParse)
        {
            if (xmlAttributeValue == null) throw new ArgumentNullException("xmlAttributeValue");
            if (newAttributeValue == null) throw new ArgumentNullException("newAttributeValue");
            if (stringParse == null) throw new ArgumentNullException("stringParse");
            CompositeElement result = null;

            string rawValue = xmlAttributeValue.UnquotedValue;

            try
            {
                result = stringParse(rawValue);
            }
            catch (SyntaxError syntaxError)
            {
                result = (CompositeElement)syntaxError.ParsingResult;
                result = handleError(result, syntaxError);
            }

            newAttributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));
            newAttributeValue.AddChild(result);
            int resultLegth = result.GetText().Length;
            if(resultLegth < rawValue.Length)
            {
                string suffix = rawValue.Substring(resultLegth);
                StringBuffer sb = new StringBuffer(suffix);
                XmlToken suffixToken = new XmlToken(L4NTokenNodeType.TEXT , sb, 0, suffix.Length);
                newAttributeValue.AddChild(suffixToken);
            }
            newAttributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));

            return (IXmlAttributeValue)newAttributeValue;
        }
        // Token: 0x06007862 RID: 30818 RVA: 0x00224C48 File Offset: 0x00222E48
        private void UpdateContent(StickyNoteControl snc, bool updateAnnotation, XmlToken token)
        {
            Invariant.Assert(snc != null, "Sticky Note Control is null.");
            Invariant.Assert((token & (XmlToken.Text | XmlToken.Ink)) > (XmlToken)0, "No token specified.");
            StickyNoteContentControl content = snc.Content;

            if (content == null)
            {
                return;
            }
            if ((token == XmlToken.Ink && content.Type != StickyNoteType.Ink) || (token == XmlToken.Text && content.Type != StickyNoteType.Text))
            {
                return;
            }
            XmlElement xmlElement = null;

            if (updateAnnotation)
            {
                AnnotationResource annotationResource = null;
                bool flag  = false;
                bool flag2 = false;
                if (!content.IsEmpty)
                {
                    SNCAnnotation.GetCargoAndRoot(this, token, out annotationResource, out xmlElement, out flag2, out flag);
                    content.Save(xmlElement);
                }
                else
                {
                    string cargoName = SNCAnnotation.GetCargoName(token);
                    annotationResource = this.FindCargo(cargoName);
                    if (annotationResource != null)
                    {
                        this._annotation.Cargos.Remove(annotationResource);
                        this._cachedXmlElements.Remove(token);
                    }
                }
                if (flag)
                {
                    Invariant.Assert(xmlElement != null, "XmlElement should have been created.");
                    Invariant.Assert(annotationResource != null, "Cargo should have been retrieved.");
                    annotationResource.Contents.Add(xmlElement);
                }
                if (flag2)
                {
                    Invariant.Assert(annotationResource != null, "Cargo should have been created.");
                    this._annotation.Cargos.Add(annotationResource);
                    return;
                }
            }
            else
            {
                XmlElement xmlElement2 = (XmlElement)this.FindData(token);
                if (xmlElement2 != null)
                {
                    content.Load(xmlElement2);
                    return;
                }
                if (!content.IsEmpty)
                {
                    content.Clear();
                }
            }
        }
示例#34
0
    /// <summary>
    /// Iterate over characters one by one to tokenize the Xml string.
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    private static List<XmlToken> LoopTokenize(string str)
    {
        //  Temp variables to build up the current token
        List<char> currentTokenText = new List<char>();

        //  Represents the list of tokens to be returned
        List<XmlToken> tokens = new List<XmlToken>();

        //  Represents the index of the first character in the token
        int tokenIndex = 0;

        bool isStartTag = false;
        bool isComment = false;
        bool isQuote = false;
        bool isAttribute = false;

        for (int i = 0; i < str.Length; i++)
        {
            //  Get the current character
            char c = str[i];

            //  Skip the "ZERO WIDTH NO-BREAK SPACE" character resulting from encoding
            if (c == 65279)
            {
                continue;
            }

            //  Handle the escape sequence case
            if (c == '&')
            {
                if (currentTokenText.Count > 0)
                {
                    XmlToken token = new XmlToken();
                    token.Index = tokenIndex;
                    token.Text = new string(currentTokenText.ToArray());
                    tokens.Add(token);
                    currentTokenText.Clear();

                    //  Determine token type
                    if (isQuote)
                    {
                        token.Type = XmlTokenType.Value;
                    }
                    else if (isComment)
                    {
                        token.Type = XmlTokenType.Comment;
                    }
                    else if (isStartTag)
                    {
                        if (isAttribute)
                        {
                            token.Type = XmlTokenType.Attribute;
                        }
                        else
                        {
                            token.Type = XmlTokenType.Element;
                        }
                    }
                    else
                    {
                        token.Type = XmlTokenType.None;
                    }
                }

                currentTokenText.Add('&');

                XmlToken escapeToken = new XmlToken();
                escapeToken.Type = XmlTokenType.Escape;
                escapeToken.Index = i;
                i++;

                while (i < str.Length && char.IsLetterOrDigit(str[i]))
                {
                    currentTokenText.Add(str[i]);
                    i++;
                }

                if (i < str.Length && c == ';')
                {
                    currentTokenText.Add(';');
                    i++;
                }

                escapeToken.Text = new string(currentTokenText.ToArray());
                currentTokenText.Clear();
                tokens.Add(escapeToken);
                continue;
            }

            //  Only if the character is not between "" that is in a tag
            if(!isQuote)
            {
                //  Only if the character is not in a comment
                if(!isComment)
                {
                    //  Only if we already have a start tag
                    if(isStartTag)
                    {
                        if (char.IsLetterOrDigit(c))
                        {
                            //  We're starting to build up a token, so save its index
                            if (currentTokenText.Count == 0)
                            {
                                tokenIndex = i;
                            }

                            currentTokenText.Add(c);
                        }
                        else
                        {
                            //  Add the previous token that could be an element or an attribute
                            if (currentTokenText.Count > 0)
                            {
                                XmlToken token = new XmlToken();
                                token.Text = new string(currentTokenText.ToArray());
                                currentTokenText.Clear();
                                token.Index = tokenIndex;

                                if (isAttribute)
                                {
                                    token.Type = XmlTokenType.Attribute;
                                }
                                else
                                {
                                    token.Type = XmlTokenType.Element;
                                }

                                tokens.Add(token);
                            }

                            //  Check if we have something like <!-- to flag that we have a comment
                            if (c == '-')
                            {
                                if (i - 2 >= 0 && i + 1 < str.Length)
                                {
                                    if (str[i - 2] == '<' && str[i - 1] == '!' && str[i + 1] == '-')
                                    {
                                        isStartTag = false;
                                        isComment = true;
                                        i += 1;
                                    }
                                }
                            }
                            //  Check if our start tag is now closed
                            else if (c == '>')
                            {
                                isStartTag = false;
                                isAttribute = false;
                            }
                            //  We hit another start tag
                            else if (c == '<')
                            {
                                isAttribute = false;
                            }
                            //  We're starting a quote
                            else if (c == '"')
                            {
                                isQuote = true;
                            }
                            
                            //  Check if we now have an attribute
                            if (char.IsWhiteSpace(c))
                            {
                                 isAttribute = true;
                            }
                            else
                            {
                                tokens.Add(new XmlToken(c.ToString(), i, XmlTokenType.SpecialChar));
                            }
                        }
                    }
                    //  If we didn't have a start tag, check if we now have one
                    else
                    {
                        if (c == '<')
                        {
                            if (currentTokenText.Count > 0)
                            {
                                XmlToken token = new XmlToken();
                                token.Index = tokenIndex;
                                token.Text = new string(currentTokenText.ToArray());
                                token.Type = XmlTokenType.None;
                                tokens.Add(token);
                                currentTokenText.Clear();
                            }

                            isStartTag = true;
                            tokens.Add(new XmlToken("<", i, XmlTokenType.SpecialChar));
                        }
                        else
                        {
                            if (currentTokenText.Count == 0)
                            {
                                tokenIndex = i;
                            }

                            currentTokenText.Add(c);
                        }
                    }
                }
                //  In case we have a comment
                else
                {
                    //  We're starting to build up a token, so save its index
                    if (currentTokenText.Count == 0)
                    {
                        tokenIndex = i;
                    }

                    currentTokenText.Add(c);

                    //  Check if we have something like --> to see if we're closing a comment
                    //  or if we're at the end
                    if (i + 2 < str.Length)
                    {
                        if (c == '-')
                        {
                            if (str[i + 1] == '-' && str[i + 2] == '>')
                            {
                                isComment = false;
                                i += 2;
                            }
                        }
                    }
                    else
                    {
                        isComment = false;
                    }

                    if (!isComment)
                    {
                        XmlToken token = new XmlToken();
                        token.Type = XmlTokenType.Comment;
                        token.Index = tokenIndex;
                        token.Text = new string(currentTokenText.ToArray());
                        tokens.Add(token);
                        currentTokenText.Clear();
                    }
                }
            }
            //  In case we have a quote
            else
            {
                //  We're starting to build up a token, so save its index
                if (currentTokenText.Count == 0)
                {
                    tokenIndex = i;
                }

                //  Check if we no longer have a quote
                if (c == '"')
                {
                    isQuote = false;
                    XmlToken token = new XmlToken();
                    token.Type = XmlTokenType.Value;
                    token.Index = tokenIndex;
                    token.Text = new string(currentTokenText.ToArray());
                    tokens.Add(token);
                    currentTokenText.Clear();
                }
                else
                {
                    currentTokenText.Add(c);
                }
            }
        }

        //  Handle the last element
        if (currentTokenText.Count > 0)
        {
            XmlToken token = new XmlToken();
            token.Index = tokenIndex;
            token.Text = new string(currentTokenText.ToArray());
            tokens.Add(token);
            currentTokenText.Clear();

            //  Determine token type
            if (isQuote)
            {
                token.Type = XmlTokenType.Value;
            }
            else if (isComment)
            {
                token.Type = XmlTokenType.Comment;
            }
            else if (isStartTag)
            {
                if (isAttribute)
                {
                    token.Type = XmlTokenType.Attribute;
                }
                else
                {
                    token.Type = XmlTokenType.Element;
                }
            }
            else
            {
                token.Type = XmlTokenType.None;
            }
        }

        return tokens;
    }
示例#35
0
 private ReferenceTable CreateReferenceTable(XmlToken token)
 {
     ReferenceTable referenceTable = new ReferenceTable();
     referenceTable.AppendNewChild(token);
     return referenceTable;
 }
示例#36
0
        /// <summary>
        /// In the body state - no doctypes and declarations allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        private void InBody(XmlToken token)
        {
            switch (token.Type)
            {
            case XmlTokenType.StartTag:
            {
                var tagToken = (XmlTagToken)token;
                var element  = CreateElement(tagToken.Name);
                CurrentNode.AppendChild(element);

                for (var i = 0; i < tagToken.Attributes.Count; i++)
                {
                    var attr = tagToken.Attributes[i];
                    var item = CreateAttribute(attr.Key, attr.Value.Trim());
                    element.Attributes.FastAddItem(item);
                }

                if (!tagToken.IsSelfClosing)
                {
                    _openElements.Add(element);
                }
                else if (_openElements.Count == 0)
                {
                    _currentMode = XmlTreeMode.After;
                }

                if (_options.OnCreated != null)
                {
                    _options.OnCreated.Invoke(element, tagToken.Position);
                }

                break;
            }

            case XmlTokenType.EndTag:
            {
                var tagToken = (XmlTagToken)token;

                if (!CurrentNode.NodeName.Is(tagToken.Name))
                {
                    if (_options.IsSuppressingErrors)
                    {
                        break;
                    }

                    throw XmlParseError.TagClosingMismatch.At(token.Position);
                }

                _openElements.RemoveAt(_openElements.Count - 1);

                if (_openElements.Count == 0)
                {
                    _currentMode = XmlTreeMode.After;
                }

                break;
            }

            case XmlTokenType.ProcessingInstruction:
            case XmlTokenType.Comment:
            {
                InMisc(token);
                break;
            }

            case XmlTokenType.CData:
            {
                var cdataToken = (XmlCDataToken)token;
                CurrentNode.AppendText(cdataToken.Data);
                break;
            }

            case XmlTokenType.Character:
            {
                var charToken = (XmlCharacterToken)token;
                CurrentNode.AppendText(charToken.Data);
                break;
            }

            case XmlTokenType.EndOfFile:
            {
                if (_options.IsSuppressingErrors)
                {
                    break;
                }

                throw XmlParseError.EOF.At(token.Position);
            }

            case XmlTokenType.Doctype:
            {
                if (_options.IsSuppressingErrors)
                {
                    break;
                }

                throw XmlParseError.XmlDoctypeAfterContent.At(token.Position);
            }

            case XmlTokenType.Declaration:
            {
                if (_options.IsSuppressingErrors)
                {
                    break;
                }

                throw XmlParseError.XmlDeclarationMisplaced.At(token.Position);
            }
            }
        }
 // Token: 0x06007855 RID: 30805 RVA: 0x002244C0 File Offset: 0x002226C0
 public static void UpdateStickyNoteControl(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
 {
     Invariant.Assert((token & (XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset | XmlToken.Width | XmlToken.Height | XmlToken.IsExpanded | XmlToken.Author | XmlToken.Text | XmlToken.Ink | XmlToken.ZOrder)) > (XmlToken)0, "No token specified.");
     Invariant.Assert(snc != null, "Sticky Note Control is null.");
     Invariant.Assert(sncAnnotation != null, "Annotation is null.");
     if ((token & XmlToken.Ink) != (XmlToken)0 && sncAnnotation.HasInkData)
     {
         sncAnnotation.UpdateContent(snc, false, XmlToken.Ink);
     }
     if ((token & XmlToken.Text) != (XmlToken)0 && sncAnnotation.HasTextData)
     {
         sncAnnotation.UpdateContent(snc, false, XmlToken.Text);
     }
     if ((token & XmlToken.Author) != (XmlToken)0)
     {
         int    count         = sncAnnotation._annotation.Authors.Count;
         string listSeparator = snc.Language.GetSpecificCulture().TextInfo.ListSeparator;
         string text          = string.Empty;
         for (int i = 0; i < count; i++)
         {
             if (i != 0)
             {
                 text = text + listSeparator + sncAnnotation._annotation.Authors[i];
             }
             else
             {
                 text += sncAnnotation._annotation.Authors[i];
             }
         }
         snc.SetValue(StickyNoteControl.AuthorPropertyKey, text);
     }
     if ((token & XmlToken.Height) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Height);
         if (xmlAttribute != null)
         {
             double num = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             snc.SetValue(FrameworkElement.HeightProperty, num);
         }
         else
         {
             snc.ClearValue(FrameworkElement.HeightProperty);
         }
     }
     if ((token & XmlToken.Width) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Width);
         if (xmlAttribute != null)
         {
             double num2 = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             snc.SetValue(FrameworkElement.WidthProperty, num2);
         }
         else
         {
             snc.ClearValue(FrameworkElement.WidthProperty);
         }
     }
     if ((token & XmlToken.IsExpanded) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.IsExpanded);
         if (xmlAttribute != null)
         {
             bool isExpanded = Convert.ToBoolean(xmlAttribute.Value, CultureInfo.InvariantCulture);
             snc.IsExpanded = isExpanded;
         }
         else
         {
             snc.ClearValue(StickyNoteControl.IsExpandedProperty);
         }
     }
     if ((token & XmlToken.ZOrder) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.ZOrder);
         if (xmlAttribute != null)
         {
             ((IAnnotationComponent)snc).ZOrder = Convert.ToInt32(xmlAttribute.Value, CultureInfo.InvariantCulture);
         }
     }
     if ((token & (XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset)) != (XmlToken)0)
     {
         TranslateTransform translateTransform = new TranslateTransform();
         if ((token & XmlToken.Left) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Left);
             if (xmlAttribute != null)
             {
                 double num3 = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
                 if (snc.FlipBothOrigins)
                 {
                     num3 = -(num3 + snc.Width);
                 }
                 translateTransform.X = num3;
             }
         }
         if ((token & XmlToken.Top) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Top);
             if (xmlAttribute != null)
             {
                 double y = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
                 translateTransform.Y = y;
             }
         }
         if ((token & XmlToken.XOffset) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.XOffset);
             if (xmlAttribute != null)
             {
                 snc.XOffset = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             }
         }
         if ((token & XmlToken.YOffset) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.YOffset);
             if (xmlAttribute != null)
             {
                 snc.YOffset = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             }
         }
         snc.PositionTransform = translateTransform;
     }
 }
示例#38
0
 public static void Set(ref XmlToken evnt, XmlNodeType nodeType, QName name, string value)
 {
     evnt._nodeType = nodeType;
     evnt._name     = name;
     evnt._value    = value;
 }
示例#39
0
 protected virtual ReferenceModule CreateReferenceModule(XmlToken token)
 {
     ReferenceModule referenceModule = new ReferenceModule();
     referenceModule.AppendNewChild(token);
     return referenceModule;
 }
示例#40
0
 ///<summary>
 ///
 ///            Bind this reference to given Declared Element. May insert using directive.
 ///            
 ///</summary>
 ///
 ///<returns>
 ///new "this"
 ///</returns>
 ///
 public IReference BindTo(IDeclaredElement element)
 {
     using(WriteLockCookie cookie = WriteLockCookie.Create())
     {
         XmlToken token = NameToken;
         Assert.CheckNotNull(token);
         StringBuffer buffer = new StringBuffer(element.ShortName);
         XmlToken newToken = new XmlToken(token.GetTokenType(), buffer, 0, buffer.Length);
         LowLevelModificationUtil.ReplaceChildRange(token, token, new ITreeNode[] { newToken });
         ResetReferences();
     }
     return this;
 }
示例#41
0
        private XmlToken CreateModuleNameToken(int start, int end, bool unexpectedToken)
        {
            if(start == 0 && end == 0)
                throw new UnexpectedToken("Unexpected token");

            XmlToken ret = new XmlToken(L4NTokenNodeType.IDENTIFIER, lexer.Buffer, start, end);
            if(unexpectedToken)
            {
                UnexpectedToken ex = new UnexpectedToken("Unexpected token");
                ex.ParsingResult = ret;
                throw ex;
            }

            return ret;
        }
示例#42
0
 /// <summary>
 /// Consumes a token and processes it.
 /// </summary>
 /// <param name="token">The token to consume.</param>
 void Consume(XmlToken token)
 {
     switch (_currentMode)
     {
         case XmlTreeMode.Initial:
             Initial(token);
             break;
         case XmlTreeMode.Prolog:
             BeforeDoctype(token);
             break;
         case XmlTreeMode.Misc:
             InMisc(token);
             break;
         case XmlTreeMode.Body:
             InBody(token);
             break;
         case XmlTreeMode.After:
             AfterBody(token);
             break;
     }
 }
示例#43
0
        private TreeElement ParseReferenceNameInternal(TreeElement qualifier)
        {
            CompositeElement result = null;
            TreeElement tempParsingResult = null;
            try
            {
                result = CreateReferenceName();
                tempParsingResult = qualifier;
                result.AppendNewChild(tempParsingResult);
                TokenNodeType tokenType = lexer.TokenType;
                if (tokenType == CSharpTokenType.DOT)
                {
                    tokenType = lexer.TokenType;
                    if (tokenType == CSharpTokenType.DOT)
                    {
                        tempParsingResult =
                            new XmlToken(L4NTokenNodeType.DOT, lexer.Buffer, lexer.TokenStart, lexer.TokenEnd);
                        lexer.Advance();
                        result.AppendNewChild(tempParsingResult);
                    }
                    else
                    {
                        if (result.firstChild == null)
                        {
                            result = null;
                        }
                        throw new UnexpectedToken("Unexpected token");
                    }

                    tempParsingResult = this.ParseIdentifier();
                    result.AppendNewChild(tempParsingResult);
                }
            }
            catch (SyntaxError e)
            {
                if (((qualifier != null) && (qualifier.Parent == null)) && (qualifier != null))
                {
                    result.AppendNewChild(qualifier);
                }
                if ((e.ParsingResult != null) && (result != null))
                {
                    result.AppendNewChild(e.ParsingResult);
                }
                if (result != null)
                {
                    e.ParsingResult = result;
                }
                throw;
            }
            return result;
        }
示例#44
0
        /// <summary>
        /// The initial state. Expects an XML declaration.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        void Initial(XmlToken token)
        {
            if (token.Type == XmlTokenType.Declaration)
            {
                var declarationToken = (XmlDeclarationToken)token;
                _standalone = declarationToken.Standalone;

                if (!declarationToken.IsEncodingMissing)
                {
                    SetEncoding(declarationToken.Encoding);
                }

                if (!CheckVersion(declarationToken.Version) && !_options.IsSuppressingErrors)
                {
                    throw XmlParseError.XmlDeclarationVersionUnsupported.At(token.Position);
                }
            }
            else
            {
                _currentMode = XmlTreeMode.Prolog;
                BeforeDoctype(token);
            }
        }
 // Token: 0x0600785D RID: 30813 RVA: 0x002249AF File Offset: 0x00222BAF
 private static string GetXmlName(XmlToken token)
 {
     return(SNCAnnotation.s_xmlTokeFullNames[token]);
 }
示例#46
0
文件: XmlReader.cs 项目: noear/Snacks
        //------------------------
        public bool Read()
        {
            Token = XmlToken.None;
            Value = null;
            int buffer_char = 0;
            int buffer_peek = 0;

            while (true)
            {
                buffer_char = text_read();

                if (buffer_char < 0)
                {
                    Token = XmlToken.End;
                    return(true);
                }

                if (buffer_char == '<')
                {
                    buffer_peek = text_peek();

                    if (buffer_peek == '/')
                    {
                        Token = XmlToken.TargetEnd;
                        ReadName();
                        return(true);
                    }
                    else if (buffer_peek == '!')
                    {
                        text_read();
                        buffer_peek = text_peek();
                        if (buffer_peek == '-')//<!-- 注释
                        {
                            text_jump('>');
                        }
                        else //<![CDATA[
                        {
                            text_jump(6);
                            Token = XmlToken.CDATA;
                            ReadCDATA();
                            return(true);
                        }
                    }
                    else if (buffer_peek == '?')
                    {
                        text_jump('>');
                    }
                    else
                    {
                        Token = XmlToken.TargetStart;
                        ReadName();
                        return(true);
                    }
                }
                else
                {
                    if (Token == XmlToken.None && buffer_char > 32)
                    {
                        Token = XmlToken.Value;
                        ReadValue();
                        return(true);
                    }
                }
            }
        }