我需要使用java服务在AEM中创建一个节点。我创建了一个工作流,其中一个进程触发<form>
<input type="radio" name="gender" value="general" checked> General<br>
<input type="radio" name="gender" value="medium"> Medium<br>
<input type="radio" name="gender" value="high"> High
</form>
内的java服务。
我是否需要使用java服务创建节点或者只是以编程方式创建节点?
答案 0 :(得分:3)
可以使用各种API来创建节点:
1.使用节点API
Node node = resource.adaptTo(Node.class);
node.addNode(nodeName, NodePrimaryType);
答案 1 :(得分:1)
工作流会话可以适应JCR会话,您可以通过JCR API访问读/写。
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
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 javax.jcr.Node;
import javax.jcr.Session;
@Component
@Service
@Properties({@Property(name = Constants.SERVICE_DESCRIPTION, value = "Some Service")})
public class AddTheNodeWorkflow implements WorkflowProcess {
@Override
public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
try {
final String payloadPath = getPayloadPath(workItem);
final Session session = workflowSession.adaptTo(Session.class);
// get the node for the workflow payload
final Node payloadNode = session.getNode(payloadPath);
// add the node
final Node somenode = payloadNode.addNode("somenode");
somenode.setProperty("myproperty", "my property value");
} catch (Exception e) {
e.printStackTrace();
}
}
private String getPayloadPath(WorkItem workItem) {
return workItem.getWorkflowData().getPayload().toString();
}
}