[Yanel-commits] rev 20334 -
public/yanel/trunk/src/core/java/org/wyona/yanel/servlet
michi at wyona.com
michi at wyona.com
Sat Nov 25 14:12:09 CET 2006
Author: michi
Date: 2006-11-25 14:12:08 +0100 (Sat, 25 Nov 2006)
New Revision: 20334
Modified:
public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/CreateUsecaseHelper.java
Log:
pass Yanel instance and clean up
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/CreateUsecaseHelper.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/CreateUsecaseHelper.java 2006-11-25 08:34:09 UTC (rev 20333)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/CreateUsecaseHelper.java 2006-11-25 13:12:08 UTC (rev 20334)
@@ -49,133 +49,27 @@
/**
*
*/
- public HttpServletResponse create(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ public HttpServletResponse create(HttpServletRequest request, HttpServletResponse response, org.wyona.yanel.core.Yanel yanel) throws IOException {
String createName = request.getParameter("create.name");
String resourceType = request.getParameter("resource.type");
String create = request.getParameter("create");
+ PrintWriter w = response.getWriter();
if (resourceType == null || createName == null) {
- PrintWriter w = response.getWriter();
w.print(resourcesTypeSelectScreen(createName));
} else {
if(create == null){
- PrintWriter w = response.getWriter();
- w.print(createResourceScreen(createName, resourceType));
- } else{
- PrintWriter w = response.getWriter();
- w.print(doCreate(resourceType, request, createName));
- }
- }
- return response;
-
-
-
-
-
-/*
- String create = request.getParameter("create");
- String path = request.getRequestURI();
-
-
- if (create != null && create.equals("create.resource")) {
-
- String[] PropertyNames = null;
-
- ResourceTypeRegistry rtr = new ResourceTypeRegistry();
- try {
- Resource resource = rtr.newResource(resourceType);
- if (resource != null) {
- if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Creatable", "2")) {
- PropertyNames = ((CreatableV2) resource).getPropertyNames();
-
- for (int i = 0; i < PropertyNames.length; i++) {
-
- if(PropertyNames[i].equals("Name")){
- ((CreatableV2) resource).create(path+"/"+request.getParameter(PropertyNames[i]));
- }
- }
-
- try {
- String parent = request.getRequestURL().toString().substring(0,request.getRequestURL().toString().indexOf("?"));
- URL url = new URL(parent+"/"+createName);
-
- response.setHeader("Location", url.toString());
- response.setStatus(javax.servlet.http.HttpServletResponse.SC_MOVED_PERMANENTLY);
- return response;
- } catch (Exception e) {
- log.error(e);
- }
-
- return response;
- }
-
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- String message = e.toString();
- log.error(e.getMessage(), 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 response;
- }
-
-
-
- }
- // if no resourceType is available it returns the resourcesSelectScreen
- if (resourceType == null) {
- String resourcesSelectScreen = this.resourcesTypeSelectScreen(createName);
-
- PrintWriter w = response.getWriter();
- w.print(resourcesSelectScreen);
- return response;
- } else {
- String resourcesCreateScreen = this.createResourceScreen(createName, resourceType);
- if (ResourceExistsHelper.resourceExists(path)) {
- if (createName == null) {
- // make child of path, ask for name
- System.out.println("make child of path, ask for name. resourec " + path
- + " exists");
- createResourceScreen("", resourceType);
+ if (resourceType.equals("") || createName.equals("")) {
+ w.print(resourcesTypeSelectScreen(createName));
} else {
- // create child of request path with name createName
- System.out.println("create child of request path with name createName. resourec "
- + path + " exists");
- createResourceScreen(createName, resourceType);
+ w.print(createResourceScreen(createName, resourceType));
}
- } else {
- // check if parent exists
- String parent = "";
- if (path.lastIndexOf("/") != -1) {
- parent = path.substring(0, path.lastIndexOf("/"));
- }
- if (ResourceExistsHelper.resourceExists(parent)) {
- createName = path.substring(path.lastIndexOf("/"), path.length());
- log.debug("the requested resource (" + path
- + ") does not exist, will create it");
- // build this path
- System.out.println("build this path. resource " + path + " exists");
- createResourceScreen(createName, resourceType);
- } else {
- log.debug("the requested resource (" + path
- + ") does not exist, even not its parent ( " + parent
- + " ). please create the parent first");
- // build this path
- System.out.println("the requested resource (" + path
- + ") does not exist, even not its parent( " + parent
- + " ). please create the parent first");
- }
+ } else{
+ w.print(doCreate(resourceType, request, createName, yanel));
}
- PrintWriter w = response.getWriter();
- w.print(resourcesCreateScreen);
- return response;
}
-*/
-
+ return response;
}
/**
@@ -291,7 +185,7 @@
/**
*
*/
- public String doCreate(String resourceType, HttpServletRequest request, String createName ) {
+ public String doCreate(String resourceType, HttpServletRequest request, String createName, org.wyona.yanel.core.Yanel yanel) {
String responseAfterCreationScreen = null;
ResourceTypeRegistry rtr = new ResourceTypeRegistry();
String[] PropertyNames = null;
@@ -299,6 +193,8 @@
try {
Resource resource = rtr.newResource(resourceType);
if (resource != null) {
+ resource.setYanel(yanel);
+ //resource.setRDT();
if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Creatable", "2")) {
PropertyNames = ((CreatableV2) resource).getPropertyNames();
More information about the Yanel-commits
mailing list