rtm 0.1.6 → 0.2

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.
Files changed (163) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +32 -3
  4. data/lib/rtm.rb +126 -74
  5. data/lib/rtm/axes.rb +298 -0
  6. data/lib/rtm/axes/association.rb +76 -0
  7. data/lib/rtm/axes/associations.rb +96 -0
  8. data/lib/rtm/axes/assocs_names_occs.rb +56 -0
  9. data/lib/rtm/axes/characteristic.rb +68 -0
  10. data/lib/rtm/axes/characteristics.rb +93 -0
  11. data/lib/rtm/axes/string.rb +76 -0
  12. data/lib/rtm/axes/strings.rb +87 -0
  13. data/lib/rtm/axes/topic.rb +233 -0
  14. data/lib/rtm/axes/topics.rb +280 -0
  15. data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
  16. data/lib/rtm/engine.rb +101 -0
  17. data/lib/rtm/extensions.rb +65 -5
  18. data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
  19. data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
  20. data/lib/rtm/helpers/uri.rb +13 -0
  21. data/lib/rtm/io.rb +19 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/tmapix_from.rb +155 -0
  24. data/lib/rtm/io/tmapix_to.rb +223 -0
  25. data/lib/rtm/io/to_hash.rb +154 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +45 -0
  28. data/lib/rtm/io/to_string.rb +21 -8
  29. data/lib/rtm/io/to_xtm1.rb +6 -4
  30. data/lib/rtm/io/to_xtm2.rb +10 -8
  31. data/lib/rtm/io/to_yaml.rb +59 -100
  32. data/lib/rtm/navigation.rb +23 -0
  33. data/lib/rtm/navigation/association/players.rb +25 -0
  34. data/lib/rtm/navigation/name/atomify.rb +19 -0
  35. data/lib/rtm/navigation/name/characteristics.rb +33 -0
  36. data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
  37. data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
  38. data/lib/rtm/navigation/topic/characteristics.rb +33 -0
  39. data/lib/rtm/navigation/topic/indicators.rb +31 -0
  40. data/lib/rtm/navigation/topic/items.rb +31 -0
  41. data/lib/rtm/navigation/topic/locators.rb +31 -0
  42. data/lib/rtm/navigation/topic/players.rb +27 -0
  43. data/lib/rtm/navigation/topic/supertypes.rb +166 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +109 -0
  46. data/lib/rtm/psi.rb +39 -2
  47. data/lib/rtm/sugar.rb +47 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +58 -0
  50. data/lib/rtm/sugar/occurrence/external.rb +53 -0
  51. data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
  52. data/lib/rtm/sugar/role/counterparts.rb +139 -46
  53. data/lib/rtm/sugar/topic/best_name.rb +74 -0
  54. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  55. data/lib/rtm/sugar/topic/counterparts.rb +145 -10
  56. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  57. data/lib/rtm/sugar/topic/scoped.rb +114 -0
  58. data/lib/rtm/sugar/topic/topic_ref.rb +86 -0
  59. data/lib/rtm/sugar/topic/typed.rb +207 -0
  60. data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
  61. data/lib/rtm/sugar/topic_map/themes.rb +53 -0
  62. data/lib/rtm/sugar/typed/types.rb +38 -0
  63. data/lib/rtm/validation.rb +7 -4
  64. data/lib/rtm/version.rb +30 -0
  65. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  66. data/spec/rtm/axes/association_spec.rb +88 -0
  67. data/spec/rtm/axes/associations_spec.rb +60 -0
  68. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  69. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  70. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  71. data/spec/rtm/axes/string_spec.rb +145 -0
  72. data/spec/rtm/axes/strings_spec.rb +168 -0
  73. data/spec/rtm/axes/topic_spec.rb +124 -0
  74. data/spec/rtm/axes/topics_spec.rb +103 -0
  75. data/spec/rtm/base_spec.rb +32 -0
  76. data/spec/rtm/io/tmapix_from_spec.rb +76 -0
  77. data/spec/rtm/io/tmapix_to_spec.rb +159 -0
  78. data/spec/rtm/io/to_hash_spec.rb +90 -0
  79. data/spec/rtm/io/to_rdf_spec.rb +37 -0
  80. data/spec/rtm/io/to_string_spec.rb +122 -0
  81. data/spec/rtm/io/to_yaml_spec.rb +89 -0
  82. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  83. data/spec/rtm/navigation/association_spec.rb +52 -0
  84. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  85. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  86. data/spec/rtm/navigation/name_spec.rb +52 -0
  87. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  88. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  89. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  90. data/spec/rtm/navigation/string_spec.rb +51 -0
  91. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  92. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  93. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  94. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  95. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  96. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  97. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  98. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  99. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  100. data/spec/rtm/navigation/topic_spec.rb +153 -0
  101. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  102. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +171 -0
  103. data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
  104. data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
  105. data/spec/rtm/sugar/role/counterparts_spec.rb +193 -0
  106. data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
  107. data/spec/rtm/sugar/topic/characteristics_spec.rb +333 -0
  108. data/spec/rtm/sugar/topic/counterparts_spec.rb +224 -0
  109. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  110. data/spec/rtm/sugar/topic/scoped_spec.rb +195 -0
  111. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  112. data/spec/rtm/sugar/topic/typed_spec.rb +217 -0
  113. data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
  114. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  115. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  116. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  117. data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
  118. data/spec/rtm/tmapi/core/name_spec.rb +270 -0
  119. data/spec/rtm/tmapi/core/occurrence_spec.rb +53 -0
  120. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  121. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  122. data/spec/rtm/tmapi/core/scoped_spec.rb +441 -0
  123. data/spec/rtm/tmapi/core/topic_map_spec.rb +716 -0
  124. data/spec/rtm/tmapi/core/topic_spec.rb +1468 -0
  125. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  126. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  127. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  128. data/spec/rtm/tmapi_spec.rb +44 -0
  129. data/spec/rtm/utils/sparql_spec.rb +26 -0
  130. data/spec/rtm_spec.rb +93 -0
  131. data/spec/spec_helper.rb +28 -0
  132. data/test/javalibs/junit-4.5.jar +0 -0
  133. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
  134. data/test/tmapi_tests.rb +25 -0
  135. metadata +169 -65
  136. data/COPYRIGHT +0 -4
  137. data/lib/Rakefile.rb +0 -42
  138. data/lib/activetopicmaps.rb +0 -278
  139. data/lib/rtm/backend/active_record.rb +0 -58
  140. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  141. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  142. data/lib/rtm/backend/active_record/locators.rb +0 -55
  143. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  144. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  145. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  146. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  147. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  148. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  149. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  150. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  151. data/lib/rtm/backend/active_record/topic.rb +0 -87
  152. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  153. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  154. data/lib/rtm/base.rb +0 -92
  155. data/lib/rtm/connect.rb +0 -92
  156. data/lib/rtm/core_ext.rb +0 -6
  157. data/lib/rtm/io/from_xtm2.rb +0 -263
  158. data/lib/rtm/merging/merging.rb +0 -307
  159. data/lib/rtm/pimp_my_api.rb +0 -28
  160. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  161. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  162. data/lib/run_main_project.rb +0 -16
  163. data/test/base_test.rb +0 -162
