[Yanel-commits] rev 22620 - public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Tue Feb 13 16:41:47 CET 2007


Author: michi
Date: 2007-02-13 16:41:46 +0100 (Tue, 13 Feb 2007)
New Revision: 22620

Modified:
   public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
Log:
introspection added

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	2007-02-13 15:32:21 UTC (rev 22619)
+++ public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2007-02-13 15:41:46 UTC (rev 22620)
@@ -435,8 +435,8 @@
      *
      */
     public void create(HttpServletRequest request) {
-        // TODO: XHTML template should not be hardcoded!
         try {
+            // TODO: XHTML template should not be hardcoded!
             Repository repo = getRealm().getRepository();
             Writer writer = new java.io.OutputStreamWriter(repo.getNode(getPath()).getOutputStream());
             writer.write("<?xml version=\"1.0\"?>");
@@ -449,6 +449,17 @@
             writer.write("</body>");
             writer.write("</html>");
             writer.close();
+
+            // TODO: Introspection should not be hardcoded!
+            String name = new org.wyona.commons.io.Path(getPath()).getName();
+            String parent = new org.wyona.commons.io.Path(getPath()).getParent().toString();
+            String nameWithoutSuffix = name;
+            int lastIndex = name.lastIndexOf(".");
+            if (lastIndex > 0) nameWithoutSuffix = name.substring(0, lastIndex);
+            String introspectionPath = parent + "/introspection-" + nameWithoutSuffix + ".xml";
+            writer = new java.io.OutputStreamWriter(repo.getNode(introspectionPath).getOutputStream());
+            writer.write(getIntrospection(name));
+            writer.close();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }
@@ -494,4 +505,23 @@
     public void setProperty(String name, Object value) {
         log.warn("Not implemented yet!");
     }
+    
+    /**
+     * @param name
+     * @return introspection as string
+     */
+    private String getIntrospection(String name) {
+        StringBuffer sb = new StringBuffer();
+        sb.append("<?xml version=\"1.0\"?>");
+        sb.append("\n");
+        sb.append("\n<introspection xmlns=\"http://www.wyona.org/neutron/1.0\">");
+        sb.append("\n");
+        sb.append("\n  <edit mime-type=\"application/xhtml+xml\" name=\"" + name + "\">");
+        sb.append("\n    <checkout url=\"" + name + "?yanel.resource.viewid=source&amp;yanel.resource.usecase=checkout\" method=\"GET\"/>");
+        sb.append("\n    <checkin  url=\"" + name + "?yanel.resource.usecase=checkin\" method=\"PUT\"/>");
+        sb.append("\n  </edit>");
+        sb.append("\n</introspection>");
+        
+        return sb.toString();
+    }    
 }




More information about the Yanel-commits mailing list