Skip navigation
Currently Being Moderated

REGARDING EXTRACTING OF PROPERTIES

Jul 23, 2012 11:40 PM

Tags: #cq5

Hi,

I am fairly new to ADOBE DAY CQ.. I want to extract properties of a particular node...

 

I am using the following code....

 

Node aName= session.getNode(absPath);

String propertyName= aName.getPRoperty("Name").getValue().getString();

 

I am aware that there is an abstract class named ABSTRACTSESSION which extends the OBJECT class and implements SESSION interface...

 

and getNode is a method defined in the class ABSTRACTSESSION...

 

What i want to know is "is there any class which extends the ABSTRACTSESSION??? Where can i find material to read about the session management in cq?

 

 

Regards and Thanks in advance,

 

Heidi.

 
Replies
  • Currently Being Moderated
    Jul 24, 2012 7:05 PM   in reply to Heidi albert

    In my opinion, it is generally more appropriate to use the Resource representation of your node.  You can use the adaptTo() method to convert it to a ValueMap and call .get("property name", Clazz.class) to retrieve properties.  Don't go all the way down to the JCR API unless you need to.

     

    The JavaDocs should tell you if there are any classes that extend AbstractSession.  Since it sounds like an abstract class, I would imagine there are classes that extend it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 2:10 AM   in reply to Heidi albert

    Hi  Heidi,

     

    As Ryan replied You can use ResourceResolver to get the Node resource and using adapTo() method convert this resource to Node.

    Below code snippets will help you to get the node properties:

     

    Resource res =  resourceResolver.getResource("Node Path like /content/myweb/en/home");

    Node node =  res.adaptTo(Node.class);

     

    PropertyIterator pIterator =  node.getProperties();

    while (pIterator.hasNext()){

              Property property =  pIterator.nextProperty();

              Value value = property.getValue();

              String strValue =  value.getString();

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 7:37 AM   in reply to Heidi albert

    You shouldn't have to use the Node API at all.  It's way lower-level than you need.  Use the resource resolver to do something like this...

     

    Resource resource = resourceResolver.getResouce("path/to/node");

     

    Then you can adapt that resource to a ValueMap to pull properties off of it, like this...

     

    String propertyValue = resource.adaptTo(ValueMap.class).get("propertyName", String.class);

     

    Adapting to a Node or retrieving a Node is not needed.  A resource is a more abstracted entity, and it's easier to work with.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 12:22 AM   in reply to Heidi albert

    Heidi,

     

    You need to import only javax.jcr.* package. All required class used in given code are available in javax.jcr package.

    If you wanted to access a particular property of a node, you can use similar to this:

     

    String propValue = node.getProperty("jcr:title").getValue().getString();

     

    I have done this way only, you can try Ryan approach also.

     

    Thanks

    Brijesh.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    Jul 31, 2012 8:23 AM   in reply to Heidi albert

    Heidi albert wrote:

    <%strProductPath =child.getPath()+"/jcr:content/par/productassignment";

    Resource res =  resourceResolver.getResource("strProductPath");

    LINE 46: Node nodes =  res.adaptTo(Node.class);

    productTitle = nodes.getProperty("name").getValue().getString();

        %> <%=productTitle%>

     

    I am getting the following error message:

     

    org.apache.sling.api.scripting.ScriptEvaluationException: An exception occurred processing JSP page /apps/trainings/components/productp/productp.jsp at line 46......

     

     

    Can you please help me out?

     

    Regards & Thanks,

    Heidi...

     

    What is the root exception? My guess is that it is a NullPointerException because 'res' is null.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    Jul 31, 2012 10:38 AM   in reply to Heidi albert

    Hi Heidi,

    I didn't say res was null. I said that you should provide the root  exception and that my guess was that res was null.

     

    That said, if you literally have the code:

    Resource res =  resourceResolver.getResource("strProductPath");

     

    then res will naturally be null because "strProductPath" isn't a path that exists. You probably mean

     

    Resource res =  resourceResolver.getResource(strProductPath);

     

    Regards,

    Justin

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    Aug 1, 2012 9:30 AM   in reply to Heidi albert

    Hi Heidi,

    Again, you need to get the root exception. There should be a stack trace in the log which contains this. That will tell you what the actual problem is, rather than me continuing to guess at a problem on a system I don't have access to.

     

    Regards,

    Justin

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    Aug 24, 2012 2:43 PM   in reply to Heidi albert

    Heidi-

    As I've said a few times now, you need to provide the root exception. If you want to Private Message me a package which contains both the content and the components, I can try to help you out further. But without the root exception, it is hard to tell what is going on.

     

    Justin

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points