[xwiki-commits] r946 - in xwiki/trunk/src/main: java/com/xpn/xwiki/api java/com/xpn/xwiki/render/macro resources

jeremi joslin jeremi23 at gmail.com
Mon Feb 27 13:11:50 CET 2006


On 2/27/06, Ludovic Dubost <ludovic at users.forge.objectweb.org> wrote:
> Author: ludovic
> Date: 2006-02-27 13:00:00 +0100 (Mon, 27 Feb 2006)
> New Revision: 946
>
> Added:
>    xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/DisplayMacro.java
>    xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/UseMacro.java
> Modified:
>    xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
>    xwiki/trunk/src/main/resources/radeox_markup_xwiki.properties
> Log:
> Added $doc.use API which allows to set the object to be used by subsequent calls to $doc.DisplayMacro.java
> A {use:} macro has also been created as well as the {display:} macro which is equivalent to {field:}
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java   2006-02-27 11:55:00 UTC (rev 945)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java   2006-02-27 12:00:00 UTC (rev 946)
> @@ -54,6 +54,7 @@
>
>  public class Document extends Api {
>      private XWikiDocument doc;
> +    private Object currentObj;
>
>      public Document(XWikiDocument doc, XWikiContext context) {
>          super(context);
> @@ -420,7 +421,32 @@
>          }
>      }
>
> +    public void use(Object object) {
> +        currentObj = object;
> +    }
>
> +    public void use(String className) {
> +        currentObj = getObject(className);
> +    }
> +
> +    public void use(String className, int nb) {
> +        currentObj = getObject(className, nb);
> +    }
> +
> +    public String display(String fieldname) {
> +        if (currentObj==null)
> +         return doc.display(fieldname, context);
> +        else
> +         return doc.display(fieldname, "view", currentObj.getBaseObject(), context);
> +    }
> +
> +    public String display(String fieldname, String mode) {
> +        if (currentObj==null)
> +         return doc.display(fieldname, mode, context);
> +        else
> +         return doc.display(fieldname, mode, currentObj.getBaseObject(), context);
> +    }
> +
>      public String display(String fieldname, Object obj) {
>          if (obj==null)
>              return "";
> @@ -433,10 +459,6 @@
>          return doc.display(fieldname, mode, obj.getBaseObject(), context);
>      }
>
> -    public String display(String fieldname) {
> -        return doc.display(fieldname, context);
> -    }
> -
>      public String displayForm(String className,String header, String format) {
>          return doc.displayForm(className, header, format, context);
>      }
>
> Added: xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/DisplayMacro.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/DisplayMacro.java      2006-02-27 11:55:00 UTC (rev 945)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/DisplayMacro.java      2006-02-27 12:00:00 UTC (rev 946)
> @@ -0,0 +1,42 @@
> +/**
> + * ===================================================================
> + *
> + * Copyright (c) 2003,2004 Ludovic Dubost, All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU Lesser General Public License for more details, published at
> + * http://www.gnu.org/copyleft/lesser.html or in lesser.txt in the
> + * root folder of this distribution.
> +
> + * Created by
> + * User: Ludovic Dubost
> + * Date: 25 ao�t 2004
> + * Time: 13:43:19
> + */
> +package com.xpn.xwiki.render.macro;
> +
> +import java.io.IOException;
> +import java.io.Writer;
> +
> +import org.radeox.api.engine.RenderEngine;
> +import org.radeox.api.engine.context.RenderContext;
> +import org.radeox.macro.BaseLocaleMacro;
> +import org.radeox.macro.parameter.MacroParameter;
> +
> +import com.xpn.xwiki.XWikiContext;
> +import com.xpn.xwiki.doc.XWikiDocument;
> +import com.xpn.xwiki.objects.BaseObject;
> +import com.xpn.xwiki.render.XWikiRadeoxRenderEngine;
> +
> +public class DisplayMacro extends FieldMacro {
> +  public String getLocaleKey() {
> +    return "macro.display";
> +  }
> +}
>
> Added: xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/UseMacro.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/UseMacro.java  2006-02-27 11:55:00 UTC (rev 945)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/UseMacro.java  2006-02-27 12:00:00 UTC (rev 946)
> @@ -0,0 +1,71 @@
> +/**
> + * ===================================================================
> + *
> + * Copyright (c) 2003,2004 Ludovic Dubost, All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU Lesser General Public License for more details, published at
> + * http://www.gnu.org/copyleft/lesser.html or in lesser.txt in the
> + * root folder of this distribution.
> +
> + * Created by
> + * User: Ludovic Dubost
> + * Date: 25 ao�t 2004
> + * Time: 13:43:19
> + */
> +package com.xpn.xwiki.render.macro;
> +
> +import java.io.IOException;
> +import java.io.Writer;
> +
> +import org.radeox.api.engine.RenderEngine;
> +import org.radeox.api.engine.context.RenderContext;
> +import org.radeox.macro.BaseLocaleMacro;
> +import org.radeox.macro.parameter.MacroParameter;
> +import org.apache.velocity.VelocityContext;
> +
> +import com.xpn.xwiki.XWikiContext;
> +import com.xpn.xwiki.api.Document;
> +import com.xpn.xwiki.doc.XWikiDocument;
> +import com.xpn.xwiki.objects.BaseObject;
> +import com.xpn.xwiki.render.XWikiRadeoxRenderEngine;
> +
> +public class UseMacro extends BaseLocaleMacro {
> +  public String getLocaleKey() {
> +    return "macro.use";
> +  }
> +
> +  public void execute(Writer writer, MacroParameter params)
> +      throws IllegalArgumentException, IOException {
> +
> +    RenderContext context = params.getContext();
> +    RenderEngine engine = context.getRenderEngine();
> +    XWikiContext xcontext = ((XWikiRadeoxRenderEngine)engine).getContext();
> +    VelocityContext vcontext = (VelocityContext) context.get("vcontext");
> +    Document doc = (Document) vcontext.get("doc");
> +    com.xpn.xwiki.api.Object obj;
> +
> +      // We lookup the className for this object
> +    String classname = params.get("classname", 0);
> +
> +    // Optionnaly we see if it was asked for an object number
> +    String snb = params.get("nb", 1);
> +
> +    // We find the corresponding object
> +    if (snb!=null)
> +     obj = doc.getObject(classname, Integer.parseInt(snb));
> +    else
> +     obj = doc.getObject(classname);
> +
> +    // We assign this object as the used object
> +    // Future calls to doc.display() or {field} will make use of this object
> +    doc.use(obj);
> +  }
> +}
>
> Modified: xwiki/trunk/src/main/resources/radeox_markup_xwiki.properties
> ===================================================================
> --- xwiki/trunk/src/main/resources/radeox_markup_xwiki.properties       2006-02-27 11:55:00 UTC (rev 945)
> +++ xwiki/trunk/src/main/resources/radeox_markup_xwiki.properties       2006-02-27 12:00:00 UTC (rev 946)
> @@ -3,6 +3,7 @@
>  macro.image.name=image
>  macro.attach.name=attach
>  macro.field.name=field
> +macro.display.name=display
>  macro.form.name=form
>  macro.graphviz.name=graphviz
>  macro.laszlo.name=laszlo
>
>
>
>


Hi,
can you change the header to be the same as the others files and add
your name to @author?
(copyright to xpertnet)

Jérémi

--
Blog: http://www.jeremi.info
LinkedIn: https://www.linkedin.com/profile?viewProfile=&key=1437724
Project Manager XWiki: http://www.xwiki.org
skype: jeremi23 -- msn et gtalk : jeremi23 at gmail.com


More information about the Xwiki-notifications mailing list