[Yanel-commits] rev 22603 - public/yanel/trunk/src/contributions/resources/resource-creator/src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Tue Feb 13 10:55:09 CET 2007


Author: michi
Date: 2007-02-13 10:55:07 +0100 (Tue, 13 Feb 2007)
New Revision: 22603

Modified:
   public/yanel/trunk/src/contributions/resources/resource-creator/src/java/org/wyona/yanel/impl/resources/ResourceCreatorResource.java
Log:
formatting and get default properties added

Modified: public/yanel/trunk/src/contributions/resources/resource-creator/src/java/org/wyona/yanel/impl/resources/ResourceCreatorResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/resource-creator/src/java/org/wyona/yanel/impl/resources/ResourceCreatorResource.java	2007-02-13 09:54:11 UTC (rev 22602)
+++ public/yanel/trunk/src/contributions/resources/resource-creator/src/java/org/wyona/yanel/impl/resources/ResourceCreatorResource.java	2007-02-13 09:55:07 UTC (rev 22603)
@@ -27,6 +27,8 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationUtil;
 
+import org.w3c.dom.Document;
+
 /**
  *
  */
@@ -265,17 +267,17 @@
             Resource resource = rtr.newResource(universalName);
             if (resource != null) {
                 if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Creatable", "2")) {
-                    String[] propertyNames = ((CreatableV2) resource).getPropertyNames();
-                    //((CreatableV2) resource).setProperty("Name", createName);
 
                     sb.append("<h4>Create resource (step 2)</h4>");
                     sb.append("<h2>Enter/Select resource specific parameters and \"Save As\"</h2>");
                     sb.append("<p>Resource Type: " + resName + " ("+resNamespace+")</p>");
                     sb.append("<form>");
                     // TODO: Add this parameter to the continuation within the session!
-                    sb.append("<input type=\"hidden\" name=\"resource-type\" value=\""+rtps+"\"/>");
+                    sb.append("<input type=\"hidden\" name=\"resource-type\" value=\"" + rtps + "\"/>");
 
-                    if (propertyNames != null && propertyNames.length > 0) {
+                    Property[] defaultProperties = getDefaultProperties(resName, resNamespace);
+                    String[] propertyNames = ((CreatableV2) resource).getPropertyNames();
+                    if ((propertyNames != null && propertyNames.length > 0) || defaultProperties != null) {
                         sb.append("<p>Resource specific properties:</p>");
                         for (int i = 0; i < propertyNames.length; i++) {
                             sb.append(propertyNames[i] + ": ");
@@ -314,9 +316,9 @@
                     Sitetree sitetree = (Sitetree) getYanel().getBeanFactory().getBean("nav-sitetree");
                     Node node = sitetree.getNode(getRealm(), getPath());
                     if (node.isCollection()) {
-                        log.error("DEBUG: Collection: " + node.getName());
+                        log.error("DEBUG: Is Collection: " + node.getName());
                     } else if (node.isResource()) {
-                        log.error("DEBUG: Resource: " + node.getName());
+                        log.error("DEBUG: Is Resource: " + node.getName());
                     } else {
                         log.error("Neither collection nor resource: " + getPath());
                     }
@@ -382,26 +384,26 @@
     }
 
     /**
-     *
+     * Create resource configuration (yanel-rti respectively yanel-rc)
      */
     private void createConfiguration(Resource newResource) throws Exception {
-                    StringBuffer rtiContent = new StringBuffer(newResource.getResourceTypeUniversalName() + "\n");
-                    java.util.HashMap rtiProperties = ((CreatableV2) newResource).createRTIProperties(request);
-                    if (rtiProperties != null) {
-                        log.error("DEBUG: " + rtiProperties + " " + PathUtil.getRTIPath(newResource.getPath()));
-                        java.util.Iterator iterator = rtiProperties.keySet().iterator();
-                        while (iterator.hasNext()) {
-                            String property = (String) iterator.next();
-                            String value = (String) rtiProperties.get(property);
-                            rtiContent.append(property + ": " + value + "\n");
-                            log.error("DEBUG: " + property + ", " + value);
-                        }
-                    } else {
-                        log.warn("No RTI properties: " + newResource.getPath());
-                    }
-                    java.io.Writer writer = newResource.getRealm().getRTIRepository().getWriter(new org.wyona.yarep.core.Path(PathUtil.getRTIPath(newResource.getPath())));
-                    writer.write(rtiContent.toString());
-                    writer.close();
+        StringBuffer rtiContent = new StringBuffer(newResource.getResourceTypeUniversalName() + "\n");
+        java.util.HashMap rtiProperties = ((CreatableV2) newResource).createRTIProperties(request);
+        if (rtiProperties != null) {
+            log.error("DEBUG: " + rtiProperties + " " + PathUtil.getRTIPath(newResource.getPath()));
+            java.util.Iterator iterator = rtiProperties.keySet().iterator();
+            while (iterator.hasNext()) {
+                String property = (String) iterator.next();
+                String value = (String) rtiProperties.get(property);
+                rtiContent.append(property + ": " + value + "\n");
+                log.error("DEBUG: " + property + ", " + value);
+            }
+        } else {
+            log.warn("No RTI properties: " + newResource.getPath());
+        }
+        java.io.Writer writer = newResource.getRealm().getRTIRepository().getWriter(new org.wyona.yarep.core.Path(PathUtil.getRTIPath(newResource.getPath())));
+        writer.write(rtiContent.toString());
+        writer.close();
     }
 
     /**
@@ -410,7 +412,7 @@
     private ResourceTypeDefinition[] getResourceTypeDefinitions() {
         ResourceTypeRegistry rtr = new ResourceTypeRegistry();
         ResourceConfiguration rc = getConfiguration();
-        org.w3c.dom.Document customConfigDoc = rc.getCustomConfiguration();
+        Document customConfigDoc = rc.getCustomConfiguration();
         if (customConfigDoc != null) {
             Configuration config = ConfigurationUtil.toConfiguration(customConfigDoc.getDocumentElement());
             Configuration resourceTypesConfig = config.getChild("resource-types", false);
@@ -434,4 +436,40 @@
         ResourceTypeDefinition[] rtds = rtr.getResourceTypeDefinitions();
         return rtds;
     }
+
+    /**
+     * Get default properties from custom configuration
+     */
+    private Property[] getDefaultProperties(String resName, String resNamespace) {
+        Document customConfigDoc = getConfiguration().getCustomConfiguration();
+        if (customConfigDoc != null) {
+            Configuration config = ConfigurationUtil.toConfiguration(customConfigDoc.getDocumentElement());
+            Configuration resourceTypesConfig = config.getChild("resource-types", false);
+            if (resourceTypesConfig != null) {
+                Configuration[] resourceTypeConfigs = resourceTypesConfig.getChildren("resource-type");
+                if (resourceTypeConfigs.length == 0) return null;
+                ResourceTypeDefinition[] rtds = new ResourceTypeDefinition[resourceTypeConfigs.length];
+                for (int i = 0; i < resourceTypeConfigs.length; i++) {
+                    try {
+                        if (resourceTypeConfigs[i].getAttribute("namespace").equals(resNamespace) && resourceTypeConfigs[i].getAttribute("name").equals(resName)) {
+                            log.error("DEBUG: Resource Type Found: " + resName + ", " + resNamespace);
+                        }
+                    } catch (Exception e) {
+                        log.error(e.getMessage(), e);
+                        return null;
+                    }
+                }
+            }
+        }
+        return null;
+    }
 }
+
+/**
+ *
+ */
+class Property {
+
+    String name;
+    String value;
+}




More information about the Yanel-commits mailing list