[Yanel-commits] rev 20662 - in public/yanel/trunk/src:
contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources
contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources
core/java/org/wyona/yanel/cmdl core/java/org/wyona/yanel/core
core/java/org/wyona/yanel/core/api/attributes
core/java/org/wyona/yanel/core/attributes/viewable
core/java/org/wyona/yanel/core/map core/java/org/wyona/yanel/servlet
impl/java/org/wyona/yanel/impl/map
resources/file/src/java/org/wyona/yanel/impl/resources
resources/xml/src/java/org/wyona/yanel/impl/resources
resources/xml/src/test/junit/org/wyona/yanel/impl/resources
test/junit/org/wyona/yanel/junit
michi at wyona.com
michi at wyona.com
Thu Dec 7 19:42:03 CET 2006
Author: michi
Date: 2006-12-07 19:42:01 +0100 (Thu, 07 Dec 2006)
New Revision: 20662
Modified:
public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java
public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/DavCollection.java
public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/XmlViewResource.java
public/yanel/trunk/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/Path.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/Resource.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/Yanel.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV2.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV2.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Map.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java
public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java
public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java
public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
public/yanel/trunk/src/resources/xml/src/test/junit/org/wyona/yanel/impl/resources/XMLResourceTest.java
public/yanel/trunk/src/test/junit/org/wyona/yanel/junit/AbstractYanelTest.java
Log:
refactoring patches of Josias added
Modified: public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -19,9 +19,8 @@
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.ModifiableV1;
import org.wyona.yanel.core.api.attributes.ModifiableV2;
-import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.api.attributes.ViewableV2;
import org.wyona.yanel.core.attributes.viewable.View;
import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
@@ -53,7 +52,7 @@
/**
*
*/
-public class AtomEntryResource extends Resource implements ViewableV1, ModifiableV1, ModifiableV2 {
+public class AtomEntryResource extends Resource implements ViewableV2, ModifiableV2 {
private static Category log = Category.getInstance(AtomEntryResource.class);
@@ -73,7 +72,7 @@
/**
*
*/
- public View getView(Path path, String viewId) {
+ public View getView(String viewId) {
View defaultView = new View();
String mimeType = getMimeType(path, viewId);
defaultView.setMimeType(mimeType);
@@ -164,14 +163,7 @@
/**
*
*/
- public View getView(HttpServletRequest request, String viewId) {
- return getView(new Path(request.getServletPath()), viewId);
- }
-
- /**
- *
- */
- public Reader getReader(Path path) throws Exception {
+ public Reader getReader() 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()));
}
@@ -179,7 +171,7 @@
/**
*
*/
- public InputStream getInputStream(Path path) throws Exception {
+ public InputStream getInputStream() 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()));
@@ -188,7 +180,7 @@
/**
*
*/
- public Reader getReader(Topic topic) throws Exception {
+ public Writer getWriter() {
log.error("Not implemented yet!");
return null;
}
@@ -196,75 +188,42 @@
/**
*
*/
- public Writer getWriter(Path path) {
- log.error("Not implemented yet!");
- return null;
+ public OutputStream getOutputStream() throws Exception {
+ 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()));
}
/**
*
*/
- 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);
+ public void write(InputStream in) throws Exception {
+ org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
+ Parser parser = abdera.getParser();
+ Document doc = parser.parse(in);
+ Entry entry = (Entry) doc.getRoot();
+ java.util.Date date = new java.util.Date();
+ entry.setUpdated(date);
+ java.util.Date publishedDate = entry.getPublished();
+ if (publishedDate == null) {
+ log.error("No published date!");
+ entry.setPublished(date);
}
- return null;
- }
- /**
- *
- */
- public Path write(Path path, InputStream in) throws Exception {
- try {
- org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
- Parser parser = abdera.getParser();
- Document doc = parser.parse(in);
- Entry entry = (Entry) doc.getRoot();
- java.util.Date date = new java.util.Date();
- entry.setUpdated(date);
- java.util.Date publishedDate = entry.getPublished();
- if (publishedDate == null) {
- log.error("No published date!");
- entry.setPublished(date);
- }
+ RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
+ OutputStream out = rp.getRepo().getOutputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
- RepoPath rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()), getRepositoryFactory());
- OutputStream out = rp.getRepo().getOutputStream(new org.wyona.yarep.core.Path(rp.getPath().toString()));
+ org.apache.abdera.writer.Writer writer = abdera.getWriter();
+ writer.writeTo(entry, out);
- org.apache.abdera.writer.Writer writer = abdera.getWriter();
- writer.writeTo(entry, out);
-
- log.error("DEBUG: Atom entry has been written: " + path);
- } catch(Exception e) {
- log.error(e);
- throw e;
- }
- return path;
+ log.error("DEBUG: Atom entry has been written: " + 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 {
+ 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()));
}
/**
@@ -314,19 +273,19 @@
/**
*
*/
- 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 {
+ 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()));
}
protected RepositoryFactory getRepositoryFactory() {
return yanel.getRepositoryFactory("DefaultRepositoryFactory");
}
+ public boolean exists() throws Exception {
+ log.warn("Not implemented yet!");
+ return true;
+ }
+
}
Modified: public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/DavCollection.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/DavCollection.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/DavCollection.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -10,6 +10,7 @@
import org.apache.log4j.Category;
import org.wyona.yanel.core.Path;
import org.wyona.yanel.core.api.attributes.ViewableV2;
+import org.wyona.yanel.core.attributes.viewable.View;
import org.wyona.yarep.core.Repository;
import org.wyona.yarep.core.RepositoryFactory;
import org.wyona.yarep.util.RepoPath;
@@ -17,6 +18,13 @@
public class DavCollection extends XmlViewResource implements ViewableV2 {
+ public boolean exists() throws Exception {
+ // TODO Auto-generated method stub
+ log.warn("Not implemented yet!");
+ return false;
+ }
+
+
private static Category log = Category.getInstance(DavCollection.class);
// WebDAV namespace definition
@@ -49,7 +57,7 @@
// TODO Auto-generated constructor stub
}
- public void buildXmlView(Path path, String viewId, HttpServletRequest request, HttpServletResponse response) throws SAXException {
+ public void buildXmlView(Path path, String viewId) throws SAXException {
response.setStatus(207, "Multi Status");
Modified: public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/XmlViewResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/XmlViewResource.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/contributions/resources/davcollection/src/java/org/wyona/yanel/impl/resources/XmlViewResource.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -68,27 +68,20 @@
* @param requestParameters
* @throws SAXException
*/
- public abstract void buildXmlView(Path path, String viewId, HttpServletRequest request, HttpServletResponse response) throws SAXException;
+ public abstract void buildXmlView(Path path, String viewId) throws SAXException;
- public void getView(HttpServletRequest request, HttpServletResponse response, String viewId) throws Exception {
- // set the output stream for the XML serializer
- this.xmlSerializer.setOutputByteStream(response.getOutputStream());
+ public View getView(String viewId) throws Exception {
- this.contentHandler = xmlSerializer.asContentHandler();
-
- buildXmlView(new Path(request.getServletPath()), viewId, request, response);
- }
-
- public View getView(Path path, OutputStream outputStream, String viewId) throws Exception {
-
// set the output stream for the XML serializer
- this.xmlSerializer.setOutputByteStream(outputStream);
+ this.xmlSerializer.setOutputByteStream(response.getOutputStream());
this.contentHandler = xmlSerializer.asContentHandler();
- buildXmlView(path, viewId, null, null);
+ buildXmlView(path, viewId);
- return null;
+ View view = new View();
+ view.setResponse(false); // this resource writes the response itself
+ return view;
}
public ViewDescriptor[] getViewDescriptors() {
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -16,6 +16,8 @@
package org.wyona.yanel.cmdl;
+import org.wyona.yanel.cmdl.communication.CommandLineRequest;
+import org.wyona.yanel.cmdl.communication.CommandLineResponse;
import org.wyona.yanel.core.Path;
import org.wyona.yanel.core.Resource;
import org.wyona.yanel.core.ResourceTypeDefinition;
@@ -118,9 +120,13 @@
Resource res = null;
+ CommandLineRequest request = new CommandLineRequest(path.toString());
+ CommandLineResponse response = new CommandLineResponse();
try {
res = rtr.newResource(rti);
res.setYanel(yanel);
+ res.setRequest(request);
+ res.setResponse(response);
} catch(Exception e) {
System.err.println("Exception 435435: " + e);
return;
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/Path.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/Path.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/Path.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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/trunk/src/core/java/org/wyona/yanel/core/Resource.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/Resource.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/Resource.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -16,13 +16,22 @@
package org.wyona.yanel.core;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+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;
+ protected HttpServletRequest request;
+ protected HttpServletResponse response;
/**
*
@@ -79,4 +88,45 @@
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;
+ }
+
+ public HttpServletRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(HttpServletRequest request) {
+ this.request = request;
+ }
+
+ public HttpServletResponse getResponse() {
+ return response;
+ }
+
+ public void setResponse(HttpServletResponse response) {
+ this.response = response;
+ }
+
}
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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/trunk/src/core/java/org/wyona/yanel/core/Yanel.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/Yanel.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/Yanel.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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-*-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(null, null, realm, path);
}
+
+
}
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV2.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV2.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV2.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -16,63 +16,51 @@
package org.wyona.yanel.core.api.attributes;
-import org.wyona.yanel.core.Path;
-import org.wyona.yanel.core.Topic;
-
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import org.wyona.yanel.core.Path;
+
/**
* DEV (not released yet), please be aware that this interface still might change ...
*/
public interface ModifiableV2 {
- // TODO: Shouldn't it be the other way around, that the Resource is passed to a Repository instead the Repository to the Resource?!
- //TODO: Shouldn't we use java.io.Serializable (writeObject, readObject)?!
/**
*
*/
- public Reader getReader(Path path) throws Exception;
+ public Reader getReader() throws Exception;
/**
*
*/
- public InputStream getInputStream(Path path) throws Exception;
-
+ public InputStream getInputStream() throws Exception;
+
/**
*
*/
- public Reader getReader(Topic topic) throws Exception;
+ public Writer getWriter() throws Exception;
/**
*
*/
- public Writer getWriter(Path path);
+ public OutputStream getOutputStream() throws Exception;
/**
- * To write data
+ * To write data and allowing the resource to modify data during writing,
+ * e.g. "updated" element of atom entry
*/
- public Writer getWriter(Topic topic);
-
+ public void write(InputStream in) throws Exception;
+
/**
- * To write data
- */
- public OutputStream getOutputStream(Path path);
-
- /**
- * To write data and allowing the resource to modify data during writing, e.g. "updated" element of atom entry
- */
- public Path write(Path path, InputStream in) throws Exception;
-
- /**
*
*/
- public long getLastModified(Path path);
+ public long getLastModified() throws Exception;
/**
*
*/
- public boolean delete(Path path);
+ public boolean delete() throws Exception;
}
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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:
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV2.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV2.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/ViewableV2.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -16,13 +16,9 @@
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;
/**
@@ -35,18 +31,15 @@
*/
public ViewDescriptor[] getViewDescriptors();
+ public View getView(String viewId) throws Exception;
+
/**
* NOTE: A resource does not necessarily have a path
*/
- public View getView(Path path, OutputStream out, String viewId) throws Exception;
+ //public View getView(Path path, OutputStream out, String viewId) throws Exception;
/**
- *
- */
- public void getView(HttpServletRequest request, HttpServletResponse response, String viewId) throws Exception;
-
- /**
*
*/
- public boolean exists(Path path);
+ public boolean exists() throws Exception;
}
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -25,6 +25,7 @@
private String mt;
private InputStream is;
+ private boolean isResponse = true;
/**
*
@@ -53,4 +54,22 @@
public InputStream getInputStream() {
return is;
}
+
+ /**
+ * Checks if this view will be used by Yanel to write the response.
+ * The default is true, and may be turned off for resources which want to
+ * write the response themselves.
+ */
+ public boolean isResponse() {
+ return isResponse;
+ }
+
+ /**
+ * Choose whether this view will be used by Yanel to write the response.
+ * The default is true, and may be turned off for resources which want to
+ * write the response themselves.
+ */
+ public void setResponse(boolean isResponse) {
+ this.isResponse = isResponse;
+ }
}
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Map.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Map.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Map.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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,6 +20,7 @@
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;
@@ -30,6 +33,8 @@
import org.wyona.yanel.core.map.Realm;
import org.wyona.yanel.servlet.CreateUsecaseHelper;
+import org.wyona.yanel.servlet.communication.HttpRequest;
+import org.wyona.yanel.servlet.communication.HttpResponse;
import org.wyona.yanel.util.ResourceAttributeHelper;
import org.wyona.security.core.api.Identity;
@@ -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,10 @@
rtiElement.setAttribute("local-name", rtd.getResourceTypeLocalName());
try {
- res = rtr.newResource(rti);
+ HttpRequest httpRequest = new HttpRequest(request);
+ HttpResponse httpResponse = new HttpResponse(response);
+ res = yanel.getResourceManager().getResource(httpRequest, httpResponse, 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")) {
@@ -253,14 +282,13 @@
} else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Viewable", "2")) {
log.error("DEBUG: Resource is viewable V2");
String viewId = request.getParameter("yanel.resource.viewid");
- ((ViewableV2) res).getView(request, response, viewId);
- return;
+ view = ((ViewableV2) res).getView(viewId);
} else {
Element noViewElement = (Element) resourceElement.appendChild(doc.createElement("no-view"));
noViewElement.appendChild(doc.createTextNode(res.getClass().getName() + " is not viewable!"));
}
if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "2")) {
- lastModified = ((ModifiableV2) res).getLastModified(new Path(request.getServletPath()));
+ lastModified = ((ModifiableV2) res).getLastModified();
Element lastModifiedElement = (Element) resourceElement.appendChild(doc.createElement("last-modified"));
lastModifiedElement.appendChild(doc.createTextNode(new java.util.Date(lastModified).toString()));
} else {
@@ -269,7 +297,7 @@
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++) {
@@ -321,9 +349,20 @@
if (view != null) {
+ // check if the view contatins the response (otherwise assume that the resource
+ // wrote the response, and just return).
+ if (!view.isResponse()) return;
+
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;
@@ -399,17 +438,13 @@
log.error("DEBUG: Atom Feed: " + request.getServletPath() + " " + request.getRequestURI());
Path entryPath = new Path(request.getServletPath() + "/" + new java.util.Date().getTime() + ".xml");
- Path p = ((ModifiableV2)atomEntry).write(entryPath, in);
- if (p != null) {
- log.error("DEBUG: Atom entry has been created: " + p);
- } else {
- log.error("Atom entry has NOT been created!");
- // TODO: Return HTTP ...
- }
+ atomEntry.setPath(entryPath);
+
+ ((ModifiableV2)atomEntry).write(in);
byte buffer[] = new byte[8192];
int bytesRead;
- InputStream resourceIn = ((ModifiableV2)atomEntry).getInputStream(entryPath);
+ InputStream resourceIn = ((ModifiableV2)atomEntry).getInputStream();
OutputStream responseOut = response.getOutputStream();
while ((bytesRead = resourceIn.read(buffer)) != -1) {
responseOut.write(buffer, 0, bytesRead);
@@ -459,8 +494,11 @@
atomEntry.setYanel(yanel);
log.error("DEBUG: Atom Entry: " + request.getServletPath() + " " + request.getRequestURI());
Path entryPath = new Path(request.getServletPath());
+
+ atomEntry.setPath(entryPath);
+
// TODO: There seems to be a problem ...
- Path p = ((ModifiableV2)atomEntry).write(entryPath, in);
+ ((ModifiableV2)atomEntry).write(in);
// NOTE: This method does not update updated date
/*
@@ -495,45 +533,44 @@
* HTTP DELETE implementation
*/
public void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- Resource res = getResource(request);
- if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "2")) {
- if (((ModifiableV2) res).delete(new Path(request.getServletPath()))) {
- log.debug("Resource has been deleted: " + res);
- response.setStatus(response.SC_OK);
- return;
+ try {
+ Resource res = getResource(request, response);
+ res.setPath(new Path(request.getServletPath()));
+ if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "2")) {
+ if (((ModifiableV2) res).delete()) {
+ log.debug("Resource has been deleted: " + res);
+ response.setStatus(response.SC_OK);
+ return;
+ } else {
+ log.warn("Resource could not be deleted: " + res);
+ response.setStatus(response.SC_FORBIDDEN);
+ return;
+ }
} else {
- log.warn("Resource could not be deleted: " + res);
- response.setStatus(response.SC_FORBIDDEN);
+ log.error("Resource '" + res + "' has interface ModifiableV2 not implemented." );
+ response.sendError(response.SC_NOT_IMPLEMENTED);
return;
}
- } else {
- log.error("Resource '" + res + "' has interface ModifiableV2 not implemented." );
- response.sendError(response.SC_NOT_IMPLEMENTED);
- return;
+ } catch (Exception e) {
+ log.error("Could not delete resource with URL " + request.getRequestURL() + " " + e.getMessage(), e);
+ throw new ServletException(e.getMessage(), e);
}
}
/**
*
*/
- 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()+"\"/>");
+ private Resource getResource(HttpServletRequest request, HttpServletResponse response) {
+ try {
+ Realm realm = map.getRealm(request.getServletPath());
+ Path path = map.getPath(realm, request.getServletPath());
+ HttpRequest httpRequest = new HttpRequest(request);
+ HttpResponse httpResponse = new HttpResponse(response);
+ Resource res = yanel.getResourceManager().getResource(httpRequest, httpResponse, realm, path);
+
+ return res;
+ } catch(Exception e) {
+ log.error(e.getMessage(), e);
return null;
}
}
@@ -624,11 +661,16 @@
*/
OutputStream out = null;
- Resource res = getResource(request);
+ Resource res = getResource(request, response);
if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "1")) {
out = ((ModifiableV1) res).getOutputStream(new Path(request.getServletPath()));
} else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Modifiable", "2")) {
- out = ((ModifiableV2) res).getOutputStream(new Path(request.getServletPath()));
+ try {
+ out = ((ModifiableV2) 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/trunk/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/map/MapImpl.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java
===================================================================
--- public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/FileResource.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -21,7 +21,7 @@
import org.wyona.yanel.core.Topic;
import org.wyona.yanel.core.api.attributes.ModifiableV2;
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.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 ViewableV2, ModifiableV2, 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,42 @@
/**
*
*/
- 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;
- }
+ public boolean exists() throws Exception {
+ log.warn("Not implemented yet!");
+ return true;
}
- protected RepositoryFactory getRepositoryFactory() {
- return yanel.getRepositoryFactory("DefaultRepositoryFactory");
- }
}
Modified: public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
===================================================================
--- public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -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.VersionableV2;
import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.api.attributes.ViewableV2;
import org.wyona.yanel.core.attributes.viewable.View;
import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
@@ -35,6 +35,7 @@
import org.wyona.yarep.util.RepoPath;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@@ -44,6 +45,7 @@
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
+import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
@@ -58,11 +60,9 @@
/**
*
*/
-public class XMLResource extends Resource implements ViewableV1, ModifiableV1, ModifiableV2, VersionableV2 {
+public class XMLResource extends Resource implements ViewableV2, ModifiableV2, VersionableV2 {
private static Category log = Category.getInstance(XMLResource.class);
-
- private String language = "en";
/**
*
@@ -80,33 +80,34 @@
/**
*
*/
- 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) {
+ 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));
+
InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
/*
I18nTransformer i18nTransformer = new I18nTransformer("global", language);
@@ -120,7 +121,7 @@
return defaultView;
} else {
log.debug("Mime-Type: " + mimeType);
- defaultView.setInputStream(getContentXML(rp, yanelPath));
+ defaultView.setInputStream(getContentXML(repo, yanelPath));
}
} catch(Exception e) {
log.error(e);
@@ -129,18 +130,40 @@
return defaultView;
}
+ /**
+ *
+ */
+ public View getView(HttpServletRequest request, HttpServletResponse response, String viewid) {
+ return getView(viewid);
+
+ }
+
+ private String getLanguage() {
+ String language = "en";
+ try {
+ language = getRequest().getParameter("yanel.meta.language");
+ } catch(Exception e) {
+ //use fallback language
+ language = "en";
+ }
+ if(language != null && language.length() > 0) return language;
+ return "en";
+ }
+
+
/**
*
*/
- 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(getRequest(), getResponse(),
+ getRealm(), new Path(yanelPath));
if (ResourceAttributeHelper.hasAttributeImplemented(res, "Viewable", "1")) {
// TODO: Pass the request ...
- View view = ((ViewableV1) res).getView(path, null);
+ String viewV1path = getRealm().getMountPoint() + yanelPath.substring(1);
+ log.debug("including document: " + viewV1path);
+ View view = ((ViewableV1) res).getView(new Path(viewV1path), null);
if (view.getMimeType().indexOf("xml") >= 0) {
// TODO: Shall the mime-type be transfered?
return view.getInputStream();
@@ -151,14 +174,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();
@@ -183,40 +207,21 @@
/**
*
*/
- public View getView(HttpServletRequest request, String viewId) {
- String _language = language;
- try {
- _language = request.getParameter("yanel.meta.language");
- } catch(Exception e) {
- //use fallback language
- _language = language;
- }
- if(_language != null && !("").equals(_language)) language = _language;
-
- 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;
}
@@ -224,60 +229,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;
@@ -305,51 +279,17 @@
/**
*
*/
- 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");
+ public boolean exists() throws Exception {
+ log.warn("Not implemented yet!");
+ return true;
}
+
}
Modified: public/yanel/trunk/src/resources/xml/src/test/junit/org/wyona/yanel/impl/resources/XMLResourceTest.java
===================================================================
--- public/yanel/trunk/src/resources/xml/src/test/junit/org/wyona/yanel/impl/resources/XMLResourceTest.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/resources/xml/src/test/junit/org/wyona/yanel/impl/resources/XMLResourceTest.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -24,6 +24,10 @@
import java.io.Writer;
import org.wyona.yanel.core.Path;
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.api.attributes.ModifiableV2;
+import org.wyona.yanel.core.map.Map;
+import org.wyona.yanel.core.map.Realm;
import org.wyona.yanel.junit.AbstractYanelTest;
/**
@@ -33,22 +37,30 @@
protected XMLResource resource;
- protected Path path;
-
public void setUp() throws Exception {
super.setUp();
this.testName = "Test for the XML Resource";
- this.resource = new XMLResource();
- this.path = new Path("/yanel-website/test-xml-resource.html");
- this.resource.setYanel(this.yanel);
-
+
+ Realm realm = yanel.getMap().getRealm("/yanel-website/");
+ Path path = new Path("/test-xml-resource.html");
+ resource = new XMLResource();
+ resource.setPath(path);
+ resource.setRealm(realm);
+
+ /*
+ String url = "/yanel-website/test-xml-resource.html";
+ Map map = yanel.getMap();
+ Realm realm = yanel.getMap().getRealm(url);
+ Path path = yanel.getMap().getPath(realm, url);
+ this.resource = yanel.getResourceManager().getResource(null, null, realm, path);
+ */
}
public void testWriteRead() throws Exception {
// Write resource
- OutputStream os = this.resource.getOutputStream(path);
- assertNotNull("getOutputStream() should not return null for path: " + path, os);
+ OutputStream os = ((ModifiableV2)this.resource).getOutputStream();
+ assertNotNull("getOutputStream() should not return null for path: " + this.resource.getPath(), os);
Writer writer = new OutputStreamWriter(os, "UTF-8");
String testContent = "Hello World! " + System.currentTimeMillis();
@@ -56,8 +68,8 @@
writer.close();
// Read resource
- InputStream is = this.resource.getInputStream(path);
- assertNotNull("getInputStream() should not return null for path: " + path, is);
+ InputStream is = ((ModifiableV2)this.resource).getInputStream();
+ assertNotNull("getInputStream() should not return null for path: " + this.resource.getPath(), is);
Reader reader = new InputStreamReader(is, "UTF-8");
BufferedReader br = new BufferedReader(reader);
String line = br.readLine();
Modified: public/yanel/trunk/src/test/junit/org/wyona/yanel/junit/AbstractYanelTest.java
===================================================================
--- public/yanel/trunk/src/test/junit/org/wyona/yanel/junit/AbstractYanelTest.java 2006-12-07 18:40:16 UTC (rev 20661)
+++ public/yanel/trunk/src/test/junit/org/wyona/yanel/junit/AbstractYanelTest.java 2006-12-07 18:42:01 UTC (rev 20662)
@@ -71,6 +71,7 @@
this.logger = log;
this.yanel = Yanel.getInstance();
+ yanel.init();
}
/*
More information about the Yanel-commits
mailing list