Author: tmortagne
Date: 2007-10-10 15:45:03 +0200 (Wed, 10 Oct 2007)
New Revision: 5346

Modified:
   
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/doc/objects/classes/AbstractSuperClass.java
Log:
XAAM-19: When there is no class template document or sheet template document 
AbstractSuperClass first try to find the content to set in the new 
sheet/template document from the resources. If it can't find any resource it 
used getClassSheetDefaultContent or getClassTemplateDefaultContent.
 - For class sheet document the resource path is : "sheets/" + 
SuperClass.getClassSheetFullName() + ".vm"
 - For class template document the resource path is : "templates/" + 
SuperClass.getClassTemplateFullName() + ".vm"

Modified: 
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/doc/objects/classes/AbstractSuperClass.java
===================================================================
--- 
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/doc/objects/classes/AbstractSuperClass.java
       2007-10-10 10:36:13 UTC (rev 5345)
+++ 
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/doc/objects/classes/AbstractSuperClass.java
       2007-10-10 13:45:03 UTC (rev 5346)
@@ -20,6 +20,10 @@
 
 package com.xpn.xwiki.plugin.applicationmanager.core.doc.objects.classes;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.HashSet;
 import java.util.List;
 
@@ -380,6 +384,33 @@
     }
 
     /**
+     * Load an entire resource text file into [EMAIL PROTECTED] String}.
+     * 
+     * @param path the path to the resource file.
+     * @return the entire content of the resource text file.
+     */
+    private String getResourceDocumentContent(String path)
+    {
+        InputStream in = 
this.getClass().getClassLoader().getResourceAsStream(path);
+
+        if (in != null)
+            try {
+                StringBuffer content = new StringBuffer(in.available());
+
+                BufferedReader reader = new BufferedReader(new 
InputStreamReader(in));
+                for (String str; (str = reader.readLine()) != null;) {
+                    content.append(str);
+                    content.append('\n');
+                }
+
+                return content.toString();
+            } catch (IOException e) {
+            }
+
+        return null;
+    }
+
+    /**
      * Check if class sheet document exists in this context and update. Create 
if not exists.
      * 
      * @param context the XWiki context.
@@ -402,7 +433,9 @@
         }
 
         if (doc.isNew()) {
-            doc.setContent(getClassSheetDefaultContent());
+            String content =
+                getResourceDocumentContent("templates/" + 
getClassSheetFullName() + ".vm");
+            doc.setContent(content != null ? content.toString() : 
getClassSheetDefaultContent());
         }
 
         if (doc.isNew() || needsUpdate)
@@ -447,12 +480,16 @@
         }
 
         if (doc.isNew()) {
-            doc.setContent(getClassTemplateDefaultContent());
+            String content =
+                getResourceDocumentContent("templates/" + 
getClassTemplateFullName() + ".vm");
+            doc.setContent(content != null ? content.toString()
+                : getClassTemplateDefaultContent());
+
             doc.setParent(getClassFullName());
         }
 
         needsUpdate |= updateClassTemplateDocument(doc);
-        
+
         if (doc.isNew() || needsUpdate)
             xwiki.saveDocument(doc, context);
     }

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to