~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlAttribute.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Collections.ObjectModel;
 
7
using System.Collections.Specialized;
 
8
using System.Diagnostics;
 
9
using System.Globalization;
 
10
using System.Linq;
 
11
 
 
12
using ICSharpCode.AvalonEdit.Document;
 
13
 
 
14
namespace ICSharpCode.AvalonEdit.Xml
 
15
{
 
16
        /// <summary>
 
17
        /// Name-value pair in a tag
 
18
        /// </summary>
 
19
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
 
20
        public class AXmlAttribute: AXmlObject
 
21
        {
 
22
                /// <summary> Name with namespace prefix - exactly as in source file </summary>
 
23
                public string Name { get;  internal set; }
 
24
                /// <summary> Equals sign and surrounding whitespace </summary>
 
25
                public string EqualsSign { get; internal set; }
 
26
                /// <summary> The raw value - exactly as in source file (*probably* quoted and escaped) </summary>
 
27
                public string QuotedValue { get; internal set; }
 
28
                /// <summary> Unquoted and dereferenced value of the attribute </summary>
 
29
                public string Value { get; internal set; }
 
30
                
 
31
                internal override void DebugCheckConsistency(bool checkParentPointers)
 
32
                {
 
33
                        DebugAssert(Name != null, "Null Name");
 
34
                        DebugAssert(EqualsSign != null, "Null EqualsSign");
 
35
                        DebugAssert(QuotedValue != null, "Null QuotedValue");
 
36
                        DebugAssert(Value != null, "Null Value");
 
37
                        base.DebugCheckConsistency(checkParentPointers);
 
38
                }
 
39
                
 
40
                #region Helpper methods
 
41
                
 
42
                /// <summary> The element containing this attribute </summary>
 
43
                /// <returns> Null if orphaned </returns>
 
44
                public AXmlElement ParentElement {
 
45
                        get {
 
46
                                AXmlTag tag = this.Parent as AXmlTag;
 
47
                                if (tag != null) {
 
48
                                        return tag.Parent as AXmlElement;
 
49
                                }
 
50
                                return null;
 
51
                        }
 
52
                }
 
53
                
 
54
                /// <summary> The part of name before ":"</summary>
 
55
                /// <returns> Empty string if not found </returns>
 
56
                public string Prefix {
 
57
                        get {
 
58
                                return GetNamespacePrefix(this.Name);
 
59
                        }
 
60
                }
 
61
                
 
62
                /// <summary> The part of name after ":" </summary>
 
63
                /// <returns> Whole name if ":" not found </returns>
 
64
                public string LocalName {
 
65
                        get {
 
66
                                return GetLocalName(this.Name);
 
67
                        }
 
68
                }
 
69
                
 
70
                /// <summary>
 
71
                /// Resolved namespace of the name.  Empty string if not found
 
72
                /// From the specification: "The namespace name for an unprefixed attribute name always has no value."
 
73
                /// </summary>
 
74
                public string Namespace {
 
75
                        get {
 
76
                                if (string.IsNullOrEmpty(this.Prefix)) return NoNamespace;
 
77
                                
 
78
                                AXmlElement elem = this.ParentElement;
 
79
                                if (elem != null) {
 
80
                                        return elem.ResolvePrefix(this.Prefix);
 
81
                                }
 
82
                                return NoNamespace; // Orphaned attribute
 
83
                        }
 
84
                }
 
85
                
 
86
                /// <summary> Attribute is declaring namespace ("xmlns" or "xmlns:*") </summary>
 
87
                public bool IsNamespaceDeclaration {
 
88
                        get {
 
89
                                return this.Name == "xmlns" || this.Prefix == "xmlns";
 
90
                        }
 
91
                }
 
92
                
 
93
                #endregion
 
94
                
 
95
                /// <inheritdoc/>
 
96
                public override void AcceptVisitor(IAXmlVisitor visitor)
 
97
                {
 
98
                        visitor.VisitAttribute(this);
 
99
                }
 
100
                
 
101
                /// <inheritdoc/>
 
102
                internal override bool UpdateDataFrom(AXmlObject source)
 
103
                {
 
104
                        if (!base.UpdateDataFrom(source)) return false;
 
105
                        AXmlAttribute src = (AXmlAttribute)source;
 
106
                        if (this.Name != src.Name ||
 
107
                                this.EqualsSign != src.EqualsSign ||
 
108
                                this.QuotedValue != src.QuotedValue ||
 
109
                                this.Value != src.Value)
 
110
                        {
 
111
                                OnChanging();
 
112
                                this.Name = src.Name;
 
113
                                this.EqualsSign = src.EqualsSign;
 
114
                                this.QuotedValue = src.QuotedValue;
 
115
                                this.Value = src.Value;
 
116
                                OnChanged();
 
117
                                return true;
 
118
                        } else {
 
119
                                return false;
 
120
                        }
 
121
                }
 
122
                
 
123
                /// <inheritdoc/>
 
124
                public override string ToString()
 
125
                {
 
126
                        return string.Format(CultureInfo.InvariantCulture, "[{0} '{1}{2}{3}']", base.ToString(), this.Name, this.EqualsSign, this.Value);
 
127
                }
 
128
        }
 
129
}