Module: VCDOM::MiniDOM::ModNamespaceURIManageable

Included in:
AttrNS, ElementNS
Defined in:
lib/vcdom/minidom/mod_namespaceuri_manageable.rb

Instance Method Summary collapse

Instance Method Details

#init_mod_namespaceuri_manageable(namespace_uri, qualified_name) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vcdom/minidom/mod_namespaceuri_manageable.rb', line 110

def init_mod_namespaceuri_manageable( namespace_uri, qualified_name )
  # namespace_uri が空文字列であるならば, nil として扱う
  @namespace_uri = ( namespace_uri == '' ? nil : namespace_uri )
  if /\A([^:]+)(?::([^:]+))?\Z/u =~ qualified_name then
    name_prefix = ( $2.nil? ? nil : $1 )
  else
    # the qualified name is malformed
    raise DOMException.new( DOMException::NAMESPACE_ERR, 
            'The qualified name "' + qualified_name + '" is malformed.' )
  end
  if ! name_prefix.nil? then
    if @namespace_uri.nil? then
      # the qualified name has a prefix and the namespace URI is null
      raise DOMException.new( DOMException::NAMESPACE_ERR,
              'The qualified name "' + qualified_name + '" has a prefix, but the namespace URI is null.' )
    end
    if name_prefix == 'xml' and @namespace_uri != "http://www.w3.org/XML/1998/namespace" then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The qualified name has a prefix "xml", but the namespace URI is different from "http://www.w3.org/XML/1998/namespace".' )
    end
    if name_prefix == 'xmlns' and @namespace_uri != "http://www.w3.org/2000/xmlns/" then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The qualified name has a prefix "xmlns", but the namespace URI is different from "http://www.w3.org/2000/xmlns/".' )
    end
    if name_prefix != 'xmlns' and @namespace_uri == "http://www.w3.org/2000/xmlns/" then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The namespace URI is "http://www.w3.org/2000/xmlns/", but the prefix of the qualified name is not "xmlns".' )
    end
  else
    if qualified_name == 'xmlns' and @namespace_uri != "http://www.w3.org/2000/xmlns/" then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The qualified name is "xmlns", but the namespace URI is different from "http://www.w3.org/2000/xmlns/".' )
    end
    if qualified_name != 'xmlns' and @namespace_uri == "http://www.w3.org/2000/xmlns/" then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The namespace URI is "http://www.w3.org/2000/xmlns/", but the qualified name is not "xmlns".' )
    end
  end
end

#local_nameObject

localName of type DOMString, readonly, introduced in DOM Level 2

Returns the local part of the qualified name of this node.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes 
created with a DOM Level 1 method, such as Document.createElement(), 
this is always null.


29
30
31
32
# File 'lib/vcdom/minidom/mod_namespaceuri_manageable.rb', line 29

def local_name
  qname_arr = self.node_name.split(/:/u)
  return qname_arr[-1]
end

#namespace_uriObject

namespaceURI of type DOMString, readonly, introduced in DOM Level 2

The namespace URI of this node, or null if it is unspecified (see XML Namespaces).
This is not a computed value that is the result of a namespace lookup based on 
an examination of the namespace declarations in scope. 
It is merely the namespace URI given at creation time.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and 
nodes created with a DOM Level 1 method, such as Document.createElement(), 
this is always null.

Note: Per the Namespaces in XML Specification [XML Namespaces] an attribute 
      does not inherit its namespace from the element it is attached to. 
      If an attribute is not explicitly given a namespace, it simply has 
      no namespace.


20
21
22
# File 'lib/vcdom/minidom/mod_namespaceuri_manageable.rb', line 20

def namespace_uri
  return @namespace_uri
end

#prefixObject

prefix of type DOMString, introduced in DOM Level 2

The namespace prefix of this node, or null if it is unspecified. 
  #=> このノードの名前空間接頭辞, または null (指定されていない場合) です.
When it is defined to be null, setting it has no effect, including if the node is read-only.
  #=> null と明示されている場合, およびノードが読み取り専用の場合は, 値の代入は何の効果もありません.  
Note that setting this attribute, when permitted, changes the nodeName attribute, 
which holds the qualified name, as well as the tagName and name attributes of the Element 
and Attr interfaces, when applicable.
  #=> (代入可能な場合に) 値の代入を行うと, nodeName 属性 (qualified name を保持している) が変化します.
  #=> Element インターフェイスの tagName 属性や Attr インターフェイスの name 属性も同様です. (それらに応用可能な場合)
Setting the prefix to null makes it unspecified, setting it to an empty string is implementation dependent.
Note also that changing the prefix of an attribute that is known to have a default value, 
does not make a new attribute with the default value and the original prefix appear, 
since the namespaceURI and localName do not change.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created 
with a DOM Level 1 method, such as createElement from the Document interface, this is always null.

Exceptions on setting
  DOMException
    INVALID_CHARACTER_ERR:
      Raised if the specified prefix contains an illegal character according to the XML version 
      in use specified in the Document.xmlVersion attribute.
    NO_MODIFICATION_ALLOWED_ERR: 
      Raised if this node is readonly.
    NAMESPACE_ERR: 
      Raised if the specified prefix is malformed per the Namespaces in XML specification, 
      if the namespaceURI of this node is null, if the specified prefix is "xml" and 
      the namespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace", 
      if this node is an attribute and the specified prefix is "xmlns" and 
      the namespaceURI of this node is different from "http://www.w3.org/2000/xmlns/", 
      or if this node is an attribute and the qualifiedName of this node is "xmlns" [XML Namespaces].


65
66
67
68
# File 'lib/vcdom/minidom/mod_namespaceuri_manageable.rb', line 65

def prefix
  qname_arr = self.node_name.split(/:/u)
  return qname_arr[-2]
end

#prefix=(value) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/vcdom/minidom/mod_namespaceuri_manageable.rb', line 69

def prefix=( value )
  if self.is_readonly then
    raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR, 
            'This node is readonly.' )
  end
  unless value.nil? or value.is_a? String then
    begin
      value = value.to_str()
    rescue
      raise TypeError.new( 'The argument value must be String object or nil.' )
    end
  end
  if value.nil? or value.length == 0 then
    self.node_name = self.local_name
  end
  if XMLRegExp::NCNAME =~ value then
    if self.namespace_uri.nil? then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The namespace URI of this node is null, so an prefix can\'t be set.' )
    end
    if value == "xml" and self.namespace_uri != "http://www.w3.org/XML/1998/namespace" then
      raise DOMException.new( DOMException::NAMESPACE_ERR, 
              'The specified prefix is "xml" and the namespace URI of this node is different from "http://www.w3.org/XML/1998/namespace"' )
    end
    if self.node_type == Node::ATTRIBUTE_NODE then
      if value == 'xmlns' and self.namespace_uri != "http://www.w3.org/2000/xmlns/" then
        raise DOMException.new( DOMException::NAMESPACE_ERR, 
                'The specified prefix is "xmlns" and the namespaceURI of this node is different from "http://www.w3.org/2000/xmlns/".' )
      end
      if self.node_name == 'xmlns' then
        raise DOMException.new( DOMException::NAMESPACE_ERR, 
                'The qualifiedName of this node is "xmlns".' )
      end
    end
    self.tagname = value + ':' + self.local_name
  else
    raise DOMException.new( DOMException::INVALID_CHARACTER_ERR, 
            'The specified prefix "' + value + '" contains an illegal character.' )
  end
end