talia_core 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/README.rdoc +41 -0
  2. data/bin/talia +33 -0
  3. data/lib/JXslt/jxslt.rb +60 -0
  4. data/lib/acts_as_roled.rb +11 -0
  5. data/lib/core_ext/platform.rb +9 -0
  6. data/lib/core_ext/string.rb +6 -0
  7. data/lib/core_ext.rb +1 -0
  8. data/lib/custom_template.rb +4 -0
  9. data/lib/loader_helper.rb +62 -0
  10. data/lib/mysql.rb +1214 -0
  11. data/lib/progressbar.rb +236 -0
  12. data/lib/role.rb +12 -0
  13. data/lib/talia_cl/command_line.rb +39 -0
  14. data/lib/talia_cl/commands/standalone/cl_options.rb +9 -0
  15. data/lib/talia_cl/commands/standalone/standalone_generate.rb +75 -0
  16. data/lib/talia_cl/commands/standalone.rb +25 -0
  17. data/lib/talia_cl/commands/talia_console/cl_options.rb +55 -0
  18. data/lib/talia_cl/commands/talia_console/console_commands.rb +37 -0
  19. data/lib/talia_cl/commands/talia_console/talia_commands.rb +131 -0
  20. data/lib/talia_cl/commands/talia_console.rb +47 -0
  21. data/lib/talia_cl/core_commands.rb +11 -0
  22. data/lib/talia_cl.rb +47 -0
  23. data/lib/talia_core/active_source.rb +372 -0
  24. data/lib/talia_core/active_source_parts/class_methods.rb +378 -0
  25. data/lib/talia_core/active_source_parts/predicate_handler.rb +89 -0
  26. data/lib/talia_core/active_source_parts/rdf.rb +131 -0
  27. data/lib/talia_core/active_source_parts/sql_helper.rb +36 -0
  28. data/lib/talia_core/active_source_parts/xml/base_builder.rb +47 -0
  29. data/lib/talia_core/active_source_parts/xml/generic_reader.rb +363 -0
  30. data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +88 -0
  31. data/lib/talia_core/active_source_parts/xml/source_builder.rb +73 -0
  32. data/lib/talia_core/active_source_parts/xml/source_reader.rb +20 -0
  33. data/lib/talia_core/agent.rb +14 -0
  34. data/lib/talia_core/background_jobs/job.rb +82 -0
  35. data/lib/talia_core/background_jobs/progress_job.rb +68 -0
  36. data/lib/talia_core/collection.rb +13 -0
  37. data/lib/talia_core/data_types/data_loader.rb +92 -0
  38. data/lib/talia_core/data_types/data_record.rb +105 -0
  39. data/lib/talia_core/data_types/delayed_copier.rb +76 -0
  40. data/lib/talia_core/data_types/file_record.rb +59 -0
  41. data/lib/talia_core/data_types/file_store.rb +306 -0
  42. data/lib/talia_core/data_types/iip_data.rb +153 -0
  43. data/lib/talia_core/data_types/iip_loader.rb +127 -0
  44. data/lib/talia_core/data_types/image_data.rb +32 -0
  45. data/lib/talia_core/data_types/media_link.rb +19 -0
  46. data/lib/talia_core/data_types/mime_mapping.rb +45 -0
  47. data/lib/talia_core/data_types/path_helpers.rb +77 -0
  48. data/lib/talia_core/data_types/pdf_data.rb +42 -0
  49. data/lib/talia_core/data_types/simple_text.rb +36 -0
  50. data/lib/talia_core/data_types/temp_file_handling.rb +85 -0
  51. data/lib/talia_core/data_types/xml_data.rb +169 -0
  52. data/lib/talia_core/dc_resource.rb +20 -0
  53. data/lib/talia_core/dummy_handler.rb +34 -0
  54. data/lib/talia_core/dummy_source.rb +20 -0
  55. data/lib/talia_core/errors.rb +25 -0
  56. data/lib/talia_core/initializer.rb +427 -0
  57. data/lib/talia_core/ordered_source.rb +228 -0
  58. data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +13 -0
  59. data/lib/talia_core/rails_ext/actionpack/action_controller.rb +1 -0
  60. data/lib/talia_core/rails_ext/actionpack.rb +1 -0
  61. data/lib/talia_core/rails_ext.rb +1 -0
  62. data/lib/talia_core/rdf_import.rb +90 -0
  63. data/lib/talia_core/rdf_resource.rb +159 -0
  64. data/lib/talia_core/semantic_collection_item.rb +93 -0
  65. data/lib/talia_core/semantic_collection_wrapper.rb +324 -0
  66. data/lib/talia_core/semantic_property.rb +7 -0
  67. data/lib/talia_core/semantic_relation.rb +67 -0
  68. data/lib/talia_core/source.rb +323 -0
  69. data/lib/talia_core/source_transfer_object.rb +38 -0
  70. data/lib/talia_core/workflow/base.rb +15 -0
  71. data/lib/talia_core/workflow/publication_workflow.rb +62 -0
  72. data/lib/talia_core/workflow.rb +300 -0
  73. data/lib/talia_core.rb +9 -0
  74. data/lib/talia_dependencies.rb +12 -0
  75. data/lib/talia_util/bar_progressor.rb +15 -0
  76. data/lib/talia_util/configuration/config_file.rb +48 -0
  77. data/lib/talia_util/configuration/database_config.rb +40 -0
  78. data/lib/talia_util/configuration/mysql_database_setup.rb +104 -0
  79. data/lib/talia_util/data_import.rb +91 -0
  80. data/lib/talia_util/image_conversions.rb +82 -0
  81. data/lib/talia_util/import_job_helper.rb +132 -0
  82. data/lib/talia_util/io_helper.rb +54 -0
  83. data/lib/talia_util/progressable.rb +38 -0
  84. data/lib/talia_util/progressbar.rb +236 -0
  85. data/lib/talia_util/rdf_update.rb +80 -0
  86. data/lib/talia_util/some_sigla.xml +1960 -0
  87. data/lib/talia_util/test_helpers.rb +151 -0
  88. data/lib/talia_util/util.rb +226 -0
  89. data/lib/talia_util/yaml_import.rb +80 -0
  90. data/lib/talia_util.rb +13 -0
  91. data/lib/user.rb +116 -0
  92. data/lib/version.rb +15 -0
  93. data/test/core_ext/string_test.rb +11 -0
  94. data/test/custom_template_test.rb +8 -0
  95. data/test/talia_core/active_source_predicate_test.rb +54 -0
  96. data/test/talia_core/active_source_rdf_test.rb +89 -0
  97. data/test/talia_core/active_source_test.rb +631 -0
  98. data/test/talia_core/data_types/data_loader_test.rb +123 -0
  99. data/test/talia_core/data_types/data_record_test.rb +40 -0
  100. data/test/talia_core/data_types/file_record_test.rb +171 -0
  101. data/test/talia_core/data_types/iip_data_test.rb +130 -0
  102. data/test/talia_core/data_types/image_data_test.rb +88 -0
  103. data/test/talia_core/data_types/pdf_data_test.rb +68 -0
  104. data/test/talia_core/data_types/xml_data_test.rb +134 -0
  105. data/test/talia_core/generic_xml_test.rb +83 -0
  106. data/test/talia_core/initializer_test.rb +36 -0
  107. data/test/talia_core/ordered_source_test.rb +398 -0
  108. data/test/talia_core/rdf_resource_test.rb +115 -0
  109. data/test/talia_core/semantic_collection_item_test.rb +129 -0
  110. data/test/talia_core/source_reader_test.rb +33 -0
  111. data/test/talia_core/source_test.rb +484 -0
  112. data/test/talia_core/source_transfer_object_test.rb +24 -0
  113. data/test/talia_core/workflow/publication_workflow_test.rb +242 -0
  114. data/test/talia_core/workflow/user_class_for_workflow.rb +35 -0
  115. data/test/talia_core/workflow/workflow_base_test.rb +21 -0
  116. data/test/talia_core/workflow_test.rb +19 -0
  117. data/test/talia_util/import_job_helper_test.rb +46 -0
  118. data/test/test_helper.rb +68 -0
  119. metadata +262 -0
