r1685 - xwiki/trunk/core/src/main/java/com/xpn/xwiki/render/macro

Marta Girdea marta_girdea at users.forge.objectweb.org
Wed Dec 6 16:21:08 CET 2006


Author: marta_girdea
Date: 2006-12-06 16:21:07 +0100 (Wed, 06 Dec 2006)
New Revision: 1685

Modified:
   xwiki/trunk/core/src/main/java/com/xpn/xwiki/render/macro/ImageMacro.java
Log:
XWIKI-400: Need to find a way to center an image

Added the halign macro parameter.


Modified: xwiki/trunk/core/src/main/java/com/xpn/xwiki/render/macro/ImageMacro.java
===================================================================
--- xwiki/trunk/core/src/main/java/com/xpn/xwiki/render/macro/ImageMacro.java	2006-12-06 14:19:39 UTC (rev 1684)
+++ xwiki/trunk/core/src/main/java/com/xpn/xwiki/render/macro/ImageMacro.java	2006-12-06 15:21:07 UTC (rev 1685)
@@ -37,12 +37,15 @@
 /**
  * Macro that displays images.
  * 
- * Syntax: {image:text|height|width|align|document|alt|title|link|fromIncludingDoc}
+ * Syntax: {image:text|height|width|align|halign|float|document|alt|title|link|fromIncludingDoc}
  * <ul>
  * <li>text: The target filename.</li>
  * <li>height: The height attribute of the img.</li>
  * <li>width: The width attribute of the img.</li>
  * <li>align: The align attribute of the img.</li>
+ * <li>halign: Horizontal alignment for the image. If missing, 
+ *   the image is displayed inline. Accepted values:
+ *   floatleft, left, center, right, floatright</li>
  * <li>document: The document to which the file is attached. If missing, 
  *   the current document is used.</li>
  * <li>alt: The alt attribute of the link. If missing, title is used.
@@ -83,23 +86,27 @@
         if (null == align || align.indexOf("=") != -1) {
             align = null;
         }
-        String document = params.get("document", 4);
+        String halign = params.get("halign", 4);
+        if (null == align || align.indexOf("=") != -1) {
+            align = null;
+        }
+        String document = params.get("document", 5);
         if (null == document || document.indexOf("=") != -1) {
             document = null;
         }
-        String alt = params.get("alt", 5);
+        String alt = params.get("alt", 6);
         if (null == alt || alt.indexOf("=") != -1) {
             alt = null;
         }
-        String title = params.get("title", 6);
+        String title = params.get("title", 7);
         if (null == title || title.indexOf("=") != -1) {
             title = null;
         }
-        String link = params.get("link", 7);
+        String link = params.get("link", 8);
         if (null == link || link.indexOf("=") != -1 || link.toLowerCase().startsWith("f")) {
             link = null;
         }
-        String useIncluder = params.get("fromIncludingDoc", 8);
+        String useIncluder = params.get("fromIncludingDoc", 9);
         if (null == useIncluder || useIncluder.indexOf("=") != -1 || useIncluder.toLowerCase().startsWith("f")) {
             useIncluder = null;
         }
@@ -134,6 +141,9 @@
 
         // Create the img code
         StringBuffer str = new StringBuffer();
+        if (halign != null && !halign.equals("none")){
+            str.append("<div class=\"img" + halign.trim() + "\">");
+        }
         if (link != null) {
             str.append("<a href=\"" + doc.getAttachmentURL(img, "download", xcontext) + "\">");
         }
@@ -162,7 +172,9 @@
         if (link != null) {
             str.append("</a>");
         }
-
+        if (halign != null && !halign.equals("none")){
+            str.append("</div>");
+        }
         // All done, flush the StringBufer
         writer.write(str.toString());
     }





More information about the Xwiki-notifications mailing list