[Yanel-commits] rev 20498 - in public/yanel/branches/sandbox/src: core/java/org/wyona/yanel/core core/java/org/wyona/yanel/core/api/attributes core/java/org/wyona/yanel/core/map core/java/org/wyona/yanel/servlet impl/java/org/wyona/yanel/impl/map realms/yanel-website/content realms/yanel-website/content/about realms/yanel-website/content/wiki resources/file/src/java/org/wyona/yanel/impl/resources resources/xml/src/java/org/wyona/yanel/impl/resources

josias at wyona.com josias at wyona.com
Fri Dec 1 14:25:50 CET 2006


Author: josias
Date: 2006-12-01 14:25:48 +0100 (Fri, 01 Dec 2006)
New Revision: 20498

Added:
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceManager.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeIdentifier.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV3.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV3.java
Modified:
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Path.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Resource.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Yanel.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Map.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Realm.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java
   public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
   public/yanel/branches/sandbox/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java
   public/yanel/branches/sandbox/src/realms/yanel-website/content/about/en.xhtml
   public/yanel/branches/sandbox/src/realms/yanel-website/content/download.xhtml
   public/yanel/branches/sandbox/src/realms/yanel-website/content/wiki/hello-world.txt
   public/yanel/branches/sandbox/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java
   public/yanel/branches/sandbox/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
Log:
Refactoring:

- Mapping between url and path is now done by the Map class.
  It uses the realm configuration (realms.xml) instead of the repository to do the mapping to a realm.
  
- Resource instances are now bound to their realm and path:
  When a resource is created, the realm and the path are passed to the resource, 
  and the resource has methods getPath() and getRealm().
  The path is relative to the realm, e.g.:
  url: /yanel-website/foo/bar.html
  realm: yanel-website
  path: /foo/bar.html

- Added abstraction of rti file: ResourceTypeIdentifier.java
  This class reads an rti file and provides methods to access the rt identifier string
  and the properties (similar to a java.util.Map)
  Resource instances can do getRTI().getProperty("myproperty") to access a property

- The repositories are now associated with the realms:
  Each realm has a default repository and an rti repository.
  A resource may access the default repository like this:
  getRealm().getRepository().getInputStream(path);
  (no need to use YarepUtil anymore)

- Added ResourceManager.java and moved some methods to this class to create resources and 
  access the RTIs.




Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Path.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Path.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Path.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -21,7 +21,7 @@
 /**
  *
  */
