How to get selected properties of a child node under a node? - json

i am new in adobe cq5 .I created a page test in my repository inside the
content node of page.I have 100 nodes example test-1 , test-2,test-3....test-100.I want to retrieve the selected properties of these nodes like name , modification date etc.How can i achieve this ? can anybody help regarding this.

From your question title, you want to get a JSON representation of your nodes. This is a built in feature (which should be blocked on the dispatcher though):
Just add .X.json to your path whereas X is a the depth, e.g. http://localhost:4502/content.2.json
If you want to have XML you can just add the extenstion .xml to your path, though there it will just return the properties of the specified page and not the complete hierarchy as with JSON.

If you want get data through all hierarchy use 'infinity' selector and 'json' extension.
for example
http://localhost:4502/content/geometrixx/en/toolbar.infinity.json

Out of the box you can use the parent-folder-of-your-nodes.N.json notation as shown above.
If you need a specific format with just those properties you can write a script or servlet and mount it on a specific selector so that parent-folder-of-your-nodes.your-selector.json returns your custom format.
The http://sling.apache.org/documentation/the-sling-engine/servlets.html documentation should help with that, and there are numerous examples of such Sling servlets and scripts in the Apache Sling source code, for example under http://svn.apache.org/repos/asf/sling/trunk/launchpad/

Related

Custom JSON renderer in AEM/Sling

I've been playing around with this for a while now, and I think, I've - almost - cracked it, but I am still not fully satisfied with my solution.
So, what I want to do, is having a piece of content, a list of items, which would have two views: The standard HTML one, so people can view and edit it; and then a JSON endpoint for other services to consume.
First I thought it's a simple matter of creating two JSP scripts to render the content:
/apps/my-stuff/components/list-page/html.jsp
/apps/my-stuff/components/list-page/json.jsp
However the Apache Sling DefaultServlet seems to be rather ignorant of the json.jsp script.
As a second attempt, I created another script, in /apps/foundation/components/primary/cq/Page/json.jsp which will be actually called, and renders the page, as I expected. However there are a couple of worries/questions regarding this:
First of all, why is this being honoured by the system, and not the one in the more specific place?
The documentation states, that to find the appropriate renderer, first sling:resourceType will be inspected, then sling:resourceSuperType and then, only as a fallback will jcr:PrimaryType checked. However I think this is rather: jcr:PrimaryType, then the DefaultServlet, and then all the other things.
Most worryingly however, I have to admit, this is rather generic, so it'll break all the contnet with jcr:PrmaryType = Page, so that could have some side-effects.
A solution could be creating a new type: ListPage extends Page; and then create a renderer for that in /apps/foundation.... However I have this bad feeling, that might introduce other problems.
So my question is two fold: What is the proper way of doing this, and/or what am I missing from the way the URL -> script resolution is working in AEM/Sling. (Because it seems to be slightly different that described here and here.)
(Obviously I am trying to keep the default JSON renderer for other pages, as that might be needed for other things in the page. I am not even sure, changing this one page won't break the UI for this particular page...)
However the Apache Sling DefaultServlet seems to be rather ignorant of the json.jsp script.
Have you tried renaming your JSP like so: "list-page.json.jsp"?
If you're using AEM 6.3, you should look at Sling model Exporters. They allow you to automatically register a servlet against your Sling Model (that you can create to model your list content). That servlet can generate a JSON representation of the model for you using Jackson.
If you're not using AEM 6.3, I would suggest you create a servlet registered against your resource type and use an additional selector.
#SlingServlet(
selectors = "json",
resourceType = "my-stuff/components/list-page",
methods = "GET")
More information on Sling Servlets can be found here.

con:settings Elements in Workspace and Project Files

I am using the free edition of SoapUI (version 4.6.1) with multiple workspaces. One of my frustrations is that SoapUI does not seem to support workspace-level custom properties.
The *-soapui-workspace.xml files I have reviewed contain an empty con:settings element (i.e. <con:settings/>). Same in the *-soapui-project.xml files I have reviewed.
My intuition & hope is that these elements allow workspace- or project-level additions to or overrides of settings I see in my general soapui-settings.xml file - e.g. additional global properties that I want when a given workspace is loaded.
However, when I create a settings file SomeService Tests-soapui-settings.xml that contains...
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-settings xmlns:con="http://eviware.com/soapui/config">
<con:setting id="GlobalPropertySettings#properties"><![CDATA[<xml-fragment xmlns:con="http://eviware.com/soapui/config">
<con:property>
<con:name>WorkspaceCustomPropertyTest</con:name>
<con:value>some value</con:value>
</con:property>
</xml-fragment>]]>
</con:setting>
</con:soapui-settings>
...and set the con:settings element in the SomeService Tests-soapui-workspace.xml file like so...
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-workspace name="SomeService Tests" soapui-version="4.6.1" projectRoot="${workspaceDir}" xmlns:con="http://eviware.com/soapui/config">
<con:description>Workspace to organize all SomeService test projects.</con:description>
<con:settings>SomeService Tests-soapui-settings.xml</con:settings> <!-- Reference the workspace settings file. -->
<con:project name="SomeService Authentication Tests">SomeService Authentication Tests-soapui-project.xml</con:project>
</con:soapui-workspace>
..., nothing happens.
I do not get an error upon loading the workspace, but I also do not get any indication that the con:settings element is doing anything either. For example, SoapUI Preferences > Global Properties does not list a WorkspaceCustomPropertyTest property.
I can keep tinkering of course, but an explanation of the workspace- and project-file con:settings elements would help.
Searching SO, the SmartBear SoapUI forum, and more broadly for an explanation of the workspace- and project-file con:settings elements has yielded nothing so far.
Can anyone explain how to use the workspace- and project-file con:settings elements?
Alternatively, can anyone shed light on how to achieve a similar result (i.e. workspace-level custom properties) with the free edition of SoapUI?
What about that?
Create a ini("myconfig.groovy") file("assuming that this file will be in the same directory of your project file"):
global_property='Global value'
Use this groovy script to grab the property:
// Script imports
import com.eviware.soapui.support.GroovyUtils
import groovy.util.ConfigSlurper
// Grovvy utils handle OS directories path abstraction
def groovyUtils = new GroovyUtils(context)
def config = new ConfigSlurper().parse(new File(groovyUtils.projectPath + '/myconfig.groovy').toURL())
// Just logging the property but you can set the property here
log.info config.global_property
Then you can add the value to the desired object at run time.
It doesn't seem possible to do it at the workspace level. You could do it at one of the testing levels, see: http://www.soapui.org/Functional-Testing/working-with-properties.html
SoapUI does support global properties.
In File> Preferences> Global Properties
Here you can assign Global Properties that spans all projects. Sadly, currently, it will be used for all work spaces. Hope this helps, having a groovy script to manually handle everything just seems a bit over kill to me.

