ea 0.6.160 → 0.6.162

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49b4c14803c18a073f0865fd62b669e4fa406fc4ce2a834e93ee336f116cdb07
4
- data.tar.gz: 7cdde2b925a364a8a2d751178799d20e7bef4b2b41319bd1ad891dc8a481760e
3
+ metadata.gz: 8fcde69536b5b7dd6c30e012412acf1dcf21b102de3d47029442dae72705b3c1
4
+ data.tar.gz: 2b579326135166ae5c7d78ddba7d107efa1acd1a1ce666c4eacf294d4c7e1aac
5
5
  SHA512:
6
- metadata.gz: 9a3fc9dc18856ea421b83ab03044651e48bc51f71bbcc580f25c631a8a022e1faee6712da9ff80cd606461bc58d250c7cbb763b0a44b6efb2aebf8c9277b04bf
7
- data.tar.gz: 99252d51bca9cfe0856828a07e3df362bf7019de874a431631a39e36f4a0d275ad64d8a555a348b31a35c11de713ace45f83efa57075c69d210fde69705284c3
6
+ metadata.gz: a1b2335a9715c4aab2b33f935d82c3e15428230bfdd4cb67f09761ad88a943d85bf6f5300aeb1cf720a6cae591e1a85322e68890efad8037e026ed8ca0f26e06
7
+ data.tar.gz: 9017d649a98b044157acfc471d8877b0dd704b3a5cf92986e15edd817b294a41a919432ee45dc85c01ff2cf8ef749f075954d9d7fe50ca8e4500bd996706516c
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Export
@@ -30,12 +30,12 @@ module Ea
30
30
  def self.from_path(path)
31
31
  return new if path.nil? || !File.exist?(path)
32
32
 
33
- from_nokogiri(Nokogiri::XML(File.read(path)))
33
+ from_xml(Ea::Xml.parse_file(path))
34
34
  end
35
35
 
36
- # @param doc [Nokogiri::XML::Document]
36
+ # @param doc [Moxml::Wrappers::Document]
37
37
  # @return [ClassMapping]
38
- def self.from_nokogiri(doc)
38
+ def self.from_xml(doc)
39
39
  mappings = {}
40
40
  doc.xpath("//Class").each do |node|
41
41
  name = node["name"]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Export
@@ -46,13 +46,14 @@ module Ea
46
46
  private
47
47
 
48
48
  def build_schema_doc(target_namespace, prefix)
49
- builder = Nokogiri::XML::Builder.new do |xml|
50
- xml.schema("xmlns" => XSD_NS,
51
- "xmlns:#{prefix}" => target_namespace,
52
- "targetNamespace" => target_namespace,
53
- "elementFormDefault" => "qualified")
54
- end
55
- builder.doc
49
+ doc = Moxml.new.create_document
50
+ schema = doc.create_element("schema")
51
+ schema["xmlns"] = XSD_NS
52
+ schema["xmlns:#{prefix}"] = target_namespace
53
+ schema["targetNamespace"] = target_namespace
54
+ schema["elementFormDefault"] = "qualified"
55
+ doc.root = schema
56
+ doc
56
57
  end
57
58
 
58
59
  def walk_model(model, doc)
@@ -107,16 +108,16 @@ module Ea
107
108
  end
108
109
 
109
110
  def element_node(doc, name, type_name)
110
- el = doc.create_element("element", "xmlns" => XSD_NS)
111
+ el = xsd_element(doc)
111
112
  el["name"] = name
112
113
  el["type"] = "tns:#{type_name}"
113
114
  el
114
115
  end
115
116
 
116
117
  def complex_type_node(doc, type_name, classifier)
117
- ct = doc.create_element("complexType", "xmlns" => XSD_NS)
118
+ ct = xsd_element(doc, "complexType")
118
119
  ct["name"] = type_name
