Hi devs,
Following "[VOTE] Move component related events to their own project"
I also need to separate api and implementation in observation project
because component-observation depends on observation api and i need to
make observation manager listen to component events which mean
depending on component-observation.
Here is my +1
Thanks,
--
Thomas Mortagne
I seem to have DNS problems on myxwiki. I can't yet tell if this is a problem with foafssl.org
or with myxwiki.org, but I think it is with xwiki. Below is an extract of what Dirk
(Chief Architect of the BBC) has to say
On 14 Sep 2010, at 21:08, Dirk-Willem van Gulik wrote:
> Op 14 sep 2010, om 21:59 heeft Henry Story het volgende geschreven:
>
>> That has not been updated for a while it seems, since 2000 at least
>> http://sourceforge.net/projects/dnswalk/files/
>
> I suspect that DNS has not changed that much since then.
>
>> # dig ns myxwiki.org
>>
>> ; <<>> DiG 9.3.3rc2 <<>> ns myxwiki.org
>
> Ok.
>
>> ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 3
>
> So an answer; but whatever answers is not authoritive.
>>
>> myxwiki.org. 8 IN NS lanai.xpertnet.biz.
>> myxwiki.org. 8 IN NS maui.xpertnet.biz.
>> myxwiki.org. 8 IN NS ns-fr.xpertnet.biz.
>>
> These should be auhtoriative.
>>
>> # dig -t any @maui.xpertnet.biz
>
> So you are asking these.
>
>> ;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 0
>
> And no answer.
>
>> ;; AUTHORITY SECTION:
>> . 518400 IN NS A.ROOT-SERVERS.NET.
>>
> And defers you to the root servers. And it is sure of that.
>
> -> conclusion - this guy is not configured as your dns server; i.e. it does not know your zone.
>
>> # dig -t any @ns-fr.xpertnet.biz
>> [[ AT THIS POINT IT HANGS FOR A WHILE]]
>> ; <<>> DiG 9.3.3rc2 <<>> -t any @ns-fr.xpertnet.biz
>> ; (1 server found)
>> ;; global options: printcmd
>> ;; connection timed out; no servers could be reached
>
> And this guy is not running at all. Or in other words - your entire domain is foobar - but luckily not with huge TTL's or anything - so it is not hard to recover; either have the authoritive servers fixed - or move it somewhere else. If you are stuck - let me know - happy to run some zones over here or pull zones from SVN/hidden-master.
If I run this from a server in Ireland I get
$ dig -t any @ns-fr.xpertnet.biz
; <<>> DiG 9.6.0-APPLE-P2 <<>> -t any @ns-fr.xpertnet.biz
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 55036
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;. IN NS
;; Query time: 39 msec
;; SERVER: 188.165.123.33#53(188.165.123.33)
;; WHEN: Tue Sep 14 22:31:55 2010
;; MSG SIZE rcvd: 17
Which sounds like the problem is the same here.
>
> Dw.
Social Web Architect
http://bblfish.net/
I removed a method which was inaccessible to any code which might
use it:
protected BaseProperty getBaseProperty()
and made final a field which is not altered anywhere.
Assuming nobody has extended c.x.x.api.* these are not api breaks.
I would like to block clierr from breaking the build rather than
merging out this change.
WDYT?
Caleb
cjdelisle (SVN) wrote:
> Author: cjdelisle
> Date: 2010-09-14 12:03:32 +0200 (Tue, 14 Sep 2010)
> New Revision: 31093
>
> Modified:
> platform/core/trunk/xwiki-core/pom.xml
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Element.java
> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Property.java
> Log:
> [cleanup] Documented c.x.x.api.Property, removed an unnecessary override and an unusable method, and made an un-reassignable field final.
>
> Modified: platform/core/trunk/xwiki-core/pom.xml
> ===================================================================
> --- platform/core/trunk/xwiki-core/pom.xml 2010-09-14 09:14:38 UTC (rev 31092)
> +++ platform/core/trunk/xwiki-core/pom.xml 2010-09-14 10:03:32 UTC (rev 31093)
> @@ -896,7 +896,6 @@
> **/api/Document.java,
> **/api/DocumentSection.java,
> **/api/Object.java,
> - **/api/Property.java,
> **/api/Util.java,
> **/api/XWiki.java,
> **/atom/lifeblog/LifeblogServices.java,
>
> Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Element.java
> ===================================================================
> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Element.java 2010-09-14 09:14:38 UTC (rev 31092)
> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Element.java 2010-09-14 10:03:32 UTC (rev 31093)
> @@ -33,7 +33,7 @@
> public class Element extends Api
> {
> /** The internal element which this wraps. */
> - protected BaseElement element;
> + protected final BaseElement element;
>
> /**
> * The Constructor.
>
> Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Property.java
> ===================================================================
> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Property.java 2010-09-14 09:14:38 UTC (rev 31092)
> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Property.java 2010-09-14 10:03:32 UTC (rev 31093)
> @@ -18,28 +18,33 @@
> * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> *
> */
> +
> package com.xpn.xwiki.api;
>
> import com.xpn.xwiki.XWikiContext;
> import com.xpn.xwiki.objects.BaseProperty;
>
> +/**
> + * Property is a single attribute of an XWiki {@link com.xpn.xwiki.api.Object}.
> + *
> + * @version $Id$
> + */
> public class Property extends Element
> {
> + /**
> + * The Constructor.
> + *
> + * @param property the internal {@link com.xpn.xwiki.objects.BaseProperty} to wrap.
> + * @param context the XWikiContext which may be used to get information about the current request.
> + */
> public Property(BaseProperty property, XWikiContext context)
> {
> super(property, context);
> }
>
> - protected BaseProperty getBaseProperty()
> - {
> - return (BaseProperty) element;
> - }
> -
> - public String getName()
> - {
> - return element.getName();
> - }
> -
> + /**
> + * @return the internal {@link com.xpn.xwiki.objects.BaseProperty} which this Property wraps.
> + */
> public BaseProperty getProperty()
> {
> if (hasProgrammingRights()) {
> @@ -49,8 +54,12 @@
> }
> }
>
> + /**
> + * @return the actual value of the property, as a String, Number or List.
> + */
> public java.lang.Object getValue()
> {
> + // This is evil, any property which happens to be called 'password' will be masked. TODO fix.
> if (element.getName().equals("password")
> && !getXWikiContext().getWiki().getRightService().hasProgrammingRights(
> getXWikiContext())) {
>
> _______________________________________________
> notifications mailing list
> notifications(a)xwiki.org
> http://lists.xwiki.org/mailman/listinfo/notifications
>
Hi devs,
I've been working on a CSRF protection mechanism for quite some time.
It is based on so called secret tokens (also called nonces) that are
included into forms and links and checked on server side. The
implementation allows to resubmit a failed request (e.g. in case the
user is logged out in the meanwhile), so that the data is not lost in
case of bugs.
JIRA issue:
http://jira.xwiki.org/jira/browse/XWIKI-4873
Component implementation:
http://svn.xwiki.org/svnroot/xwiki/contrib/sandbox/xwiki-csrftoken/
Old proposal:
http://lists.xwiki.org/pipermail/devs/2010-March/017727.html
I think it is time to move the CSRF component to the main repository and
start using it everywhere. The protection will be disabled by default
until all bugs are fixed.
The steps to do would be:
1. Move CSRF token component to platform
2. Fix all templates to use CSRF tokens
3. Fix all applications to use CSRF tokens
4. Fix all actions to check CSRF tokens
5. Fix all integration tests to work with enabled CSRF protection
I have patches for steps 2-4, but NOT for 5. Many (about 30-40 last time
I counted) integration tests still fail with enabled CSRF protection,
because they (mis)use CSRF to set up tests (edit/create pages).
Here is my +1
WDYT?
Thanks,
Alex
Hi xwikiers,
Since May and actively since end of August I'm working on a POC for
the future (long awaited) Extension Manager. It's now in a state where
you can play with it a bit !
So here is a quick advertisement.
You can find it on
http://svn.xwiki.org/svnroot/xwiki/contrib/sandbox/xwiki-extension/
What it does already:
- display remote extension and its dependencies as a tree
- install remote extension and its dependencies from repositories
- framework support any kind of extension using ExtensionInstaller
component interface but only jar installer is implemented right now
- framework support any kind of repository using RepositoryFactory
component interface but only maven is implemented right now
- load installed application when XWiki starts
Critical features not yet supported:
- miscellaneous rights protections in extension manager script service
- uninstall/upgrade support: need to find a way to remove a jar from
classloader. Note that you can remove an extension from local
repository and restart.
- xar installer: just need to provide a ExtensionInstaller
implementation with role hint "xar" since this needs access to the
whole model the first version will probably be implemented with old
APIs (XWikiDocument, etc.) on xwiki-core side
- install extension not coming from a repository: the current API is
very repository centric but you can do it "by hand" by putting
directly the extension jar file in the local repository.
- real descriptors in local repository for installed extensions (to
store in a repository independent way extension information as well as
some local only metadas like the fact that an extension as been
installed as a dependency of another etc.)
- others on http://svn.xwiki.org/svnroot/xwiki/contrib/sandbox/xwiki-extension/README.t…
I'm preparing some design documentation that will go on
http://dev.xwiki.org/xwiki/bin/view/Design/ExtensionManagerProposal
but i don't have much time right now so it will probably be tomorrow
(GMT).
The current state is not final at all but it still introduce a lot of
APIs and design, lets call it an over designed POC. It needs to be
discussed in all it's aspects before having its experimental tag
removed. The plan is to distribute it with XE coming with 2.5 whatever
it's state (when it does not represent a risk for XE obviously) as an
experimental playground with all the required warnings in the UI and
promote it when we are happy with a first version.
Thanks,
--
Thomas Mortagne
Although this makes sense from a code and organisation POV, I don't think it makes sense from a user POV.
Personally I'd prefer to keep the old style since it's less confusing for users and more logical. I know there's a risk of namespace clash but it's very small and can be solved by changing property names if need be.
What do others think?
I'm not too hung up on this but I want to make it as easy as possible for users and prevent the "WTF?" feeling (aka as the "don't make me think" feeling) :)
Thanks
-Vincent
On Sep 14, 2010, at 9:00 AM, mflorea (SVN) wrote:
> Author: mflorea
> Date: 2010-09-14 09:00:57 +0200 (Tue, 14 Sep 2010)
> New Revision: 31088
>
> Modified:
> platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm
> Log:
> XTCONFRES-50: Add configuration for including image dimensions in the image URL and for limiting image dimensions
> * Changed "rendering." prefix to "rendering.xwiki." for XWiki-specific rendering configuration properties
>
>
> Modified: platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm
> ===================================================================
> --- platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm 2010-09-14 06:58:39 UTC (rev 31087)
> +++ platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm 2010-09-14 07:00:57 UTC (rev 31088)
> @@ -68,7 +68,7 @@
> #-# downloaded, improving thus the page loading speed.
> #-#
> #-# Default value is true.
> -# rendering.includeImageDimensionsInImageURL = true
> +# rendering.xwiki.imageDimensionsIncludedInImageURL = true
>
> #-# [Since 2.5M2]
> #-# One way to improve page load speed is to resize images on the server side just before rendering the page. The
> @@ -79,13 +79,13 @@
> #-# The default value is -1 which means image width is not limited by default. Use a value greater than 0 to limit the
> #-# image width (pixels). Note that the aspect ratio is kept even when both the width and the height of the image are
> #-# limited.
> -# rendering.imageWidthLimit = 1024
> -# rendering.imageWidthLimit = -1
> +# rendering.xwiki.imageWidthLimit = 1024
> +# rendering.xwiki.imageWidthLimit = -1
>
> #-# [Since 2.5M2]
> #-# See rendering.imageWidthLimit
> -# rendering.imageHeightLimit = 768
> -# rendering.imageHeightLimit = -1
> +# rendering.xwiki.imageHeightLimit = 768
> +# rendering.xwiki.imageHeightLimit = -1
>
> #-------------------------------------------------------------------------------------
> # Cache
>
Hi Alex,
All commits that fix something or make some changes (except refactoring, ie same behavior, just internal way the code is written) must reference a jira issue.
If this problem was caused by some changes in the trunk that wasn't released yet, you should use the same jira issue. If it's a fix over some previously released version then it needs a new jira issue. The idea is that a user who looks at the release notes must be able to see what was modified vs the version he has.
Thanks
-Vincent
On Sep 11, 2010, at 7:15 PM, abusenius (SVN) wrote:
> Author: abusenius
> Date: 2010-09-11 19:15:10 +0200 (Sat, 11 Sep 2010)
> New Revision: 31048
>
> Modified:
> platform/web/trunk/standard/src/main/webapp/templates/editobject.vm
> Log:
> [misc] Fixed broken URL
>
> Modified: platform/web/trunk/standard/src/main/webapp/templates/editobject.vm
> ===================================================================
> --- platform/web/trunk/standard/src/main/webapp/templates/editobject.vm 2010-09-11 02:32:40 UTC (rev 31047)
> +++ platform/web/trunk/standard/src/main/webapp/templates/editobject.vm 2010-09-11 17:15:10 UTC (rev 31048)
> @@ -16,7 +16,7 @@
> #macro(displayObject $obj $class $props $firstfield)
> <div id="xobject_${escapetool.xml($class.name)}_${obj.number}" class="xobject">
> <div id="xobject_${escapetool.xml($class.name)}_${obj.number}_title" class="xobject-title"><h3>#cleanClassname(${class.name}) ${obj.number}: $!{escapetool.xml($doc.display($firstfield, $obj))}
> - <a href="$doc.getURL('objectremove', "classname=${escapetool.url($class.name)}&classid=${obj.number}&xredirect=${doc.getURL('edit', 'editor=object')}")" class="xobject-action delete" title="$msg.get('core.editors.object.removeObject.tooltip')">$msg.get('core.editors.object.removeObject')</a>
> + <a href="$doc.getURL('objectremove', "classname=${escapetool.url($class.name)}&classid=${obj.number}&xredirect=${escapetool.url($doc.getURL('edit', 'editor=object'))}")" class="xobject-action delete" title="$msg.get('core.editors.object.removeObject.tooltip')">$msg.get('core.editors.object.removeObject')</a>
> #if(!$hasCustomObject) <a href="$doc.getURL("edit", "editor=object&classname=${escapetool.url($class.name)}&object=${obj.number}")" class="xobject-action edit" title="$msg.get('core.editors.object.editSingleObject.tooltip')">$msg.get('core.editors.object.editSingleObject')</a> #end
> </h3></div>
> <div id="xobject_${escapetool.xml($class.name)}_${obj.number}_content" class="xobject-content"><div>
Hi Marius,
I think there are some changes we need to discuss in this commit:
- new config api methods
- new wiki model api methods
- new deps introduced in the rendering module (makes it harder to use without maven)
These 2 are important as they are important public apis. The WikiModel one is the most important and we need to be 100% sure we want to add a new methods. There must absolutely be the minimal number of methods in this class. Also we're going to break people using the rendering module outside of xwiki (guys from eXo for example, so we need to be careful).
I haven't thought too much about it yet but my first feeling is that the methods added look quite specific. I'd like to have Thomas's opinion on this since he's the one who's the most knowledgeable about the rendering module.
Thanks
-Vincent
On Sep 12, 2010, at 1:30 PM, mflorea (SVN) wrote:
> Author: mflorea
> Date: 2010-09-12 13:30:15 +0200 (Sun, 12 Sep 2010)
> New Revision: 31053
>
> Modified:
> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/configuration/RenderingConfiguration.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/configuration/DefaultRenderingConfiguration.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/DefaultXHTMLImageRenderer.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/wiki/WikiModel.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/pom.xml
> platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfiguration.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/wiki/XWikiWikiModel.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfigurationTest.java
> platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/wiki/XWikiWikiModelTest.java
> Log:
> XWIKI-5479: Include image dimensions in the image URL for server side image resizing
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/configuration/RenderingConfiguration.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/configuration/RenderingConfiguration.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/configuration/RenderingConfiguration.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -50,7 +50,7 @@
> * </ul>
> * Note that if the page title is empty or not defined then it defaults to %p. This is also the case
> * if the title cannot be retrieved for the document.
> - *
> + *
> * The default is "%p". Some examples: "%s.%p", "%w:%s.%p".
> *
> * @return the format to use to display link labels when the user hasn't specified a label
> @@ -63,4 +63,42 @@
> * descriptor (ie defined by the macro author) will be used
> */
> Properties getMacroCategories();
> +
> + /**
> + * @return {@code true} to include the image dimensions extracted from the image parameters in the image URL,
> + * {@code false} otherwise; when image dimensions are included in the image URL the image can be resized
> + * on the server side before being downloaded.
> + * @since 2.5M2
> + */
> + boolean isIncludeImageDimensionsInImageURL();
> +
> + /**
> + * One way to improve page load speed is to resize images on the server side just before rendering the page. The
> + * rendering module can use the image width provided by the user to scale the image. When the user doesn't specify
> + * the image width the rendering module can limit the width of the image based on this configuration parameter.
> + * <p>
> + * The default value is {@code -1} which means image width is not limited by default. Use a value greater than 0 to
> + * limit the image width (pixels). Note that the aspect ratio is kept even when both the width and the height of the
> + * image are limited.
> + *
> + * @return the maximum image width when there's no user supplied width
> + * @see #isIncludeImageDimensionsInImageURL()
> + * @since 2.5M2
> + */
> + int getImageWidthLimit();
> +
> + /**
> + * One way to improve page load speed is to resize images on the server side just before rendering the page. The
> + * rendering module can use the image height provided by the user to scale the image. When the user doesn't specify
> + * the image height the rendering module can limit the height of the image based on this configuration parameter.
> + * <p>
> + * The default value is {@code -1} which means image height is not limited by default. Use a value greater than 0 to
> + * limit the image height (pixels). Note that the aspect ratio is kept even when both the width and the height of
> + * the image are limited.
> + *
> + * @return the maximum image height when there's no user supplied height
> + * @see #isIncludeImageDimensionsInImageURL()
> + * @since 2.5M2
> + */
> + int getImageHeightLimit();
> }
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/configuration/DefaultRenderingConfiguration.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/configuration/DefaultRenderingConfiguration.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/configuration/DefaultRenderingConfiguration.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -45,6 +45,21 @@
> private Properties macroCategories = new Properties();
>
> /**
> + * @see #getImageWidthLimit()
> + */
> + private int imageWidthLimit = -1;
> +
> + /**
> + * @see #getImageHeightLimit()
> + */
> + private int imageHeightLimit = -1;
> +
> + /**
> + * @see #isIncludeImageDimensionsInImageURL()
> + */
> + private boolean includeImageDimensionsInImageURL = true;
> +
> + /**
> * {@inheritDoc}
> *
> * @see org.xwiki.rendering.configuration.RenderingConfiguration#getLinkLabelFormat()
> @@ -84,4 +99,66 @@
> // to work even without a configuration store.
> this.macroCategories.setProperty(macroId.toString(), category);
> }
> +
> + /**
> + * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.configuration.RenderingConfiguration#getImageWidthLimit()
> + */
> + public int getImageWidthLimit()
> + {
> + return this.imageWidthLimit;
> + }
> +
> + /**
> + * @param imageWidthLimit the maximum image width when there's no user supplied width
> + */
> + public void setImageWidthLimit(int imageWidthLimit)
> + {
> + // This method is useful for those using the XWiki Rendering in standalone mode since it allows the rendering
> + // to work even without a configuration store.
> + this.imageWidthLimit = imageWidthLimit;
> + }
> +
> + /**
> + * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.configuration.RenderingConfiguration#getImageHeightLimit()
> + */
> + public int getImageHeightLimit()
> + {
> + return this.imageHeightLimit;
> + }
> +
> + /**
> + * @param imageHeightLimit the maximum image height when there's no user supplied height
> + */
> + public void setImageHeightLimit(int imageHeightLimit)
> + {
> + // This method is useful for those using the XWiki Rendering in standalone mode since it allows the rendering
> + // to work even without a configuration store.
> + this.imageHeightLimit = imageHeightLimit;
> + }
> +
> + /**
> + * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.configuration.RenderingConfiguration#isIncludeImageDimensionsInImageURL()
> + */
> + public boolean isIncludeImageDimensionsInImageURL()
> + {
> + return this.includeImageDimensionsInImageURL;
> + }
> +
> + /**
> + * @param includeImageDimensionsInImageURL {@code true} to include image dimensions extracted from the image
> + * parameters in the image URL so that the image can be resized on the server side before being
> + * downloaded, {@code false} otherwise
> + */
> + public void setIncludeImageDimensionsInImageURL(boolean includeImageDimensionsInImageURL)
> + {
> + // This method is useful for those using the XWiki Rendering in standalone mode since it allows the rendering
> + // to work even without a configuration store.
> + this.includeImageDimensionsInImageURL = includeImageDimensionsInImageURL;
> + }
> }
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/DefaultXHTMLImageRenderer.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/DefaultXHTMLImageRenderer.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/DefaultXHTMLImageRenderer.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -42,10 +42,9 @@
> * Default implementation for rendering images as XHTML. We handle both cases:
> * <ul>
> * <li>when inside a wiki (ie when an implementation of {@link WikiModel} is provided.</li>
> - * <li>when outside of a wiki. In this case we only handle external images and document images don't
> - * display anything.</li>
> + * <li>when outside of a wiki. In this case we only handle external images and document images don't display anything.</li>
> * </ul>
> - *
> + *
> * @version $Id$
> * @since 2.0M3
> */
> @@ -68,6 +67,7 @@
>
> /**
> * {@inheritDoc}
> + *
> * @see Initializable#initialize()
> */
> public void initialize() throws InitializationException
> @@ -83,7 +83,7 @@
>
> /**
> * {@inheritDoc}
> - *
> + *
> * @see XHTMLImageRenderer#setXHTMLWikiPrinter(XHTMLWikiPrinter)
> */
> public void setXHTMLWikiPrinter(XHTMLWikiPrinter printer)
> @@ -103,7 +103,7 @@
>
> /**
> * {@inheritDoc}
> - *
> + *
> * @see XHTMLImageRenderer#onImage(Image, boolean, Map)
> */
> public void onImage(Image image, boolean isFreeStandingURI, Map<String, String> parameters)
> @@ -118,8 +118,9 @@
> // that would not honor this contract.
> if (this.wikiModel != null) {
> DocumentImage documentImage = DocumentImage.class.cast(image);
> - imageURL = this.wikiModel.getAttachmentURL(documentImage.getDocumentName(),
> - documentImage.getAttachmentName());
> + imageURL =
> + this.wikiModel.getImageURL(documentImage.getDocumentName(), documentImage.getAttachmentName(),
> + parameters);
> } else {
> throw new RuntimeException("Invalid Image type. In non wiki mode, all image types must be URL images.");
> }
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/wiki/WikiModel.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/wiki/WikiModel.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/wiki/WikiModel.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -19,13 +19,15 @@
> */
> package org.xwiki.rendering.wiki;
>
> +import java.util.Map;
> +
> import org.xwiki.component.annotation.ComponentRole;
>
> /**
> * Bridge between the Rendering module and a Wiki Model. Contains wiki APIs required by Rendering classes such as
> - * Renderers. For example the XHTML Link Renderer needs to know if a wiki document exists in order to know how to
> - * generate the HTML (in order to display a question mark for non existing documents) and it also needs to get the
> - * URL pointing the wiki document.
> + * Renderers. For example the XHTML Link Renderer needs to know if a wiki document exists in order to know how to
> + * generate the HTML (in order to display a question mark for non existing documents) and it also needs to get the URL
> + * pointing the wiki document.
> *
> * @version $Id$
> * @since 2.0M1
> @@ -34,36 +36,48 @@
> public interface WikiModel
> {
> /**
> - * @param documentName the document name of the document containing the attachment. The syntax used depends on
> - * the underlying wiki system used. For example for XWiki a valid documentName would be
> - * {@code wiki:Space.Page}
> + * @param documentName the document name of the document containing the attachment. The syntax used depends on the
> + * underlying wiki system used. For example for XWiki a valid documentName would be
> + * {@code wiki:Space.Page}
> * @param attachmentName the name of the attachment in the passed document wikip page
> * @return the URL to the attachment
> */
> String getAttachmentURL(String documentName, String attachmentName);
>
> /**
> - * @param documentName the document name as a String. The syntax used depends on
> - * the underlying wiki system used. For example for XWiki a valid documentName would be
> - * {@code wiki:Space.Page}
> + * Generate image specific URL. The difference with {@link #getAttachmentURL(String, String)} is that in some
> + * implementation we want to make a distinction between displayed image and a simple link targeting an attachment
> + * file.
> + *
> + * @param documentName the document name of the document containing the attachment. The syntax used depends on the
> + * underlying wiki system used. For example for XWiki a valid documentName would be
> + * {@code wiki:Space.Page}
> + * @param attachmentName the name of the attachment in the passed document wiki page
> + * @param parameters custom parameters
> + * @return the URL to the image
> + * @since 2.5M2
> + */
> + String getImageURL(String documentName, String attachmentName, Map<String, String> parameters);
> +
> + /**
> + * @param documentName the document name as a String. The syntax used depends on the underlying wiki system used.
> + * For example for XWiki a valid documentName would be {@code wiki:Space.Page}
> * @return true if the document exists and can be viewed or false otherwise
> */
> boolean isDocumentAvailable(String documentName);
>
> /**
> - * @param documentName the document name as a String. The syntax used depends on
> - * the underlying wiki system used. For example for XWiki a valid documentName would be
> - * {@code wiki:Space.Page}
> + * @param documentName the document name as a String. The syntax used depends on the underlying wiki system used.
> + * For example for XWiki a valid documentName would be {@code wiki:Space.Page}
> * @param anchor an anchor pointing to some place inside the document or null
> * @param queryString a query string specifying some parameters or null
> * @return the URL to view the specified wiki document
> */
> String getDocumentViewURL(String documentName, String anchor, String queryString);
> -
> +
> /**
> - * @param documentName the document name as a String. The syntax used depends on
> - * the underlying wiki system used. For example for XWiki a valid documentName would be
> - * {@code wiki:Space.Page}
> + * @param documentName the document name as a String. The syntax used depends on the underlying wiki system used.
> + * For example for XWiki a valid documentName would be {@code wiki:Space.Page}
> * @param anchor an anchor pointing to some place inside the document or null
> * @param queryString a query string specifying some parameters or null
> * @return the URL to edit the specified wiki document
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/pom.xml
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/pom.xml 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/pom.xml 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -54,6 +54,12 @@
> <artifactId>xwiki-core-script</artifactId>
> <version>${pom.version}</version>
> </dependency>
> + <dependency>
> + <!-- For parsing the CSS from the style attribute. -->
> + <groupId>net.sourceforge.cssparser</groupId>
> + <artifactId>cssparser</artifactId>
> + <version>0.9.5</version>
> + </dependency>
> <!-- Testing dependencies -->
> <dependency>
> <groupId>org.xwiki.platform</groupId>
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfiguration.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfiguration.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfiguration.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -19,13 +19,13 @@
> */
> package org.xwiki.rendering.internal.configuration;
>
> +import java.util.Properties;
> +
> import org.xwiki.component.annotation.Component;
> import org.xwiki.component.annotation.Requirement;
> import org.xwiki.configuration.ConfigurationSource;
> import org.xwiki.rendering.configuration.RenderingConfiguration;
>
> -import java.util.Properties;
> -
> /**
> * All configuration options for the rendering subsystem.
> *
> @@ -46,7 +46,7 @@
> private static final String DEFAULT_LINK_LABEL_FORMAT = "%p";
>
> /**
> - * Defines from where to read the rendering configuration data.
> + * Defines from where to read the rendering configuration data.
> */
> @Requirement
> private ConfigurationSource configuration;
> @@ -58,16 +58,46 @@
> */
> public String getLinkLabelFormat()
> {
> - return this.configuration.getProperty(PREFIX + "linkLabelFormat", DEFAULT_LINK_LABEL_FORMAT);
> + return this.configuration.getProperty(PREFIX + "linkLabelFormat", DEFAULT_LINK_LABEL_FORMAT);
> }
>
> /**
> * {@inheritDoc}
> - *
> + *
> * @see org.xwiki.rendering.configuration.RenderingConfiguration#getMacroCategories()
> */
> public Properties getMacroCategories()
> {
> return this.configuration.getProperty(PREFIX + "macroCategories", Properties.class);
> }
> +
> + /**
> + * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.configuration.RenderingConfiguration#getImageWidthLimit()
> + */
> + public int getImageWidthLimit()
> + {
> + return this.configuration.getProperty(PREFIX + "imageWidthLimit", -1);
> + }
> +
> + /**
> + * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.configuration.RenderingConfiguration#getImageHeightLimit()
> + */
> + public int getImageHeightLimit()
> + {
> + return this.configuration.getProperty(PREFIX + "imageHeightLimit", -1);
> + }
> +
> + /**
> + * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.configuration.RenderingConfiguration#isIncludeImageDimensionsInImageURL()
> + */
> + public boolean isIncludeImageDimensionsInImageURL()
> + {
> + return this.configuration.getProperty(PREFIX + "includeImageDimensionsInImageURL", true);
> + }
> }
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/wiki/XWikiWikiModel.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/wiki/XWikiWikiModel.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/main/java/org/xwiki/rendering/internal/wiki/XWikiWikiModel.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -19,17 +19,25 @@
> */
> package org.xwiki.rendering.internal.wiki;
>
> +import java.io.IOException;
> +import java.io.StringReader;
> import java.io.UnsupportedEncodingException;
> import java.net.URLEncoder;
> +import java.util.Map;
>
> import org.apache.commons.lang.StringUtils;
> +import org.w3c.css.sac.InputSource;
> +import org.w3c.dom.css.CSSStyleDeclaration;
> import org.xwiki.bridge.DocumentAccessBridge;
> -import org.xwiki.model.reference.DocumentReference;
> import org.xwiki.component.annotation.Component;
> import org.xwiki.component.annotation.Requirement;
> +import org.xwiki.model.reference.DocumentReference;
> import org.xwiki.model.reference.EntityReferenceSerializer;
> +import org.xwiki.rendering.configuration.RenderingConfiguration;
> import org.xwiki.rendering.wiki.WikiModel;
>
> +import com.steadystate.css.parser.CSSOMParser;
> +
> /**
> * Implementation using the Document Access Bridge ({@link DocumentAccessBridge}).
> *
> @@ -39,14 +47,47 @@
> @Component
> public class XWikiWikiModel implements WikiModel
> {
> + /**
> + * The suffix used to mark an amount of pixels.
> + */
> + private static final String PIXELS = "px";
> +
> + /**
> + * The name of the {@code width} image parameter.
> + */
> + private static final String WIDTH = "width";
> +
> + /**
> + * The name of the {@code height} image parameter.
> + */
> + private static final String HEIGHT = "height";
> +
> + /**
> + * The component used to access configuration parameters.
> + */
> @Requirement
> + private RenderingConfiguration renderingConfiguration;
> +
> + /**
> + * The component used to access the underlying XWiki model.
> + */
> + @Requirement
> private DocumentAccessBridge documentAccessBridge;
>
> + /**
> + * The component used to serialize entity references to strings.
> + */
> @Requirement
> private EntityReferenceSerializer<String> entityReferenceSerializer;
>
> /**
> + * The object used to parse the CSS from the image style parameter.
> + */
> + private final CSSOMParser cssParser = new CSSOMParser();
> +
> + /**
> * {@inheritDoc}
> + *
> * @see WikiModel#getAttachmentURL(String, String)
> */
> public String getAttachmentURL(String documentName, String attachmentName)
> @@ -55,7 +96,112 @@
> }
>
> /**
> + * Extracts the specified image dimension from the image parameters.
> + *
> + * @param dimension either {@code width} or {@code height}
> + * @param imageParameters the image parameters; may include the {@code width}, {@code height} and {@code style}
> + * parameters
> + * @return the value of the passed dimension if it is specified in the image parameters, {@code null} otherwise
> + */
> + private String getImageDimension(String dimension, Map<String, String> imageParameters)
> + {
> + // Check first if the style parameter contains information about the given dimension. In-line style has priority
> + // over the dimension parameters.
> + String value = null;
> + String style = imageParameters.get("style");
> + if (StringUtils.isNotBlank(style)) {
> + try {
> + CSSStyleDeclaration sd = cssParser.parseStyleDeclaration(new InputSource(new StringReader(style)));
> + value = sd.getPropertyValue(dimension);
> + } catch (IOException e) {
> + // Ignore the style parameter.
> + }
> + }
> + if (StringUtils.isBlank(value)) {
> + // Fall back on the value of the dimension parameter.
> + value = imageParameters.get(dimension);
> + }
> + return value;
> + }
> +
> + /**
> + * Creates the query string that can be added to an image URL to resize the image on the server side.
> + *
> + * @param imageParameters image parameters, including width and height then they are specified
> + * @return the query string to be added to an image URL in order to resize the image on the server side
> + */
> + private StringBuilder getImageURLQueryString(Map<String, String> imageParameters)
> + {
> + String width = StringUtils.chomp(getImageDimension(WIDTH, imageParameters), PIXELS);
> + String height = StringUtils.chomp(getImageDimension(HEIGHT, imageParameters), PIXELS);
> + boolean useHeight = StringUtils.isNotEmpty(height) && StringUtils.isNumeric(height);
> + StringBuilder queryString = new StringBuilder();
> + if (StringUtils.isEmpty(width) || !StringUtils.isNumeric(width)) {
> + // Width is unspecified or is not measured in pixels.
> + if (useHeight) {
> + // Height is specified in pixels.
> + queryString.append('&').append(HEIGHT).append('=').append(height);
> + } else {
> + // If image width and height are unspecified or if they are not expressed in pixels then limit the image
> + // size to best fit the rectangle specified in the configuration (keeping aspect ratio).
> + int widthLimit = renderingConfiguration.getImageWidthLimit();
> + if (widthLimit > 0) {
> + queryString.append('&').append(WIDTH).append('=').append(widthLimit);
> + }
> + int heightLimit = renderingConfiguration.getImageHeightLimit();
> + if (heightLimit > 0) {
> + queryString.append('&').append(HEIGHT).append('=').append(heightLimit);
> + }
> + if (widthLimit > 0 && heightLimit > 0) {
> + queryString.append("&keepAspectRatio=").append(true);
> + }
> + }
> + } else {
> + // Width is specified in pixels.
> + queryString.append('&').append(WIDTH).append('=').append(width);
> + if (useHeight) {
> + // Height is specified in pixels.
> + queryString.append('&').append(HEIGHT).append('=').append(height);
> + }
> + }
> + return queryString;
> + }
> +
> + /**
> * {@inheritDoc}
> + *
> + * @see org.xwiki.rendering.wiki.WikiModel#getImageURL(java.lang.String, java.lang.String, java.util.Map)
> + */
> + public String getImageURL(String documentName, String attachmentName, Map<String, String> parameters)
> + {
> + String url = getAttachmentURL(documentName, attachmentName);
> + if (!renderingConfiguration.isIncludeImageDimensionsInImageURL()) {
> + return url;
> + }
> +
> + StringBuilder queryString = getImageURLQueryString(parameters);
> + if (queryString.length() == 0) {
> + return url;
> + }
> +
> + // Determine the insertion point.
> + int insertionPoint = url.lastIndexOf('#');
> + if (insertionPoint < 0) {
> + // No fragment identifier.
> + insertionPoint = url.length();
> + }
> + if (url.lastIndexOf('?', insertionPoint) < 0) {
> + // No query string.
> + queryString.setCharAt(0, '?');
> + }
> +
> + // Insert the query string.
> + return new StringBuilder(url).insert(insertionPoint, queryString).toString();
> + }
> +
> + /**
> + * {@inheritDoc}
> + *
> * @see WikiModel#isDocumentAvailable(String)
> */
> public boolean isDocumentAvailable(String documentName)
> @@ -65,6 +211,7 @@
>
> /**
> * {@inheritDoc}
> + *
> * @see WikiModel#getDocumentViewURL(String, String, String)
> */
> public String getDocumentViewURL(String documentName, String anchor, String queryString)
> @@ -74,6 +221,7 @@
>
> /**
> * {@inheritDoc}
> + *
> * @see WikiModel#getDocumentEditURL(String, String, String)
> */
> public String getDocumentEditURL(String documentName, String anchor, String queryString)
> @@ -89,17 +237,17 @@
> // See http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
> // TODO: Once the xwiki-url module is usable, refactor this code to use it and remove the need to
> // perform explicit encoding here.
> - modifiedQueryString =
> + modifiedQueryString =
> "parent=" + URLEncoder.encode(this.entityReferenceSerializer.serialize(reference), "UTF-8");
> } catch (UnsupportedEncodingException e) {
> // Not supporting UTF-8 as a valid encoding for some reasons. We consider XWiki cannot work
> // without that encoding.
> - throw new RuntimeException("Failed to URL encode [" + this.entityReferenceSerializer.serialize(
> - reference) + "] using UTF-8.", e);
> + throw new RuntimeException("Failed to URL encode ["
> + + this.entityReferenceSerializer.serialize(reference) + "] using UTF-8.", e);
> }
> }
> }
> -
> +
> return this.documentAccessBridge.getURL(documentName, "create", modifiedQueryString, anchor);
> }
> }
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfigurationTest.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfigurationTest.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/configuration/XWikiRenderingConfigurationTest.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -22,9 +22,9 @@
> import java.util.Properties;
>
> import org.jmock.Expectations;
> -import org.xwiki.configuration.ConfigurationSource;
> import org.junit.Assert;
> import org.junit.Test;
> +import org.xwiki.configuration.ConfigurationSource;
> import org.xwiki.test.AbstractMockingComponentTestCase;
> import org.xwiki.test.annotation.MockingRequirement;
>
> @@ -43,10 +43,13 @@
> public void testGetLinkLabelFormat() throws Exception
> {
> final ConfigurationSource source = getComponentManager().lookup(ConfigurationSource.class);
> - getMockery().checking(new Expectations() {{
> - allowing(source).getProperty("rendering.linkLabelFormat", "%p");
> + getMockery().checking(new Expectations()
> + {
> + {
> + allowing(source).getProperty("rendering.linkLabelFormat", "%p");
> will(returnValue("%p"));
> - }});
> + }
> + });
>
> Assert.assertEquals("%p", this.configuration.getLinkLabelFormat());
> }
> @@ -55,12 +58,60 @@
> public void testGetMacroCategories() throws Exception
> {
> final ConfigurationSource source = getComponentManager().lookup(ConfigurationSource.class);
> - getMockery().checking(new Expectations() {{
> - allowing(source).getProperty("rendering.macroCategories", Properties.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + allowing(source).getProperty("rendering.macroCategories", Properties.class);
> will(returnValue(new Properties()));
> - }});
> + }
> + });
>
> Assert.assertNotNull(this.configuration.getMacroCategories());
> Assert.assertEquals(0, this.configuration.getMacroCategories().size());
> }
> +
> + @Test
> + public void testGetImageWidthLimit() throws Exception
> + {
> + final ConfigurationSource source = getComponentManager().lookup(ConfigurationSource.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + allowing(source).getProperty("rendering.imageWidthLimit", -1);
> + will(returnValue(100));
> + }
> + });
> +
> + Assert.assertEquals(100, this.configuration.getImageWidthLimit());
> + }
> +
> + @Test
> + public void testGetImageHeightLimit() throws Exception
> + {
> + final ConfigurationSource source = getComponentManager().lookup(ConfigurationSource.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + allowing(source).getProperty("rendering.imageHeightLimit", -1);
> + will(returnValue(150));
> + }
> + });
> +
> + Assert.assertEquals(150, this.configuration.getImageHeightLimit());
> + }
> +
> + @Test
> + public void testIsIncludeImageDimensionsInImageURL() throws Exception
> + {
> + final ConfigurationSource source = getComponentManager().lookup(ConfigurationSource.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + allowing(source).getProperty("rendering.includeImageDimensionsInImageURL", true);
> + will(returnValue(false));
> + }
> + });
> +
> + Assert.assertFalse(this.configuration.isIncludeImageDimensionsInImageURL());
> + }
> }
>
> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/wiki/XWikiWikiModelTest.java
> ===================================================================
> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/wiki/XWikiWikiModelTest.java 2010-09-11 17:15:46 UTC (rev 31052)
> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/internal/wiki/XWikiWikiModelTest.java 2010-09-12 11:30:15 UTC (rev 31053)
> @@ -19,12 +19,20 @@
> */
> package org.xwiki.rendering.internal.wiki;
>
> +import java.util.Collections;
> +import java.util.HashMap;
> +import java.util.Map;
> +
> +import junit.framework.Assert;
> +
> import org.jmock.Expectations;
> -import org.jmock.Mockery;
> +import org.junit.Test;
> import org.xwiki.bridge.DocumentAccessBridge;
> import org.xwiki.model.reference.DocumentReference;
> -import org.xwiki.component.util.ReflectionUtils;
> import org.xwiki.model.reference.EntityReferenceSerializer;
> +import org.xwiki.rendering.configuration.RenderingConfiguration;
> +import org.xwiki.test.AbstractMockingComponentTestCase;
> +import org.xwiki.test.annotation.MockingRequirement;
>
> /**
> * Unit tests for {@link XWikiWikiModel}.
> @@ -32,31 +40,321 @@
> * @version $Id$
> * @since 2.0M1
> */
> -public class XWikiWikiModelTest
> +public class XWikiWikiModelTest extends AbstractMockingComponentTestCase
> {
> - @org.junit.Test
> + @MockingRequirement
> + private XWikiWikiModel wikiModel;
> +
> + @Test
> public void testGetDocumentEditURLWhenNoQueryStringSpecified() throws Exception
> {
> - Mockery mockery = new Mockery();
> - XWikiWikiModel wikiModel = new XWikiWikiModel();
> + final EntityReferenceSerializer< ? > entityReferenceSerializer =
> + getComponentManager().lookup(EntityReferenceSerializer.class);
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getCurrentDocumentReference();
> + will(returnValue(documentReference));
> + oneOf(entityReferenceSerializer).serialize(documentReference);
> + will(returnValue("wiki:Space.Page\u20AC"));
>
> - final EntityReferenceSerializer mockEntityReferenceSerializer = mockery.mock(EntityReferenceSerializer.class);
> - ReflectionUtils.setFieldValue(wikiModel, "entityReferenceSerializer", mockEntityReferenceSerializer);
> + // The test is here: we verify that getURL is called with the query string already encoded since
> + // getURL() doesn't encode it.
> + oneOf(documentAccessBridge).getURL("Space.Page\u20AC", "create", "parent=wiki%3ASpace.Page%E2%82%AC",
> + "anchor");
> + }
> + });
>
> - final DocumentAccessBridge mockDocumentAccessBridge = mockery.mock(DocumentAccessBridge.class);
> - ReflectionUtils.setFieldValue(wikiModel, "documentAccessBridge", mockDocumentAccessBridge);
> + wikiModel.getDocumentEditURL("Space.Page\u20AC", "anchor", null);
> + }
>
> - final DocumentReference docReference = new DocumentReference("wiki", "Space", "Page");
> - mockery.checking(new Expectations() {{
> - oneOf(mockDocumentAccessBridge).getCurrentDocumentReference(); will(returnValue(docReference));
> - oneOf(mockEntityReferenceSerializer).serialize(docReference); will(returnValue("wiki:Space.Page\u20AC"));
> + /**
> + * Tests that the proper image URL is generated when both the width and the height image parameters are specified.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenBothWidthAndHeightAttributesAreSpecified() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("width", "100px");
> + parameters.put("height", "50");
> + Assert.assertEquals("?width=100&height=50", wikiModel.getImageURL("", "", parameters));
> + }
>
> - // The test is here: we verify that getURL is called with the query string already encoded since getURL()
> - // doesn't encode it.
> - oneOf(mockDocumentAccessBridge).getURL("Space.Page\u20AC", "create", "parent=wiki%3ASpace.Page%E2%82%AC",
> - "anchor");
> - }});
> + /**
> + * Tests that the proper image URL is generated when both the width and the height image parameters are specified
> + * but including them in the image URL is forbidden from the rendering configuration.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenIncludingImageDimensionsIsForbidden() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(false));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("width", "101px");
> + parameters.put("height", "55px");
> + Assert.assertEquals("", wikiModel.getImageURL("", "", parameters));
> + }
>
> - wikiModel.getDocumentEditURL("Space.Page\u20AC", "anchor", null);
> + /**
> + * Tests that the proper image URL is generated when both the width and the height CSS properties are specified.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenBothWidthAndHeightCSSPropertiesAreSpecified() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("style", "border: 1px; height: 30px; margin-top: 2em; width: 70px");
> + Assert.assertEquals("?width=70&height=30", wikiModel.getImageURL("", "", parameters));
> }
> +
> + /**
> + * Tests that the proper image URL is generated when only the width image parameter is specified.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenOnlyWidthAttributeIsSpecified() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("width", "150");
> + parameters.put("height", "30%");
> + Assert.assertEquals("?width=150", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when only the height CSS property is specified.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenOnlyHeightCSSPropertyIsSpecified() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("style", "width: 5cm; height: 80px");
> + Assert.assertEquals("?height=80", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when both the width and the height are unspecified and image size is
> + * limited in the configuration.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsLimited() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + oneOf(configuration).getImageWidthLimit();
> + will(returnValue(200));
> + oneOf(configuration).getImageHeightLimit();
> + will(returnValue(170));
> + }
> + });
> + Map<String, String> parameters = Collections.emptyMap();
> + Assert.assertEquals("?width=200&height=170&keepAspectRatio=true", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when both the width and the height are unspecified and only the
> + * image width is limited in the configuration.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenBothWidthAndHeightAreUnspecifiedAndOnlyImageWidthIsLimited() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + oneOf(configuration).getImageWidthLimit();
> + will(returnValue(25));
> + oneOf(configuration).getImageHeightLimit();
> + will(returnValue(-1));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("width", "45%");
> + parameters.put("style", "height:10em");
> + Assert.assertEquals("?width=25", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when both the width and the height are unspecified and the image
> + * size is not limited in the configuration.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsNotLimited() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + oneOf(configuration).getImageWidthLimit();
> + will(returnValue(-1));
> + oneOf(configuration).getImageHeightLimit();
> + will(returnValue(-1));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("style", "bad CSS declaration");
> + Assert.assertEquals("", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when the attachment URL has a fragment identifier.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenAttachmentURLHasFragmentIdentifier() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue("test#fragment"));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("width", "23");
> + Assert.assertEquals("test?width=23#fragment", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when the attachment URL has a query string and a fragment
> + * identifier.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenAttachmentURLHasQueryStringAndFragmentIdentifier() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue("test?param=value#fragment"));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("height", "17");
> + Assert.assertEquals("test?param=value&height=17#fragment", wikiModel.getImageURL("", "", parameters));
> + }
> +
> + /**
> + * Tests that the proper image URL is generated when both the style and the dimension parameters are specified.
> + *
> + * @throws Exception if an exception occurs while running the test
> + */
> + @Test
> + public void testGetImageURLWhenBothStyleAndDimensionParametersAreSpecified() throws Exception
> + {
> + final DocumentAccessBridge documentAccessBridge = getComponentManager().lookup(DocumentAccessBridge.class);
> + final RenderingConfiguration configuration = getComponentManager().lookup(RenderingConfiguration.class);
> + getMockery().checking(new Expectations()
> + {
> + {
> + oneOf(documentAccessBridge).getAttachmentURL("", "");
> + will(returnValue(""));
> + oneOf(configuration).isIncludeImageDimensionsInImageURL();
> + will(returnValue(true));
> + }
> + });
> + Map<String, String> parameters = new HashMap<String, String>();
> + parameters.put("height", "46");
> + parameters.put("width", "101px");
> + parameters.put("style", "width: 20%; height:75px");
> + // Note that the style parameter take precedence over the dimension parameters and the width is actually 20% but
> + // we can't use it for resizing the image on the server side so it's omitted from the query string.
> + Assert.assertEquals("?height=75", wikiModel.getImageURL("", "", parameters));
> + }
> }