Adobe CQ5:fetch properties from the JCR

fetch properties from the edit mode:

<%@page session="false"  contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>

<!-- JiaThis Button BEGIN -->
<%@include file="/libs/foundation/global.jsp"%>
<%@page import="javax.jcr.Node"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.HashSet"%>
<%@page import="javax.jcr.Value"%>
<%@page import="java.util.Arrays"%><div style="width:100%">
<div class="jiathis_style_24x24" style="height:50px; width:960px;z-index:999;margin: 0 auto;">
  <%
            Node node = null;
            String componentPath = "/content/BravoFor/zh/jcr:content";
            if (null == resourceResolver.getResource(componentPath)) {
                log.error("social media is null ----------------------[{}]", resourceResolver.getResource(componentPath));
                %>
               <h2>Please set social media</h2>
                <%
                return;
           } else {
               node = resourceResolver.getResource(componentPath).adaptTo(Node.class);
           }
        try {
            if (!node.hasProperty("socials")) {
                 %>
               <h2>Please set social media</h2>
                <%
                return;
            }
           //Node node = currentPage.getContentResource("socails").adaptTo(Node.class);
           log.error("node ----1111------------------- [{}]", node.getPath()); 
           log.error("node ----------------------- [{}]", node.getProperty("socials")); 

           Value[] socials = node.getProperty("socials").getValues();
           //put the values to a haseset to remove the repeat elements.
           Set<String> socialSet = new HashSet<String>();
           if (null != socials && socials.length > 0) {
              for (int i=0; i < socials.length; i ++ ) {
                   socialSet.add(socials[i].getString());
              }
           }
           Iterator<String> iter = socialSet.iterator();
           while(iter.hasNext()) {
        	   String social = iter.next();
        	   if (null != social) {
        		   %> <%= social %>  <% 
        	   }
           }
        }catch (Exception e) {
            log.error("social media is just a string ----------------------[{}]", node.getProperty("socials").getString());
             %> <%= node.getProperty("socials").getString() %>  <% 
        } 
        %>

</div>
</div>    
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

fetch properties from the design mode:

<%@page session="false"  contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ page import="com.day.cq.commons.Doctype,
    com.day.cq.wcm.api.components.DropTarget,
    com.day.cq.wcm.foundation.Image" %><%
%>

<%@include file="/libs/foundation/global.jsp"%>
<!-- JiaThis Button BEGIN -->

<%@page import="java.util.Set"%>
<%@page import="java.util.HashSet"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.util.Iterator"%><div style="width:100%">
<div class="jiathis_style_24x24" style="height:50px; width:960px;z-index:999;margin: 0 auto;">
<%
 
     log.error("currentStyle ---------- [{}]", currentStyle.getPath());
     if (null != currentStyle.getPath() && !currentStyle.getPath().endsWith("jcr:content/page/socials") ) {
         currentStyle = currentDesign.getStyle("/page/socials");
         log.error("currentStyle------------------- [{}]", currentStyle.getPath());
     }

     String[] socials = currentStyle.get("socials", String[].class);
     if (null != socials && socials.length > 0) {
         Set<String> socialsSet = new HashSet(Arrays.asList(socials));
         Iterator<String> iter = socialsSet.iterator();
         while (iter.hasNext()) {
             String social = iter.next();
             log.error("social simple ---------&&&&&&&&&&&&& [{}]", social);
             if (null != social) {
                 %> <%= social %>  <% 
             }
         }
     }
%>


</div>
</div>    
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->


你可能感兴趣的:(design,PageProperties,AdobeCQ5)