@@ -1,3 +1,6 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
1
4
  module RTM
2
5
  # Some helpers for locators which could ideally mixed into String and Locator.
3
6
  # Anyway, they are not here to not clutter up the namespace too much.
@@ -5,7 +8,9 @@ module RTM
5
8
  # removes "=" (and possible whitespace thereafter) from the beginning of a String or Locator if it is there
6
9
  def self.slo2iri(slo)
7
10
  slo = slo.to_s
8
- slo = slo[1..-1].lstrip if slo[0] == "="[0] # remove = if slo starts with it
11
+ slo =~ /^(=|sl:)\s*(.+)/
12
+ return $2 if $2
13
+ # old: slo[1..-1].lstrip if slo[0] == "="[0] # remove = if slo starts with it
9
14
  slo
10
15
  end
11
16
 
@@ -17,7 +22,8 @@ module RTM
17
22
 
18
23
  # returns true if the String or Locator given starts with "="
19
24
  def self.is_a_slo?(iri)
20
- iri.to_s[0] == "="[0]
25
+ # iri.to_s[0] == "="[0] # old version
26
+ iri =~ /^(=|sl:)\s*(.+)/
21
27
  end
22
28
 
23
29
  def self.iid2iri(slo)
@@ -33,7 +39,12 @@ module RTM
33
39
  # returns true if the String or Locator given starts with "^".
