Module: StixRuby::Marshall::ClassMethods

Defined in:
lib/ruby_stix/marshall.rb

Instance Method Summary collapse

Instance Method Details

#dom_writerObject



106
107
108
109
110
111
112
113
# File 'lib/ruby_stix/marshall.rb', line 106

def dom_writer
  if @transformer.nil?
    factory = javax.xml.transform.TransformerFactory.new_instance
    @transformer = factory.new_transformer
    @transformer.set_output_property("{http://xml.apache.org/xslt}indent-amount", "4")
  end
  return @transformer
end

#from_xml(input) ⇒ Object



91
92
93
# File 'lib/ruby_stix/marshall.rb', line 91

def from_xml(input)
  unmarshaller.unmarshal(to_java_inio(input))
end

#jaxb_contextObject



115
116
117
# File 'lib/ruby_stix/marshall.rb', line 115

def jaxb_context
  @context ||= javax.xml.bind.JAXBContext.new_instance(org.mitre.stix.core.STIXType.java_class)
end

#marshallerObject



119
120
121
122
123
124
125
126
# File 'lib/ruby_stix/marshall.rb', line 119

def marshaller
  if @marshaller.nil?
    @marshaller = jaxb_context.create_marshaller
    @marshaller.set_property("com.sun.xml.internal.bind.namespacePrefixMapper", StixRuby::Marshall::StixNamespaceMapper.new);
  end

  return @marshaller
end

#new_domObject



136
137
138
139
140
141
142
143
# File 'lib/ruby_stix/marshall.rb', line 136

def new_dom
  if @document_builder.nil?
    dbf = javax.xml.parsers.DocumentBuilderFactory.new_instance
    dbf.namespace_aware = true
    @document_builder = dbf.new_document_builder
  end
  @document_builder.new_document
end

#to_java_inio(io) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/ruby_stix/marshall.rb', line 95

def to_java_inio(io)
  if io.kind_of?(StringIO) || io.kind_of?(File)
    io.to_inputstream
  elsif io.kind_of?(String)
    sio = StringIO.new(io)
    sio.to_inputstream
  else
    io
  end
end

#unmarshallerObject



128
129
130
131
132
133
134
# File 'lib/ruby_stix/marshall.rb', line 128

def unmarshaller
  if @unmarshaller.nil?
    @unmarshaller = jaxb_context.create_unmarshaller
  end

  return @unmarshaller
end