JTree Node Names / Group names are not visible

I've written a JTree with couple of nodes. When I launch the program, I only see the node icons like folder or file and not the names associated with them. I could expand and collapse the nodes. When I debug, I see that the nodes are set with proper data whatever I used while building the model. In this program, i've written wrappers for JTree, TreeModel, DefaultMutableTreeNode. What could be the problem? Any pointers would be of great help.
-Paul
Sorry for not posting more details/code. Anyway, I've found the problem with my code. The problem was that I had overridden the toString() method in the class that I use to set as user object for the tree node, but that was returning null. As the method was returning null, there was nothing displayed. I made it to return the string to be displayed. It is working good now.
Thanks guys..!

JTreeTable model updating

I'm following the example of JTreeTable filesystem2 taken from the sun site http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html#updating_the
My problem is that I can't update my model (and then my JTreeTable)...
In fact I create my model, I pass it to the JTreeTable and all work fine...but I need to modify the model...
I've yet answer a similar question, but now I've changed my code, without find a solution.
The problem is when and how I have to call the method fireTreeNodesChanged()...in the example above is used the method getPath() to retrieve information about the root node...but this is a method of File class..not my case...
Does anyone have a link to a simple code which shows how create a TreeTabelModel (with objects as nodes) and how update it?
FileBrowser is a good example of modeling a hierarchical file system as a tree. While its TreeModel is implemented using DefaultTreeModel, an alternative FileTreeModel is shown here. As mentioned in How to Use Trees: Creating a Data Model "the TreeModel interface accepts any kind of object as a tree node."

What is a language binding?

My good friend, Wikipedia, didn't give me a very good response to that question. So:
What are language bindings?
How do they work?
Specifically accessing functions from code written in language X of a library written in language Y.
Let's say you create a C library to post stuff to stackoverflow. Now you want to be able to use the same library from Python. In this case, you will write Python bindings for your library.
Also see SWIG: http://www.swig.org
In the context of code libraries, bindings are wrapper libraries that bridge between two programming languages so that a library that was written for one language can also be implicitly used in another language.
For example, libsvn is the API for Subversion and was written in C. If you want to access Subversion from within Java code you can use libsvn-java. libsvn-java depends on libsvn being installed because libsvn-java is a mere bridge between the Java programming language and libsvn, providing an API that merely calls functions of libsvn to do the real work.
Okay, now the question has been clarified, this isn't really relevant so I'm moving it to a new question
Binding generally refers to a mapping of one thing to another - i.e. a datasource to a presentation object. It can typically refer to binding data from a database, or similar source (XML file, web service etc) to a presentation control or element - think list or table in HTML, combo box or data grid in desktop software.
...If that's the kind of binding you're interested in, read on...
You generally have to bind the presentation element to the datasource, not the other way around. This would involve some kind of mapping - i.e. which fields from the datasource do you want to appear in the output.
For more information in a couple of environments see:
Data binding in .Net using Windows Forms
http://www.codeproject.com/KB/database/databindingconcepts.aspx
http://www.akadia.com/services/dotnet_databinding.html
ASP.NET data binding
http://support.microsoft.com/kb/307860
http://www.15seconds.com/issue/040630.htm
http://www.w3schools.com/ASPNET/aspnet_databinding.asp
Java data binding
http://www.xml.com/pub/a/2003/09/03/binding.html
Python data binding
http://www.xml.com/pub/a/2005/07/27/py-xml.html
General XML data binding
http://www.rpbourret.com/xml/XMLDataBinding.htm
In Flex (Actionscript 3). Source
A data binding copies the value of a property in one object to a property in another object. You can bind the properties of following objects: Flex components, Flex data models, and Flex data services.
The object property that provides the data is known as the source property. The object property that receives the data is known as the destination property.
The following example binds the text property of a TextInput component (the source property) to the text property of a Label component (the destination property) so that text entered in the TextInput component is displayed by the Label component:
<mx:TextInput id="LNameInput"></mx:TextInput>
...
<mx:Label text="{LNameInput.text}"></mx:Label>
Data binding is usually a simple way to bind a model to user interface components. For example, you have a class with a FirstName property. In flex you could easily bind that property to a textbox by setting the value of the textbox to {Object.FirstName}. Then, every time that FirstName property changes, the textbox will be updated without requiring you to write any code to monitor that property for changes.
Hope that helps.
Matt