119
- seq = doc.create_element("sequence", "xmlns" => XSD_NS)
120
+ seq = xsd_element(doc, "sequence")
120
121
  classifier.attributes.each do |attr|
121
122
  seq.add_child(attribute_element(doc, attr))
122
123
  end
@@ -125,12 +126,20 @@ module Ea
125
126
  end
126
127
 
127
128
  def attribute_element(doc, attr)
128
- el = doc.create_element("element", "xmlns" => XSD_NS)
129
+ el = xsd_element(doc)
129
130
  el["name"] = attr[:name].to_s
130
131
  el["type"] = "xs:string"
131
132
  el["minOccurs"] = "0"
132
133
  el
133
134
  end
135
+
136
+ # Schema children carry the XSD namespace explicitly, matching
137
+ # the reference EA output.
138
+ def xsd_element(doc, name = "element")
139
+ el = doc.create_element(name)
140
+ el["xmlns"] = XSD_NS
141
+ el
142
+ end
134
143
  end
135
144
  end
136
145
  end
@@ -32,16 +32,16 @@ module Ea
32
32
  def self.from_path(path)
33
33
  return new if path.nil? || !File.exist?(path)
34
34
 
35
- require "nokogiri"
36
- doc = Nokogiri::XML(File.read(path))
37
- from_nokogiri(doc)
35
+ require "moxml"
36
+ doc = Ea::Xml.parse_file(path)
37
+ from_xml(doc)
38
38
  end
39
39
 
40
- # Build from a parsed Nokogiri document. Tested separately so
40
+ # Build from a parsed XML document. Tested separately so
41
41
  # the parser path is exercised without file IO.
42
- # @param doc [Nokogiri::XML::Document]
42
+ # @param doc [Moxml::Wrappers::Document]
43
43
  # @return [StereotypeAliasRegistry]
44
- def self.from_nokogiri(doc)
44
+ def self.from_xml(doc)
45
45
  aliases = {}
46
46
  doc.xpath("//Stereotype").each do |stereo|
47
47
  canonical = stereo["name"]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "leptris"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -32,28 +32,28 @@ module Ea
32
32
  @seen_owners = {}
33
33
  @blocks_seen = {}
34
34
  @skip_block = false
35
- File.open(xmi_path) { |io| Nokogiri::XML::Reader(io).each { |node| visit(node) } }
35
+ Leptris::XML::Pull.parse(File.read(xmi_path)).each { |event| visit(event) }
36
36
  @grouped
37
37
  end
38
38
 
39
- def visit(node)
40
- case node.node_type
41
- when Nokogiri::XML::Reader::TYPE_END_ELEMENT
39
+ def visit(event)
40
+ case event.type
41
+ when :end_element
42
42
  @owner = nil if @path.pop == "element"
43
- when Nokogiri::XML::Reader::TYPE_ELEMENT
44
- enter(node)
45
- @path.push(node.local_name) unless node.self_closing?
43
+ when :start_element
44
+ enter(event)
45
+ @path.push(event.name)
46
46
  end
47
47
  end
48
48
 
49
- def enter(node)
50
- if node.local_name == "element" && @path.last == "elements" && !node.self_closing?
51
- @owner = first_block_owner(node.attribute("xmi:idref"))
52
- elsif node.local_name == "constraints" && @owner && @path.last == "element"
49
+ def enter(event)
50
+ if event.name == "element" && @path.last == "elements"
51
+ @owner = first_block_owner(event.attrs&.fetch("xmi:idref", nil))
52
+ elsif event.name == "constraints" && @owner && @path.last == "element"
53
53
  @skip_block = @blocks_seen.key?(@owner)
54
54
  @blocks_seen[@owner] = true
55
- elsif node.local_name == "constraint" && @owner && !@skip_block && @path.last(2) == %w[element constraints]
56
- (@grouped[@owner] ||= []) << constraint(node)
55
+ elsif event.name == "constraint" && @owner && !@skip_block && @path.last(2) == %w[element constraints]
56
+ (@grouped[@owner] ||= []) << constraint(event)
57
57
  end