34
40
  # This catches only the prefixing-style, not the local-identifier (non-absolute-iri) style
35
41
  def self.is_a_iid?(iri)
36
- iri.to_s[0] == "^"[0]
37
- end
42
+ iri =~ /^(\^|ii:)\s*(.*)/
43
+ # iri.to_s[0] == "^"[0] # old version
44
+ end
45
+
46
+ def self.is_a_sid?(iri)
47
+ iri =~ /^(si:)\s*(.+)/
48
+ end
38
49
  end
39
50
  end
@@ -1,3 +1,6 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
1
4
  # Executes the given block while suppressing all standard output.
2
5
  def no_output
3
6
  $stdout = File.open( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null", "w" )
@@ -0,0 +1,13 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::RTM
5
+ def is_uri?(test)
6
+ begin
7
+ URI(test)
8
+ rescue Exception => e
9
+ end
10
+
11
+ e ? false : true
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ require 'rtm/io/to_rdf'
5
+ require 'rtm/io/to_hash'
6
+
7
+
8
+ # Check if JSON is available and load JTM if it is
9
+ if Object.const_defined?(:JSON)
10
+ require 'rtm/io/to_jtm'
11
+ end
12
+ # old code to check for JSON (has Gem-dependency)
13
+ #require 'rtm/io/to_jtm' unless (Gem.source_index.find_name('json/ext').empty? && Gem.source_index.find_name('json/pure').empty?)
14
+
15
+
16
+ require 'rtm/io/to_yaml'
17
+ require 'rtm/io/tmapix_from'
18
+ require 'rtm/io/tmapix_to'
19
+ require 'rtm/io/to_string'
@@ -1,4 +1,5 @@
1
- # Ruby Topic Maps (RTM) http://rtm.rubyforge.org/
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
2
3
 
3
4
  module RTM
4
5
  def self.from_xtm2lx(*args)
@@ -0,0 +1,155 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::IO
5
+ # Import for TMAPI Topic Maps
6
+ # Utilizing the TMAPIX libary http://code.google.com/p/tmapix/
7
+ # Consequently the deserializers provided here are only wrappers
8
+
9
+ module TmapiXFrom
10
+ module TopicMap
11
+
12
+ def from_anything(reader_class, *args)
13
+ raise "Only supported for TMAPI backends!!" unless self.kind_of?(Java::OrgTmapiCore::TopicMap) || self.kind_of?(Java::OrgTmapiCore::TopicMapSystem)
14
+
15
+ params = {}
16
+ # See if we got a params hash. It must be at the end, if it is given.
17
+ # Take it off, so it won't be unshifted later.
18
+ params = args.pop if args.last.is_a?(Hash)
19
+
20
+ # Take the source as next (i.e. second after the writer) positional parameter or from hash.
21
+ # Leave nil if neither found.
22
+ source = args.shift || params[:source]
23
+
24
+ # Take the base_iri as next (i.e. third after the file) positional parameter or from the hash.
25
+ # Use the topic maps's base_iri if neither found.
26
+ base_iri = args.shift || params[:base_iri]
27
+ unless base_iri
28
+ if self.kind_of?(RTM::TopicMap)
29
+ base_iri = self.base_iri
30
+ else
31
+ base_iri = "imported:FIXME"
32
+ end
33
+ end
34
+
35
+ if self.kind_of?(RTM::TopicMap)
36
+ topic_map = self
37
+ else
38
+ topic_map = create(base_iri)
39
+ end
40
+
41
+ reader_class.new(topic_map, java.io.File.new(source)).read
42
+ topic_map
43
+ end
44
+
45
+ # Reads a Topic Map from an LTM File
46
+ # whose location is given as String parameter.
47
+ #
48
+ # :call-seq:
49
+ # from_ltm(filename)
50
+ #
51
+ def from_ltm(*args)
52
+ from_anything(org.tmapix.io.LTMTopicMapReader, *args)
53
+ end
54
+
55
+ # Reads a Topic Map from an CTM File
56
+ # whose location is given as String parameter.
57
+ #
58
+ # :call-seq:
59
+ # from_ctm(filename)
60
+ #
61
+ def from_ctm(*args)
62
+ from_anything(org.tmapix.io.CTMTopicMapReader, *args)
63
+ end
64
+
65
+ # Reads a JSON Topic Maps (JTM) File
66
+ # whose location is given as String parameter.
67
+ #
68
+ # :call-seq:
69
+ # from_jtm(filename)
70
+ #
71
+ def from_jtm(*args)
72
+ # seems not to acceped all files that are found to be valid by the JTM validator
73
+ from_anything(org.tmapix.io.JTMTopicMapReader, *args)
74
+ end
75
+
76
+ # Reads a Friendly Topic Maps XML (TM/XML) File
77
+ # independent of the version
78
+ # whose location is given as String parameter.
79
+ #
80
+ # :call-seq:
81
+ # from_tmxml(filename)
82
+ #
83
+ def from_tmxml(*args)
84
+ from_anything(org.tmapix.io.TMXMLTopicMapReader, *args)
85
+ end
86
+
87
+ # Reads a XML Topic Maps (XTM) 1.0 File
88
+ # whose location is given as String parameter.
89
+ #
90
+ # :call-seq:
91
+ # from_xtm10(filename)
92
+ #
93
+ def from_xtm10(*args)
94
+ from_anything(org.tmapix.io.XTM10TopicMapReader, *args)
95
+ end
96
+ alias :from_xtm1 :from_xtm10
97
+
98
+ # Reads a XML Topic Maps (XTM) 2.0 File
99
+ # whose location is given as String parameter.
100
+ #
101
+ # :call-seq:
102
+ # from_xtm20(filename)
103
+ #
104
+ def from_xtm20(*args)
105
+ from_xtm(*args)
106
+ end
107
+ alias :from_xtm2 :from_xtm20
108
+
109
+ # Reads a XML Topic Maps (XTM) File
110
+ # independent of the version
111
+ # whose location is given as String parameter.
112
+ #
113
+ # :call-seq:
114
+ # from_xtm(filename)
115
+ #
116
+ def from_xtm(*args)
117
+ from_anything(org.tmapix.io.XTMTopicMapReader, *args)
118
+ end
119
+
120
+ # Reads a Notation3 (N3) File
121
+ # whose location is given as String .
122
+ # The source vocabulary must
123
+ # provide the mapping vocabulary.
124
+ # The syntax of the vocabulary is guessed.
125
+ #
126
+ # :call-seq:
127
+ # from_n3(filename, source vocabulary)
128
+ #
129
+ def from_n3(filename, vocab)
130
+ raise "Only supported for TMAPI backends!!" unless self.kind_of? Java::OrgTmapiCore::TopicMap
131
+ reader = org.tmapix.io.N3TopicMapReader.new self, java.io.File.new(filename)
132
+ reader.setMappingSource(java.io.File.new(vocab))
133
+ reader.read
134
+ end
135
+
136
+ # Reads a RDF/XML File
137
+ # whose location is given as String
138
+ # The source vocabulary must
139
+ # provide the mapping vocabulary.
140
+ # The syntax of the vocabulary is guessed.
141
+ #
142
+ # :call-seq:
143
+ # from_rdfxml(filename, source vocabulary)
144
+ #
145
+ def from_rdfxml(filename, vocab)
146
+ raise "Only supported for TMAPI backends!!" unless self.kind_of? Java::OrgTmapiCore::TopicMap
147
+ reader = org.tmapix.io.RDFXMLTopicMapReader.new self, java.io.File.new(filename)
148
+ reader.setMappingSource(java.io.File.new(vocab))
149
+ reader.read
150
+ end
151
+ end
152
+ TopicMapSystem = TopicMap # We want importers for both, TopicMap and TopicMapSystem
153
+ RTM.register_extension(self)
154
+ end
155
+ end
@@ -0,0 +1,223 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::IO
5
+ # Export of TMAPI Topic Maps
6
+ # Utilizing the TMAPIX libary http://code.google.com/p/tmapix/
7
+ # Consequently the serializers provided here are only wrappers
8
+
9
+ module TmapiXTo
10
+ module TopicMap
11
+
12
+ private
13
+ # Serializes a Topic Map using the given writer.
14
+ #
15
+ # If the optional file is given (using the positional parameter or the :file keys in the params hash),
16
+ # it is written to that file, otherwise a String will be returned.
17
+ # The file can be provided as a String (which is then interpreted as a filename) or as a java.io.OutputStream.
18
+ # E.g. to_anything(my_writer, "/some/file") # writes to the file
19
+ # to_anything(my_writer, some_output_stream) # writes to the outputstream
20
+ # E.g. to_anything(my_writer, :file => "/some/file") # writes to the file
21
+ # to_anything(my_writer) # returns a string
22
+ #
23
+ # If the optional base_iri is given (using the positional parameter or the :base_iri key in the params hash),
24
+ # the given base_iri will be used during export. Otherwise the topic maps's base_iri will be used.
25
+ # E.g. to_anything(my_writer, "/some/file", "http://example.org/something") # uses the base_iri given
26
+ # to_anything(my_writer) # uses the base_iri of the topic map
27
+ #
28
+ # Please be aware that you cannot leave out the filename positional parameter and just provide the base_iri.
29
+ # If you want to provide a base_iri but no filename provide +nil+ as filename or use the params hash.
30
+ # E.g. to_anything(my_writer, nil, my_base_iri)
31
+ # to_anything(my_writer, :base_iri => my_base_iri)
32
+ #
33
+ # :call-seq:
34
+ # to_anything(writer_class, params = {})
35
+ # to_anything(writer_class, file, params = {})
36
+ # to_anything(writer_class, file, base_iri, params={})
37
+ #
38
+ def to_anything(writer_class, *args)
39
+ raise("Only supported for TMAPI backends.") unless self.kind_of?(Java::OrgTmapiCore::TopicMap)
40
+ params = {}
41
+ # See if we got a params hash. It must be at the end, if it is given.
42
+ # Take it off, so it won't be unshifted later.
43
+ params = args.pop if args.last.is_a?(Hash)
44
+
45
+ # Take the file as next (i.e. second after the writer) positional parameter or from hash.
46
+ # Leave nil if neither found.
47
+ file = args.shift || params[:file]
48
+
49
+ # Take the base_iri as next (i.e. third after the file) positional parameter or from the hash.
50
+ # Use the topic maps's base_iri if neither found.
51
+ base_iri = args.shift || params[:base_iri] || self.base_iri
52
+
53
+ # If a file was provided somehow, we wrap it with output streams
54
+ if file
55
+ if file.is_a?(java.io.OutputStream)
56
+ out_stream = file
57
+ else
58
+ out_stream = java.io.BufferedOutputStream.new(java.io.FileOutputStream.new(file))
59
+ end
60
+ else
61
+ # if no file was given we want to return a string which will be written into a stream by the writer
62
+ out_stream = java.io.ByteArrayOutputStream.new
63
+ end
64
+
65
+ # create the java writer
66
+ writer = writer_class.new(out_stream, base_iri)
67
+ # set params
68
+ params.each do |k,v|
69
+ # skip our params, as they're not of interest for the writer
70
+ next if k == :file || k == :base_iri
71
+ writer.setProperty(k.to_s,v.to_s)
72
+ end if writer.respond_to?(:setProperty)
73
+ # do the actual work
74
+ writer.write(self)
75
+ out_stream.flush
76
+
77
+ # close the file unless we were provided with a stream
78
+ out_stream.close unless file && file.is_a?(java.io.OutputStream)
79
+
80
+ # if there was no file, we have a ByteArrayOutputStream. Get the String out of it (and return it)
81
+ # otherwise, we return true
82
+ return file ? true : out_stream.to_s
83
+ end
84
+
85
+ public
86
+ # Serializes an RTM::TopicMap to XTM v. 2.0.
87
+ #
88
+ # If no argument is given, a String is returned.
89
+ #
90
+ # The argument file can be provided as a String
91
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
92
+ #
93
+ # The argument base_iri may be used to define a new base_iri, if not, the current
94
+ # one is used. Base_iri may be a String.
95
+ #
96
+ # :call-seq:
97
+ # to_xtm20
98
+ # to_xtm20(file)
99
+ # to_xtm20(file, base_iri)
100
+ #
101
+ def to_xtm20(*args)
102
+ to_anything(org.tmapix.io.XTM20TopicMapWriter, *args)
103
+ end
104
+ alias :to_xtm :to_xtm20
105
+ alias :to_xtm2 :to_xtm20
106
+
107
+ # Serializes an RTM::TopicMap to XTM v. 1.0.
108
+ #
109
+ # If no argument is given, a String is returned.
110
+ #
111
+ # The argument file can be provided as a String
112
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
113
+ #
114
+ # The argument base_iri may be used to define a new base_iri, if not, the current
115
+ # one is used. Base_iri may be a String.
116
+ #
117
+ # :call-seq:
118
+ # to_xtm10
119
+ # to_xtm10(file)
120
+ # to_xtm10(file, base_iri)
121
+ #
122
+ def to_xtm10(*args)
123
+ to_anything(org.tmapix.io.XTM10TopicMapWriter, *args)
124
+ end
125
+ alias :to_xtm1 :to_xtm10
126
+
127
+ # Serializes an RTM::TopicMap to JTM.
128
+ #
129
+ # If no argument is given, a String is returned.
130
+ #
131
+ # The argument file can be provided as a String
132
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
133
+ #
134
+ # The argument base_iri may be used to define a new base_iri, if not, the current
135
+ # one is used. Base_iri may be a String.
136
+ #
137
+ # :call-seq:
138
+ # to_jtm
139
+ # to_jtm(file)
140
+ # to_jtm(file, base_iri)
141
+ #
142
+ def to_jtm(*args)
143
+ to_anything(org.tmapix.io.JTMTopicMapWriter, *args)
144
+ end
145
+ alias :to_json :to_jtm
146
+
147
+ # Serializes an RTM::TopicMap to LTM.
148
+ #
149
+ # If no argument is given, a String is returned.
150
+ #
151
+ # The argument file can be provided as a String
152
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
153
+ #
154
+ # The argument base_iri may be used to define a new base_iri, if not, the current
155
+ # one is used. Base_iri may be a String.
156
+ #
157
+ # :call-seq:
158
+ # to_ltm
159
+ # to_ltm(file)
160
+ # to_ltm(file, base_iri)
161
+ #
162
+ def to_ltm(*args)
163
+ to_anything(org.tmapix.io.LTMTopicMapWriter, *args)
164
+ end
165
+
166
+ # Serializes an RTM::TopicMap to TM/XML.
167
+ #
168
+ # If no argument is given, a String is returned.
169
+ #
170
+ # The argument file can be provided as a String
171
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
172
+ #
173
+ # The argument base_iri may be used to define a new base_iri, if not, the current
174
+ # one is used. Base_iri may be a String.
175
+ #
176
+ # :call-seq:
177
+ # to_tmxml
178
+ # to_tmxml(file)
179
+ # to_tmxml(file, base_iri)
180
+ #
181
+ def to_tmxml(*args)
182
+ to_anything(org.tmapix.io.TMXMLTopicMapWriter, *args)
183
+ end
184
+
185
+ # Serializes an RTM::TopicMap to CTM.
186
+ #
187
+ # If no argument is given, a String is returned.
188
+ #
189
+ # The argument file can be provided as a String
190
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
191
+ #
192
+ # The argument base_iri may be used to define a new base_iri, if not, the current
193
+ # one is used. Base_iri may be a String.
194
+ #
195
+ # A property-Hash may be given to set properties of the writer.
196
+ #
197
+ # :call-seq:
198
+ # to_ctm(properties={})
199
+ # to_ctm(file, properties={})
200
+ # to_ctm(file, base_iri, properties={})
201
+ #
202
+ def to_ctm(*args)
203
+ # set default params
204
+ default_params = {
205
+ "writer.features.export.itemidentifier" => false,
206
+ "writer.features.prefixDetection.enabled" => false,
207
+ "writer.features.templateDetection.enabled" => false,
208
+ "writer.features.templateDetection.topicTemplates" => false,
209
+ "writer.features.templateDetection.associationTemplates" => false,
210
+ "writer.features.templateMerger.enabled" => false
211
+ }
212
+ # enhance the args with the default params
213
+ if args.last.is_a?(Hash)
214
+ args.push(default_params.merge(args.pop))
215
+ else
216
+ args.push(default_params)
217
+ end
218
+ to_anything(de.topicmapslab.ctm.writer.core.CTMTopicMapWriter, *args)
219
+ end
220
+ end
221
+ RTM.register_extension(self)
222
+ end
223
+ end