-public class Path extends org.wyona.commons.io.Path {
+public class Path extends org.wyona.yarep.core.Path {
 
     private static Category log = Category.getInstance(Path.class);
 

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Resource.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Resource.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Resource.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -16,13 +16,18 @@
 
 package org.wyona.yanel.core;
 
+import org.wyona.yanel.core.map.Realm;
+
 /**
  *
  */
 public abstract class Resource {
 
     protected ResourceTypeDefinition rtd;
+    protected ResourceTypeIdentifier rti;
     protected Yanel yanel;
+    protected Path path;
+    protected Realm realm;
 
     /**
      *
@@ -79,4 +84,29 @@
     public String getResourceTypeNamespace() {
         return rtd.getResourceTypeNamespace();
     }
+    
+    public Path getPath() {
+        return path;
+    }
+
+    public void setPath(Path path) {
+        this.path = path;
+    }
+
+    public Realm getRealm() {
+        return realm;
+    }
+
+    public void setRealm(Realm realm) {
+        this.realm = realm;
+    }
+
+    public ResourceTypeIdentifier getRTI() {
+        return rti;
+    }
+
+    public void setRTI(ResourceTypeIdentifier rti) {
+        this.rti = rti;
+    }
+
 }

Added: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceManager.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceManager.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceManager.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.core;
+
+import java.io.Reader;
+
+import org.apache.log4j.Category;
+import org.wyona.yanel.core.map.Map;
+import org.wyona.yanel.core.map.Realm;
+import org.wyona.yarep.core.NoSuchNodeException;
+
+/**
+ *
+ */
+public class ResourceManager {
+
+    private static Category log = Category.getInstance(ResourceTypeRegistry.class);
+    
+    protected ResourceTypeRegistry rtRegistry;
+    
+    /**
+     *
+     */
+    public ResourceManager() {
+    }
+    
+    public void setResourceTypeRegistry(ResourceTypeRegistry registry) {
+        this.rtRegistry = registry;
+    }
+
+    /**
+     * Creates a new resource object in the given realm with the given path and the given type.
+     */
+    public Resource getResource(Realm realm, Path path, ResourceTypeDefinition rtd, ResourceTypeIdentifier rti) throws Exception {
+        String universalName = rtd.getResourceTypeUniversalName();
+        if (rtd != null) {
+            Resource resource = (Resource) Class.forName(rtd.getResourceTypeClassname()).newInstance();
+
+            resource.setRTD(rtd);
+            resource.setYanel(Yanel.getInstance());
+            resource.setRealm(realm);
+            resource.setPath(path);
+            resource.setRTI(rti);
+            
+            return resource;
+        } else {
+            log.error("No resource registered for rti: " + universalName);
+            return null;
+        }
+    }
+
+    /**
+     * Creates a new resource object in the given realm and with the given path.
+     */
+    public Resource getResource(Realm realm, Path path) throws Exception {
+        ResourceTypeIdentifier rti = getResourceTypeIdentifier(realm, path);
+        ResourceTypeDefinition rtd = rtRegistry.getResourceTypeDefinition(rti.getUniversalName());
+        Resource resource = getResource(realm, path, rtd, rti);
+        return resource;
+    }
+
+    /**
+     * Returns the abstraction of the rti file for the given path in the realm.
+     * TODO: move this method to some RTIManager class ?
+     */
+    public ResourceTypeIdentifier getResourceTypeIdentifier(Realm realm, Path path) throws Exception {
+        log.debug("Original path: " + path);
+        try {
+            Reader reader = realm.getRTIRepository().getReader(path.getRTIPath());
+            return new ResourceTypeIdentifier(reader);
+        } catch(NoSuchNodeException e) {
+            log.warn(e.getMessage());
+            log.warn("TODO: Implement chain of responsibility ...");
+            return new ResourceTypeIdentifier("<{http://www.wyona.org/yanel/resource/1.0}file/>", null);
+        } 
+    }
+    
+
+}


Property changes on: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceManager.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeIdentifier.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeIdentifier.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeIdentifier.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.core;
+
+import java.io.BufferedReader;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Category;
+
+/**
+ * Abstraction of an rti file.
+ * Convention:
+ * - first line contains resource type identifier string: <{http://www.wyona.org/yanel/resource/1.0}file/>
+ * - all remaining lines contain properties in the following format:
+ *        key:value
+ * - lines starting with '#' are ignored
+ * - lines which don't contain a ':' are ignored
+ *        
+ * TODO: this class should be renamed
+ */
+public class ResourceTypeIdentifier {
+
+    private Category log = Category.getInstance(ResourceTypeDefinition.class);
+
+    protected Map properties;
+    protected String universalName;
+    
+    public ResourceTypeIdentifier(Reader reader) throws Exception {
+        BufferedReader br = new BufferedReader(reader);
+
+        this.universalName = br.readLine();
+        this.properties = new HashMap();
+        
+        String property;
+        while ((property = br.readLine()) != null) {
+            int colonIndex = property.indexOf(":");
+            if (colonIndex > 0 && !property.trim().startsWith("#")) {
+                String name = property.substring(0, colonIndex).trim();
+                String value = property.substring(colonIndex + 1).trim();
+                this.properties.put(name, value);
+            }
+        }
+    }
+    
+    public ResourceTypeIdentifier(String universalName, Map properties) {
+        if (properties == null) {
+            this.properties = new HashMap();
+        } else {
+            this.properties = properties;
+        }
+        this.universalName = universalName;
+    }
+    
+    public String getUniversalName() {
+        return universalName;
+    }
+    
+    /**
+     * @param key
+     * @return value for this key or null if no value exists for this key.
+     */
+    public String getProperty(String key) {
+        return (String)properties.get(key);
+    }
+    
+    public boolean containsKey(String key) {
+        return properties.containsKey(key);
+    }
+
+
+}


Property changes on: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeIdentifier.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -26,6 +26,8 @@
 import org.apache.log4j.Category;
 
 import org.wyona.commons.io.FileUtil;
+import org.wyona.yanel.core.map.Map;
+import org.wyona.yanel.core.map.Realm;
 
 /**
  *
@@ -110,7 +112,7 @@
     }
 
     /**
-     *
+     * @deprecated
      */
     public Resource newResource(String universalName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
 	ResourceTypeDefinition rtd = (ResourceTypeDefinition) hm.get(universalName);
@@ -128,6 +130,7 @@
         }
     }
 
+
     /**
      *
      */

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Yanel.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Yanel.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/Yanel.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -17,6 +17,8 @@
 package org.wyona.yanel.core;
 
 import org.wyona.yanel.core.map.Map;
+import org.wyona.yanel.core.map.Realm;
+import org.wyona.yanel.core.map.RealmConfiguration;
 import org.wyona.yarep.core.RepositoryFactory;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.context.ApplicationContext;
@@ -30,6 +32,8 @@
     private Map map = null;
     private ResourceTypeRegistry rtr = null;
     private ApplicationContext applicationContext;
+    private RealmConfiguration realmConfig;
+    private ResourceManager resourceManager;
     
     private static final String SPRING_CONFIG_FILE = "spring-yanel-config.xml"; 
 
@@ -40,8 +44,16 @@
     */
    private Yanel() throws Exception {
        applicationContext = new ClassPathXmlApplicationContext(SPRING_CONFIG_FILE);
+   } 
+   
+   public void init() throws Exception {
        map = (Map) applicationContext.getBean("map");
+       realmConfig = new RealmConfiguration();
+       map.setRealmConfiguration(realmConfig);
+
        rtr = new ResourceTypeRegistry();
+       resourceManager = new ResourceManager();
+       resourceManager.setResourceTypeRegistry(rtr);
     }
    
     public static Yanel getInstance() throws Exception {
@@ -62,22 +74,25 @@
     /**
      *
      */
-    public Resource getResource(Path path) throws Exception {
-        String rti = map.getResourceTypeIdentifier(path);
-        Resource resource = rtr.newResource(rti);
-
-        ResourceTypeDefinition rtd = rtr.getResourceTypeDefinition(rti);
-        resource.setRTD(rtd);
-
-        resource.setYanel(this);
-
-        return resource;
+    public Map getMap() throws Exception {
+        return map;
     }
-
+    
+    public ResourceTypeRegistry getResourceTypeRegistry() {
+        return rtr;
+    }
+    
+    public ResourceManager getResourceManager() {
+        return resourceManager;
+    }
+    
     /**
-     *
+     * @deprecated
+     * use getResourceManager().getResource() instead 
      */
-    public Map getMap() throws Exception {
-        return map;
+    public Resource getResource(Realm realm, Path path) throws Exception {
+        return resourceManager.getResource(realm, path);
     }
+
+
 }

Added: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV3.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV3.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV3.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.core.api.attributes;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * DEV (not released yet), please be aware that this interface still might change ...
+ */
+public interface ModifiableV3 {
+
+    /**
+     *
+     */
+    public Reader getReader() throws Exception;
+
+    /**
+     *
+     */
+    public InputStream getInputStream() throws Exception;
+
+    /**
+     *
+     */
+    public Writer getWriter() throws Exception;
+
+    /**
+     *
+     */
+    public OutputStream getOutputStream() throws Exception;
+
+    /**
+     * To write data and allowing the resource to modify data during writing, 
+     * e.g. "updated" element of atom entry
+     */
+    public void write(InputStream in) throws Exception;
+
+    /**
+     *
+     */
+    public long getLastModified() throws Exception;
+
+    /**
+     *
+     */
+    public boolean delete() throws Exception;
+}


Property changes on: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV3.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -29,7 +29,7 @@
  */
 public interface VersionableV2 {
 
-    public String[] getRevisions(Path path);
+    public String[] getRevisions() throws Exception;
     
     /*
      * Methods which could be added to this interface:

Added: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV3.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV3.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV3.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.core.api.attributes;
+
+import org.wyona.yanel.core.Path;
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.OutputStream;
+
+/**
+ * DEV (not released yet), please be aware that this interface still might change ...
+ */
+public interface ViewableV3 {
+
+    /**
+     *
+     */
+    public ViewDescriptor[] getViewDescriptors();
+
+    /**
+     * NOTE: A resource does not necessarily have a path
+     */
+    public View getView(String viewId) throws Exception;
+
+    /**
+     *
+     */
+    //public void getView(HttpServletRequest request, HttpServletResponse response, String viewId) throws Exception;
+    
+    /**
+     * 
+     */
+    //public boolean exists();
+}


Property changes on: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV3.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Map.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Map.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Map.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -19,7 +19,7 @@
 import org.wyona.yanel.core.Path;
 
 /**
- *
+ * Mapping from urls to realms/paths.
  */
 public interface Map {
 
@@ -29,17 +29,39 @@
     public String getUUID();
 
     /**
-     *
+     * @deprecated
      */
     public String getResourceTypeIdentifier(Path path);
 
     /**
-     *
+     * @deprecated
      */
     public Realm[] getRealms();
 
     /**
-     *
+     * @deprecated
      */
     public Realm getRealm(Path path);
+
+    
+
+    public void setRealmConfiguration(RealmConfiguration realmConfig);
+
+    /**
+     * Gets the realm for the given url, according to the configuration in realms.xml.
+     * 
+     * @param url url without context path prefix
+     * @return the first realm whose mount-point is a matching prefix of the given url.
+     * @throws Exception
+     */
+    public Realm getRealm(String url) throws Exception;
+    
+    /**
+     * Maps the given url to a path in the given realm. A path is relative to the realm.
+     * @param realm
+     * @param url
+     * @return
+     * @throws Exception
+     */
+    public Path getPath(Realm realm, String url) throws Exception;
 }

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Realm.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Realm.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/Realm.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -17,6 +17,7 @@
 package org.wyona.yanel.core.map;
 
 import org.wyona.commons.io.Path;
+import org.wyona.yarep.core.Repository;
 
 /**
  *
@@ -26,6 +27,8 @@
     private String name;
     private String id;
     private Path mountPoint;
+    private Repository repository;
+    private Repository rtiRepository;
 
     private String proxyHostName;
     private String proxyPort;
@@ -107,4 +110,22 @@
         }
         return descr;
     }
+    
+    public Repository getRepository() throws Exception {
+        return repository;
+    }
+    
+    public void setRepository(Repository repository) throws Exception {
+        this.repository = repository;
+    }
+
+    public Repository getRTIRepository() throws Exception {
+        return rtiRepository;
+    }
+    
+    public void setRTIRepository(Repository repository) throws Exception {
+        this.rtiRepository = repository;
+    }
+
+
 }

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -21,6 +21,7 @@
 import java.lang.IllegalAccessException;
 import java.lang.InstantiationException;
 import java.net.URL;
+import java.util.LinkedHashMap;
 import java.util.Properties;
 
 import org.apache.log4j.Category;
@@ -29,6 +30,8 @@
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 
 import org.wyona.commons.io.FileUtil;
+import org.wyona.yanel.core.Yanel;
+import org.wyona.yarep.core.RepositoryFactory;
 
 /**
  *
@@ -44,7 +47,7 @@
 
     private File realmsConfigFile; 
 
-    private java.util.HashMap hm = new java.util.HashMap();
+    private LinkedHashMap hm = new LinkedHashMap();
     private Realm rootRealm = null;
 
     /**
@@ -77,6 +80,7 @@
             }
             log.debug("Realms Configuration: " + realmsConfigFile);
             readRealms();
+            assignRepositories();
         } catch (Exception e) {
             log.error(e);
         }
@@ -136,6 +140,14 @@
     }
 
     /**
+     * Get all realms in the order they given in the (local.)yanel.properties file.
+     */
+    public Realm[] getRealms() {
+        Realm[] realms = new Realm[hm.size()];
+        return realms = (Realm[])hm.values().toArray(realms);
+    }
+
+    /**
      *
      */
     public Realm getRootRealm() {
@@ -156,4 +168,24 @@
             }
         }
     }
+    
+    /**
+     * Assigns the repositories to the realms.
+     * Each realm has a default data repository and a rti repository.
+     * The id of the realm matches the id of the repository.
+     */
+    private void assignRepositories() throws Exception {
+        RepositoryFactory defaultRepoFactory = Yanel.getInstance().getRepositoryFactory("DefaultRepositoryFactory");
+        RepositoryFactory rtiRepoFactory = Yanel.getInstance().getRepositoryFactory("RTIRepositoryFactory");
+        
+        java.util.Iterator keyIterator = hm.keySet().iterator();
+        while(keyIterator.hasNext()) {
+            String key = (String)keyIterator.next();
+            Realm realm = (Realm)hm.get(key);
+            
+            realm.setRepository(defaultRepoFactory.newRepository(realm.getID()));
+            realm.setRTIRepository(rtiRepoFactory.newRepository(realm.getID()));
+        }
+        
+    }
 }

Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -1,7 +1,9 @@
 package org.wyona.yanel.servlet;
 
+import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.Writer;
@@ -18,13 +20,16 @@
 import org.wyona.yanel.core.Path;
 import org.wyona.yanel.core.Resource;
 import org.wyona.yanel.core.ResourceTypeDefinition;
+import org.wyona.yanel.core.ResourceTypeIdentifier;
 import org.wyona.yanel.core.ResourceTypeRegistry;
 import org.wyona.yanel.core.Yanel;
 import org.wyona.yanel.core.api.attributes.ModifiableV1;
 import org.wyona.yanel.core.api.attributes.ModifiableV2;
+import org.wyona.yanel.core.api.attributes.ModifiableV3;
 import org.wyona.yanel.core.api.attributes.VersionableV2;
 import org.wyona.yanel.core.api.attributes.ViewableV1;
 import org.wyona.yanel.core.api.attributes.ViewableV2;
+import org.wyona.yanel.core.api.attributes.ViewableV3;
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.map.Map;
 import org.wyona.yanel.core.map.Realm;
@@ -79,8 +84,9 @@
         
         try {
             yanel = Yanel.getInstance();
+            yanel.init();
             
-            rtr = new ResourceTypeRegistry();
+            rtr = yanel.getResourceTypeRegistry();
 
             pm = (PolicyManager) yanel.getBeanFactory().getBean("policyManager");
 
@@ -175,6 +181,11 @@
         String servletContextRealPath = config.getServletContext().getRealPath("/");
         rootElement.setAttribute("servlet-context-real-path", servletContextRealPath);
 
+        
+        //log.deubg("servletContextRealPath: " + servletContextRealPath);
+        //log.debug("contextPath: " + request.getContextPath());
+        //log.debug("servletPath: " + request.getServletPath());
+        
         Element requestElement = (Element) rootElement.appendChild(doc.createElement("request"));
         requestElement.setAttribute("uri", request.getRequestURI());
         requestElement.setAttribute("servlet-path", request.getServletPath());
@@ -194,13 +205,32 @@
             sessionAttributeElement.appendChild(doc.createTextNode(value));
         }
 
-        String rti = map.getResourceTypeIdentifier(new Path(request.getServletPath()));
+        Realm realm;
+        Path path;
+        ResourceTypeIdentifier rti;
+        
+        try {
+            realm = map.getRealm(request.getServletPath());
+            path = map.getPath(realm, request.getServletPath());
+            rti = yanel.getResourceManager().getResourceTypeIdentifier(realm, path);
+        } catch (Exception e) {
+            String message = "URL could not be mapped to realm/path " + e.getMessage();
+            log.error(message, e);
+            Element exceptionElement = (Element) rootElement.appendChild(doc.createElement("exception"));
+            exceptionElement.appendChild(doc.createTextNode(message));
+
+            setYanelOutput(response, doc);
+            response.setStatus(javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
+        }
+        
+        //String rti = map.getResourceTypeIdentifier(new Path(request.getServletPath()));
         Resource res = null;
         long lastModified = -1;
         if (rti != null) {
-            ResourceTypeDefinition rtd = rtr.getResourceTypeDefinition(rti);
+            ResourceTypeDefinition rtd = rtr.getResourceTypeDefinition(rti.getUniversalName());
             if (rtd == null) {
-                String message = "No such resource type registered: " + rti + ", check " + rtr.getConfigurationFile();
+                String message = "No such resource type registered: " + rti.getUniversalName() + ", check " + rtr.getConfigurationFile();
                 log.error(message);
                 Element exceptionElement = (Element) rootElement.appendChild(doc.createElement("exception"));
                 exceptionElement.appendChild(doc.createTextNode(message));
@@ -215,11 +245,8 @@
             rtiElement.setAttribute("local-name",  rtd.getResourceTypeLocalName());
 
             try {
-                res = rtr.newResource(rti);
+                res = yanel.getResourceManager().getResource(realm, path, rtd, rti);
                 if (res != null) {
-                    // TODO: This has been already set by ResourceTypeRegistry
-                    res.setRTD(rtd);
-                    res.setYanel(yanel);
 
                     Element resourceElement = (Element) rootElement.appendChild(doc.createElement("resource"));
                     if (ResourceAttributeHelper.hasAttributeImplemented(res, "Viewable", "1")) {
@@ -255,6 +282,10 @@
                         String viewId = request.getParameter("yanel.resource.viewid");
                         ((ViewableV2) res).getView(request, response, viewId);
                         return;
+                    } else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Viewable", "3")) {
+                        log.error("DEBUG: Resource is viewable V3");
+                        String viewId = request.getParameter("yanel.resource.viewid");
+                        view = ((ViewableV3) res).getView(viewId);
                     } else {
                          Element noViewElement = (Element) resourceElement.appendChild(doc.createElement("no-view"));
                          noViewElement.appendChild(doc.createTextNode(res.getClass().getName() + " is not viewable!"));
@@ -263,13 +294,17 @@
                         lastModified = ((ModifiableV2) res).getLastModified(new Path(request.getServletPath()));
                         Element lastModifiedElement = (Element) resourceElement.appendChild(doc.createElement("last-modified"));
                         lastModifiedElement.appendChild(doc.createTextNode(new java.util.Date(lastModified).toString()));
+                    } else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "3")) {
+                            lastModified = ((ModifiableV3) res).getLastModified();
+                            Element lastModifiedElement = (Element) resourceElement.appendChild(doc.createElement("last-modified"));
+                            lastModifiedElement.appendChild(doc.createTextNode(new java.util.Date(lastModified).toString()));
                     } else {
                         Element noLastModifiedElement = (Element) resourceElement.appendChild(doc.createElement("no-last-modified"));
                     }
                     if (ResourceAttributeHelper.hasAttributeImplemented(res, "Versionable", "2")) {
                         // retrieve the revisions, but only in the meta usecase (for performance reasons):
                         if (request.getParameter("yanel.resource.meta") != null) {
-                            String[] revisions = ((VersionableV2)res).getRevisions(new Path(request.getServletPath()));
+                            String[] revisions = ((VersionableV2)res).getRevisions();
                             Element revisionsElement = (Element) resourceElement.appendChild(doc.createElement("revisions"));
                             if (revisions != null) {
                                 for (int i=0; i<revisions.length; i++) {
@@ -323,7 +358,14 @@
         if (view != null) {
             response.setContentType(patchContentType(view.getMimeType(), request));
             InputStream is = view.getInputStream();
+            
+            
+            //BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+            //String line;
+            //System.out.println("getContentXML: "+path);
+            //while ((line = reader.readLine()) != null) System.out.println(line);
 
+
             byte buffer[] = new byte[8192];
             int bytesRead;
            
@@ -516,23 +558,14 @@
      *
      */
     private Resource getResource(HttpServletRequest request) {
-        String rti = map.getResourceTypeIdentifier(new Path(request.getServletPath()));
-        if (rti != null) {
-            ResourceTypeDefinition rtd = rtr.getResourceTypeDefinition(rti);
-
-            try {
-                Resource res = rtr.newResource(rti);
-                // TODO: This has been already set by ResourceTypeRegistry
-                res.setRTD(rtd);
-                res.setYanel(yanel);
-
-                return res;
-            } catch(Exception e) {
-                log.error(e.getMessage(), e);
-                return null;
-            }
-        } else {
-            log.error("<no-resource-type-identifier-found servlet-path=\""+request.getServletPath()+"\"/>");
+        try {
+            Realm realm = map.getRealm(request.getServletPath());
+            Path path = map.getPath(realm, request.getServletPath());
+            Resource res = yanel.getResourceManager().getResource(realm, path);
+            
+            return res;
+        } catch(Exception e) {
+            log.error(e.getMessage(), e);
             return null;
         }
     }
@@ -628,6 +661,13 @@
             out = ((ModifiableV1) res).getOutputStream(new Path(request.getServletPath()));
         } else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "2")) {
             out = ((ModifiableV2) res).getOutputStream(new Path(request.getServletPath()));
+        } else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "3")) {
+            try {
+                out = ((ModifiableV3) res).getOutputStream();
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                throw new ServletException(e.getMessage(), e);
+            }
         } else {
             String message = res.getClass().getName() + " is not modifiable (neither V1 nor V2)!";
             log.warn(message);

Modified: public/yanel/branches/sandbox/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java
===================================================================
--- public/yanel/branches/sandbox/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -38,23 +38,20 @@
     private static Category log = Category.getInstance(MapImpl.class);
 
     RealmConfiguration realmConfig;
+    
 
     /**
      *
      */
     public MapImpl() {
-        try {
-            // NOTE: Separate ResourceTypeIdentifier mapping from whatever else is using yarep ...
-
-            realmConfig = new RealmConfiguration();
-        } catch(Exception e) {
-            log.error(e.getMessage(), e);
-        }
     }
     
+    public void setRealmConfiguration(RealmConfiguration realmConfig) {
+        this.realmConfig = realmConfig;
+    }
+    
     protected RepositoryFactory getRepositoryFactory() throws Exception {
         return Yanel.getInstance().getRepositoryFactory("RTIRepositoryFactory");
-        //repoFactory = new RepositoryFactory();
     }
 
     /**
@@ -66,6 +63,7 @@
 
     /**
      * See James Clark's explanation on namespaces: http://www.jclark.com/xml/xmlns.htm
+     * @deprecated
      */
     public String getResourceTypeIdentifier(Path path) {
         log.debug("Original path: " + path);
@@ -89,7 +87,7 @@
     }
 
     /**
-     *
+     * @deprecated
      */
     public Realm[] getRealms() {
         try {
@@ -119,7 +117,7 @@
     }
 
     /**
-     *
+     * @deprecated
      */
     public Realm getRealm(Path path) {
         try {
@@ -143,4 +141,49 @@
             return null;
         }
     }
+    
+    /* (non-Javadoc)
+     * @see org.wyona.yanel.core.map.Map#getRealm(java.lang.String)
+     */
+    public Realm getRealm(String url) throws Exception {
+        log.debug("getRealm(): URL: " + url);
+        Realm[] realms = realmConfig.getRealms();
+        
+        for (int i=0; i<realms.length; i++) {
+            log.debug("checking realm : " + realms[i].getID() + " with mountpoint: " + realms[i].getMountPoint().toString());
+            if (url.startsWith(realms[i].getMountPoint().toString())) {
+                log.debug("matched!");
+                return realms[i];
+            }
+        }
+        log.debug("nothing matched! - > root realm");
+        return realmConfig.getRootRealm();
+    }
+
+    /**
+     * Maps the given url to a path. This default implementation does a one-to-one mapping,
+     * but removes the realm prefix (mount-point).
+     * E.g. if the url is /yanel-website/foo/bar.html, it will return /foo/bar.html.
+     */
+    public Path getPath(Realm realm, String url) throws Exception {
+        log.debug("getPath(): URL: " + url);
+        /*Realm[] realms = realmConfig.getRealms();
+        
+        for (int i=0; i<realms.length; i++) {
+            String mountPoint = realms[i].getMountPoint().toString();
+            log.debug("checking realm : " + realms[i].getID() + " with mountpoint: " + mountPoint);
+            if (url.startsWith(mountPoint)) {
+                log.debug("matched!");
+                return new Path("/" + url.substring(mountPoint.length()));
+            }
+        }
+        log.debug("nothing matched! - > return url as path");*/
+        String mountPoint = realm.getMountPoint().toString();
+        if (!url.startsWith(mountPoint)) {
+            throw new Exception("Cannot map url [" + url + "] to path because the url does not " + 
+                    "belong to the given realm : " + realm.getID() + ": " + mountPoint);
+        }
+        return new Path("/" + url.substring(mountPoint.length()));
+    }
+
 }

Modified: public/yanel/branches/sandbox/src/realms/yanel-website/content/about/en.xhtml
===================================================================
--- public/yanel/branches/sandbox/src/realms/yanel-website/content/about/en.xhtml	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/realms/yanel-website/content/about/en.xhtml	2006-12-01 13:25:48 UTC (rev 20498)
@@ -8,8 +8,8 @@
 </head>
 <body>
 <table width="100%">
-<tr><td align="right"><font size="-1">EN | <a href="../de/ueber.html">DE</a> | <a href="../es/acerca.html">ES</a></font></td></tr>
-</table>
+<tbody><tr><td align="right"><font size="-1">EN | <a href="../de/ueber.html">DE</a> | <a href="../es/acerca.html">ES</a></font></td></tr>
+</tbody></table>
 <h3>About</h3>
 <p>
 Everything is content management (WCMS, DMS, CRM, ERP, E-Mail, DRM, ...) and Yanel
@@ -22,7 +22,7 @@
 
 <h3>Download</h3>
 <p>
-See the <a href="../download.html">download</a> page for information on obtaining releases, snapshots, etc.
+See the <a href="../download.html">download</a> page for information onnnnnnn obtaining releases, snapshots, etc.
 </p>
 
 <h3>Main Features</h3>
@@ -38,4 +38,4 @@
   <li>Cross-Platform (Continuously tested on Linux, Mac OS X, Windows)</li>
 </ul>
 </body>
-</html>
+</html>
\ No newline at end of file

Modified: public/yanel/branches/sandbox/src/realms/yanel-website/content/download.xhtml
===================================================================
--- public/yanel/branches/sandbox/src/realms/yanel-website/content/download.xhtml	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/realms/yanel-website/content/download.xhtml	2006-12-01 13:25:48 UTC (rev 20498)
@@ -16,7 +16,7 @@
 </p>
 
 <p>
-In the near future one will be able to find updates through <a href="download/update.rdf">update.rdf</a>
+In the near future one will be able to fiiiiiiiiiiiiiind updates through <a href="download/update.rdf">update.rdf</a>
 </p>
 </body>
-</html>
+</html>
\ No newline at end of file

Modified: public/yanel/branches/sandbox/src/realms/yanel-website/content/wiki/hello-world.txt
===================================================================
--- public/yanel/branches/sandbox/src/realms/yanel-website/content/wiki/hello-world.txt	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/realms/yanel-website/content/wiki/hello-world.txt	2006-12-01 13:25:48 UTC (rev 20498)
@@ -1,8 +1,7 @@
 !Wiki Test Page
 
 {{{
-Hello
-  Pre
+Hellooooooo
 }}}
 
 ----

Modified: public/yanel/branches/sandbox/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java
===================================================================
--- public/yanel/branches/sandbox/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -19,9 +19,9 @@
 import org.wyona.yanel.core.Path;
 import org.wyona.yanel.core.Resource;
 import org.wyona.yanel.core.Topic;
-import org.wyona.yanel.core.api.attributes.ModifiableV2;
+import org.wyona.yanel.core.api.attributes.ModifiableV3;
 import org.wyona.yanel.core.api.attributes.VersionableV2;
-import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.api.attributes.ViewableV3;
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
 
@@ -41,7 +41,7 @@
 /**
  *
  */
-public class FileResource extends Resource implements ViewableV1, ModifiableV2, VersionableV2 {
+public class FileResource extends Resource implements ViewableV3, ModifiableV3, VersionableV2 {
 
     private static Category log = Category.getInstance(FileResource.class);
 
@@ -61,40 +61,23 @@
     /**
      *
      */
-    public View getView(Path path, String viewId) throws Exception {
+    public View getView(String viewId) throws Exception {
         View defaultView = new View();
         
-            org.wyona.yarep.util.RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            
-            defaultView.setInputStream(rp.getRepo().getInputStream(new org.wyona.yarep.core.Path(rp.getPath().toString())));
+        defaultView.setInputStream(getRealm().getRepository().getInputStream(path));
+        defaultView.setMimeType(getMimeType(viewId));
 
-            defaultView.setMimeType(getMimeType(path, viewId));
-
         return defaultView;
     }
 
     /**
      *
      */
-    private String getMimeType(Path path, String viewId) {
-        String mimeType = null;
-        try {
-            // TODO: Get yanel RTI yarep properties file name from framework resp. use MapFactory ...!
-            org.wyona.yarep.util.RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), yanel.getRepositoryFactory("RTIRepositoryFactory"));
-            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI.getRepo().getReader(new org.wyona.yarep.core.Path(new Path(rpRTI.getPath().toString()).getRTIPath().toString())));
-            br.readLine();
-            mimeType = br.readLine();
-            if (mimeType != null) {
-                if (mimeType.indexOf("mime-type:") == 0) {
-                    mimeType = mimeType.substring(11);
-                    log.info("*" + mimeType + "*");
-                    // TODO: Maybe validate mime-type based on mime.types config ...
-                    return mimeType;
-                }
-            }
-        } catch(Exception e) {
-            log.warn(e);
-        }
+    private String getMimeType(String viewId) throws Exception {
+        
+        String mimeType = getRTI().getProperty("mime-type");
+        
+        if (mimeType != null) return mimeType;
 
         // TODO: Load config mime.types ...
         String suffix = path.getSuffix();
@@ -147,30 +130,27 @@
      *
      */
     public View getView(HttpServletRequest request, String viewId) throws Exception {
-        return getView(new Path(request.getServletPath()), viewId);
+        return getView(viewId);
     }
 
     /**
      *
      */
-    public Reader getReader(Path path) throws Exception {
-        org.wyona.yarep.util.RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-        return rp.getRepo().getReader(new org.wyona.yarep.core.Path(rp.getPath().toString()));
+    public Reader getReader() throws Exception {
+        return getRealm().getRepository().getReader(path);
     }
 
     /**
      *
      */
-    public InputStream getInputStream(Path path) throws Exception {
-        // Reuse stuff from getReader ...
-        org.wyona.yarep.util.RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-        return rp.getRepo().getInputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
+    public InputStream getInputStream() throws Exception {
+        return getRealm().getRepository().getInputStream(path);
     }
 
     /**
      *
      */
-    public Reader getReader(Topic topic) throws Exception {
+    public Writer getWriter() throws Exception {
         log.error("Not implemented yet!");
         return null;
     }
@@ -178,80 +158,37 @@
     /**
      *
      */
-    public Writer getWriter(Path path) {
-        log.error("Not implemented yet!");
-        return null;
+    public OutputStream getOutputStream() throws Exception {
+        return getRealm().getRepository().getOutputStream(path);
     }
 
     /**
      *
      */
-    public Writer getWriter(Topic topic) {
-        log.error("Not implemented yet!");
-        return null;
+    public void write(InputStream in) throws Exception {
+        log.warn("Not implemented yet!");
     }
 
     /**
      *
      */
-    public OutputStream getOutputStream(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().getOutputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-        }
-        return null;
+    public long getLastModified() throws Exception {
+        return getRealm().getRepository().getLastModified(path);
     }
 
     /**
      *
      */
-    public Path write(Path path, InputStream in) {
-        log.warn("Not implemented yet!");
-        OutputStream out = getOutputStream(path);
-        return path;
+    public boolean delete() throws Exception {
+        return getRealm().getRepository().delete(path);
     }
-
+    
     /**
      *
      */
-    public long getLastModified(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().getLastModified(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-        }
-        // TODO: Does that actually make sense?!
-        return -1;
+    public String[] getRevisions() throws Exception {
+        return getRealm().getRepository().getRevisions(path);
     }
 
-    /**
-     *
-     */
-    public boolean delete(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().delete(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-            return false;
-        }
-    }
     
-    public String[] getRevisions(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().getRevisions(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-            return null;
-        }
-    }
-
-    protected RepositoryFactory getRepositoryFactory() {
-        return yanel.getRepositoryFactory("DefaultRepositoryFactory");
-    }    
-    
 }

Modified: public/yanel/branches/sandbox/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
===================================================================
--- public/yanel/branches/sandbox/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2006-12-01 12:52:15 UTC (rev 20497)
+++ public/yanel/branches/sandbox/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2006-12-01 13:25:48 UTC (rev 20498)
@@ -20,10 +20,10 @@
 import org.wyona.yanel.core.Resource;
 import org.wyona.yanel.core.Topic;
 import org.wyona.yanel.core.Yanel;
-import org.wyona.yanel.core.api.attributes.ModifiableV1;
-import org.wyona.yanel.core.api.attributes.ModifiableV2;
+import org.wyona.yanel.core.api.attributes.ModifiableV3;
 import org.wyona.yanel.core.api.attributes.VersionableV2;
 import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.api.attributes.ViewableV3;
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
 
@@ -41,6 +41,7 @@
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.transform.stream.StreamResult;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -54,7 +55,7 @@
 /**
  *
  */
-public class XMLResource extends Resource implements ViewableV1, ModifiableV1, ModifiableV2, VersionableV2 {
+public class XMLResource extends Resource implements ViewableV3, ModifiableV3, VersionableV2 {
 
     private static Category log = Category.getInstance(XMLResource.class);
 
@@ -74,38 +75,39 @@
     /**
      *
      */
-    public View getView(Path path, String viewId) {
+    public View getView(String viewId) {
         View defaultView = new View();
         String mimeType = getMimeType(path, viewId);
         defaultView.setMimeType(mimeType);
 
-        String yanelPath = getProperty(path, "yanel-path");
+        String yanelPath = getRTI().getProperty("yanel-path");
+        //if (yanelPath == null) yanelPath = path.toString();
 
         Path xsltPath = getXSLTPath(path);
 
         try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
+            Repository repo = getRealm().getRepository();
 
 	    if (xsltPath != null) {
                 TransformerFactory tf = TransformerFactory.newInstance();
                 //tf.setURIResolver(null);
-                Transformer transformer = tf.newTransformer(new StreamSource(rp.getRepo().getInputStream(new org.wyona.yarep.core.Path(xsltPath.toString()))));
+                Transformer transformer = tf.newTransformer(new StreamSource(repo.getInputStream(xsltPath)));
                 transformer.setParameter("yanel.path.name", path.getName());
                 transformer.setParameter("yanel.path", path.toString());
                 transformer.setParameter("yanel.back2context", backToRoot(path, ""));
-                transformer.setParameter("yarep.back2realm", backToRoot(new org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
+                transformer.setParameter("yarep.back2realm", backToRoot(path, ""));
                 // TODO: Is this the best way to generate an InputStream from an OutputStream?
                 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
 
                 org.xml.sax.XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
                 xmlReader.setEntityResolver(new org.apache.xml.resolver.tools.CatalogResolver());
-                transformer.transform(new SAXSource(xmlReader, new org.xml.sax.InputSource(getContentXML(rp, yanelPath))), new StreamResult(baos));
+                transformer.transform(new SAXSource(xmlReader, new org.xml.sax.InputSource(getContentXML(repo, yanelPath))), new StreamResult(baos));
                 defaultView.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
 
                 return defaultView;
             } else {
                 log.debug("Mime-Type: " + mimeType);
-                defaultView.setInputStream(getContentXML(rp, yanelPath));
+                defaultView.setInputStream(getContentXML(repo, yanelPath));
             }
         } catch(Exception e) {
             log.error(e);
@@ -114,15 +116,14 @@
         return defaultView;
     }
 
+
     /**
      *
      */
-    private InputStream getContentXML(RepoPath rp, String yanelPath) throws Exception {
+    private InputStream getContentXML(Repository repo, String yanelPath) throws Exception {
         if (yanelPath != null) {
             log.debug("Yanel Path: " + yanelPath);
-            Yanel yanel = getYanel();
-            Path path = new Path("/" + rp.getRepo().getID() + yanelPath);
-            Resource res = yanel.getResource(path);
+            Resource res = yanel.getResourceManager().getResource(realm, new Path(yanelPath));
             if (ResourceAttributeHelper.hasAttributeImplemented(res, "Viewable", "1")) {
                 // TODO: Pass the request ...
                 View view = ((ViewableV1) res).getView(path, null);
@@ -136,14 +137,15 @@
                 log.warn("Resource is not ViewableV1: " + path);
             }
         }
-        return rp.getRepo().getInputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
+        
+        return repo.getInputStream(path);
     }
 
     /**
      * Get mime type
      */
     private String getMimeType(Path path, String viewId) {
-        String mimeType = getProperty(path, "mime-type");
+        String mimeType = getRTI().getProperty("mime-type");
         if (mimeType != null) return mimeType;
 
         String suffix = path.getSuffix();
@@ -168,31 +170,21 @@
     /**
      *
      */
-    public View getView(HttpServletRequest request, String viewId) {
-        return getView(new Path(request.getServletPath()), viewId);
+    public Reader getReader() throws Exception {
+        return getRealm().getRepository().getReader(path);
     }
 
     /**
      *
      */
-    public Reader getReader(Path path) throws Exception {
-        RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-        return rp.getRepo().getReader(new org.wyona.yarep.core.Path(rp.getPath().toString()));
+    public InputStream getInputStream() throws Exception {
+        return getRealm().getRepository().getInputStream(path);
     }
 
     /**
      *
      */
-    public InputStream getInputStream(Path path) throws Exception {
-        // TODO: Reuse stuff from getReader ...
-        RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-        return rp.getRepo().getInputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-    }
-
-    /**
-     *
-     */
-    public Reader getReader(Topic topic) throws Exception {
+    public Writer getWriter() throws Exception {
         log.error("Not implemented yet!");
         return null;
     }
@@ -200,60 +192,29 @@
     /**
      *
      */
-    public Writer getWriter(Path path) {
-        log.error("Not implemented yet!");
-        return null;
+    public OutputStream getOutputStream() throws Exception {
+        return getRealm().getRepository().getOutputStream(path);
     }
 
     /**
      *
      */
-    public Writer getWriter(Topic topic) {
-        log.error("Not implemented yet!");
-        return null;
-    }
-
-    /**
-     *
-     */
-    public OutputStream getOutputStream(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().getOutputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-        }
-        return null;
-    }
-
-    /**
-     *
-     */
-    public Path write(Path path, InputStream in) {
-        OutputStream out = getOutputStream(path);
+    public void write(InputStream in) throws Exception {
         log.warn("Not implemented yet!");
-        return path;
     }
 
     /**
      *
      */
-    public long getLastModified(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().getLastModified(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-        }
-        // TODO: Does that actually make sense?!
-        return -1;
+    public long getLastModified() throws Exception {
+        return getRealm().getRepository().getLastModified(path);
     }
 
     /**
      * Get XSLT path
      */
     private Path getXSLTPath(Path path) {
-        String xsltPath = getProperty(path, "xslt");
+        String xsltPath = getRTI().getProperty("xslt");
         if (xsltPath != null) return new Path(xsltPath);
         log.info("No XSLT Path within: " + path);
         return null;
@@ -281,51 +242,12 @@
     /**
      *
      */
-    public boolean delete(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().delete(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-            return false;
-        }
+    public boolean delete() throws Exception {
+        return getRealm().getRepository().delete(path);
     }
 
-    /**
-     *
-     */
-    private String getProperty(Path path, String name) {
-        String property = null;
-        try {
-            // TODO: Get yanel RTI yarep properties file name from framework resp. use MapFactory ...!
-            RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), yanel.getRepositoryFactory("RTIRepositoryFactory"));
-            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI.getRepo().getReader(new org.wyona.yarep.core.Path(new Path(rpRTI.getPath().toString()).getRTIPath().toString())));
-
-            while ((property = br.readLine()) != null) {
-                if (property.indexOf(name + ":") == 0) {
-                    property = property.substring(name.length() + 2);
-                    log.info("*" + property + "*");
-                    return property;
-                }
-            }
-        } catch(Exception e) {
-            log.warn(e);
-        }
-
-        return property;
+    public String[] getRevisions() throws Exception {
+        return getRealm().getRepository().getRevisions(path);
     }
-    
-    public String[] getRevisions(Path path) {
-        try {
-            RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
-            return rp.getRepo().getRevisions(new org.wyona.yarep.core.Path(rp.getPath().toString()));
-        } catch(Exception e) {
-            log.error(e);
-            return null;
-        }
-    }
 
-    protected RepositoryFactory getRepositoryFactory() {
-        return yanel.getRepositoryFactory("DefaultRepositoryFactory");
-    }
 }




More information about the Yanel-commits mailing list