58
58
  end
59
59
 
@@ -69,10 +69,10 @@ module Ea
69
69
  def constraint(node)
70
70
  Ea::Model::Constraint.new(
71
71
  id: IdNormalizer.synthetic_id(@owner, "constraint", @grouped[@owner].to_a.size.to_s),
72
- name: node.attribute("name").to_s,
73
- kind: node.attribute("type").to_s,
74
- body: node.attribute("description").to_s,
75
- status: node.attribute("status").to_s
72
+ name: node.attrs&.fetch("name", nil).to_s,
73
+ kind: node.attrs&.fetch("type", nil).to_s,
74
+ body: node.attrs&.fetch("description", nil).to_s,
75
+ status: node.attrs&.fetch("status", nil).to_s
76
76
  )
77
77
  end
78
78
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
+ require "leptris"
4
5
 
5
6
  module Ea
6
7
  module Sources
@@ -76,21 +77,59 @@ module Ea
76
77
 
77
78
  def scan_metadata
78
79
  data = { connectors: {}, proxies: {}, classes: [] }
79
- File.open(@xmi_path) do |file|
80
- Nokogiri::XML::Reader(file).each { |node| read_node(node, data) }
80
+ @capture = nil
81
+ # Single streaming pass over the XMI: reconstruct each
82
+ # <element>/<connector>'s outer XML from the pull stream and
83
+ # parse it as a subtree for the attribute lookups below.
84
+ Leptris::XML::Pull.parse(File.read(@xmi_path)).each do |event|
85
+ case event.type
86
+ when :start_element
87
+ if @capture
88
+ @capture[:depth] += 1
89
+ @capture[:xml] << write_start(event)
90
+ elsif %w[element connector].include?(event.name)
91
+ @capture = { kind: event.name, depth: 1, xml: +write_start(event) }
92
+ end
93
+ when :end_element
94
+ next unless @capture
95
+
96
+ @capture[:xml] << "</#{event.name}>"
97
+ @capture[:depth] -= 1
98
+ if @capture[:depth].zero?
99
+ subtree = Moxml.parse(scrub(@capture[:xml])).root
100
+ send("read_#{@capture[:kind]}", subtree, data)
101
+ @capture = nil
102
+ end
103
+ when :text
104
+ @capture[:xml] << escape_text(event.text) if @capture
105
+ end
81
106
  end
82
107
  data
83
108
  end
84
109
 
