Tuesday 5 July 2011

Looping through the children of a specified node

Here is a JSP to dump out the child nodes of a specified parent node, & the properties of the child nodes.


<%request.setAttribute("silentAuthor", new Boolean(true));%><%
%><%@include file="/libs/foundation/global.jsp"%><%
response.setContentType("text");
response.setCharacterEncoding("utf-8");
%><%@ page import="java.util.Iterator,
com.day.cq.wcm.foundation.Paragraph,
com.day.cq.wcm.foundation.ParagraphSystem,
com.day.text.Text,
com.day.cq.tagging.Tag,
com.day.cq.wcm.api.PageFilter,
com.day.cq.tagging.TagManager,
com.day.cq.wcm.api.components.IncludeOptions,
java.util.Calendar,
java.util.Collection,
java.util.regex.*,
java.util.Map,
org.apache.sling.api.resource.ResourceUtil,
org.apache.commons.lang.StringUtils,
org.apache.commons.lang.StringEscapeUtils"%><%

//slingResponse.setContentType("application/xml;charset=utf-8");
slingResponse.setCharacterEncoding("utf-8");

String fullRecipeList = slingRequest.getParameter("pathsList");
if (!StringUtils.isEmpty(fullRecipeList))
{
String[] recipeList = fullRecipeList.split("\n");


for (int recipeCount=0; recipeCount < recipeList.length; recipeCount++)
{
if (StringUtils.isEmpty(recipeList[recipeCount].trim()))
{
continue;
}

// Strip off everything after the ".html"
int positionOfHtml = recipeList[recipeCount].indexOf(".html");
String currentRecipePath = "";
if (positionOfHtml > 0)
{
currentRecipePath = recipeList[recipeCount].substring(0, positionOfHtml);
}
else
{
currentRecipePath = recipeList[recipeCount];
}

Resource resRootPage = slingRequest.getResourceResolver().resolve(currentRecipePath);

if (resRootPage == null)
{
continue;
}

Iterator children = ResourceUtil.listChildren(resRootPage);

while (children.hasNext())
{
Resource resourcePage2 = children.next();

if (resourcePage2.getPath().indexOf("jcr:content") > -1)
{
continue;
}

Node n = resourcePage2.adaptTo(Node.class);
if (n == null)
{
continue;
}
%>
<%= n.getPath() %> <%
PropertyIterator resProps = n.getProperties();
if (resProps == null)
{
continue;
}

long nProps = resProps.getSize();
for (int i = 0; i < nProps; i++)
{
Property p = resProps.nextProperty();
if (!p.getDefinition().isMultiple())
{
%> <%= p.getName() %> <%= p.getString() %> <%
}
}
}
}
}
%>

7 comments:

  1. Need custom essay writing services? We are a professional assignment help company
    ready to serve you. essay writer

    ReplyDelete
    Replies
    1. My Aem (Cq) Blog: Looping Through The Children Of A Specified Node >>>>> Download Now

      >>>>> Download Full

      My Aem (Cq) Blog: Looping Through The Children Of A Specified Node >>>>> Download LINK

      >>>>> Download Now

      My Aem (Cq) Blog: Looping Through The Children Of A Specified Node >>>>> Download Full

      >>>>> Download LINK M5

      Delete
  2. A very good article. Thanks to the author. It is very important to support and help students. Come to our service and tell the assistant : write my paper for me

    ReplyDelete
  3. You have such a great blog! I love reading it. I am a writer at https://ewriters.pro/and I always enjoy visiting your platform for my own inspiration.

    ReplyDelete
  4. Thats a pretty simple and effective way to write a node. In other cases if you need some advice on how to write a footnote you should check out this blog post. It has some tips and examples that may be helpful

    ReplyDelete
  5. They are exotic and unusually beautiful. But more interestingly, these women are asian brides wonderful wives and mothers.

    ReplyDelete
  6. Hi, guys! Some weeks ago I had experience with ordering an opinion essay from an online source with writers and I was so surprised with the result. My paper was prepared with all my instructions applied and was delivered on time so I would recommend it to students and pupils anyway.

    ReplyDelete