data/README.rdoc ADDED
@@ -0,0 +1,41 @@
1
+ = TaliaCore
2
+
3
+ This is the "core" of the Talia semantic digital web library system. Talia can
4
+ be used with Ruby on Rails, or as a standalone package.
5
+
6
+ More documentation can be found on the Talia website:
7
+ http:///trac.talia.discovery-project.eu/
8
+
9
+ The RDoc documentation may be created directly from the sources, or you can find
10
+ it at http://net7.github.com/talia_core/
11
+
12
+ = Installation
13
+
14
+ If you have the Talia files on your sytem, you're almost there. For now,
15
+ please consult the web page for installation instructions.
16
+
17
+ = Configuration
18
+
19
+ When you're in Rails, you can start Talia in the environment.rb, using the
20
+ TaliaCore::Initializer - if you're building a standalone application, it's
21
+ almost the same (although you'll have to use standalone_db=yes to configure
22
+ ActiveRecord manually)
23
+
24
+ There are some sample configuration files in the distribution:
25
+
26
+ * talia_core.yml - This file contains the main configuration.
27
+ * database.yml - Standalon Db configuration. Same format as for Rails.
28
+ * rdfstore.yml - RDF storage configuration.
29
+
30
+ The default configuration (talia_core.yml) will use the database.yml and
31
+ rdfstore.yml to configure the data storage. See the example filme for an
32
+ explanation of the options. The database configuration will only be used if
33
+ you are running Talia standalone; otherwise you must use RAILS' existing
34
+ database connection.
35
+
36
+ The options for the RDF store vary depending on the store that you have selected,
37
+ but some examples are provideed.
38
+
39
+ = DB Migrations
40
+
41
+ = Importing data
data/bin/talia ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- Ruby -*-
3
+
4
+ # Talia command line tool
5
+ # Helper for local requires
6
+ def local_requires
7
+ require "talia_cl"
8
+ end
9
+
10
+ # Little helper for running the command line in development mode/without gem
11
+ # installed. If the
12
+ begin
13
+ local_requires
14
+ rescue LoadError
15
+ puts "Talia gem does not seem to be installed, trying fallback locations."
16
+ lib_path_local = File.expand_path(File.join(".", "lib"))
17
+ lib_path_rails = File.expand_path(File.join(".", "vendor", "plugins", "talia_core", "lib"))
18
+ if(FileTest.exists?(File.join(lib_path_local, "talia_cl.rb")))
19
+ puts "...seems to be the local talia directory. Using local config."
20
+ $: << lib_path_local
21
+ local_requires
22
+ elsif(FileTest.exists?(File.join(lib_path_rails, "talia_cl.rb")))
23
+ puts "... seems to be a rails installation with talia. Using Rails config."
24
+ $: << lib_path_rails
25
+ $: << lib_path_local # Also put the path to the "local" rails-specific stuff
26
+ local_requires
27
+ else
28
+ puts "No Talia installation found. Try to run this within the Talia root dir."
29
+ raise LoadError, "Talia installation not found."
30
+ end
31
+ end
32
+
33
+ run_command_line
@@ -0,0 +1,60 @@
1
+ include Java if jruby?
2
+ module JXslt
3
+ Dir["#{RAILS_ROOT}/lib/saxon*.jar"].each { |jar| require jar }
4
+ include_class "javax.xml.transform.TransformerFactory"
5
+ include_class "javax.xml.transform.Transformer"
6
+ include_class "javax.xml.transform.stream.StreamSource"
7
+ include_class "javax.xml.transform.stream.StreamResult"
8
+ include_class "java.lang.System"
9
+
10
+ class XsltProcessor
11
+
12
+ puts $CLASSPATH
13
+
14
+
15
+ def transform(xslt, infile, outfile, options)
16
+ if options[:in] == "stream"
17
+ in_var = StreamSource.new(infile)
18
+ else
19
+ sr = java.io.StringReader.new(infile)
20
+ in_var = StreamSource.new(sr)
21
+ end
22
+ if options[:out] == "stream"
23
+ out_var = StreamResult.new(outfile)
24
+ else
25
+ sw = java.io.StringWriter.new()
26
+ out_var = StreamResult.new(sw)
27
+ end
28
+ if options[:xslt] == "stream"
29
+ xslt_var = StreamSource.new(xslt)
30
+ else
31
+ sxs = java.io.StringReader.new(xslt)
32
+ xslt_var = StreamSource.new(sxs)
33
+ end
34
+ transformer = @tf.newTransformer(xslt_var)
35
+ unless options[:transformer_parameters].nil?
36
+ options[:transformer_parameters].each do |key, value|
37
+ transformer.setParameter(key, java.lang.String.new(value))
38
+ end
39
+ end
40
+ transformer.transform(in_var, out_var)
41
+ if options[:out] != "stream"
42
+ outfile = sw.toString()
43
+ end
44
+ end
45
+ end # XsltProcessor
46
+ class Saxon < XsltProcessor
47
+ TRANSFORMER_FACTORY_IMPL = "net.sf.saxon.TransformerFactoryImpl"
48
+ def initialize
49
+ System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
50
+ @tf = TransformerFactory.newInstance
51
+ end
52
+ end
53
+ class Xalan < XsltProcessor
54
+ TRANSFORMER_FACTORY_IMPL = "org.apache.xalan.processor.TransformerFactoryImpl"
55
+ def initialize
56
+ System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
57
+ @tf = TransformerFactory.newInstance
58
+ end
59
+ end
60
+ end if jruby?
@@ -0,0 +1,11 @@
1
+ module ActsAsRoled
2
+ def self.included(mod)
3
+ Role.find_all_names.each do |role|
4
+ mod.class_eval <<-END
5
+ def #{role}?
6
+ has_role?('#{role}')
7
+ end
8
+ END
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Platform # :nodoc:
2
+ extend self
3
+
4
+ def jruby?
5
+ RUBY_PLATFORM =~ /java/
6
+ end
7
+ end
8
+
9
+ extend Platform
@@ -0,0 +1,6 @@
1
+ class String
2
+ # Transform the current string into a permalink.
3
+ def to_permalink
4
+ self.gsub(/\W+/, ' ').strip.downcase.titleize.gsub(/\ +/, '_')
5
+ end
6
+ end
data/lib/core_ext.rb ADDED
@@ -0,0 +1 @@
1
+ Dir['lib/core_ext/**/*.rb'].each{|f| require f}
@@ -0,0 +1,4 @@
1
+ class CustomTemplate < ActiveRecord::Base
2
+ validates_presence_of :name, :content
3
+ validates_format_of :template_type, :with => /css|xslt/
4
+ end
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+
3
+ # Some helpers for the Talia bootstrapping (when the module is loaded)
4
+ module TLoad
5
+
6
+ # This tries to load the the given module.
7
+ # It first attempts to load from local_path/lib/local_name
8
+ # The local path is always appended to the directory of the script
9
+ # currently running.
10
+ # If that fails, it tries to load the given gem
11
+ def self.require_module(gem_name, local_name, local_path, gem_version = nil)
12
+ begin
13
+ # Try to loaTad from local if it exists
14
+ search_dir = File.expand_path(File.join(File.dirname(__FILE__), local_path, "lib"))
15
+ if(File.exists?(search_dir))
16
+ $:.unshift(search_dir)
17
+ require local_name
18
+ else
19
+ load_from_gem(gem_name, local_name, gem_version)
20
+ end
21
+ rescue LoadError
22
+ load_from_gem(gem_name, local_name, gem_version)
23
+ end
24
+ end
25
+
26
+ def self.start_dir
27
+ @start_dir ||= begin
28
+ # adding talia_core subdirectory to the ruby loadpath
29
+ file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
30
+ this_dir = File.dirname(File.expand_path(file))
31
+ $: << this_dir
32
+ $: << this_dir + '/talia_core/'
33
+ this_dir
34
+ end
35
+ end
36
+
37
+ # Forces the loading of the parts of the rails framework that are used
38
+ # by Talia
39
+ def self.force_rails_parts
40
+ require_module("activerecord", "active_record", "/../../../rails/activerecord", RAILS_GEM_VERSION) unless(defined?(ActiveRecord))
41
+ require_module("activesupport", "active_support", "/../../../rails/activesupport", RAILS_GEM_VERSION) unless(defined?(ActiveSupport))
42
+ require_module("actionpack", "action_controller", "/../../../rails/actionpack", RAILS_GEM_VERSION)
43
+ # This sets the automatic loader path for Talia, allowing the ActiveSupport
44
+ # classes to automatically load classes from this directory.
45
+ ActiveSupport::Dependencies.load_paths << TLoad.start_dir unless(ActiveSupport::Dependencies.load_paths.include?(TLoad.start_dir))
46
+ end
47
+
48
+ private
49
+
50
+ def self.load_from_gem(gem_name, local_name, gem_version)
51
+ if gem_version
52
+ gem gem_name, gem_version
53
+ else
54
+ gem gem_name
55
+ end
56
+
57
+ require local_name
58
+ end
59
+
60
+ end
61
+
62
+ TLoad.start_dir # Load the paths and start directory