diff --git a/config/routes.rb b/config/routes.rb
index df77b46a..a43cd4c9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -91,6 +91,6 @@ RedmineApp::Application.routes.draw do
mount DAV4Rack::Handler.new(
# :root => Rails.root.to_s,
:root_uri_path => "/dmsf/webdav",
- :resource_class => RedmineDmsf::Webdav::ResourceFactory
+ :resource_class => RedmineDmsf::Webdav::ResourceProxy,
), :at => "/dmsf/webdav"
end
diff --git a/lib/redmine_dmsf/webdav.rb b/lib/redmine_dmsf/webdav.rb
index ee012cfa..26598dac 100644
--- a/lib/redmine_dmsf/webdav.rb
+++ b/lib/redmine_dmsf/webdav.rb
@@ -1 +1,5 @@
-require 'redmine_dmsf/webdav/resource_factory'
+require 'redmine_dmsf/webdav/resource_proxy'
+
+require 'redmine_dmsf/webdav/base_resource'
+
+require 'redmine_dmsf/webdav/index_resource'
diff --git a/lib/redmine_dmsf/webdav/base_resource.rb b/lib/redmine_dmsf/webdav/base_resource.rb
new file mode 100644
index 00000000..bdfb3215
--- /dev/null
+++ b/lib/redmine_dmsf/webdav/base_resource.rb
@@ -0,0 +1,75 @@
+module RedmineDmsf
+ module Webdav
+
+ class BaseResource < DAV4Rack::Resource
+
+ DIR_FILE = "
| %s | %s | %s | %s |
"
+
+ def initialize(public_path, path, request, response, options)
+ super(public_path, path, request, response, options)
+ pinfo = path.split('/').drop(1)
+ if pinfo.length > 0
+ @project = Project.find(pinfo.first)
+ end
+ end
+
+ def accessor=(klass)
+ @__proxy = klass
+ end
+
+ def name
+ nil
+ end
+
+ def long_name
+ nil
+ end
+
+
+ def html_display
+
+ @response.body = ""
+ #@response.body << "HELLO WORLD
"
+ Confict unless collection?
+ entities = children.map{|child| DIR_FILE % [child.public_path.html_safe, child.long_name || child.name, "-", child.content_type, child.last_modified]} * "\n"
+ page = index_page % [ path.empty? ? "/" : path, path.empty? ? "/" : path , entities ]
+ page.each_line{|l| @response.body << l}
+ end
+
+ def child(name)
+ @__proxy.child(name)
+ end
+
+ def index_page
+ return <<-PAGE
+
+ %s
+
+
+
+%s
+
+
+
+ | Name |
+ Size |
+ Type |
+ Last Modified |
+
+%s
+
+
+
+ PAGE
+ end
+ end
+ end
+end
+
+
diff --git a/lib/redmine_dmsf/webdav/index_resource.rb b/lib/redmine_dmsf/webdav/index_resource.rb
new file mode 100644
index 00000000..2042cdd5
--- /dev/null
+++ b/lib/redmine_dmsf/webdav/index_resource.rb
@@ -0,0 +1,29 @@
+module RedmineDmsf
+ module Webdav
+ class IndexResource < BaseResource
+
+ def children
+ projects = Project.visible.find(:all, :order => 'lft')
+ return nill if projects.nil? || projects.empty?
+ projects.delete_if { |node| node.module_enabled?('dmsf').nil? }
+ projects.map do |p|
+ child p.identifier
+ end
+ end
+
+ def collection?
+ true
+ end
+
+ #Index resource ALWAYS exists
+ def exist?
+ true
+ end
+
+ def get(request, response)
+ html_display
+ OK
+ end
+ end
+ end
+end
diff --git a/lib/redmine_dmsf/webdav/project_resource.rb b/lib/redmine_dmsf/webdav/project_resource.rb
new file mode 100644
index 00000000..582bdd69
--- /dev/null
+++ b/lib/redmine_dmsf/webdav/project_resource.rb
@@ -0,0 +1,35 @@
+module RedmineDmsf
+ module Webdav
+ class ProjectResource < BaseResource
+
+ def name
+ @project.name
+ end
+
+ def exist?
+ !@Project.nil?
+ end
+
+ def collection?
+ exist?
+ end
+
+ def last_modified
+ @project.updated_on unless @project.nil?
+ end
+
+ def name
+ @project.identifier unless @project.nil?
+ end
+
+ def long_name
+ @project.name unless @project.nil?
+ end
+
+ def content_type
+ "Project" #l(:field_project)
+ end
+
+ end
+ end
+end
diff --git a/lib/redmine_dmsf/webdav/resource_factory.rb b/lib/redmine_dmsf/webdav/resource_factory.rb
deleted file mode 100644
index 9872b449..00000000
--- a/lib/redmine_dmsf/webdav/resource_factory.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-module RedmineDmsf
- module Webdav
- class ResourceFactory < DAV4Rack::Resource
-
- def initialize(public_path, path, request, response, options)
- super(public_path, path, request, response, options)
- if (path == "")
- end
- end
-
- def authenticate(username, password)
- User.try_to_login(username, password) ? true : false
- end
-
- end
- end
-end
diff --git a/lib/redmine_dmsf/webdav/resource_proxy.rb b/lib/redmine_dmsf/webdav/resource_proxy.rb
new file mode 100644
index 00000000..39bdda50
--- /dev/null
+++ b/lib/redmine_dmsf/webdav/resource_proxy.rb
@@ -0,0 +1,76 @@
+require 'webrick/httputils'
+
+module RedmineDmsf
+ module Webdav
+ class ResourceProxy < DAV4Rack::Resource
+
+ include WEBrick::HTTPUtils
+
+ def initialize(public_path, path, request, response, options)
+ super(public_path, path, request, response, options)
+ pinfo = path.split('/').drop(1)
+ if (pinfo.length == 0) #If this is the base_path, we're at root
+ @resource_c = IndexResource.new(public_path, path, request, response, options)
+ elsif (pinfo.length == 1) #This is first level, and as such, project path
+ @resource_c = ProjectResource.new(public_path, path, request, response, options)
+ else #We made it all the way to DMSF Data
+ end
+
+ @resource_c.accessor= self unless @resource_c.nil?
+ end
+
+ def authenticate(username, password)
+ User.current = User.try_to_login(username, password) || nil
+ !User.current.nil?
+ end
+
+ def children
+ @resource_c.children
+ end
+
+ def collection?
+ @resource_c.collection?
+ end
+
+ def exist?
+ @resource_c.exist?
+ end
+
+ def creation_date
+ @resource_c.creation_date
+ end
+
+ def last_modified
+ @resource_c.last_modified
+ end
+
+ def last_modified=(time)
+ @resource_c.last_modified=(time)
+ end
+
+ def etag
+ @resource_c.etag
+ end
+
+ def content_type
+ @resource_c.content_type
+ end
+
+ def content_length
+ @resource_c.content_length
+ end
+
+ def get(request, response)
+ @resource_c.get(request, response)
+ end
+
+ def name
+ @resource_c.name
+ end
+
+ def long_name
+ @resource_c.long_name
+ end
+ end
+ end
+end