Author: sdumitriu
Date: 2008-02-09 12:09:34 +0100 (Sat, 09 Feb 2008)
New Revision: 7463

Modified:
   xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
Log:
XWIKI-2096: Allow skin document attachments to override/provide templates
XWIKI-2098: Make the way parseTemplate considers where to find a template 
consistent with the way SkinAction does that
Fixed.


Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 
2008-02-09 02:10:36 UTC (rev 7462)
+++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 
2008-02-09 11:09:34 UTC (rev 7463)
@@ -1423,29 +1423,41 @@
     public String parseTemplate(String template, String skin, XWikiContext 
context)
     {
         try {
-            String path = "/skins/" + skin + "/" + template;
-            String content = getResourceContent(path);
-            return XWikiVelocityRenderer.evaluate(content, path, 
(VelocityContext) context
-                .get("vcontext"), context);
-        } catch (Exception e) {
-        }
-
-        try {
             XWikiDocument doc = getDocument(skin, context);
             if (!doc.isNew()) {
+                // Try parsing the object property
                 BaseObject object = doc.getObject("XWiki.XWikiSkins", 0);
                 if (object != null) {
                     String content = object.getStringValue(template);
-                    if ((content != null) && (!content.equals(""))) {
+                    if (!StringUtils.isBlank(content)) {
                         // Let's use this template
                         return XWikiVelocityRenderer.evaluate(content, skin + 
"#" + template,
                             (VelocityContext) context.get("vcontext"), 
context);
                     }
                 }
+                // Try parsing a document attachment
+                XWikiAttachment attachment = doc.getAttachment(template);
+                if (attachment != null) {
+                    String content = new 
String(attachment.getContent(context));
+                    if (!StringUtils.isBlank(content)) {
+                        // Let's use this template
+                        return XWikiVelocityRenderer.evaluate(content, skin + 
"+" + template,
+                            (VelocityContext) context.get("vcontext"), 
context);
+                    }
+                }
             }
         } catch (Exception e) {
         }
 
+        // Try parsing a file located in the directory with the same name.
+        try {
+            String path = "/skins/" + skin + "/" + template;
+            String content = getResourceContent(path);
+            return XWikiVelocityRenderer.evaluate(content, path, 
(VelocityContext) context
+                .get("vcontext"), context);
+        } catch (Exception e) {
+        }
+
         return null;
     }
 

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

Reply via email to