Hello,
maybe I'm a bit stupid but I tried using the Groovy Console app
it works perfectly but it requires loading/saving scripts into
XWiki.ConsoleScriptClass.
But where is this class because I can't find it?
Moreover, when a script is stored in one object of this class, how to use
it? Is there a kind of extension such as jsx or ssx?
regards
Pascal
On Sat, Jul 11, 2009 at 10:09, Vincent Massol<vincent(a)massol.net> wrote:
> Summarizing (I've now understood):
> - We have input syntaxes (parser syntaxes) and output syntaxes
> (renderer syntaxes)
>
> Proposal
> =======
>
> a- we rename SyntaxFactory.getAvailableSyntaxes() in
> getAvailableInputSyntaxes() (or getAvailableParserSyntaxes())
+1 , since it's in rendering module we should always use same
vocabulary so +1 for getAvailableParserSyntaxes
> b- we add SyntaFactory.getAvailableOutputSyntaxes() (or
> getAvailableRendererSyntaxes())
+1 for getAvailableRendererSyntaxes
> c- (optional) we add a Renderer.getSyntax() interface method (for
> later use when renderers will be components)
let's wait for when we will make renderers componenents since it
depends on how we do that exactly
> d- we rename Document/XWikiDocument/XWiki methods for getting syntaxes
> to use Input/Ouput (or Parser/Renderer) in their names.
+1
>
> Note that b) means that we'll hardcode the list of available renderer
> syntaxes but that's ok for now (this is hat is currently done in
> PrintRendererFactory). This will be made dynamic when Renderer are
> made components.
The advantage of putting this in PrintRendererFactory is that you have
less chance to forget to update the list when you add a new renderer
but i doubt we will add one before making renderers real components
actually so i guess it ok.
>
> WDYT?
>
> Thanks
> -Vincent
>
> On Jul 10, 2009, at 6:49 PM, Thomas Mortagne wrote:
>
>> On Fri, Jul 10, 2009 at 09:41, Vincent Massol<vincent(a)massol.net>
>> wrote:
>>>
>>> On Jul 4, 2009, at 2:44 PM, tmortagne (SVN) wrote:
>>>
>>>> Author: tmortagne
>>>> Date: 2009-07-04 14:44:30 +0200 (Sat, 04 Jul 2009)
>>>> New Revision: 21811
>>>>
>>>> Modified:
>>>> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>>>> Document.java
>>>> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>>>> XWiki.java
>>>> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/
>>>> XWikiDocument.java
>>>> platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/api/
>>>> XWikiTest.java
>>>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>>>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>>>> java/org/xwiki/rendering/internal/renderer/
>>>> DefaultPrintRendererFactory.java
>>>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>>>> java/org/xwiki/rendering/parser/Syntax.java
>>>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>>>> java/org/xwiki/rendering/parser/SyntaxType.java
>>>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>>>> java/org/xwiki/rendering/renderer/PrintRendererFactory.java
>>>> platform/web/trunk/standard/src/main/webapp/templates/
>>>> contentview.vm
>>>> platform/web/trunk/standard/src/main/webapp/templates/plain.vm
>>>> Log:
>>>> XWIKI-4042: Add a way to choose the renderer when viewing a page
>>>
>>>>
>>>> Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/
>>>> xwiki/
>>>> api/Document.java
>>>> ===================================================================
>>>> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>>>> Document.java 2009-07-04 12:42:14 UTC (rev 21810)
>>>> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>>>> Document.java 2009-07-04 12:44:30 UTC (rev 21811)
>>>> @@ -37,6 +37,7 @@
>>>> import org.suigeneris.jrcs.diff.DifferentiationFailedException;
>>>> import org.suigeneris.jrcs.diff.delta.Delta;
>>>> import org.suigeneris.jrcs.rcs.Version;
>>>> +import org.xwiki.rendering.parser.Syntax;
>>>>
>>>> import com.xpn.xwiki.XWiki;
>>>> import com.xpn.xwiki.XWikiContext;
>>>> @@ -473,6 +474,16 @@
>>>> }
>>>>
>>>> /**
>>>> + * @param targetSyntax the syntax in which render the document
>>>> content
>>>> + * @return the rendered content
>>>> + * @throws XWikiException error when rendering content
>>>> + */
>>>> + public String getRenderedContent(Syntax targetSyntax) throws
>>>> XWikiException
>>>> + {
>>>> + return this.doc.getRenderedContent(targetSyntax,
>>>> getXWikiContext());
>>>> + }
>>>
>>> Since this is for Velocity, isn't it better to use a syntax Id String
>>> instead of a Syntax object which is hard to construct from velocity?
>>
>> The problem is that it was not easy to find a right signature since
>> there is already getRenderedContent taking string fo the parser
>> syntax. Since anyway it's necessary to give a supported syntax by
>> looking at existing one it was easier to not have to directly give the
>> found valid syntax object.
>>
>>>
>>>> +
>>>> + /**
>>>> * return a escaped version of the content of this document
>>>> */
>>>> public String getEscapedContent() throws XWikiException
>>>>
>>>> Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/
>>>> xwiki/
>>>> api/XWiki.java
>>>> ===================================================================
>>>> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>>>> XWiki.java 2009-07-04 12:42:14 UTC (rev 21810)
>>>> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>>>> XWiki.java 2009-07-04 12:44:30 UTC (rev 21811)
>>>> @@ -30,6 +30,8 @@
>>>> import org.apache.commons.logging.LogFactory;
>>>> import org.suigeneris.jrcs.diff.delta.Chunk;
>>>> import org.xwiki.query.QueryManager;
>>>> +import org.xwiki.rendering.parser.Syntax;
>>>> +import org.xwiki.rendering.renderer.PrintRendererFactory;
>>>>
>>>> import com.xpn.xwiki.XWikiContext;
>>>> import com.xpn.xwiki.XWikiException;
>>>> @@ -2685,4 +2687,42 @@
>>>> {
>>>> return this.xwiki.getDefaultDocumentSyntax();
>>>> }
>>>> +
>>>> + /**
>>>> + * Find the corresponding available renderer syntax.
>>>> + * <p>
>>>> + * If <code>syntaxVersion</code> is null the last version of
>>>> the available provided syntax type is returned.
>>>> + *
>>>> + * @param syntaxType the syntax type
>>>> + * @param syntaxVersion the syntax version
>>>> + * @return the available corresponding {@link Syntax}. Null if
>>>> no available renderer can be found.
>>>> + */
>>>> + public Syntax getAvailableRendererSyntax(String syntaxType,
>>>> String syntaxVersion)
>>>> + {
>>>> + Syntax syntax = null;
>>>> +
>>>> + PrintRendererFactory printRendererFactory =
>>>> + (PrintRendererFactory)
>>>> Utils.getComponent(PrintRendererFactory.class);
>>>> +
>>>> + List<Syntax> availableSyntaxes =
>>>> printRendererFactory.getAvailableSyntaxes();
>>>
>>> We already have the notion of available syntaxes in the
>>> SyntaxFactory.
>>
>> No, we have the notion of available parsers, the method name is just
>> wrong in SyntaxFactory... The only place where we know the available
>> renderers is the PrintRendererFactory since it's impossible to get all
>> renderers otherwise until renderer are made components.
>>
>>> I don't understand why we need to have them in the
>>> PrintRendererFactory (which is not supposed to return syntaxes BTW,
>>> it's only supposed to return PrintRenderer(s).
>>>
>>>> +
>>>> + for (Syntax availableSyntax : availableSyntaxes) {
>>>
>>> Why not instead do:
>>> SyntaxType syntaxType = SyntaxType.getSyntaxType(syntaxTypeAsString);
>>>
>>> And then (when syntaxVersion != null):
>>> Syntax syntax = new Syntax(syntaxType, syntaxVersion);
>>>
>>> And then:
>>> syntaxFatory.getAvailableSyntaxes().contains(syntax)
>>
>> It's not that simple since we have to support the use case where
>> syntaxVersion is not given (which is most of the time).
>>
>>>
>>> hmmm.... Actually thinking more about it, I believe this whole code
>>> should be moved out of XWikiDocument and instead go in the rendering
>>> module in SyntaxFactory.
>>
>> Again in SyntaxFactory you have no idea what are the available
>> renderers syntaxes and here we don't care about parsers.
>> Until we have clean renderer componet my goal was to put as less as
>> possible temporary code in rendering module.
>>
>>>
>>>> + if (syntaxVersion != null) {
>>>> + if
>>>> (availableSyntax.getType().toIdString().equalsIgnoreCase(syntaxType)
>>>> + &&
>>>> availableSyntax.getVersion().equals(syntaxVersion)) {
>>>> + syntax = availableSyntax;
>>>> + break;
>>>> + }
>>>> + } else {
>>>> + // TODO: improve version comparaison since it does
>>>> not work when comparing 2.0 and 10.0 for example. We
>>>> + // should have a Version which implements
>>>> Comparable like we have SyntaxId in Syntax
>>>> + if
>>>> (availableSyntax.getType().toIdString().equalsIgnoreCase(syntaxType)
>>>> + && (syntax == null ||
>>>> availableSyntax.getVersion().compareTo(syntax.getVersion()) > 0)) {
>>>> + syntax = availableSyntax;
>>>> + }
>>>> + }
>>>> + }
>>>> +
>>>> + return syntax;
>>>> + }
>>>> }
>>>
>>> [snip]
>>>>
>>>> /**
>>>> + * @return the syntax of the document
>>>> + */
>>>> + private Syntax getSyntax()
>>>> + {
>>>> + Syntax syntax = null;
>>>> +
>>>> + String syntaxId = getDefaultDocumentSyntax();
>>>> + try {
>>>> + syntax =
>>>> this.syntaxFactory.createSyntaxFromIdString(getSyntaxId());
>>>
>>> Shouldn't we save the Syntax object instead of syntaxId in
>>> XWikiDocument so that we don't perform the conversion every time
>>> getSyntax is called?
>>
>> I did not planed to refactor the whole XWikiDocument, i just done what
>> was needed but at some point yes we should have Syntax and XDOM
>> instead of the syntax/content strings :)
>>
>>>
>>>> + } catch (ParseException e) {
>>>> + LOG.error("Failed to genrate Syntax object for syntax
>>>> identifier [" + syntaxId + "] in page ["
>>>
>>> Typo: generate
>>>
>>>> + + getDocumentName() + "]", e);
>>>> +
>>>> + syntaxId = getDefaultDocumentSyntax();
>>>
>>> I don't understand this line above, it's the same as the one a few
>>> lines above.
>>>
>>>> + try {
>>>> + syntax =
>>>> this
>>>> .syntaxFactory.createSyntaxFromIdString(getDefaultDocumentSyntax());
>>>
>>> It seems you're not using the syntaxId variable.
>>
>> Yes it's an error, I added the variables when added the error message
>> and forgot to change the "real" code properly.
>>
>>>
>>>> + } catch (ParseException e1) {
>>>> + LOG.error("Failed to genrate default Syntax object.
>>>> The defautlt syntax id in [" + syntaxId + "]", e);
>>>
>>> same typo
>>>
>>> [snip]
>>>
>>>> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/
>>>> pom.xml
>>>> ===================================================================
>>>> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>>>> 2009-07-04 12:42:14 UTC (rev 21810)
>>>> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>>>> 2009-07-04 12:44:30 UTC (rev 21811)
>>>> @@ -187,7 +187,9 @@
>>>> <!-- Excludes for the 2.0 M2 release. Once it's
>>>> released remove them. -->
>>>> <exclude>org/xwiki/rendering/macro/MacroManager</
>>>> exclude>
>>>> <exclude>org/xwiki/rendering/macro/MacroSource</
>>>> exclude>
>>>> - <exclude>org/xwiki/rendering/macro/
>>>> AbstractMacroSource</exclude>
>>>> + <exclude>org/xwiki/rendering/macro/
>>>> AbstractMacroSource</exclude>
>>>> + <!-- Seems clirr plugin consider adding new API as
>>>> an error (which I don't understand). -->
>>>
>>> It doesn't normally (it' considered as an INFO level) unless it
>>> breaks
>>> binary compatibility. But I don't know why in your case (would need
>>> to
>>> check more the code, i'm only looking at the svn diff).
>>
>> If you remove this the plugin clearly say that there is an error and
>> it also clearly say that the error is that there is new api in
>> PrintRendererFactory. Maybe the error message is wrong but i check and
>> rechecked and this is the only difference.
>>
>>>
>>>> + <exclude>org/xwiki/rendering/renderer/
>>>> PrintRendererFactory</exclude>
>>>> </excludes>
>>>> </configuration>
>>>> </execution>
>>>>
>>>> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/
>>>> src/main/java/org/xwiki/rendering/internal/renderer/
>>>> DefaultPrintRendererFactory.java
>>>> ===================================================================
>>>> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/
>>>> main/
>>>> java/org/xwiki/rendering/internal/renderer/
>>>> DefaultPrintRendererFactory.java 2009-07-04 12:42:14 UTC (rev
>>>> 21810)
>>>> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/
>>>> main/
>>>> java/org/xwiki/rendering/internal/renderer/
>>>> DefaultPrintRendererFactory.java 2009-07-04 12:44:30 UTC (rev
>>>> 21811)
>>>> @@ -19,6 +19,10 @@
>>>> */
>>>> package org.xwiki.rendering.internal.renderer;
>>>>
>>>> +import java.util.Arrays;
>>>> +import java.util.Collections;
>>>> +import java.util.List;
>>>> +
>>>> import org.xwiki.component.annotation.Component;
>>>> import org.xwiki.component.annotation.Requirement;
>>>> import org.xwiki.rendering.parser.Syntax;
>>>> @@ -43,6 +47,10 @@
>>>> @Component
>>>> public class DefaultPrintRendererFactory implements
>>>> PrintRendererFactory
>>>> {
>>>> + private static final List<Syntax> AVAILABLE_SYNTAXES =
>>>> +
>>>> Collections.unmodifiableList(Arrays.asList(Syntax.XHTML_1_0,
>>>> Syntax.XWIKI_2_0, Syntax.EVENT_1_0,
>>>> + Syntax.TEX_1_0, Syntax.PLAIN_1_0));
>>>
>>> I don't like this, see above.
>>
>> Again it's a factory, it's the only place where we really now what are
>> the renderers. I don't like this either but since renderer are not
>> component there is no choice.
>>
>>>
>>>> +
>>>> /**
>>>> * Factory to easily create an XHTML Image and Link Renderers.
>>>> */
>>>> @@ -55,6 +63,16 @@
>>>> /**
>>>> * {@inheritDoc}
>>>> *
>>>> + * @see
>>>> org
>>>> .xwiki
>>>> .rendering.renderer.PrintRendererFactory#getAvailableSyntaxes()
>>>> + */
>>>> + public List<Syntax> getAvailableSyntaxes()
>>>> + {
>>>> + return AVAILABLE_SYNTAXES;
>>>> + }
>>>> +
>>>
>>> I don't like this, see above.
>>>
>>> [snip]
>>>
>>> Thanks
>>> -Vincent
>>>
>>> _______________________________________________
>>> devs mailing list
>>> devs(a)xwiki.org
>>> http://lists.xwiki.org/mailman/listinfo/devs
>>>
>>
>>
>>
>> --
>> Thomas Mortagne
>> _______________________________________________
>> devs mailing list
>> devs(a)xwiki.org
>> http://lists.xwiki.org/mailman/listinfo/devs
>
> _______________________________________________
> devs mailing list
> devs(a)xwiki.org
> http://lists.xwiki.org/mailman/listinfo/devs
>
--
Thomas Mortagne
On Jul 9, 2009, at 12:15 PM, tmortagne (SVN) wrote:
> Author: tmortagne
> Date: 2009-07-09 12:15:53 +0200 (Thu, 09 Jul 2009)
> New Revision: 21863
>
> Modified:
> platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/
> xwiki/plugin/wikimanager/WikiManagerException.java
> Log:
> [misc] Add serialize id
>
> Modified: platform/xwiki-plugins/trunk/wiki-manager/src/main/java/
> com/xpn/xwiki/plugin/wikimanager/WikiManagerException.java
> ===================================================================
> --- platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/
> xwiki/plugin/wikimanager/WikiManagerException.java 2009-07-09
> 09:56:02 UTC (rev 21862)
> +++ platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/
> xwiki/plugin/wikimanager/WikiManagerException.java 2009-07-09
> 10:15:53 UTC (rev 21863)
> @@ -30,11 +30,6 @@
> public class WikiManagerException extends PluginException
> {
> /**
> - * Serialize id.
> - */
> - private static final long serialVersionUID =
> -6451750749104331619L;
> -
> - /**
> * Error when trying to use provided user that does not exists.
> * <p>
> * TODO : move in XWikiException
> @@ -98,6 +93,11 @@
> // //////
>
> /**
> + * Serialize id.
> + */
> + private static final long serialVersionUID =
> -6451750749104331619L;
> +
I've asked myself several times how to document this. I've used
different versions:
- "Unique ID for Class Serialization."
- "Class id for Serialization."
and the more descriptive:
/**
* Needed to identify the version of this code when serializing/
deserializing (since Exception is Serializable).
* Note that the value needs to be modified whenever a non
transient field is added or removed in this class.
*/
The last one is the one I prefer (I think) since not everyone knows
about this and it makes it clear that the id needs to be modified
whenever a new field is added/removed.
We could also add a link to some URL describing class serialization.
WDYT?
Thanks
-Vincent
On Fri, Jul 10, 2009 at 09:41, Vincent Massol<vincent(a)massol.net> wrote:
>
> On Jul 4, 2009, at 2:44 PM, tmortagne (SVN) wrote:
>
>> Author: tmortagne
>> Date: 2009-07-04 14:44:30 +0200 (Sat, 04 Jul 2009)
>> New Revision: 21811
>>
>> Modified:
>> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>> Document.java
>> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>> XWiki.java
>> platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/
>> XWikiDocument.java
>> platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/api/
>> XWikiTest.java
>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>> java/org/xwiki/rendering/internal/renderer/
>> DefaultPrintRendererFactory.java
>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>> java/org/xwiki/rendering/parser/Syntax.java
>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>> java/org/xwiki/rendering/parser/SyntaxType.java
>> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>> java/org/xwiki/rendering/renderer/PrintRendererFactory.java
>> platform/web/trunk/standard/src/main/webapp/templates/contentview.vm
>> platform/web/trunk/standard/src/main/webapp/templates/plain.vm
>> Log:
>> XWIKI-4042: Add a way to choose the renderer when viewing a page
>
>>
>> Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/
>> api/Document.java
>> ===================================================================
>> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>> Document.java 2009-07-04 12:42:14 UTC (rev 21810)
>> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>> Document.java 2009-07-04 12:44:30 UTC (rev 21811)
>> @@ -37,6 +37,7 @@
>> import org.suigeneris.jrcs.diff.DifferentiationFailedException;
>> import org.suigeneris.jrcs.diff.delta.Delta;
>> import org.suigeneris.jrcs.rcs.Version;
>> +import org.xwiki.rendering.parser.Syntax;
>>
>> import com.xpn.xwiki.XWiki;
>> import com.xpn.xwiki.XWikiContext;
>> @@ -473,6 +474,16 @@
>> }
>>
>> /**
>> + * @param targetSyntax the syntax in which render the document
>> content
>> + * @return the rendered content
>> + * @throws XWikiException error when rendering content
>> + */
>> + public String getRenderedContent(Syntax targetSyntax) throws
>> XWikiException
>> + {
>> + return this.doc.getRenderedContent(targetSyntax,
>> getXWikiContext());
>> + }
>
> Since this is for Velocity, isn't it better to use a syntax Id String
> instead of a Syntax object which is hard to construct from velocity?
The problem is that it was not easy to find a right signature since
there is already getRenderedContent taking string fo the parser
syntax. Since anyway it's necessary to give a supported syntax by
looking at existing one it was easier to not have to directly give the
found valid syntax object.
>
>> +
>> + /**
>> * return a escaped version of the content of this document
>> */
>> public String getEscapedContent() throws XWikiException
>>
>> Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/
>> api/XWiki.java
>> ===================================================================
>> --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>> XWiki.java 2009-07-04 12:42:14 UTC (rev 21810)
>> +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/
>> XWiki.java 2009-07-04 12:44:30 UTC (rev 21811)
>> @@ -30,6 +30,8 @@
>> import org.apache.commons.logging.LogFactory;
>> import org.suigeneris.jrcs.diff.delta.Chunk;
>> import org.xwiki.query.QueryManager;
>> +import org.xwiki.rendering.parser.Syntax;
>> +import org.xwiki.rendering.renderer.PrintRendererFactory;
>>
>> import com.xpn.xwiki.XWikiContext;
>> import com.xpn.xwiki.XWikiException;
>> @@ -2685,4 +2687,42 @@
>> {
>> return this.xwiki.getDefaultDocumentSyntax();
>> }
>> +
>> + /**
>> + * Find the corresponding available renderer syntax.
>> + * <p>
>> + * If <code>syntaxVersion</code> is null the last version of
>> the available provided syntax type is returned.
>> + *
>> + * @param syntaxType the syntax type
>> + * @param syntaxVersion the syntax version
>> + * @return the available corresponding {@link Syntax}. Null if
>> no available renderer can be found.
>> + */
>> + public Syntax getAvailableRendererSyntax(String syntaxType,
>> String syntaxVersion)
>> + {
>> + Syntax syntax = null;
>> +
>> + PrintRendererFactory printRendererFactory =
>> + (PrintRendererFactory)
>> Utils.getComponent(PrintRendererFactory.class);
>> +
>> + List<Syntax> availableSyntaxes =
>> printRendererFactory.getAvailableSyntaxes();
>
> We already have the notion of available syntaxes in the SyntaxFactory.
No, we have the notion of available parsers, the method name is just
wrong in SyntaxFactory... The only place where we know the available
renderers is the PrintRendererFactory since it's impossible to get all
renderers otherwise until renderer are made components.
> I don't understand why we need to have them in the
> PrintRendererFactory (which is not supposed to return syntaxes BTW,
> it's only supposed to return PrintRenderer(s).
>
>> +
>> + for (Syntax availableSyntax : availableSyntaxes) {
>
> Why not instead do:
> SyntaxType syntaxType = SyntaxType.getSyntaxType(syntaxTypeAsString);
>
> And then (when syntaxVersion != null):
> Syntax syntax = new Syntax(syntaxType, syntaxVersion);
>
> And then:
> syntaxFatory.getAvailableSyntaxes().contains(syntax)
It's not that simple since we have to support the use case where
syntaxVersion is not given (which is most of the time).
>
> hmmm.... Actually thinking more about it, I believe this whole code
> should be moved out of XWikiDocument and instead go in the rendering
> module in SyntaxFactory.
Again in SyntaxFactory you have no idea what are the available
renderers syntaxes and here we don't care about parsers.
Until we have clean renderer componet my goal was to put as less as
possible temporary code in rendering module.
>
>> + if (syntaxVersion != null) {
>> + if
>> (availableSyntax.getType().toIdString().equalsIgnoreCase(syntaxType)
>> + &&
>> availableSyntax.getVersion().equals(syntaxVersion)) {
>> + syntax = availableSyntax;
>> + break;
>> + }
>> + } else {
>> + // TODO: improve version comparaison since it does
>> not work when comparing 2.0 and 10.0 for example. We
>> + // should have a Version which implements
>> Comparable like we have SyntaxId in Syntax
>> + if
>> (availableSyntax.getType().toIdString().equalsIgnoreCase(syntaxType)
>> + && (syntax == null ||
>> availableSyntax.getVersion().compareTo(syntax.getVersion()) > 0)) {
>> + syntax = availableSyntax;
>> + }
>> + }
>> + }
>> +
>> + return syntax;
>> + }
>> }
>
> [snip]
>>
>> /**
>> + * @return the syntax of the document
>> + */
>> + private Syntax getSyntax()
>> + {
>> + Syntax syntax = null;
>> +
>> + String syntaxId = getDefaultDocumentSyntax();
>> + try {
>> + syntax =
>> this.syntaxFactory.createSyntaxFromIdString(getSyntaxId());
>
> Shouldn't we save the Syntax object instead of syntaxId in
> XWikiDocument so that we don't perform the conversion every time
> getSyntax is called?
I did not planed to refactor the whole XWikiDocument, i just done what
was needed but at some point yes we should have Syntax and XDOM
instead of the syntax/content strings :)
>
>> + } catch (ParseException e) {
>> + LOG.error("Failed to genrate Syntax object for syntax
>> identifier [" + syntaxId + "] in page ["
>
> Typo: generate
>
>> + + getDocumentName() + "]", e);
>> +
>> + syntaxId = getDefaultDocumentSyntax();
>
> I don't understand this line above, it's the same as the one a few
> lines above.
>
>> + try {
>> + syntax =
>> this
>> .syntaxFactory.createSyntaxFromIdString(getDefaultDocumentSyntax());
>
> It seems you're not using the syntaxId variable.
Yes it's an error, I added the variables when added the error message
and forgot to change the "real" code properly.
>
>> + } catch (ParseException e1) {
>> + LOG.error("Failed to genrate default Syntax object.
>> The defautlt syntax id in [" + syntaxId + "]", e);
>
> same typo
>
> [snip]
>
>> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/
>> pom.xml
>> ===================================================================
>> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>> 2009-07-04 12:42:14 UTC (rev 21810)
>> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>> 2009-07-04 12:44:30 UTC (rev 21811)
>> @@ -187,7 +187,9 @@
>> <!-- Excludes for the 2.0 M2 release. Once it's
>> released remove them. -->
>> <exclude>org/xwiki/rendering/macro/MacroManager</
>> exclude>
>> <exclude>org/xwiki/rendering/macro/MacroSource</
>> exclude>
>> - <exclude>org/xwiki/rendering/macro/
>> AbstractMacroSource</exclude>
>> + <exclude>org/xwiki/rendering/macro/
>> AbstractMacroSource</exclude>
>> + <!-- Seems clirr plugin consider adding new API as
>> an error (which I don't understand). -->
>
> It doesn't normally (it' considered as an INFO level) unless it breaks
> binary compatibility. But I don't know why in your case (would need to
> check more the code, i'm only looking at the svn diff).
If you remove this the plugin clearly say that there is an error and
it also clearly say that the error is that there is new api in
PrintRendererFactory. Maybe the error message is wrong but i check and
rechecked and this is the only difference.
>
>> + <exclude>org/xwiki/rendering/renderer/
>> PrintRendererFactory</exclude>
>> </excludes>
>> </configuration>
>> </execution>
>>
>> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/
>> src/main/java/org/xwiki/rendering/internal/renderer/
>> DefaultPrintRendererFactory.java
>> ===================================================================
>> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>> java/org/xwiki/rendering/internal/renderer/
>> DefaultPrintRendererFactory.java 2009-07-04 12:42:14 UTC (rev 21810)
>> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/
>> java/org/xwiki/rendering/internal/renderer/
>> DefaultPrintRendererFactory.java 2009-07-04 12:44:30 UTC (rev 21811)
>> @@ -19,6 +19,10 @@
>> */
>> package org.xwiki.rendering.internal.renderer;
>>
>> +import java.util.Arrays;
>> +import java.util.Collections;
>> +import java.util.List;
>> +
>> import org.xwiki.component.annotation.Component;
>> import org.xwiki.component.annotation.Requirement;
>> import org.xwiki.rendering.parser.Syntax;
>> @@ -43,6 +47,10 @@
>> @Component
>> public class DefaultPrintRendererFactory implements
>> PrintRendererFactory
>> {
>> + private static final List<Syntax> AVAILABLE_SYNTAXES =
>> +
>> Collections.unmodifiableList(Arrays.asList(Syntax.XHTML_1_0,
>> Syntax.XWIKI_2_0, Syntax.EVENT_1_0,
>> + Syntax.TEX_1_0, Syntax.PLAIN_1_0));
>
> I don't like this, see above.
Again it's a factory, it's the only place where we really now what are
the renderers. I don't like this either but since renderer are not
component there is no choice.
>
>> +
>> /**
>> * Factory to easily create an XHTML Image and Link Renderers.
>> */
>> @@ -55,6 +63,16 @@
>> /**
>> * {@inheritDoc}
>> *
>> + * @see
>> org
>> .xwiki.rendering.renderer.PrintRendererFactory#getAvailableSyntaxes()
>> + */
>> + public List<Syntax> getAvailableSyntaxes()
>> + {
>> + return AVAILABLE_SYNTAXES;
>> + }
>> +
>
> I don't like this, see above.
>
> [snip]
>
> Thanks
> -Vincent
>
> _______________________________________________
> devs mailing list
> devs(a)xwiki.org
> http://lists.xwiki.org/mailman/listinfo/devs
>
--
Thomas Mortagne
I like this. Shouldn't we also remove the automatic creation of Tag
objects in all documents by default?
I have never understood why we do this for Tags and not for Rights,
and all other objects. For me the objects should be created only when
required and not by default.
Thanks
-Vincent
On Jul 4, 2009, at 5:22 PM, sdumitriu (SVN) wrote:
> Author: sdumitriu
> Date: 2009-07-04 17:22:41 +0200 (Sat, 04 Jul 2009)
> New Revision: 21818
>
> Modified:
> platform/xwiki-plugins/trunk/tag/src/main/java/com/xpn/xwiki/
> plugin/tag/TagPlugin.java
> Log:
> XATAG-20: Adding tags fails when there is no Tag object attached to
> the document
> Fixed.
>
> Modified: platform/xwiki-plugins/trunk/tag/src/main/java/com/xpn/
> xwiki/plugin/tag/TagPlugin.java
> ===================================================================
> --- platform/xwiki-plugins/trunk/tag/src/main/java/com/xpn/xwiki/
> plugin/tag/TagPlugin.java 2009-07-04 15:22:34 UTC (rev 21817)
> +++ platform/xwiki-plugins/trunk/tag/src/main/java/com/xpn/xwiki/
> plugin/tag/TagPlugin.java 2009-07-04 15:22:41 UTC (rev 21818)
> @@ -29,12 +29,18 @@
>
> import org.apache.commons.collections.CollectionUtils;
> import org.apache.commons.lang.StringUtils;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
>
> import com.xpn.xwiki.XWikiContext;
> import com.xpn.xwiki.XWikiException;
> import com.xpn.xwiki.api.Api;
> import com.xpn.xwiki.doc.XWikiDocument;
> +import com.xpn.xwiki.objects.BaseObject;
> import com.xpn.xwiki.objects.BaseProperty;
> +import com.xpn.xwiki.objects.DBStringListProperty;
> +import com.xpn.xwiki.objects.classes.BaseClass;
> +import com.xpn.xwiki.objects.classes.PropertyClass;
> import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
> import com.xpn.xwiki.plugin.XWikiPluginInterface;
>
> @@ -45,6 +51,9 @@
> */
> public class TagPlugin extends XWikiDefaultPlugin implements
> XWikiPluginInterface
> {
> + /** Logging helper object. */
> + public static final Log LOG = LogFactory.getLog(TagPlugin.class);
> +
> /**
> * The identifier for this plugin; used for accessing the plugin
> from velocity, and as the action returning the
> * extension content.
> @@ -116,10 +125,40 @@
> private void setDocumentTags(XWikiDocument document,
> List<String> tags, XWikiContext context)
> {
> BaseProperty prop = (BaseProperty)
> document.getObject(TAG_CLASS, true, context).safeget(TAG_PROPERTY);
> + // Properties aren't added to an object unless a value is
> specified either from the Web or from an XML.
> + if (prop == null) {
> + prop = createTagProperty(document.getObject(TAG_CLASS,
> true, context), context);
> + }
> prop.setValue(tags);
> }
>
> /**
> + * Create and add the main tag property to the provided tag
> object. The new property corresponds to the definition
> + * in the tag class, but in case of an error, the default type
> is a relational-stored list.
> + *
> + * @param tagObject the target tag object
> + * @param context the current request context
> + * @return the created property
> + * @see #TAG_PROPERTY
> + */
> + private BaseProperty createTagProperty(BaseObject tagObject,
> XWikiContext context)
> + {
> + BaseProperty tagProperty;
> + try {
> + BaseClass tagClass =
> context.getWiki().getClass(TAG_CLASS, context);
> + PropertyClass tagPropertyDefinition = (PropertyClass)
> tagClass.getField(TAG_PROPERTY);
> + tagProperty = tagPropertyDefinition.newProperty();
> + } catch (XWikiException ex) {
> + LOG.warn("Failed to properly create tag property for
> the tag object, creating a default one");
> + tagProperty = new DBStringListProperty();
> + }
> + tagProperty.setName(TAG_PROPERTY);
> + tagProperty.setObject(tagObject);
> + tagObject.safeput(TAG_PROPERTY, tagProperty);
> + return tagProperty;
> + }
> +
> + /**
> * Get all tags within the wiki.
> *
> * @param context XWiki context.
>
> _______________________________________________
> notifications mailing list
> notifications(a)xwiki.org
> http://lists.xwiki.org/mailman/listinfo/notifications
I've implemented the simplest EventListener possible by just implementing the EventListener required methods, adding an @Component("mystartup") line and adding my class to components.txt.
However, on startup I get an error Failed to lookup component [role = [org.xwiki.observation.ObservationManager] hint = [default]]
What am I missing? Is this a chicken and egg problem?
@Component("mystartup")
public class MyStartup implements EventListener {
public List<Event> getEvents() {
return Arrays.asList(new ApplicationStartedEvent(), new ApplicationStoppedEvent());
}
public String getName() {
return "mystartup";
}
public void onEvent(Event arg0, Object arg1, Object arg2) {
// TODO Auto-generated method stub
}
java.lang.RuntimeException: Failed to find the Observation Manager component
at org.xwiki.container.servlet.XWikiServletContextListener.contextInitialized(XWikiServletContextListener.java:79)
at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1239)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:466)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:523)
at org.mortbay.start.Main.main(Main.java:119)
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [role = [org.xwiki.observation.ObservationManager] hint = [default]]
at org.xwiki.component.embed.EmbeddableComponentManager.initialize(EmbeddableComponentManager.java:263)
at org.xwiki.component.embed.EmbeddableComponentManager.lookup(EmbeddableComponentManager.java:93)
at org.xwiki.container.servlet.XWikiServletContextListener.contextInitialized(XWikiServletContextListener.java:76)
... 22 more
Caused by: java.lang.NullPointerException
at org.xwiki.observation.internal.DefaultObservationManager.addListener(DefaultObservationManager.java:157)
at org.xwiki.observation.internal.DefaultObservationManager.initialize(DefaultObservationManager.java:128)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:328)
at org.xwiki.component.embed.EmbeddableComponentManager.initialize(EmbeddableComponentManager.java:254)
... 24 more
Hi Devs,
This is because of several reasons,
1. Having one wiki macro per wiki page makes it clean to group a single
WikiMacroClass object and several WikiMacroParameterClass objects together
and we do not need to keep a reference from WikiMacroParameterClass objects
as to which macro in belongs to.
2. It makes the wiki macro registration / updating easy. I mean we only need
to track document save / update events involving WikiMacroClass objects. On
the other hand if we allow WikiMacros to have their parameters defined in
some other documents, things get a little complex.
3. This will make wiki macro presentation easy. We can define a sheet that
will present a single wiki macro (inside a single wiki page) in a unque
manner to the user. This sheet will not have to bother about other wiki
macros in the same document or worry about wiki macro parameters located
elsewhere.
WDYT?
Thanks.
- Asiri
Hi,
Is there a way to get all the values for the properties of an object
attached to a page? For example, in my case, I need to get all the
properties that were defined and their values for an object which belongs to
XWiki.XWikiUsers class, given the name of the document (that the object
belongs to).
>From my component I use DocumentAccessBridge, but the only methods to get
properties values are the ones like:
public String getProperty(String documentName, String className, String
propertyName)
Is there a more elegant way to get all of them, besides calling
.getProperty() for each of the property names ? Or, is there a way to get
all the properties defined for a class? (i.e. for the XWiki.XWikiUsers
class).
Are there any other components which provide access to the data model? From
what I understood from here [0], the XWiki data model resides in the old
xwiki-core module, therefore must be used a bridge (like
DocumentAccessBridge).
[0] -
http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents#HTheXWi…
Thanks a lot,
Anamaria