[xwiki-devs] Is it possible to make a Comparator that compares XWiki objects by its properties?
I want to make such a Comparator so that I can sort objects retrieved by $xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects. I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even. Is it possible? If it was possible, would you give me some hints?
Ouch, there is a typo. $xwiki -> $doc #set($services=$xwiki.getDocument("Private.Snowberry Network Services").getObjects("Private.NetworkServices")) #foreach($prop in $services[0].getProperties()) $services[0].getProperty($prop.getName()).getName() = $services[0].getProperty($prop.getName()).getProperty().getClassType() #end The velocity snippet above produced an output. port = com.xpn.xwiki.objects.LongProperty protocol = com.xpn.xwiki.objects.StringListProperty application = com.xpn.xwiki.objects.StringProperty description = com.xpn.xwiki.objects.StringProperty service = com.xpn.xwiki.objects.StringProperty firewalled = com.xpn.xwiki.objects.IntegerProperty It appears that objects returned from $doc.getObjects("Class") have properties that belong to com.xpn.xwiki.objects package. I perused the package on http://maven.xwiki.org/site/docs/xwiki-javadoc-4.2.x/com/xpn/xwiki/objects/p... I guess I will have to implement a Comparator that compares each of the following properties in the com.xpn.xwiki.objects package. BaseStringProperty DateProperty DoubleProperty FloatProperty IntegerProperty LongProperty NumberProperty Am I doing it right? or is it a bad idea to make separate comparison codes for each of those properties? On Thu, Nov 15, 2012 at 9:57 PM, crocket <crockabiscuit@gmail.com> wrote:
I want to make such a Comparator so that I can sort objects retrieved by $xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects.
I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even.
Is it possible?
If it was possible, would you give me some hints?
Hi, On 11/15/2012 03:00 PM, crocket wrote:
Ouch, there is a typo. $xwiki -> $doc
#set($services=$xwiki.getDocument("Private.Snowberry Network Services").getObjects("Private.NetworkServices"))
#foreach($prop in $services[0].getProperties()) $services[0].getProperty($prop.getName()).getName() = $services[0].getProperty($prop.getName()).getProperty().getClassType() #end
The velocity snippet above produced an output.
port = com.xpn.xwiki.objects.LongProperty protocol = com.xpn.xwiki.objects.StringListProperty application = com.xpn.xwiki.objects.StringProperty description = com.xpn.xwiki.objects.StringProperty service = com.xpn.xwiki.objects.StringProperty firewalled = com.xpn.xwiki.objects.IntegerProperty
It appears that objects returned from $doc.getObjects("Class") have properties that belong to com.xpn.xwiki.objects package. I perused the package on http://maven.xwiki.org/site/docs/xwiki-javadoc-4.2.x/com/xpn/xwiki/objects/p...
I guess I will have to implement a Comparator that compares each of the following properties in the com.xpn.xwiki.objects package.
BaseStringProperty DateProperty DoubleProperty FloatProperty IntegerProperty LongProperty NumberProperty
Am I doing it right? or is it a bad idea to make separate comparison codes for each of those properties?
You might be interested by http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen... Hope this helps, Jerome
On Thu, Nov 15, 2012 at 9:57 PM, crocket <crockabiscuit@gmail.com> wrote:
I want to make such a Comparator so that I can sort objects retrieved by $xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects.
I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even.
Is it possible?
If it was possible, would you give me some hints?
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
I tried $sorttool, and it didn't work on XWiki objects. On http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen..., I saw "The sort method takes two parameters a collection and a property name or an array of property names. The property names and corresponding methods must conform to java bean standards since commons-beanutils is used to extract the property values." XWiki Objects don't support java bean standards. I guess they could be extracted by $obj.getProperty("prop").getProperty().getValue() The problem now is to figure out the right sort algorithms for sorting based on multiple properties. On Fri, Nov 16, 2012 at 3:06 AM, Jerome Velociter <jerome@velociter.fr>wrote:
Hi,
On 11/15/2012 03:00 PM, crocket wrote:
Ouch, there is a typo. $xwiki -> $doc
#set($services=$xwiki.**getDocument("Private.Snowberry Network Services").getObjects("**Private.NetworkServices"))
#foreach($prop in $services[0].getProperties()) $services[0].getProperty($**prop.getName()).getName() = $services[0].getProperty($**prop.getName()).getProperty().** getClassType() #end
The velocity snippet above produced an output.
port = com.xpn.xwiki.objects.**LongProperty protocol = com.xpn.xwiki.objects.**StringListProperty application = com.xpn.xwiki.objects.**StringProperty description = com.xpn.xwiki.objects.**StringProperty service = com.xpn.xwiki.objects.**StringProperty firewalled = com.xpn.xwiki.objects.**IntegerProperty
It appears that objects returned from $doc.getObjects("Class") have properties that belong to com.xpn.xwiki.objects package. I perused the package on http://maven.xwiki.org/site/**docs/xwiki-javadoc-4.2.x/com/** xpn/xwiki/objects/package-**summary.html<http://maven.xwiki.org/site/docs/xwiki-javadoc-4.2.x/com/xpn/xwiki/objects/package-summary.html>
I guess I will have to implement a Comparator that compares each of the following properties in the com.xpn.xwiki.objects package.
BaseStringProperty DateProperty DoubleProperty FloatProperty IntegerProperty LongProperty NumberProperty
Am I doing it right? or is it a bad idea to make separate comparison codes for each of those properties?
You might be interested by http://velocity.apache.org/** tools/devel/javadoc/org/**apache/velocity/tools/generic/**SortTool.html<http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html>
Hope this helps, Jerome
On Thu, Nov 15, 2012 at 9:57 PM, crocket <crockabiscuit@gmail.com> wrote:
I want to make such a Comparator so that I can sort objects retrieved by
$xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects.
I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even.
Is it possible?
If it was possible, would you give me some hints?
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs<http://lists.xwiki.org/mailman/listinfo/devs>
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs<http://lists.xwiki.org/mailman/listinfo/devs>
OK, $obj.getProperty("prop").getValue() gets the desired values. $sorttool.sort conforms only to java bean standards. I'll implement something like $sorttool.*sort<http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/to..., java.util.List)>*(java.util.Collection collection, java.util.List properties) that conforms to XWiki Object standards. On Fri, Nov 16, 2012 at 3:06 AM, Jerome Velociter <jerome@velociter.fr>wrote:
Hi,
On 11/15/2012 03:00 PM, crocket wrote:
Ouch, there is a typo. $xwiki -> $doc
#set($services=$xwiki.**getDocument("Private.Snowberry Network Services").getObjects("**Private.NetworkServices"))
#foreach($prop in $services[0].getProperties()) $services[0].getProperty($**prop.getName()).getName() = $services[0].getProperty($**prop.getName()).getProperty().** getClassType() #end
The velocity snippet above produced an output.
port = com.xpn.xwiki.objects.**LongProperty protocol = com.xpn.xwiki.objects.**StringListProperty application = com.xpn.xwiki.objects.**StringProperty description = com.xpn.xwiki.objects.**StringProperty service = com.xpn.xwiki.objects.**StringProperty firewalled = com.xpn.xwiki.objects.**IntegerProperty
It appears that objects returned from $doc.getObjects("Class") have properties that belong to com.xpn.xwiki.objects package. I perused the package on http://maven.xwiki.org/site/**docs/xwiki-javadoc-4.2.x/com/** xpn/xwiki/objects/package-**summary.html<http://maven.xwiki.org/site/docs/xwiki-javadoc-4.2.x/com/xpn/xwiki/objects/package-summary.html>
I guess I will have to implement a Comparator that compares each of the following properties in the com.xpn.xwiki.objects package.
BaseStringProperty DateProperty DoubleProperty FloatProperty IntegerProperty LongProperty NumberProperty
Am I doing it right? or is it a bad idea to make separate comparison codes for each of those properties?
You might be interested by http://velocity.apache.org/** tools/devel/javadoc/org/**apache/velocity/tools/generic/**SortTool.html<http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html>
Hope this helps, Jerome
On Thu, Nov 15, 2012 at 9:57 PM, crocket <crockabiscuit@gmail.com> wrote:
I want to make such a Comparator so that I can sort objects retrieved by
$xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects.
I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even.
Is it possible?
If it was possible, would you give me some hints?
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs<http://lists.xwiki.org/mailman/listinfo/devs>
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs<http://lists.xwiki.org/mailman/listinfo/devs>
Hi, I`ve recently published a snippet [1] that provides a macro for sorting lists of XWiki objects in velocity. As for platform, we should probably either include such a macro in macros.vm, or extend SortTool and expose a method for handling XWiki objects. Hope this helps, Eduard ---------- [1] http://extensions.xwiki.org/xwiki/bin/view/Extension/Sort+a+list+of+XWiki+ob... On Fri, Nov 16, 2012 at 7:40 AM, crocket <crockabiscuit@gmail.com> wrote:
OK, $obj.getProperty("prop").getValue() gets the desired values.
$sorttool.sort conforms only to java bean standards.
I'll implement something like $sorttool.*sort< http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/to... , java.util.List)>*(java.util.Collection collection, java.util.List properties) that conforms to XWiki Object standards.
On Fri, Nov 16, 2012 at 3:06 AM, Jerome Velociter <jerome@velociter.fr
wrote:
Hi,
On 11/15/2012 03:00 PM, crocket wrote:
Ouch, there is a typo. $xwiki -> $doc
#set($services=$xwiki.**getDocument("Private.Snowberry Network Services").getObjects("**Private.NetworkServices"))
#foreach($prop in $services[0].getProperties()) $services[0].getProperty($**prop.getName()).getName() = $services[0].getProperty($**prop.getName()).getProperty().** getClassType() #end
The velocity snippet above produced an output.
port = com.xpn.xwiki.objects.**LongProperty protocol = com.xpn.xwiki.objects.**StringListProperty application = com.xpn.xwiki.objects.**StringProperty description = com.xpn.xwiki.objects.**StringProperty service = com.xpn.xwiki.objects.**StringProperty firewalled = com.xpn.xwiki.objects.**IntegerProperty
It appears that objects returned from $doc.getObjects("Class") have properties that belong to com.xpn.xwiki.objects package. I perused the package on http://maven.xwiki.org/site/**docs/xwiki-javadoc-4.2.x/com/** xpn/xwiki/objects/package-**summary.html< http://maven.xwiki.org/site/docs/xwiki-javadoc-4.2.x/com/xpn/xwiki/objects/p...
I guess I will have to implement a Comparator that compares each of the following properties in the com.xpn.xwiki.objects package.
BaseStringProperty DateProperty DoubleProperty FloatProperty IntegerProperty LongProperty NumberProperty
Am I doing it right? or is it a bad idea to make separate comparison
codes
for each of those properties?
You might be interested by http://velocity.apache.org/** tools/devel/javadoc/org/**apache/velocity/tools/generic/**SortTool.html< http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen...
Hope this helps, Jerome
On Thu, Nov 15, 2012 at 9:57 PM, crocket <crockabiscuit@gmail.com> wrote:
I want to make such a Comparator so that I can sort objects retrieved by
$xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects.
I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even.
Is it possible?
If it was possible, would you give me some hints?
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs< http://lists.xwiki.org/mailman/listinfo/devs>
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs< http://lists.xwiki.org/mailman/listinfo/devs>
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
I read the code, but it doesn't sort by multiple properties. I'm writing components that help sort by properties. On Fri, Nov 16, 2012 at 11:04 PM, Eduard Moraru <enygma2002@gmail.com>wrote:
Hi,
I`ve recently published a snippet [1] that provides a macro for sorting lists of XWiki objects in velocity.
As for platform, we should probably either include such a macro in macros.vm, or extend SortTool and expose a method for handling XWiki objects.
Hope this helps, Eduard
---------- [1]
http://extensions.xwiki.org/xwiki/bin/view/Extension/Sort+a+list+of+XWiki+ob...
On Fri, Nov 16, 2012 at 7:40 AM, crocket <crockabiscuit@gmail.com> wrote:
OK, $obj.getProperty("prop").getValue() gets the desired values.
$sorttool.sort conforms only to java bean standards.
I'll implement something like $sorttool.*sort<
http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/to...
, java.util.List)>*(java.util.Collection collection, java.util.List properties) that conforms to XWiki Object standards.
On Fri, Nov 16, 2012 at 3:06 AM, Jerome Velociter <jerome@velociter.fr
wrote:
Hi,
On 11/15/2012 03:00 PM, crocket wrote:
Ouch, there is a typo. $xwiki -> $doc
#set($services=$xwiki.**getDocument("Private.Snowberry Network Services").getObjects("**Private.NetworkServices"))
#foreach($prop in $services[0].getProperties()) $services[0].getProperty($**prop.getName()).getName() = $services[0].getProperty($**prop.getName()).getProperty().** getClassType() #end
The velocity snippet above produced an output.
port = com.xpn.xwiki.objects.**LongProperty protocol = com.xpn.xwiki.objects.**StringListProperty application = com.xpn.xwiki.objects.**StringProperty description = com.xpn.xwiki.objects.**StringProperty service = com.xpn.xwiki.objects.**StringProperty firewalled = com.xpn.xwiki.objects.**IntegerProperty
It appears that objects returned from $doc.getObjects("Class") have properties that belong to com.xpn.xwiki.objects package. I perused the package on http://maven.xwiki.org/site/**docs/xwiki-javadoc-4.2.x/com/** xpn/xwiki/objects/package-**summary.html<
http://maven.xwiki.org/site/docs/xwiki-javadoc-4.2.x/com/xpn/xwiki/objects/p...
I guess I will have to implement a Comparator that compares each of
the
following properties in the com.xpn.xwiki.objects package.
BaseStringProperty DateProperty DoubleProperty FloatProperty IntegerProperty LongProperty NumberProperty
Am I doing it right? or is it a bad idea to make separate comparison codes for each of those properties?
You might be interested by http://velocity.apache.org/**
tools/devel/javadoc/org/**apache/velocity/tools/generic/**SortTool.html<
http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen...
Hope this helps, Jerome
On Thu, Nov 15, 2012 at 9:57 PM, crocket <crockabiscuit@gmail.com>
wrote:
I want to make such a Comparator so that I can sort objects retrieved
by
$xwiki.getObjects("Class") If I had the Comparator, I'd be able to pass it to a collection sort method and sort objects.
I'm planning to make that Comparator in a groovy snippet. I may be able to make a Component for that even.
Is it possible?
If it was possible, would you give me some hints?
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs< http://lists.xwiki.org/mailman/listinfo/devs>
______________________________**_________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/**mailman/listinfo/devs< http://lists.xwiki.org/mailman/listinfo/devs>
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
participants (3)
-
crocket -
Eduard Moraru -
Jerome Velociter