Load image path from node
Hi,
I have image component with uploaded image in it and I need to get path to that image so I can output it somewhere else.
For example: I have following node: "/content/myproject/mysite/mypage/mysubpage/jcr:content/imgcomp/file/jcr:content" and I need to output this image to <img> tag in my page. What should I do to add this functionality to my code?
String path = properties.get("pathToNodes", ""); //get path to nodes i want to work with if(path.length() == 0){ out.println("Enter path to nodes"); return; } try{ Node node = resourceResolver.adaptTo(Session.class).getNode(path); NodeIterator iterator = node.getNodes(); String currentPath = currentPage.getPath(); String[] titles = new String[PER_PAGE]; String[] intros = new String[PER_PAGE]; String[] images = new String[PER_PAGE]; String[] links = new String[PER_PAGE]; int i = 0; for(int j = 0; iterator.hasNext(); j++){ /* We want to print only the content of nodes on one page. So if we are not reading the nodes we want we just skip them */ if(i < (pageNum*PER_PAGE)-PER_PAGE){ iterator.nextNode(); continue; /* If we've already read all the nodes we want we can break the for */ }else if(i > pageNum*PER_PAGE){ break; } Node tmpNode = iterator.nextNode(); String tmpPath = tmpNode.getPath(); if(tmpPath.contains("jcr:content")) continue; if(tmpPath.contains(currentPath)){ continue; } tmpNode = tmpNode.getNode("jcr:content"); String[] splitted = tmpPath.split("/"); for(int k = 4; j k splitted.length; k++){ links[i]+= "/"+splitted[k]; } links[i]+=".html"; titles[i] = tmpNode.getNode("ctitle").getProperty("text").getString(); intros[i] = tmpNode.getNode("intro clr").getProperty("text").getString(); i++; } }catch(Exception e){ log.error("Error during articles output. "+e.getMessage()); }
Thanks for any help