[Yanel-commits] rev 20506 -
public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/cmdl
josias at wyona.com
josias at wyona.com
Fri Dec 1 17:16:25 CET 2006
Author: josias
Date: 2006-12-01 17:16:24 +0100 (Fri, 01 Dec 2006)
New Revision: 20506
Modified:
public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java
Log:
apdapted command line client to refactored yanel and added support for ViewableV3.
Modified: public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java
===================================================================
--- public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java 2006-12-01 16:15:27 UTC (rev 20505)
+++ public/yanel/branches/sandbox/src/core/java/org/wyona/yanel/cmdl/YanelCommandLine.java 2006-12-01 16:16:24 UTC (rev 20506)
@@ -19,12 +19,14 @@
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.CreatableV1;
import org.wyona.yanel.core.api.attributes.CreatableV2;
import org.wyona.yanel.core.api.attributes.ModifiableV1;
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.map.Map;
import org.wyona.yanel.core.map.Realm;
@@ -50,12 +52,13 @@
System.out.println("Welcome to the Yanel command line interface!\n");
Yanel yanel = Yanel.getInstance();
+ yanel.init();
Map map = (Map) yanel.getBeanFactory().getBean("map");
- ResourceTypeRegistry rtr = new ResourceTypeRegistry();
+ ResourceTypeRegistry rtr = yanel.getResourceTypeRegistry();
System.out.println("The following realms have been configured:");
- Realm[] realms = map.getRealms();
+ Realm[] realms = yanel.getRealmConfiguration().getRealms();
for (int i = 0; i < realms.length; i++) {
System.out.println("Realm: " + realms[i]);
}
@@ -68,9 +71,9 @@
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- Path path = null;
+ Path requestPath = null;
if (args.length == 1 && args[0].length() > 0) {
- path = new Path(args[0]);
+ requestPath = new Path(args[0]);
} else {
System.out.println("\nPlease enter a path (e.g. /hello/world.html):");
try {
@@ -80,7 +83,7 @@
return;
}
System.out.println("The following value has been entered: " + value);
- path = new Path(value);
+ requestPath = new Path(value);
} catch (Exception e) {
System.err.println(e);
}
@@ -91,24 +94,27 @@
String[] groupnames = {"admin", "accounting"};
- if (pm.authorize(new org.wyona.commons.io.Path(path.toString()), new Identity("lenya", groupnames), new Role("view"))) {
- System.out.println("Access granted: " + path);
+ if (pm.authorize(new org.wyona.commons.io.Path(requestPath.toString()), new Identity("lenya", groupnames), new Role("view"))) {
+ System.out.println("Access granted: " + requestPath);
} else {
// TODO: Deny access resp. start login process!
- System.out.println("Access denied: " + path);
+ System.out.println("Access denied: " + requestPath);
}
- String rti = map.getResourceTypeIdentifier(path);
- System.out.println("Resource Type Identifier: " + rti);
+ Realm realm = map.getRealm(requestPath.toString());
+ Path path = map.getPath(realm, requestPath.toString());
+ ResourceTypeIdentifier rti = yanel.getResourceManager().getResourceTypeIdentifier(realm, requestPath);
+ //String rti = map.getResourceTypeIdentifier(path);
+ System.out.println("Resource Type Identifier: " + rti.getUniversalName());
if (rti == null) {
System.err.println("Abort, because resource type identifier is null!");
return;
}
- ResourceTypeDefinition rtd = rtr.getResourceTypeDefinition(rti);
+ ResourceTypeDefinition rtd = rtr.getResourceTypeDefinition(rti.getUniversalName());
if (rtd == null) {
- System.err.println("Abort, because no such resource type registered: " + rti);
+ System.err.println("Abort, because no such resource type registered: " + rti.getUniversalName());
System.err.println("Make sure resource type is registered within " + rtr.getConfigurationFile());
return;
}
@@ -119,8 +125,7 @@
Resource res = null;
try {
- res = rtr.newResource(rti);
- res.setYanel(yanel);
+ res = yanel.getResourceManager().getResource(realm, path, rtd, rti);
} catch(Exception e) {
System.err.println("Exception 435435: " + e);
return;
@@ -154,7 +159,28 @@
System.out.println("10. Line: " + bReader.readLine());
} catch(Exception e) {
System.err.println(e);
- }
+ }
+ } else if (ResourceAttributeHelper.hasAttributeImplemented(res, "Viewable", "3")) {
+ System.out.println("View Descriptors: " + ((ViewableV3) res).getViewDescriptors());
+ String viewId = null;
+ try {
+ View view = ((ViewableV3) res).getView(viewId);
+ System.out.println("mime-type: " + view.getMimeType());
+
+ BufferedReader bReader = new BufferedReader(new java.io.InputStreamReader(view.getInputStream()));
+ System.out.println(" 1. Line: " + bReader.readLine());
+ System.out.println(" 2. Line: " + bReader.readLine());
+ System.out.println(" 3. Line: " + bReader.readLine());
+ System.out.println(" 4. Line: " + bReader.readLine());
+ System.out.println(" 5. Line: " + bReader.readLine());
+ System.out.println(" 6. Line: " + bReader.readLine());
+ System.out.println(" 7. Line: " + bReader.readLine());
+ System.out.println(" 8. Line: " + bReader.readLine());
+ System.out.println(" 9. Line: " + bReader.readLine());
+ System.out.println("10. Line: " + bReader.readLine());
+ } catch(Exception e) {
+ System.err.println(e);
+ }
} else {
System.out.println(res.getClass().getName() + " does not implement viewable interface!");
}
More information about the Yanel-commits
mailing list