vortex_client 0.5.8 → 0.5.9
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.
- data/README.rdoc +26 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/create_collection.rb +1 -1
- data/examples/disable_right_column.rb +8 -0
- data/examples/person_presentation.rb +8 -156
- data/lib/vortex_client.rb +29 -12
- data/lib/vortex_client/person.rb +224 -0
- data/test/test_vortex_person.rb +51 -0
- metadata +8 -8
- data/examples/create_collection_flymake.rb +0 -15
- data/examples/publish_article_flymake.rb +0 -16
- data/examples/publish_event_flymake.rb +0 -18
- data/examples/sitemap_flymake.rb +0 -106
- data/examples/sitemap_flymake_flymake.rb +0 -106
data/README.rdoc
CHANGED
|
@@ -22,7 +22,7 @@ Running the script.
|
|
|
22
22
|
Username: thomasfl
|
|
23
23
|
Password: *****
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
An article should now be published to "https://www-dav.server.com/news/my-title.html".
|
|
26
26
|
|
|
27
27
|
= Creating folders (collections)
|
|
28
28
|
|
|
@@ -31,7 +31,7 @@ To create a folder named "2010" in the "/news/" folder.
|
|
|
31
31
|
require 'rubygems'
|
|
32
32
|
require 'vortex_client'
|
|
33
33
|
|
|
34
|
-
vortex = Vortex::Connection.new("https://www-dav.server.com"
|
|
34
|
+
vortex = Vortex::Connection.new("https://www-dav.server.com")
|
|
35
35
|
vortex.cd("/news/")
|
|
36
36
|
collection = Vortex::ArticleListingCollection.new(:title => "News for 2009", :foldername => "2009")
|
|
37
37
|
vortex.create(collection)
|
|
@@ -50,6 +50,30 @@ If your'e having problems installing the xml parser nokogiri on is x: http://wi
|
|
|
50
50
|
Also how to compile ruby 1.9.1 on os x http://wonko.com/post/how-to-compile-ruby-191
|
|
51
51
|
On ubuntu openssl can be an issue http://blog.maxaller.name/2009/02/ruby-19-and-openssl-on-ubuntu/
|
|
52
52
|
|
|
53
|
+
= Using KeyChain authentication on OS X
|
|
54
|
+
|
|
55
|
+
To retrieve password from KeyChain on OS X, use the option :use_osx_keychain => true.
|
|
56
|
+
|
|
57
|
+
vortex = Vortex::Connection.new("https://www-dav.server.com", :use_osx_keychain => true)
|
|
58
|
+
|
|
59
|
+
When running for the first time, ruby prompts for the password. Username must be
|
|
60
|
+
the same both locally and on the server.
|
|
61
|
+
|
|
62
|
+
Password not found on OS X KeyChain.
|
|
63
|
+
Enter password to store new password on OS X KeyChain.
|
|
64
|
+
Password: *****
|
|
65
|
+
Password for 'tiger' on 'www-dav.server.com' stored on OS X KeyChain.
|
|
66
|
+
|
|
67
|
+
The next time the script is executed, ruby won't prompt for username or password.
|
|
68
|
+
|
|
69
|
+
KeyChain authentication requires 'osx_keychain' and 'RubyInline' gem.
|
|
70
|
+
|
|
71
|
+
To install:
|
|
72
|
+
|
|
73
|
+
$ sudo gem install RubyInline
|
|
74
|
+
$ sudo gem install osx_keychain
|
|
75
|
+
|
|
76
|
+
|
|
53
77
|
== Note on Patches/Pull Requests
|
|
54
78
|
|
|
55
79
|
* Fork the project.
|
data/Rakefile
CHANGED
|
@@ -14,7 +14,7 @@ begin
|
|
|
14
14
|
gem.add_dependency "net_dav", ">= 0.5.0"
|
|
15
15
|
gem.add_dependency "highline", ">= 1.5.1"
|
|
16
16
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
17
|
-
gem.files.include %w(lib/vortex_client.rb lib/vortex_client/string_utils.rb lib/vortex_client/item_extensions.rb bin/vrtx-sync)
|
|
17
|
+
gem.files.include %w(lib/vortex_client.rb lib/vortex_client/string_utils.rb lib/vortex_client/item_extensions.rb lib/vortex_client/person.rb bin/vrtx-sync)
|
|
18
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
19
19
|
end
|
|
20
20
|
rescue LoadError
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.9
|
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
require 'vortex_client'
|
|
3
3
|
include Vortex
|
|
4
4
|
|
|
5
|
-
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/"
|
|
5
|
+
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
|
|
6
6
|
vortex.cd('/brukere/thomasfl/events/')
|
|
7
7
|
|
|
8
8
|
collection = ArticleListingCollection.new(:url => 'my-collection', :title => 'My articles')
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'vortex_client'
|
|
3
|
+
|
|
4
|
+
vortex = Vortex::Connection.new('https://nyweb2-dav.uio.no/', :use_osx_keychain => true)
|
|
5
|
+
# url = 'https://nyweb2-dav.uio.no/for-ansatte/aktuelt/hf-aktuelt-mod/utg2/index.html'
|
|
6
|
+
url = '/for-ansatte/aktuelt/hf-aktuelt-mod/utg2/index.html'
|
|
7
|
+
snippet = '<hideAdditionalContent xmlns="http://www.uio.no/vrtx/__vrtx/ns/structured-resources">true</hideAdditionalContent>'
|
|
8
|
+
vortex.proppatch(url, snippet)
|
|
@@ -1,162 +1,14 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
require 'rubygems'
|
|
3
3
|
require 'vortex_client'
|
|
4
|
-
require 'open-uri'
|
|
5
|
-
require 'time'
|
|
6
|
-
## require 'ldap_util'
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
@vortex = Vortex::Connection.new("https://nyweb1-dav.uio.no/")
|
|
6
|
+
@vortex.cd('/konv/personer_test/')
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def find_pictures(src_url, dest_url, language)
|
|
16
|
-
count = 0
|
|
17
|
-
@vortex.find('.',:recursive => true,:suppress_errors => true) do |item|
|
|
18
|
-
url = item.url.to_s
|
|
19
|
-
if(item.type == :directory) then
|
|
20
|
-
new_url = url.gsub(src_url,dest_url)
|
|
21
|
-
create_person_listing_folder(new_url)
|
|
22
|
-
elsif(url.match(/\.jpg$|\.png$/i)) then
|
|
23
|
-
dest_folder = url.gsub(src_url,dest_url)
|
|
24
|
-
dest_folder = dest_folder.sub(/\.jpg$|\.png$/i,'/')
|
|
25
|
-
create_person_presentation(url, dest_folder, language)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# exit if(count > 6) # TODO Remove this
|
|
29
|
-
count += 1
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
puts
|
|
33
|
-
puts "Done creating " + count.to_s + " presentations."
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def create_person_listing_folder(new_url)
|
|
37
|
-
mkdir(new_url)
|
|
38
|
-
puts "Reading folder: " + new_url
|
|
39
|
-
props = '<v:collection-type xmlns:v="vrtx">person-listing</v:collection-type>' +
|
|
40
|
-
'<v:resourceType xmlns:v="vrtx">person-listing</v:resourceType>'
|
|
41
|
-
begin
|
|
42
|
-
@vortex.proppatch(new_url, props )
|
|
43
|
-
rescue
|
|
44
|
-
puts "Warning: problems patching folder: " + new_url
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def create_person_presentation(url, dest_folder, language)
|
|
49
|
-
username = dest_folder.sub(/\/$/,'')[/([^\/]*)$/,1]
|
|
50
|
-
dest_image_url = dest_folder + url[/([^\/]*)$/,1]
|
|
51
|
-
mkdir(dest_folder)
|
|
52
|
-
copy(url,dest_image_url)
|
|
53
|
-
create_json_doc(username, dest_folder, dest_image_url, language)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def mkdir(url)
|
|
58
|
-
begin
|
|
59
|
-
@vortex.mkdir(url)
|
|
60
|
-
rescue
|
|
61
|
-
puts "Warning: mkdir(" + url + ") exists."
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def copy(src,dest)
|
|
66
|
-
begin
|
|
67
|
-
@vortex.copy(src,dest)
|
|
68
|
-
rescue
|
|
69
|
-
puts "Warning: cp(src," + dest + ") exists."
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def person_presentation_json(args)
|
|
74
|
-
image_path = args[:image_path]
|
|
75
|
-
image_path = image_path.sub(/^https?:\/\/[^\/]*/i,'')
|
|
76
|
-
image_path = File.basename(image_path)
|
|
77
|
-
if(args[:language] && args[:language] == :english) then
|
|
78
|
-
html_xxx = '<h2>Tasks performed<\/h2>\r\n<p>Add information about job duties, as a short text or a bulleted list:<\/p>' +
|
|
79
|
-
'\r\n<ul>\r\n' +
|
|
80
|
-
'<li><Task 1><\/li>\r\n' +
|
|
81
|
-
'<li><Task 1><\/li>\r\n' +
|
|
82
|
-
'<li>...<\/li>\r\n<\/ul>\r\n<h2>Background<\/h2>\r\n<p>Add information about previous education and employment.<\/p>'
|
|
83
|
-
html = ''
|
|
84
|
-
else
|
|
85
|
-
html = '<h2>Arbeidsområder<\/h2>\r\n<p>Her kan du skrive om arbeidsområder, ' +
|
|
86
|
-
'enten som kort tekst eller som listepunkter:</p>' +
|
|
87
|
-
'\r\n' +
|
|
88
|
-
'<ul>\r\n <li><Arbeidsområde 1></li>\r\n '+
|
|
89
|
-
'<li><Arbeidsområde 1></li>\r\n <li>...</li>\r\n</ul>' +
|
|
90
|
-
'\r\n<h2>Bakgrunn</h2>\r\n<p>Eventuelt kort om tidligere arbeidserfaring og utdanning.</p>'
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
json = ''
|
|
94
|
-
json = <<EOF
|
|
95
|
-
{
|
|
96
|
-
"resourcetype": "person",
|
|
97
|
-
"properties": {
|
|
98
|
-
"getExternalPersonInfo": "true",
|
|
99
|
-
"picture": "#{image_path}",
|
|
100
|
-
"content": "#{html}",
|
|
101
|
-
"getExternalScientificInformation": "false",
|
|
102
|
-
"username": "#{args[:username]}",
|
|
103
|
-
"getRelatedGroups": "true",
|
|
104
|
-
"getRelatedProjects": "true"
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
EOF
|
|
108
|
-
return json
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def proppatch_person_presentasjon(json_url,language)
|
|
112
|
-
time = Time.now.httpdate.to_s
|
|
113
|
-
properties = '<v:publish-date xmlns:v="vrtx">' + time + '</v:publish-date>' +
|
|
114
|
-
'<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>' +
|
|
115
|
-
'<d:getcontenttype>application/json</d:getcontenttype>' +
|
|
116
|
-
'<v:resourceType xmlns:v="vrtx">person</v:resourceType>'
|
|
117
|
-
if(language == :english) then
|
|
118
|
-
properties += '<d:getcontentlanguage>en</d:getcontentlanguage>'
|
|
119
|
-
else
|
|
120
|
-
## properties += '<d:getcontentlanguage>no</d:getcontentlanguage>'
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
begin
|
|
124
|
-
@vortex.proppatch(json_url, properties)
|
|
125
|
-
rescue
|
|
126
|
-
puts "Warning: error while proppatching: " + json_url
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def create_json_doc(username, path, image_path, language)
|
|
131
|
-
json = person_presentation_json(:username => username, :image_path => image_path, :language => language)
|
|
132
|
-
json_url = path + 'index.html'
|
|
133
|
-
|
|
134
|
-
puts "Create person page: " + json_url
|
|
135
|
-
@vortex.put_string(json_url,json)
|
|
136
|
-
proppatch_person_presentasjon(json_url, language)
|
|
137
|
-
|
|
138
|
-
# realname = ldap_realname(username)
|
|
139
|
-
# if(realname) then
|
|
140
|
-
# @vortex.proppatch(path, '<v:userTitle xmlns:v="vrtx">' + realname + '</v:userTitle>')
|
|
141
|
-
# else
|
|
142
|
-
# puts "Warning: Unable to get info from ldap on: " + username
|
|
143
|
-
# end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
user = ENV['DAVUSER'] # ask("Username : ") {|q| q.echo = true}
|
|
149
|
-
pass = ENV['DAVPASS'] # ask("Password : ") {|q| q.echo = false}
|
|
150
|
-
if(!pass)then
|
|
151
|
-
puts "Usage: export DAVPASS=pass "
|
|
152
|
-
exit
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
host = 'https://www2-dav.uio.no'
|
|
156
|
-
|
|
157
|
-
src_url = host + '/personer/person-bilder/'
|
|
158
|
-
dest_url = host + '/english/people/' # 'personpresentasjoner/'
|
|
159
|
-
|
|
160
|
-
presentasjoner = PersonPresentasjon.new(src_url, user, pass)
|
|
161
|
-
presentasjoner.find_pictures(src_url, dest_url, :english)
|
|
8
|
+
person = Vortex::Person.new(:user => 'herman',
|
|
9
|
+
:image => '/konv/personer_test/placeholder.jpg',
|
|
10
|
+
:language => :english,
|
|
11
|
+
:scientific => true)
|
|
162
12
|
|
|
13
|
+
url = @vortex.publish(person)
|
|
14
|
+
puts "Published: " + url
|
data/lib/vortex_client.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
require 'net/dav'
|
|
3
3
|
require 'vortex_client/string_utils'
|
|
4
|
+
require 'vortex_client/person'
|
|
4
5
|
require 'highline/import'
|
|
5
6
|
require 'time'
|
|
6
7
|
|
|
8
|
+
require 'json'
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
# Utilities for managing content in the web content management system Vortex.
|
|
@@ -26,14 +28,15 @@ module Vortex
|
|
|
26
28
|
# Retrieve password from KeyChain if running on OS X. Username must be the
|
|
27
29
|
# the same on server as user locally.
|
|
28
30
|
#
|
|
29
|
-
# Requires 'osx_keychain' and 'RubyInline' gem. To install
|
|
30
|
-
|
|
31
|
-
#
|
|
31
|
+
# Requires 'osx_keychain' and 'RubyInline' gem. To install:
|
|
32
|
+
|
|
33
|
+
# $ sudo gem install RubyInline
|
|
34
|
+
# $ sudo gem install osx_keychain
|
|
32
35
|
#
|
|
33
36
|
#
|
|
34
37
|
# vortex = Vortex::Connection.new("https://www-dav.server.com", :use_osx_keychain => true)
|
|
35
|
-
# Password not found
|
|
36
|
-
# Enter password to store new password
|
|
38
|
+
# Password not found on OS X KeyChain.
|
|
39
|
+
# Enter password to store new password on OS X KeyChain.
|
|
37
40
|
# Password: *****
|
|
38
41
|
# Password for 'tiger' on 'www-dav.server.com' stored in OS X KeyChain.
|
|
39
42
|
#
|
|
@@ -61,14 +64,14 @@ module Vortex
|
|
|
61
64
|
pass = keychain[@uri.host, user ]
|
|
62
65
|
|
|
63
66
|
if(pass == nil) then
|
|
64
|
-
puts "Password not found
|
|
65
|
-
puts "Enter password to store new password
|
|
67
|
+
puts "Password not found on OS X KeyChain. "
|
|
68
|
+
puts "Enter password to store new password on OS X KeyChain."
|
|
66
69
|
## @handler.user = ask("Username: ") {|q| q.echo = true}
|
|
67
70
|
## Todo: store username in a config file so we can have
|
|
68
71
|
## different username locally and on server
|
|
69
72
|
pass = ask("Password: ") {|q| q.echo = "*"} # false => no echo
|
|
70
73
|
keychain[@uri.host, user] = pass
|
|
71
|
-
puts "Password for '#{user}' on '#{@uri.host}' stored
|
|
74
|
+
puts "Password for '#{user}' on '#{@uri.host}' stored on OS X KeyChain."
|
|
72
75
|
@handler.user = user
|
|
73
76
|
@handler.pass = pass
|
|
74
77
|
else
|
|
@@ -109,9 +112,9 @@ module Vortex
|
|
|
109
112
|
# Writes a document a document to the web. Same as publish, except
|
|
110
113
|
# that if document type is StructuredArticle publishDate
|
|
111
114
|
def write(object)
|
|
112
|
-
if(object.is_a? HtmlArticle or object.is_a? HtmlEvent or object.is_a? StructuredArticle)
|
|
115
|
+
if(object.is_a? HtmlArticle or object.is_a? HtmlEvent or object.is_a? StructuredArticle or object.is_a? Vortex::Person)
|
|
113
116
|
uri = @uri.merge(object.url)
|
|
114
|
-
# puts "DEBUG:
|
|
117
|
+
# puts "DEBUG: uri = " + uri.to_s
|
|
115
118
|
self.put_string(uri, object.content)
|
|
116
119
|
self.proppatch(uri, object.properties)
|
|
117
120
|
return uri.to_s
|
|
@@ -435,7 +438,7 @@ module Vortex
|
|
|
435
438
|
# Vortex article stored as JSON data.
|
|
436
439
|
class StructuredArticle < HtmlArticle
|
|
437
440
|
|
|
438
|
-
attr_accessor :title, :introduction, :
|
|
441
|
+
attr_accessor :title, :introduction, :body, :filename, :modifiedDate, :publishDate, :owner, :url, :picture, :hideAdditionalContent
|
|
439
442
|
|
|
440
443
|
# Create an article
|
|
441
444
|
# Options:
|
|
@@ -472,10 +475,11 @@ module Vortex
|
|
|
472
475
|
"resourcetype": "structured-article",
|
|
473
476
|
"properties": {
|
|
474
477
|
EOF
|
|
478
|
+
|
|
475
479
|
if(body and body.size > 0)
|
|
476
480
|
tmp_body = body
|
|
477
481
|
# Escape '"' and line shifts so html will be valid json data.
|
|
478
|
-
tmp_body =
|
|
482
|
+
tmp_body = tmp_body.gsub(/\r/,"\\\r").gsub(/\n/,"\\\n").gsub(/\"/,"\\\"") ## .to_json
|
|
479
483
|
json += " \"content\": \"#{tmp_body}\",\n"
|
|
480
484
|
end
|
|
481
485
|
if(author and author.size > 0)
|
|
@@ -643,6 +647,19 @@ module Vortex
|
|
|
643
647
|
end
|
|
644
648
|
|
|
645
649
|
|
|
650
|
+
class PersonListingCollection < Collection
|
|
651
|
+
|
|
652
|
+
def properties()
|
|
653
|
+
props = super
|
|
654
|
+
props += '<v:resourceType xmlns:v="vrtx">person-listing</v:resourceType>' +
|
|
655
|
+
'<v:collection-type xmlns:v="vrtx">person-listing</v:collection-type>'
|
|
656
|
+
return props
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
end
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
646
663
|
class EventListingCollection < Collection
|
|
647
664
|
|
|
648
665
|
def properties()
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'uri'
|
|
3
|
+
|
|
4
|
+
module Vortex
|
|
5
|
+
|
|
6
|
+
# Publish Person presentations on Vortex enabled web servers.
|
|
7
|
+
#
|
|
8
|
+
# Examples:
|
|
9
|
+
#
|
|
10
|
+
# person = Vortex::Person.new(:user => 'thomasfl',
|
|
11
|
+
# :image => '/images/thomasfl.jpg',
|
|
12
|
+
# :language => :english,
|
|
13
|
+
# :scientific => true)
|
|
14
|
+
# :publishedDate => "05.01.2010 12:00")
|
|
15
|
+
# vortex.publish(person)
|
|
16
|
+
#
|
|
17
|
+
# Mandatory parameters:
|
|
18
|
+
# :user => username
|
|
19
|
+
# :image => path to image ex. '/user
|
|
20
|
+
#
|
|
21
|
+
# Optional parameters:
|
|
22
|
+
# :language => :english or :norwegian (defaults)
|
|
23
|
+
# :scientific => false (default). Get list of publications
|
|
24
|
+
# :administrative = true (default). Same as :scientific => false
|
|
25
|
+
# :html => json encoded html. Ex
|
|
26
|
+
# :url => path to presentation. Ex. '/persons/thomas.html'
|
|
27
|
+
# :publishedDate => date to be published. Defaults to now. Ex. "05.01.2010 12:00"
|
|
28
|
+
# :filename => filename ex. 'index.html'
|
|
29
|
+
#
|
|
30
|
+
# Author: Thomas Flemming, thomasfl(at)usit.uio.no 2010
|
|
31
|
+
#
|
|
32
|
+
class Person
|
|
33
|
+
|
|
34
|
+
attr_accessor :user, :html, :url, :publishedDate, :language, :scientific, :administrative, :image, :filename
|
|
35
|
+
|
|
36
|
+
def initialize(options={})
|
|
37
|
+
options.each{|k,v|send("#{k}=",v)}
|
|
38
|
+
|
|
39
|
+
if(not(@user))then
|
|
40
|
+
raise Exception.new("missing mandatory parameter :user")
|
|
41
|
+
end
|
|
42
|
+
if(not(@image))then
|
|
43
|
+
raise Exception.new("missing mandatory parameter :image ")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Set defaults
|
|
47
|
+
if(@language == nil)then
|
|
48
|
+
@language = :norwegian
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if(@scientific == nil)then
|
|
52
|
+
@scientific = false
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if(@administrative == nil and not(@scientific))then
|
|
56
|
+
@administrative = true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def url
|
|
62
|
+
if(@url)
|
|
63
|
+
return @url
|
|
64
|
+
else
|
|
65
|
+
if(@filename)
|
|
66
|
+
return @filename
|
|
67
|
+
else
|
|
68
|
+
return @user + ".html"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def content
|
|
74
|
+
image_path = @image
|
|
75
|
+
image_path = image_path.sub(/^https?:\/\/[^\/]*/i,'')
|
|
76
|
+
image_path = File.basename(image_path)
|
|
77
|
+
|
|
78
|
+
if(@html)then
|
|
79
|
+
html = @html
|
|
80
|
+
else
|
|
81
|
+
if(@scientific)then
|
|
82
|
+
html_template = :scientific
|
|
83
|
+
else
|
|
84
|
+
html_template = :administrative
|
|
85
|
+
end
|
|
86
|
+
html = create_html(:html_template => html_template, :language => @language)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
json = <<EOF
|
|
90
|
+
{
|
|
91
|
+
"resourcetype": "person",
|
|
92
|
+
"properties": {
|
|
93
|
+
"getExternalPersonInfo": "true",
|
|
94
|
+
"picture": "#{image_path}",
|
|
95
|
+
"content": "#{html}",
|
|
96
|
+
"getExternalScientificInformation": "#{@scientific}",
|
|
97
|
+
"username": "#{@user}",
|
|
98
|
+
"getRelatedGroups": "true",
|
|
99
|
+
"getRelatedProjects": "true"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
EOF
|
|
103
|
+
return json
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def properties
|
|
108
|
+
properties = '<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>' +
|
|
109
|
+
'<d:getcontenttype>application/json</d:getcontenttype>' +
|
|
110
|
+
'<v:resourceType xmlns:v="vrtx">person</v:resourceType>'
|
|
111
|
+
|
|
112
|
+
if(@publishedDate and @publishedDate != "")
|
|
113
|
+
if(@publishedDate.kind_of? Time)
|
|
114
|
+
@publishedDate = @publishedDate.httpdate.to_s
|
|
115
|
+
end
|
|
116
|
+
props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
|
|
117
|
+
else
|
|
118
|
+
time = Time.now.httpdate.to_s
|
|
119
|
+
properties += '<v:publish-date xmlns:v="vrtx">' + time + '</v:publish-date>'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
if(language == :english) then
|
|
123
|
+
properties += '<v:contentLocale xmlns:v="vrtx">en</v:contentLocale>'
|
|
124
|
+
else
|
|
125
|
+
properties += '<v:contentLocale xmlns:v="vrtx">no_NO</v:contentLocale>'
|
|
126
|
+
end
|
|
127
|
+
return properties
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Generate html for person presentation. Defaults to presentation
|
|
131
|
+
# for administrative employees in norwegian
|
|
132
|
+
#
|
|
133
|
+
# Examples:
|
|
134
|
+
#
|
|
135
|
+
# create_html()
|
|
136
|
+
# create_html(:language => :english, :html_template => :scientific)
|
|
137
|
+
# create_html(:language => :norwegian, :html_template => :administrative)
|
|
138
|
+
#
|
|
139
|
+
def create_html(options)
|
|
140
|
+
if(options[:html_template] && options[:html_template] == :scientific) then
|
|
141
|
+
|
|
142
|
+
if(options[:language] && options[:language] == :english) then
|
|
143
|
+
html = '<h2>Academic Interests<\/h2>\r\n' +
|
|
144
|
+
'<p>Add information about academic fields of interest.<\/p>\r\n' +
|
|
145
|
+
'<h2>Teaching<\/h2>\r\n' +
|
|
146
|
+
'<ul>\r\n' +
|
|
147
|
+
' <li><Link to programme of study/course><\/li>\r\n' +
|
|
148
|
+
' <li><Link to programme of study/course><\/li>\r\n' +
|
|
149
|
+
' <li>...<\/li>\r\n' +
|
|
150
|
+
'<\/ul>\r\n' +
|
|
151
|
+
'<h2>Higher education and employment history<\/h2>\r\n' +
|
|
152
|
+
'<p>Brief introduction to previous education and employment.<\/p>\r\n' +
|
|
153
|
+
'<h2>Honoraria<\/h2>\r\n' +
|
|
154
|
+
'<ul>\r\n' +
|
|
155
|
+
' <li><Name of prize and (if applicable) link 1><\/li>\r\n' +
|
|
156
|
+
' <li><Name of prize and (if applicable) link 2><\/li>\r\n' +
|
|
157
|
+
' <li>...<\/li>\r\n' +
|
|
158
|
+
'<\/ul>\r\n' +
|
|
159
|
+
'<h2>Appointments<\/h2>\r\n' +
|
|
160
|
+
'<ul>\r\n' +
|
|
161
|
+
' <li><Title and (if applicable) link 1><\/li>\r\n' +
|
|
162
|
+
' <li><Title and (if applicable) link 2><\/li>\r\n' +
|
|
163
|
+
' <li>...<\/li>\r\n' +
|
|
164
|
+
'<\/ul>\r\n' +
|
|
165
|
+
'<h2>Cooperation<\/h2>\r\n' +
|
|
166
|
+
'<p> <\/p>'
|
|
167
|
+
else
|
|
168
|
+
html = '<h2>Faglige interesser<\/h2>\r\n' +
|
|
169
|
+
'<p>Her kan du skrive om faglige interesser.<\/p>\r\n' +
|
|
170
|
+
'<h2>Undervisning<\/h2>\r\n<p>' +
|
|
171
|
+
'<Lenke til studieprogram/emne> <br />\r\n' +
|
|
172
|
+
'<Lenke til studieprogram/emne> <br />\r\n...<\/p>\r\n' +
|
|
173
|
+
'<h2>Bakgrunn<\/h2>\r\n' +
|
|
174
|
+
'<p>Kort om tidligere arbeidserfaring og utdanning<\/p>\r\n' +
|
|
175
|
+
'<h2>Priser<\/h2>\r\n' +
|
|
176
|
+
'<p><Navn og eventuelt lenke til pris 1> <br />\r\n' +
|
|
177
|
+
'<Navn og eventuelt lenke til pris 2> <br />\r\n' +
|
|
178
|
+
'...<\/p>\r\n' +
|
|
179
|
+
'<h2>Verv<\/h2>\r\n<p>' +
|
|
180
|
+
'<Navn og eventuelt lenke til verv 1> <br />\r\n' +
|
|
181
|
+
'<Navn og eventuelt lenke til verv 2> <br />\r\n...' +
|
|
182
|
+
'<\/p>\r\n' +
|
|
183
|
+
'<h2>Samarbeid<\/h2>\r\n' +
|
|
184
|
+
'<p> <\/p>'
|
|
185
|
+
end
|
|
186
|
+
else
|
|
187
|
+
|
|
188
|
+
if(options[:language] && options[:language] == :english) then
|
|
189
|
+
html = '<h2>Tasks performed<\/h2>\r\n' +
|
|
190
|
+
'<p>Add information about job duties, as a short text or a bulleted list:<\/p>' +
|
|
191
|
+
'\r\n<ul>\r\n' +
|
|
192
|
+
' <li><Task 1><\/li>\r\n' +
|
|
193
|
+
' <li><Task 1><\/li>\r\n' +
|
|
194
|
+
' <li>...<\/li>\r\n' +
|
|
195
|
+
'<\/ul>\r\n' +
|
|
196
|
+
'<h2>Background<\/h2>\r\n' +
|
|
197
|
+
'<p>Add information about previous education and employment.<\/p>'
|
|
198
|
+
else
|
|
199
|
+
html = '<h2>Arbeidsområder<\/h2>\r\n' +
|
|
200
|
+
'<p>Her kan du skrive om arbeidsområder, ' +
|
|
201
|
+
'enten som kort tekst eller som listepunkter:</p>' +
|
|
202
|
+
'\r\n' +
|
|
203
|
+
'<ul>\r\n' +
|
|
204
|
+
' <li><Arbeidsområde 1></li>\r\n' +
|
|
205
|
+
' <li><Arbeidsområde 1></li>\r\n' +
|
|
206
|
+
' <li>...</li>\r\n' +
|
|
207
|
+
'</ul>' +
|
|
208
|
+
'\r\n' +
|
|
209
|
+
'<h2>Bakgrunn</h2>\r\n' +
|
|
210
|
+
'<p>Eventuelt kort om tidligere arbeidserfaring og utdanning.</p>'
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
return html
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def to_s
|
|
218
|
+
"#<Vortex::Person "+instance_variables.collect{|var|var+": "+instance_variable_get(var).to_s}.join(",")+">"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'helper'
|
|
3
|
+
|
|
4
|
+
class TestVortexPerson < Test::Unit::TestCase
|
|
5
|
+
include Vortex
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
if(not(@vortex))
|
|
9
|
+
user = ENV['DAVUSER']
|
|
10
|
+
pass = ENV['DAVPASS']
|
|
11
|
+
# puts "JSON testene kan foreløpig ikke kjøres på vortex.uio.no?"
|
|
12
|
+
@vortex = Connection.new("https://nyweb1-dav.uio.no/",user, pass)
|
|
13
|
+
|
|
14
|
+
if(@vortex.exists?("/konv/personer_test/thomasfl.html"))then
|
|
15
|
+
@vortex.delete("/konv/personer_test/thomasfl.html")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.zshould(*args)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
zshould "publish person presentation" do
|
|
24
|
+
@vortex.cd('/konv/personer_test/')
|
|
25
|
+
person = Vortex::Person.new(:user => 'thomasfl',
|
|
26
|
+
:image => '/brukere/thomasfl/thomasfl.jpg',
|
|
27
|
+
:language => :english,
|
|
28
|
+
:scientific => false)
|
|
29
|
+
|
|
30
|
+
assert @vortex.exists?("/konv/personer_test/thomasfl.html") == false
|
|
31
|
+
url = @vortex.publish(person)
|
|
32
|
+
assert @vortex.exists?("/konv/personer_test/thomasfl.html")
|
|
33
|
+
puts "Published: " + url
|
|
34
|
+
# puts person.content
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
should "publish default person presentation for scientists" do
|
|
38
|
+
@vortex.cd('/konv/personer_test/')
|
|
39
|
+
|
|
40
|
+
person = Vortex::Person.new(:user => 'herman',
|
|
41
|
+
:image => '/konv/personer_test/placeholder.jpg',
|
|
42
|
+
:language => :english,
|
|
43
|
+
:scientific => true)
|
|
44
|
+
|
|
45
|
+
# puts person.content
|
|
46
|
+
url = @vortex.publish(person)
|
|
47
|
+
puts "Published: " + url
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 5
|
|
8
|
-
-
|
|
9
|
-
version: 0.5.
|
|
8
|
+
- 9
|
|
9
|
+
version: 0.5.9
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Thomas Flemming
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-06
|
|
17
|
+
date: 2010-07-06 00:00:00 +02:00
|
|
18
18
|
default_executable: vrtx-sync
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -76,6 +76,7 @@ files:
|
|
|
76
76
|
- bin/vrtx-sync
|
|
77
77
|
- examples/change_folder_type.rb
|
|
78
78
|
- examples/create_collection.rb
|
|
79
|
+
- examples/disable_right_column.rb
|
|
79
80
|
- examples/ldap_util.rb
|
|
80
81
|
- examples/person_presentation.rb
|
|
81
82
|
- examples/publish_article.rb
|
|
@@ -83,6 +84,7 @@ files:
|
|
|
83
84
|
- examples/sitemap.rb
|
|
84
85
|
- lib/vortex_client.rb
|
|
85
86
|
- lib/vortex_client/item_extensions.rb
|
|
87
|
+
- lib/vortex_client/person.rb
|
|
86
88
|
- lib/vortex_client/string_utils.rb
|
|
87
89
|
- test/helper.rb
|
|
88
90
|
- test/test_acl.rb
|
|
@@ -92,6 +94,7 @@ files:
|
|
|
92
94
|
- test/test_vortex_client.rb
|
|
93
95
|
- test/test_vortex_collection.rb
|
|
94
96
|
- test/test_vortex_event.rb
|
|
97
|
+
- test/test_vortex_person.rb
|
|
95
98
|
- test/test_vortex_pic.rb
|
|
96
99
|
- test/test_vortex_tags.rb
|
|
97
100
|
- test/test_vortex_utils.rb
|
|
@@ -134,18 +137,15 @@ test_files:
|
|
|
134
137
|
- test/test_vortex_client.rb
|
|
135
138
|
- test/test_vortex_collection.rb
|
|
136
139
|
- test/test_vortex_event.rb
|
|
140
|
+
- test/test_vortex_person.rb
|
|
137
141
|
- test/test_vortex_pic.rb
|
|
138
142
|
- test/test_vortex_tags.rb
|
|
139
143
|
- test/test_vortex_utils.rb
|
|
140
144
|
- examples/change_folder_type.rb
|
|
141
145
|
- examples/create_collection.rb
|
|
142
|
-
- examples/
|
|
146
|
+
- examples/disable_right_column.rb
|
|
143
147
|
- examples/ldap_util.rb
|
|
144
148
|
- examples/person_presentation.rb
|
|
145
149
|
- examples/publish_article.rb
|
|
146
|
-
- examples/publish_article_flymake.rb
|
|
147
150
|
- examples/publish_event.rb
|
|
148
|
-
- examples/publish_event_flymake.rb
|
|
149
151
|
- examples/sitemap.rb
|
|
150
|
-
- examples/sitemap_flymake.rb
|
|
151
|
-
- examples/sitemap_flymake_flymake.rb
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'vortex_client'
|
|
3
|
-
include Vortex
|
|
4
|
-
|
|
5
|
-
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/", ENV['DAVUSER'], ENV['DAVPASS'])
|
|
6
|
-
vortex.cd('/brukere/thomasfl/events/')
|
|
7
|
-
|
|
8
|
-
collection = ArticleListingCollection.new(:url => 'my-collection', :title => 'My articles')
|
|
9
|
-
path = vortex.create(collection)
|
|
10
|
-
puts "Created folder: " + path
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
collection = EventListingCollection.new(:title => 'My events')
|
|
14
|
-
path = vortex.create(collection)
|
|
15
|
-
puts "Created folder: " + path
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'vortex_client'
|
|
3
|
-
include Vortex
|
|
4
|
-
|
|
5
|
-
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
|
|
6
|
-
|
|
7
|
-
vortex.cd('/brukere/thomasfl/nyheter/')
|
|
8
|
-
article = HtmlArticle.new(:title => "My new title",
|
|
9
|
-
:introduction => "Short introduction",
|
|
10
|
-
:body => "<p>Longer body</p>",
|
|
11
|
-
:publishedDate => Time.now,
|
|
12
|
-
:author => "Thomas Flemming")
|
|
13
|
-
path = vortex.publish(article)
|
|
14
|
-
puts "published " + path
|
|
15
|
-
|
|
16
|
-
# => published https://vortex-dav.uio.no/brukere/thomasfl/nyheter/my-new-title.html
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'vortex_client'
|
|
3
|
-
include Vortex
|
|
4
|
-
|
|
5
|
-
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
|
|
6
|
-
vortex.cd('/brukere/thomasfl/events/')
|
|
7
|
-
event = HtmlEvent.new(:title => "My Sample Event 1",
|
|
8
|
-
:introduction => "Sample event introduction",
|
|
9
|
-
:body => "<p>Hello world</p>",
|
|
10
|
-
:startDate => "19.06.2010 17:56",
|
|
11
|
-
:endDate => "19.06.2010 19:00",
|
|
12
|
-
:location => "Forskningsveien 3B",
|
|
13
|
-
:mapUrl => "http://maps.google.com/123",
|
|
14
|
-
:tags => ["vortex","testing","ruby"],
|
|
15
|
-
:publishedDate => Time.now )
|
|
16
|
-
path = vortex.publish(event)
|
|
17
|
-
puts "published " + path
|
|
18
|
-
|
data/examples/sitemap_flymake.rb
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# Generate sitemap from WebDAV tree:
|
|
3
|
-
#
|
|
4
|
-
# Example:
|
|
5
|
-
#
|
|
6
|
-
# $ruby generate_vortex_sitemap.rb http://www.iss.uio.no/
|
|
7
|
-
#
|
|
8
|
-
# Author: Thomas Flemming, thomas.flemming@usit.uio.no 2010
|
|
9
|
-
#
|
|
10
|
-
require "net/https"
|
|
11
|
-
require "uri"
|
|
12
|
-
|
|
13
|
-
require 'rubygems'
|
|
14
|
-
require 'vortex_client'
|
|
15
|
-
require 'open-uri'
|
|
16
|
-
|
|
17
|
-
user = ask("Username : ") {|q| q.echo = true}
|
|
18
|
-
pwd = ask("Pssword : ") {|q| q.echo = false}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# Returns "200" if everything's ok.
|
|
22
|
-
def responseCode(url)
|
|
23
|
-
uri = URI.parse(url)
|
|
24
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
25
|
-
if(uri.scheme == "https")
|
|
26
|
-
http.use_ssl = true
|
|
27
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
28
|
-
end
|
|
29
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
|
30
|
-
response = http.request(request)
|
|
31
|
-
return response.code
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def property(item, xpath)
|
|
36
|
-
namespaces = {'v' => "vrtx",'d' => "DAV:"}
|
|
37
|
-
xml = item.propfind
|
|
38
|
-
xml.xpath(xpath, namespaces).inner_text
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def dav_url2http_url(url)
|
|
42
|
-
if(url =~ /\/vortex-dav\./)
|
|
43
|
-
url = url.sub( /\/vortex-dav\./, '/vortex.' )
|
|
44
|
-
else
|
|
45
|
-
url = url.sub(/https:\/\/www-dav\./,'http://www.')
|
|
46
|
-
end
|
|
47
|
-
return url
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def http_url2dav_url(url)
|
|
51
|
-
url = url.sub(/^http:\/\//i,'https://')
|
|
52
|
-
url = url.sub(/^https?:\/\/www\./i,'https://www-dav.')
|
|
53
|
-
return url
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def outline_number(url)
|
|
57
|
-
@numbering = [] if(@numbering == nil)
|
|
58
|
-
@prev_url = "" if(@prev_url == nil)
|
|
59
|
-
|
|
60
|
-
size = url.split(/\//).size
|
|
61
|
-
prev_size = @prev_url.split(/\//).size
|
|
62
|
-
|
|
63
|
-
if(size > prev_size)
|
|
64
|
-
@numbering << 1
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
if(size < prev_size)
|
|
68
|
-
index = size - 1
|
|
69
|
-
# index = @numbering.size - 2
|
|
70
|
-
@numbering = @numbering[0..index]
|
|
71
|
-
@numbering[index] = @numbering.last + 1
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
if(prev_size == size)
|
|
75
|
-
index = @numbering.size - 1
|
|
76
|
-
@numbering[index] = @numbering.last + 1
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
@prev_url = url
|
|
80
|
-
return @numbering.join(".")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
url = ARGV[0]
|
|
85
|
-
dav_url = http_url2dav_url(url)
|
|
86
|
-
|
|
87
|
-
vortex = Vortex::Connection.new(dav_url,user,pwd)
|
|
88
|
-
|
|
89
|
-
vortex.find('.',:recursive => true,:suppress_errors => true) do |item|
|
|
90
|
-
url = item.url.to_s
|
|
91
|
-
if(url =~ /\/$/ ) # Print folders onlye
|
|
92
|
-
collectionTitle = property(item,'.//v:collectionTitle') # Vortex folder title
|
|
93
|
-
resourceType = property(item,'.//v:resourceType') # Vortex folder type
|
|
94
|
-
http_url = dav_url2http_url(url)
|
|
95
|
-
responseCode = responseCode(http_url)
|
|
96
|
-
path = URI.parse(url).path
|
|
97
|
-
foldername = path[/\/([^\/]*)\/$/,1]
|
|
98
|
-
|
|
99
|
-
if(responseCode == "200" and not(foldername =~ /^[\.|_]/ or path =~ /^\/vrtx\// ) )
|
|
100
|
-
number = outline_number(path)
|
|
101
|
-
puts "#{number};#{foldername};#{http_url};#{collectionTitle}"
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# Generate sitemap from WebDAV tree:
|
|
3
|
-
#
|
|
4
|
-
# Example:
|
|
5
|
-
#
|
|
6
|
-
# $ruby generate_vortex_sitemap.rb http://www.iss.uio.no/
|
|
7
|
-
#
|
|
8
|
-
# Author: Thomas Flemming, thomas.flemming@usit.uio.no 2010
|
|
9
|
-
#
|
|
10
|
-
require "net/https"
|
|
11
|
-
require "uri"
|
|
12
|
-
|
|
13
|
-
require 'rubygems'
|
|
14
|
-
require 'vortex_client'
|
|
15
|
-
require 'open-uri'
|
|
16
|
-
|
|
17
|
-
user = ask("Username : ") {|q| q.echo = true}
|
|
18
|
-
pwd = ask("Pssword : ") {|q| q.echo = false}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# Returns "200" if everything's ok.
|
|
22
|
-
def responseCode(url)
|
|
23
|
-
uri = URI.parse(url)
|
|
24
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
25
|
-
if(uri.scheme == "https")
|
|
26
|
-
http.use_ssl = true
|
|
27
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
28
|
-
end
|
|
29
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
|
30
|
-
response = http.request(request)
|
|
31
|
-
return response.code
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def property(item, xpath)
|
|
36
|
-
namespaces = {'v' => "vrtx",'d' => "DAV:"}
|
|
37
|
-
xml = item.propfind
|
|
38
|
-
xml.xpath(xpath, namespaces).inner_text
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def dav_url2http_url(url)
|
|
42
|
-
if(url =~ /\/vortex-dav\./)
|
|
43
|
-
url = url.sub( /\/vortex-dav\./, '/vortex.' )
|
|
44
|
-
else
|
|
45
|
-
url = url.sub(/https:\/\/www-dav\./,'http://www.')
|
|
46
|
-
end
|
|
47
|
-
return url
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def http_url2dav_url(url)
|
|
51
|
-
url = url.sub(/^http:\/\//i,'https://')
|
|
52
|
-
url = url.sub(/^https?:\/\/www\./i,'https://www-dav.')
|
|
53
|
-
return url
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def outline_number(url)
|
|
57
|
-
@numbering = [] if(@numbering == nil)
|
|
58
|
-
@prev_url = "" if(@prev_url == nil)
|
|
59
|
-
|
|
60
|
-
size = url.split(/\//).size
|
|
61
|
-
prev_size = @prev_url.split(/\//).size
|
|
62
|
-
|
|
63
|
-
if(size > prev_size)
|
|
64
|
-
@numbering << 1
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
if(size < prev_size)
|
|
68
|
-
index = size - 1
|
|
69
|
-
# index = @numbering.size - 2
|
|
70
|
-
@numbering = @numbering[0..index]
|
|
71
|
-
@numbering[index] = @numbering.last + 1
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
if(prev_size == size)
|
|
75
|
-
index = @numbering.size - 1
|
|
76
|
-
@numbering[index] = @numbering.last + 1
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
@prev_url = url
|
|
80
|
-
return @numbering.join(".")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
url = ARGV[0]
|
|
85
|
-
dav_url = http_url2dav_url(url)
|
|
86
|
-
|
|
87
|
-
vortex = Vortex::Connection.new(dav_url,user,pwd)
|
|
88
|
-
|
|
89
|
-
vortex.find('.',:recursive => true,:suppress_errors => true) do |item|
|
|
90
|
-
url = item.url.to_s
|
|
91
|
-
if(url =~ /\/$/ ) # Print folders onlye
|
|
92
|
-
collectionTitle = property(item,'.//v:collectionTitle') # Vortex folder title
|
|
93
|
-
resourceType = property(item,'.//v:resourceType') # Vortex folder type
|
|
94
|
-
http_url = dav_url2http_url(url)
|
|
95
|
-
responseCode = responseCode(http_url)
|
|
96
|
-
path = URI.parse(url).path
|
|
97
|
-
foldername = path[/\/([^\/]*)\/$/,1]
|
|
98
|
-
|
|
99
|
-
if(responseCode == "200" and not(foldername =~ /^[\.|_]/ or path =~ /^\/vrtx\// ) )
|
|
100
|
-
number = outline_number(path)
|
|
101
|
-
puts "#{number};#{foldername};#{http_url};#{collectionTitle}"
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|