85
- def read_node(node, data)
86
- return unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
110
+ # EA XMI files occasionally carry bytes outside the declared
111
+ # encoding; the nokogiri outer-xml path tolerated them, so scrub
112
+ # the reconstructed fragment the same way before parsing.
113
+ def scrub(buffer)
114
+ buffer.encode("UTF-8", invalid: :replace, undef: :replace)
115
+ end
116
+
117
+ def write_start(event)
118
+ attrs = (event.attrs || {}).map do |key, value|
119
+ %( #{key}="#{escape_attribute(value)}")
120
+ end.join
121
+ "<#{event.name}#{attrs}>"
122
+ end
123
+
124
+ def escape_attribute(value)
125
+ value.to_s.gsub("&", "&amp;").gsub("<", "&lt;").gsub('"', "&quot;")
126
+ end
87
127
 
88
- read_element(node, data) if node.local_name == "element"
89
- read_connector(node, data) if node.local_name == "connector"
128
+ def escape_text(text)
129
+ text.to_s.gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;")
90
130
  end
91
131
 
92
- def read_element(node, data)
93
- element = Nokogiri::XML(node.outer_xml).root
132
+ def read_element(element, data)
94
133
  id = attr(element, "idref")
95
134
  return unless id
96
135
 
@@ -99,8 +138,7 @@ module Ea
99
138
  data[:proxies][id] = attr(element, "classifier") if type == "uml:ProxyConnector"
100
139
  end
101
140
 
102
- def read_connector(node, data)
103
- connector = Nokogiri::XML(node.outer_xml).root
141
+ def read_connector(connector, data)
104
142
  id = attr(connector, "idref")
105
143
  return unless id
106
144
 
@@ -114,7 +152,7 @@ module Ea
114
152
  end
115
153
 
116
154
  def attr(node, name)
117
- node&.attribute_nodes&.find { |attribute| attribute.name == name }&.value
155
+ node&.attributes&.find { |attribute| attribute.name == name }&.value
118
156
  end
119
157
 
120
158
  def guid_key(subject)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
+ require "leptris"
4
5
 
5
6
  module Ea
6
7
  module Sources
@@ -50,17 +51,68 @@ module Ea
50
51
  def read_role_stereotypes
51
52
  return {} unless @xmi_path
52
53
 
53
- File.open(@xmi_path) do |file|
54
- Nokogiri::XML::Reader(file).each_with_object({}) do |node, roles|
55
- next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT && node.local_name == "connector"
54
+ capture_connectors(File.read(@xmi_path)).each_with_object({}) do |connector, roles|
55
+ read_connector_roles(connector, roles)
56
+ end
57
+ end
58
+
59
+ # Single streaming pass over the XMI: reconstruct each
60
+ # <connector>'s outer XML from the pull stream and parse it as a
61
+ # subtree for the role lookups below.
62
+ def capture_connectors(xml)
63
+ connectors = []
64
+ buffer = nil
65
+ depth = 0
56
66
 
57
- read_connector_roles(node, roles)
67
+ Leptris::XML::Pull.parse(xml).each do |event|
68
+ case event.type
69
+ when :start_element
70
+ if buffer
71
+ buffer << write_start(event)
72
+ depth += 1
73
+ elsif event.name == "connector"
74
+ buffer = +write_start(event)
75
+ depth = 1
76
+ end
77
+ when :end_element
78
+ next unless buffer
79
+
80
+ buffer << "</#{event.name}>"
81
+ depth -= 1
82
+ if depth.zero?
83
+ connectors << Moxml.parse(scrub(buffer)).root
84
+ buffer = nil
85
+ end
86
+ when :text
87
+ buffer << escape_text(event.text) if buffer
58
88
  end
59
89
  end
90
+ connectors
91
+ end
92
+
93
+ # EA XMI files occasionally carry bytes outside the declared
94
+ # encoding; the nokogiri outer-xml path tolerated them, so scrub
95
+ # the reconstructed fragment the same way before parsing.
96
+ def scrub(buffer)
97
+ buffer.encode("UTF-8", invalid: :replace, undef: :replace)
98
+ end
99
+
100
+ def write_start(event)
101
+ attrs = (event.attrs || {}).map do |key, value|
102
+ %( #{key}="#{escape_attribute(value)}")
103
+ end.join
104
+ "<#{event.name}#{attrs}>"
105
+ end
106
+
107
+ def escape_attribute(value)
108
+ value.to_s.gsub("&", "&amp;").gsub("<", "&lt;").gsub('"', "&quot;")
109
+ end
110
+
111
+ def escape_text(text)
112
+ text.to_s.gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;")
60
113
  end
61
114
 
62
- def read_connector_roles(node, roles)
63
- connector = Nokogiri::XML(node.outer_xml).root
115
+ def read_connector_roles(connector, roles)
64
116
  id = connector.at_xpath("@*[local-name()='idref']")&.value
65
117
  return unless id
66
118
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -52,7 +52,7 @@ module Ea
52
52
  def saved_objects
53
53
  return [] unless @xmi_path
54
54
 
55
- doc = Nokogiri::XML(File.read(@xmi_path))
55
+ doc = Ea::Xml.parse_file(@xmi_path)
56
56
  doc.xpath("//*[local-name()='Extension']/*[local-name()='elements']/*[local-name()='element']")
57
57
  end
58
58
  end
@@ -21,8 +21,10 @@ module Ea
21
21
  @property_roles ||= begin
22
22
  document = @doc
23
23
  declared = declared_properties(document)
24
- document.xpath("//*[local-name()=\"Diagram\"]").to_h do |diagram|
25
- [diagram["id"] || diagram["xmi:id"], diagram_property_roles(diagram, declared)]
24
+ document.xpath("//*[local-name()=\"Diagram\"]")
25
+ .each_with_object({}) do |diagram, hash|
26
+ hash[diagram["id"] || diagram["xmi:id"]] =
27
+ diagram_property_roles(diagram, declared)
26
28
  end
27
29
  end
28
30
  end
@@ -34,7 +36,7 @@ module Ea
34
36
  document.xpath("//*[@association][@xmi:id]", "xmi" => "http://www.omg.org/spec/XMI/20131001")
35
37
  .filter_map do |node|
36
38
  pair = [node["xmi:id"], node["association"]]
37
- pair if node.attributes["type"]&.value == "uml:Property" && members.include?(pair)
39
+ pair if node.at_xpath("@*[local-name()='type']")&.value == "uml:Property" && members.include?(pair)
38
40
  end.to_set
39
41
  end
40
42
 
@@ -50,13 +52,13 @@ module Ea
50
52
 
51
53
  def unique_edges(diagram)
52
54
  diagram.xpath("./ownedElement[@modelElement]")
53
- .select { |node| node.attributes["type"]&.value.to_s.end_with?("UMLEdge") }
55
+ .select { |node| node.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLEdge") }
54
56
  .group_by { |edge| edge["modelElement"] }
55
57
  .select { |_, edges| edges.one? }.transform_values(&:first)
56
58
  end
57
59
 
58
60
  def role_key(label)
59
- return unless label.attributes["type"]&.value.to_s.end_with?("UMLAssociationEndLabel")
61
+ return unless label.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLAssociationEndLabel")
60
62
 
61
63
  case label["xmi:id"] || label["id"]
62
64
  when /\AEAID_SEL/ then :source_role
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -41,15 +41,20 @@ module Ea
41
41
 
42
42
  private
43
43
 
44
+ # NodeSet#to_h is not Enumerable-backed across XML adapters —
45
+ # build the id-keyed maps with an explicit reduction instead.
44
46
  def ends
45
- @ends ||= doc.xpath("//*[local-name()=\"Diagram\"]").to_h do |diagram|
46
- [diagram["id"] || diagram["xmi:id"], diagram_ends(diagram)]
47
+ @ends ||= doc.xpath("//*[local-name()=\"Diagram\"]")
48
+ .each_with_object({}) do |diagram, hash|
49
+ hash[diagram["id"] || diagram["xmi:id"]] = diagram_ends(diagram)
47
50
  end
48
51
  end
49
52
 
50
53
  def label_bounds
51
- @label_bounds ||= doc.xpath("//*[local-name()=\"Diagram\"]").to_h do |diagram|
52
- [diagram["id"] || diagram["xmi:id"], diagram_label_bounds(diagram)]
54
+ @label_bounds ||= doc.xpath("//*[local-name()=\"Diagram\"]")
55
+ .each_with_object({}) do |diagram, hash|
56
+ hash[diagram["id"] || diagram["xmi:id"]] =
57
+ diagram_label_bounds(diagram)
53
58
  end
54
59
  end
55
60
 
@@ -77,7 +82,7 @@ module Ea
77
82
  end
78
83
 
79
84
  def label_key(label)
80
- type = label.attributes["type"]&.value.to_s
85
+ type = label.at_xpath("@*[local-name()='type']")&.value.to_s
81
86
  role = (label["id"] || label["xmi:id"]).to_s
82
87
  end_name = { "EAID_SEL" => "source", "EAID_SML" => "source",
83
88
  "EAID_TEL" => "target", "EAID_TML" => "target" }
@@ -97,15 +102,16 @@ module Ea
97
102
  # one edge of the diagram, whatever that edge carries.
98
103
  def unique_edges(diagram)
99
104
  diagram.xpath("./ownedElement[@modelElement]")
100
- .select { |node| node.attributes["type"]&.value.to_s.end_with?("UMLEdge") }
105
+ .select { |node| node.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLEdge") }
101
106
  .group_by { |edge| edge["modelElement"] }
102
107
  .select { |_, same| same.one? }
103
108
  .transform_values(&:first)
104
109
  end
105
110
 
106
111
  def routes
107
- @routes ||= doc.xpath("//*[local-name()=\"Diagram\"]").to_h do |diagram|
108
- [diagram["id"] || diagram["xmi:id"], diagram_routes(diagram)]
112
+ @routes ||= doc.xpath("//*[local-name()=\"Diagram\"]")
113
+ .each_with_object({}) do |diagram, hash|
114
+ hash[diagram["id"] || diagram["xmi:id"]] = diagram_routes(diagram)
109
115
  end
110
116
  end
111
117
 
@@ -121,7 +127,7 @@ module Ea
121
127
  end
122
128
 
123
129
  def doc
124
- Nokogiri::XML(File.read(@xmi_path))
130
+ Ea::Xml.parse_file(@xmi_path)
125
131
  end
126
132
  end
127
133
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -17,7 +17,7 @@ module Ea
17
17
  def self.from_path(xmi_path)
18
18
  return empty if xmi_path.nil?
19
19
 
20
- new(Nokogiri::XML(File.read(xmi_path)))
20
+ new(Ea::Xml.parse_file(xmi_path))
21
21
  end
22
22
 
23
23
  def self.empty
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -88,9 +88,11 @@ module Ea
88
88
  def extension_runstates
89
89
  return {} if xmi_path.nil?
90
90
 
91
- Nokogiri::XML(File.read(xmi_path))
92
- .xpath(RUNSTATE_XPATH)
93
- .to_h { |node| [node.parent["xmi:idref"], node["runstate"]] }
91
+ Ea::Xml.parse_file(xmi_path)
92
+ .xpath(RUNSTATE_XPATH)
93
+ .each_with_object({}) do |node, acc|
94
+ acc[node.parent["xmi:idref"]] = node["runstate"]
95
+ end
94
96
  end
95
97
  end
96
98
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -15,7 +15,7 @@ module Ea
15
15
  def grouped_by_owner
16
16
  return {} unless @xmi_path
17
17
 
18
- @grouped_by_owner ||= read_receptions(Nokogiri::XML(File.read(@xmi_path)))
18
+ @grouped_by_owner ||= read_receptions(Ea::Xml.parse_file(@xmi_path))
19
19
  end
20
20
 
21
21
  private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -22,7 +22,7 @@ module Ea
22
22
  return {} if xmi_path.nil?
23
23
 
24
24
  @grouped ||= begin
25
- doc = Nokogiri::XML(File.read(xmi_path))
25
+ doc = Ea::Xml.parse_file(xmi_path)
26
26
  # <tags><tag/></tags> lives inside per-element <element>
27
27
  # blocks within <xmi:Extension>. The element itself is in
28
28
  # no XML namespace; match by local-name to be safe.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -59,7 +59,7 @@ module Ea
59
59
  end
60
60
 
61
61
  def doc
62
- @doc ||= Nokogiri::XML(File.read(xmi_path))
62
+ @doc ||= Ea::Xml.parse_file(xmi_path)
63
63
  end
64
64
 
65
65
  def keywords_by_diagram
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Svg
@@ -34,21 +34,25 @@ module Ea
34
34
  private
35
35
 
36
36
  def our_doc
37
- @our_doc ||= Nokogiri::XML(@ours)
37
+ @our_doc ||= Ea::Xml.parse(@ours)
38
38
  end
39
39
 
40
40
  def ref_doc
41
- @ref_doc ||= Nokogiri::XML(@reference)
41
+ @ref_doc ||= Ea::Xml.parse(@reference)
42
42
  end
43
43
 
44
+ # CSS is not reliable on moxml for namespaced documents
45
+ # (lutaml/moxml#582) — tag counting goes through xpath.
44
46
  def count_diff(selector)
45
- Diff.new(ours: our_doc.css(selector).size,
46
- reference: ref_doc.css(selector).size)
47
+ xpath = "//*[local-name()=\"#{selector}\"]"
48
+ Diff.new(ours: our_doc.xpath(xpath).size,
49
+ reference: ref_doc.xpath(xpath).size)
47
50
  end
48
51
 
49
52
  def top_level_group_diff
50
- Diff.new(ours: our_doc.css("svg > g").size,
51
- reference: ref_doc.css("svg > g").size)
53
+ xpath = "/*[local-name()=\"svg\"]/*[local-name()=\"g\"]"
54
+ Diff.new(ours: our_doc.xpath(xpath).size,
55
+ reference: ref_doc.xpath(xpath).size)
52
56
  end
53
57
 
54
58
  def font_family_match
@@ -65,7 +69,8 @@ module Ea
65
69
  end
66
70
 
67
71
  def font_style_histogram(doc, property)
68
- doc.css("text").each_with_object(Hash.new(0)) do |node, acc|
72
+ doc.xpath("//*[local-name()=\"text\"]")
73
+ .each_with_object(Hash.new(0)) do |node, acc|
69
74
  value = (node["style"] || "")[/#{Regexp.quote(property)}:([^;]+)/, 1]
70
75
  acc[value] += 1 if value
71
76
  end
@@ -76,14 +81,20 @@ module Ea
76
81
  end
77
82
 
78
83
  def text_overlap_ratio
79
- our_set = our_doc.css("text").map(&:text).map(&:strip).to_set
80
- ref_set = ref_doc.css("text").map(&:text).map(&:strip).to_set
84
+ our_set = text_set(our_doc)
85
+ ref_set = text_set(ref_doc)
81
86
  return 1.0 if our_set.empty? && ref_set.empty?
82
87
  return 0.0 if our_set.empty? || ref_set.empty?
83
88
 
84
89
  (our_set & ref_set).size.to_f / (our_set | ref_set).size.to_f
85
90
  end
86
91
 
92
+ def text_set(doc)
93
+ doc.xpath("//*[local-name()=\"text\"]").map do |node|
94
+ node.text.to_s.strip
95
+ end.to_set
96
+ end
97
+
87
98
  Diff = Struct.new(:ours, :reference, keyword_init: true) do
88
99
  def delta
89
100
  ours - reference
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Svg
@@ -27,7 +27,9 @@ module Ea
27
27
  # Extracts the primitives consumed by both comparison reports.
28
28
  class PrimitiveParser
29
29
  def parse(svg)
30
- Nokogiri::XML(svg).css("g").flat_map do |group|
30
+ # xpath, not css — css is unreliable on moxml for
31
+ # namespaced documents (lutaml/moxml#582).
32
+ Ea::Xml.parse(svg).xpath('//*[local-name()="g"]').flat_map do |group|
31
33
  group.element_children.filter_map { |node| primitive(node, group["style"] || "") }
32
34
  end
33
35
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Svg
data/lib/ea/version.rb CHANGED
@@ -4,5 +4,5 @@ module Ea
4
4
  # Gem release version. Extracted to its own file so the
5
5
  # `gem-release` tool's `gem bump` can find and update it via the
6
6
  # standard `lib/<gem>/version.rb` convention.
7
- VERSION = "0.6.160"
7
+ VERSION = "0.6.162"
8
8
  end
data/lib/ea/xmi/parser.rb CHANGED
@@ -743,13 +743,21 @@ module Ea
743
743
 
744
744
  general_item.attributes.reverse_each do |attr|
745
745
  attr.upper_klass = gen_upper_klass
746
- attr.gen_name = gen_name
747
746
  attr.level = level
748
747
 
748
+ # Inherited rows are dup copies (QeaToUml parity): the
749
+ # ancestor's own attributes keep only upper_klass/level tags,
750
+ # while the copies carry the full ancestor attribution so
751
+ # later levels cannot mutate what was already collected.
752
+ inherited_attr = attr.dup
753
+ inherited_attr.upper_klass = gen_upper_klass
754
+ inherited_attr.gen_name = gen_name
755
+ inherited_attr.level = level
756
+
749
757
  if attr.association
750
- inherited_assoc_props << attr
758
+ inherited_assoc_props << inherited_attr
751
759
  else
752
- inherited_props << attr
760
+ inherited_props << inherited_attr
753
761
  end
754
762
  end
755
763
 
data/lib/ea/xmi.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
  require "xmi"
5
5
  require "liquid"
6
6
  require "cgi"
data/lib/ea/xml.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ea
4
+ # Shared XML parse entry for the gem's direct parses. Lenient by
5
+ # default — nokogiri/libxml2 parity — tolerating files whose bytes
6
+ # do not match UTF-8 (EA exports declare windows-1252 regularly and
7
+ # bundle raw CP1252 bytes alongside).
8
+ module Xml
9
+ DECLARED_ENCODING = /\A\s*<\?xml[^>]*encoding=["']([^"']+)["']/
10
+
11
+ module_function
12
+
13
+ # @param path [String] file path
14
+ # @return [Moxml::Wrappers::Document]
15
+ def parse_file(path)
16
+ parse(File.read(path))
17
+ end
18
+
19
+ # @param content [String] XML text
20
+ # @return [Moxml::Wrappers::Document]
21
+ def parse(content)
22
+ context = Moxml.new
23
+ context.config.strict_parsing = false
24
+ context.parse(normalize_encoding(content))
25
+ end
26
+
27
+ # libxml2 transcoded according to the XML declaration; moxml's
28
+ # parse validates UTF-8 strictly regardless of the declaration.
29
+ # Transcode declared non-UTF-8 content to UTF-8 and rewrite the
30
+ # declaration so downstream sees consistent text.
31
+ def normalize_encoding(content)
32
+ declared = content[DECLARED_ENCODING, 1]
33
+ return content if declared.nil? || declared.casecmp?("utf-8")
34
+
35
+ text = content.dup.force_encoding(declared).encode("UTF-8")
36
+ text.sub!(/\A(\s*<\?xml[^>]*encoding=["'])([^"']+)/) do
37
+ "#{Regexp.last_match(1)}UTF-8"
38
+ end
39
+ text
40
+ rescue StandardError
41
+ content.valid_encoding? ? content : content.scrub
42
+ end
43
+ end
44
+ end
data/lib/ea.rb CHANGED
@@ -30,6 +30,7 @@ module Ea
30
30
  autoload :Lint, "ea/lint"
31
31
  autoload :Query, "ea/query"
32
32
  autoload :Ocl, "ea/ocl"
33
+ autoload :Xml, "ea/xml"
33
34
  autoload :XmlEscape, "ea/xml_escape"
34
35
  autoload :GuidFormat, "ea/guid_format"
35
36
  autoload :Rtf, "ea/rtf"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.160
4
+ version: 0.6.162
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -663,6 +663,7 @@ files:
663
663
  - lib/ea/xmi/lookup_service.rb
664
664
  - lib/ea/xmi/parser.rb
665
665
  - lib/ea/xmi/slicer.rb
666
+ - lib/ea/xml.rb
666
667
  - lib/ea/xml_escape.rb
667
668
  - lib/ea/xref_format.rb
668
669
  - lib/ea/xref_format/legend_definition.rb