Modified: trunk/lib/workflow_processors/trident_opc.rb (2848 => 2849)
--- trunk/lib/workflow_processors/trident_opc.rb 2011-11-28 14:40:52 UTC (rev 2848)
+++ trunk/lib/workflow_processors/trident_opc.rb 2011-11-28 16:10:38 UTC (rev 2849)
@@ -29,23 +29,43 @@
# All the file extensions supported by this workflow processor.
# Must be all in lowercase.
def self.file_extensions_supported
- [ "zip" ]
+ [ "zip", "twp" ]
end
def self.can_determine_type_from_file?
- false
+ true
end
+ # It is not possible to give a 100% gurantee that a file is a valid trident package
+ # unless each zip entry is read for structure.
+ # This method thus makes sure if the package file is a valid zip file and then checks
+ # if it is atleast a valid OPC package by checking for a mandatory root file Content_Types,xml
def self.recognised?(file)
- false
+ begin
+ zipfile = Tempfile.new('package.zip')
+ zipfile.binmode
+
+ zipfile.print(file.read)
+ zipfile.close
+
+ Zip::ZipFile.open(zipfile.path, Zip::ZipFile::CREATE) {
+ |file1|
+ if nil == file1.get_entry('[Content_Types].xml')
+ return false
+ end
+ return true
+ }
+ rescue
+ return false
+ end
end
def self.can_infer_metadata?
- false
+ true
end
def self.can_generate_preview_image?
- false
+ true
end
def self.can_generate_preview_svg?
@@ -58,18 +78,106 @@
# Begin Object Initializer
def initialize(workflow_definition)
+
super(workflow_definition)
+
+ # Check if the zip file exists. If yes then remove it
+ zipfile = Tempfile.new('package.zip')
+ zipfile.binmode
+
+ @filename = zipfile.path
+ zipfile.print(workflow_definition)
+
end
# End Object Initializer
+ def filename
+ @filename = ''
+ end
-
# Begin Instance Methods
-
# These provide more specific functionality for a given workflow definition, such as parsing for metadata and image generation.
+ def get_title
+ Zip::ZipInputStream::open(@filename) {
+ |io|
+
+ while (entry = io.get_next_entry)
+ if entry.name.match('^.*/ActivityKind/.*xml$')
+ xml = io.read
+ doc, statuses = REXML::Document.new(xml), []
+ doc.elements.each('/ObjectDetails/Type') do |s1|
+ if s1.text.match('Root')
+ doc.elements.each('/ObjectDetails/Label') do |s|
+ return s.text
+ end
+ end
+ end
+ end
+ end
+ }
+ rescue
+ return ''
+ end
+ def get_description
+ Zip::ZipInputStream::open(@filename) {
+ |io|
+
+ while (entry = io.get_next_entry)
+ if entry.name.match('^.*/ActivityKind/.*xml$')
+ xml = io.read
+ doc, statuses = REXML::Document.new(xml), []
+ doc.elements.each('/ObjectDetails/Type') do |s1|
+ if s1.text.match('Root')
+ doc.elements.each('/ObjectDetails/Description') do |s|
+ return s.text
+ end
+ end
+ end
+ end
+ end
+ }
+ rescue
+ return ''
+ end
+ def get_search_terms
+ Zip::ZipInputStream::open(@filename) {
+ |io|
+
+ while (entry = io.get_next_entry)
+ if entry.name.match('^.*/ActivityKind/.*xml$')
+ xml = io.read
+ doc, statuses = REXML::Document.new(xml), []
+ doc.elements.each('/ObjectDetails/Type') do |s1|
+ if s1.text.match('Root')
+ doc.elements.each('/ObjectDetails/Keywords') do |s|
+ return s.text
+ end
+ end
+ end
+ end
+ end
+ }
+
+ rescue
+ return ''
+ end
+
+ def get_preview_image
+ Zip::ZipInputStream::open(@filename) {
+ |io|
+ while (entry = io.get_next_entry)
+ if entry.name.match('/MyExp/Image/')
+ return entry
+ end
+ end
+ }
+ rescue
+ return nil
+ end
+
# End Instance Methods
end
end