11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/ruby_stix/marshall.rb', line 11
def write(io, args = {})
clean_namespaces = args[:clean_namespaces] != false
if clean_namespaces
document = self.class.new_dom
self.class.marshaller.marshal(self, document)
namespaces = {}
namespaces[StixRuby::NAMESPACE_MAPPINGS[document.document_element.namespace_uri]] = true
for i in 0...document.document_element.child_nodes.length
collect_namespaces(document.document_element.child_nodes.item(i), namespaces, )
end
to_delete = []
for i in 0...document.document_element.attributes.length
attribute = document.document_element.attributes.item(i)
if attribute.name =~ /xmlns/
if !(namespaces[attribute.name.split(':').last] || namespaces[attribute.value])
to_delete.push(attribute.name)
end
end
end
to_delete.each {|i| document.document_element.remove_attribute(i)}
io = to_java_io(io)
self.class.dom_writer.set_output_property(javax.xml.transform.OutputKeys::INDENT, args[:no_formatting] == true ? 'no' : 'yes');
self.class.dom_writer.transform(javax.xml.transform.dom.DOMSource.new(document), javax.xml.transform.stream.StreamResult.new(io))
else
io = to_java_io(io)
self.class.marshaller.set_property(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, !(args[:no_formatting] == true))
self.class.marshaller.marshal(self, io)
end
return io
end
|