Skip to main content

Using the webdav for ScriptingComponent

13 replies [Last post]
kaplanj
Offline
Joined: 2004-07-13

> Morris Ford writes:
> I would love to be using webdav and have been waiting for information about its readiness
> and how to utilize it for some months now. Do you have information about how to implement
> it? I would be happy to utilize it instead of a separate web server.

The webdav stuff is integrated and in regular use as part of Wonderland as part of dev5. There are lots of different ways to use it, but here are a few that might be useful to you:

1. the easiest thing for startes would be for you to use webdav to serve files in the same way you do today with jetty. If you copy files into the ~/.wonderland-server/0.5-dev/run/content directory, those files will automatically be served by the Wonderland web server from the URL http://:8080/webdav/content. You should be able to point a browser there, and also to use these URLs in your scripting tutorials.

2. rather than copying files, you can use the "official" web UI for the repository by clicking on "content repository" in the Wonderland web administration page. This may be easier for tutorial users than finding the .wonderland-server directory3. From the content repository web UI, you can upload files, create directories and so on. You can do the same from the client using the "content repository" menu item on the tools menu (it's been moving around, but it's there somewhere).

3. you can use the content repository programatically from the client. To do this, you module must depend on the contentrepo module in modules/foundation. This module includes the client classes you need to read and write content in the repository. It also lets you programatically retrieve URLs for files in the repository, so it should be compatible with your current approach. From the scripting component, you can get the repository for the current session by calling:

<br />
ContentRepository repo = ContentRepositoryRegistry.getInstance().getRepository(cell.getCellCache().getSession());<br />

From there, you will be able to use the repository API to create files (ContentResource) and directories (ContentCollection).

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
morrisford
Offline
Joined: 2008-03-17

Could you tell me which jars I need to include to get this going?
Thanks.

bump

Message was edited by: morrisford

kaplanj
Offline
Joined: 2004-07-13

The jar file is in wonderland/modules/foundation/content-repository/build/client/contentrepo-client.jar.

morrisford
Offline
Joined: 2008-03-17

Here is the line of code as I used it (note the getSessionManager() at the end):
repo = ContentRepositoryRegistry.getInstance().getRepository(cell.getCellCache().getSession().getSessionManager());

A question: are there any permissions issues with the content repository? For example, Can I create a directory and file under my user space and then allow others to use that as a url? Can I create files/directories anywhere in the content repository?

Also, looks to me like there is at least one method missing, ie, boolean nodeExists(String) to find out if a collection (dir) or resource (file) exists. without that, it looks like I will have to set up a loop and take exceptions to find out if a path from root exists or needs to be created.

In addition, Is there some documentation about what parts of the content directory structure are writable and by whom? I am trying to arrange a script repository with a location by name for the type of cell for scripting properties at the cell level that is writable by the scripting attached to the cell and findable and readable by anyone trying to start up that type of cell.

I was hoping to put a properties file into the same directory where the scripts for that cell type are stored but it looks like the scripting cannot write to a file under 'contents/scripts/default' for instance.
Message was edited by: morrisford

Message was edited by: morrisford

kaplanj
Offline
Joined: 2004-07-13

There are permissions on the content repository. There are a few different types of directories:

User directories (/users/). A user has access to read and write their own directory. Other users can read the directory but not write it.

Group directories (/groups/). These can be written and read by any member of the given group, which you can set up in the group editor. Other users can read the directory but not write it.

Private directories (/users//private, /groups//private). These can't be read by anyone except the owning user or members of the group.

All other directories (/systems, /modules, etc) can be read by anyone, but not written. The only exception is members of the "admin" group, who can read and write anything.

ahill
Offline
Joined: 2008-10-23

Can you relate the above to a situation involving a standard webdav client?
For instance, I don't get any authentication challenge when connecting to the Wonderland webdav client and cannot write to the directories.
Is there a way to allow this?
I tried chmod'ing the folders but that didn't work.

kaplanj
Offline
Joined: 2004-07-13

There is a bit of a TODO in the code right now about standard webdav clients. Wonderland uses a single-sign on mechanism internally, so it authenticates to the webdav server using tokens embedded in http cookies. The authentication in the webdav server uses those tokens to verify the user's permissions and enforce the scheme defined above. Of course standard non-Wonderland webdav clients don't know anything about single-sign on or cookies, they use http basic authentication. So the TODO is to implement basic auth in addition to existing cookie-based authentication in the Server Authentication Module, or "WonderSAM" in the security module. Once we do that, the permissions described above will apply to standard webdav clients as well.

ahill
Offline
Joined: 2008-10-23

While we are waiting for basic authorization...would it be possible to configure a more full-featured WebDAV client to write to the repository?

kaplanj
Offline
Joined: 2004-07-13

If you want to remove authentication, you can try hacking WonderlandWebdavServlet in modules/tools/webdav. Just remove the lines:

[code]
FileDirContext fdc = new PermissionsDirContext(contentDir);
resources = new ProxyDirContext(new Hashtable(), fdc);
[/code]

and it should stop enforcing permissions. If that doesn't work, just return true in checkRead() and checkWrite() below.

ahill
Offline
Joined: 2008-10-23

Removing those lines caused an error, but returning true in checkWrite() allowed write access.
Thanks.

nsimpson
Offline
Joined: 2004-06-03

> 2. rather than copying files, you can use the "official" web UI for the repository by clicking on
> "content repository" in the Wonderland web administration page. This may be easier for
> tutorial users than finding the .wonderland-server directory3. From the content repository
> web UI, you can upload files, create directories and so on. You can do the same from the
> client using the "content repository" menu item on the tools menu (it's been moving
> around, but it's there somewhere).

It's in Tools > Content Browser

-- the guy who moved it

jslott
Offline
Joined: 2006-01-05

You should be able to use the content repo for any content you'd like to store. We use it, for examples, to store avatar information. We create an avatar/ subdirectory and put everything in there. You can carve out your own space under each user's directory if you like in the same way.

Also, take a look at modules/sample/samplemodule in SampleCellProperties.java for some sample code. The idea was that you can display the content browser programmatically and get a URL back from it. You can then load that URL (see #1), edit it's content (I use a simple text pane in Swing) and save it back using #3 above. I suspect you may want to do similar actions for scripting perhaps.

morrisford
Offline
Joined: 2008-03-17

Ok, got that to work too. Thanks.

morrisford
Offline
Joined: 2008-03-17

Can the webdav content area be used for arbitrary content?