Sha256: 8b16b5a77e4093e63858991a278997a7ac99e2198f285c54c04fe5f718ca6879

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
# License:   Apache License, Version 2.0


module RTM::IO
  # Import and Export of TMAPI Topic Maps
  # Utilizing the Ontopia libary http://code.google.com/p/tmapix/
  # Consequently the (de-) serializer provided here 
  # are only Wrapper
  
  module Ontopia
    module TopicMap
      def to_cxtm(file=nil)
        raise("Only supported for Ontopia.") unless self.kind_of?(net.ontopia.topicmaps.impl.tmapi2.TopicMapImpl)
        if file
          if file.is_a?(java.io.OutputStream)
            out_stream = file
          else
            out_stream = java.io.BufferedOutputStream.new(java.io.FileOutputStream.new(file))
          end
        else
          # if no file was given we want to return a string which will be written into a stream by the writer
          out_stream = java.io.ByteArrayOutputStream.new
        end

        writer = net.ontopia.topicmaps.xml.CanonicalXTMWriter.new(out_stream)
        writer.write(self.wrapped)
        out_stream.flush

        # close the file unless we were provided with a stream
        out_stream.close unless file && file.is_a?(java.io.OutputStream)

        # if there was no file, we have a ByteArrayOutputStream. Get the String out of it (and return it)
        out_stream.to_s unless file
      end
    end
    
    RTM.register_extension(self)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rtm-ontopia-0.2.1 lib/rtm/ontopia/io/to_cxtm.rb