Adobe 需要一个cq5示例吗
我是Adobe cq5的新手。浏览了许多在线博客和教程,但没有得到多少。任何人都可以提供一个AdobeCQ5应用程序示例,其中包含可以在JCR中存储和检索数据的详细说明Adobe 需要一个cq5示例吗,adobe,aem,jcr,Adobe,Aem,Jcr,我是Adobe cq5的新手。浏览了许多在线博客和教程,但没有得到多少。任何人都可以提供一个AdobeCQ5应用程序示例,其中包含可以在JCR中存储和检索数据的详细说明 提前感谢。这里是CQ 5.4的一个片段,让您开始学习。它在内容层次结构中的任意位置插入内容页和文本(作为parsys)。位置由有效负载提供,但您可以编写从命令行运行的内容,并使用任何有效的CRX路径。将其作为流程步骤的好处是,您可以为自己建立一个会话,并且可以导航到插入点 import java.text.SimpleDateF
提前感谢。这里是CQ 5.4的一个片段,让您开始学习。它在内容层次结构中的任意位置插入内容页和文本(作为parsys)。位置由有效负载提供,但您可以编写从命令行运行的内容,并使用任何有效的CRX路径。将其作为流程步骤的好处是,您可以为自己建立一个会话,并且可以导航到插入点
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowData;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import com.day.cq.wcm.api.NameConstants;
@Component
@Service
@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION,
value = "Makes a new tree of nodes, subordinate to the payload node, from the content of a file."),
@Property(name = Constants.SERVICE_VENDOR, value = "Acme Coders, LLC"),
@Property(name = "process.label", value = "Make new nodes from file")})
public class PageNodesFromFile implements WorkflowProcess {
private static final Logger log = LoggerFactory.getLogger(PageNodesFromFile.class);
private static final String TYPE_JCR_PATH = "JCR_PATH";
* * *
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args)
throws WorkflowException {
//get the payload
WorkflowData workflowData = workItem.getWorkflowData();
if (!workflowData.getPayloadType().equals(TYPE_JCR_PATH)) {
log.warn("unusable workflow payload type: " + workflowData.getPayloadType());
workflowSession.terminateWorkflow(workItem.getWorkflow());
return;
}
String payloadString = workflowData.getPayload().toString();
//the text to be inserted
String lipsum = "Lorem ipsum...";
//set up some node info
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d-MMM-yyyy-HH-mm-ss");
String newRootNodeName = "demo-page-" + simpleDateFormat.format(new Date());
SimpleDateFormat simpleDateFormatSpaces = new SimpleDateFormat("d MMM yyyy HH:mm:ss");
String newRootNodeTitle = "Demo page: " + simpleDateFormatSpaces.format(new Date());
//insert the nodes
try {
Node parentNode = (Node) workflowSession.getSession().getItem(payloadString);
Node pageNode = parentNode.addNode(newRootNodeName);
pageNode.setPrimaryType(NameConstants.NT_PAGE); //cq:Page
Node contentNode = pageNode.addNode(Node.JCR_CONTENT); //jcr:content
contentNode.setPrimaryType("cq:PageContent"); //or use MigrationConstants.TYPE_CQ_PAGE_CONTENT
//from com.day.cq.compat.migration
contentNode.setProperty(javax.jcr.Property.JCR_TITLE, newRootNodeTitle); //jcr:title
contentNode.setProperty(NameConstants.PN_TEMPLATE,
"/apps/geometrixx/templates/contentpage"); //cq:template
contentNode.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
"geometrixx/components/contentpage"); //sling:resourceType
Node parsysNode = contentNode.addNode("par");
parsysNode.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
"foundation/components/parsys");
Node textNode = parsysNode.addNode("text");
textNode.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
"foundation/components/text");
textNode.setProperty("text", lipsum);
textNode.setProperty("textIsRich", true);
workflowSession.getSession().save();
}
catch (RepositoryException e) {
log.error(e.toString(), e);
workflowSession.terminateWorkflow(workItem.getWorkflow());
return;
}
}
}
我已经发帖了
其他几点:
- 我在内容的名称和标题中加入了时间戳 要插入的页面。这样,您可以运行许多代码和测试周期 如果不清理存储库,您就知道哪个测试是 最近一次。额外的好处:没有重复的文件名,没有 含糊不清
- Adobe和Day在为 属性值、节点类型等。我使用了 我可以在别处找到并使用文字字符串
- 我没有像上次修改日期那样填写属性。编码 我会这样做的
- 我发现自己被Node.setPrimaryType()和
。这两种方法只是粗略的 补充;setter接受一个字符串,但getter返回一个字符串 包含各种信息的节点类型Node.getPrimaryNodeType()
- 在这段代码的原始版本中,我从文件中读取要插入的文本,而不仅仅是使用静态字符串“Lorem ipsum…”
完成此示例后,您应该能够使用编写从CRX读回数据的代码。如果您想了解如何编写可以存储和查询CQ JRC数据的CQ应用程序,请参阅本文: 这提供了一个循序渐进的指南,指导您完成整个过程,包括使用Maven构建OSGi包
从上面的评论中,我看到了对BND文件的引用。您应该远离CRXDE来创建OSGi并使用Maven 你读过哪些在线博客?你自己试过什么代码?在开始使用JCR数据之前,您需要对CQ5(Sling、JCR、OSGi)背后的概念有一个基本的了解。我已经尝试过了,但是在创建OSGI包时遇到了问题。我使用了您提到的JCR示例。它工作得很好。在创建简单捆绑包时尝试此链接:。您可以创建一个“Hello world”捆绑包,并通过调用组件中的方法来显示它。jsphello world捆绑包工作正常,但当我尝试在该链接中编译捆绑包时,它会在org.apache.felix.scr.annotations.component的导入语句中出错;org.apache.felix.scr.annotations.Service;org.apache.felix.scr.annotations.Activate;org.apache.felix.scr.annotations.Reference;。。就像下面提到的。。只能导入类型。org.apache.felix.scr.annotations.Activate解析为CustomerServiceImp.java/localhost_4502_cae88c4b-40f2-4421-9bc3-4facad55cfe1/WebContent/apps/com.sample.osgi.bundle/src/main/java/com/adobe/cq line 7hi riju,你能给我分享你从哪里开始学习cq5的好教程吗。。。