本文整理匯總了Java中javax.jcr.Node.addNode方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.addNode方法的具體用法?Java Node.addNode怎麽用?Java Node.addNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jcr.Node
的用法示例。
在下文中一共展示了Node.addNode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyNode
import javax.jcr.Node; //導入方法依賴的package包/類
/**
* Copies nodes.
*
* @param node Node to copy
* @param destinationParent Destination parent node
* @throws RepositoryException if problem with jcr repository occurred
*/
public void copyNode(Node node, Node destinationParent) throws RepositoryException {
LOG.debug("Copying node '{}' into '{}'", node.getPath(), destinationParent.getPath());
Node newNode = destinationParent.addNode(node.getName(), node.getPrimaryNodeType().getName());
PropertyIterator it = node.getProperties();
while (it.hasNext()) {
Property property = it.nextProperty();
if (!property.getDefinition().isProtected()) {
newNode
.setProperty(property.getName(), property.getValue().getString(), property.getType());
}
}
NodeIterator nodeIterator = node.getNodes();
while (nodeIterator.hasNext()) {
copyNode(nodeIterator.nextNode(), newNode);
}
}
示例2: setUpdateScriptJcrNode
import javax.jcr.Node; //導入方法依賴的package包/類
/**
* do the update or create a node of the groovy file
* this will not save the session
*
* @param parent parentnode of the Node te be
* @param file file to transform into a Node
* @return success
* @throws RepositoryException
*/
public static boolean setUpdateScriptJcrNode(Node parent, File file) throws RepositoryException {
ScriptClass scriptClass = getInterpretingClass(file);
if(!scriptClass.isValid()){
return false;
}
final Updater updater = scriptClass.getUpdater();
String name = updater.name();
if(parent.hasNode(name)){
parent.getNode(name).remove();
}
Node scriptNode = parent.addNode(name, HIPPOSYS_UPDATERINFO);
scriptNode.setProperty(HIPPOSYS_BATCHSIZE, updater.batchSize());
scriptNode.setProperty(HIPPOSYS_DESCRIPTION, updater.description());
scriptNode.setProperty(HIPPOSYS_PARAMETERS, updater.parameters());
scriptNode.setProperty(updater.xpath().isEmpty() ? HIPPOSYS_PATH : HIPPOSYS_QUERY,
updater.xpath().isEmpty() ? updater.path() : updater.xpath());
scriptNode.setProperty(HIPPOSYS_SCRIPT, scriptClass.getContent());
scriptNode.setProperty(HIPPOSYS_THROTTLE, updater.throttle());
return true;
}
示例3: createProject
import javax.jcr.Node; //導入方法依賴的package包/類
@Override
public RepositoryFile createProject(String projectName, User user,boolean classify) throws Exception{
if(!permissionService.isAdmin()){
throw new NoPermissionException();
}
repositoryInteceptor.createProject(projectName);
Node rootNode=getRootNode();
if(rootNode.hasNode(projectName)){
throw new RuleException("Project ["+projectName+"] already exist.");
}
Node projectNode=rootNode.addNode(projectName);
projectNode.addMixin("mix:versionable");
projectNode.setProperty(FILE, true);
projectNode.setProperty(CRATE_USER,user.getUsername());
projectNode.setProperty(COMPANY_ID, user.getCompanyId());
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
DateValue dateValue = new DateValue(calendar);
projectNode.setProperty(CRATE_DATE, dateValue);
session.save();
createResourcePackageFile(projectName,user);
createClientConfigFile(projectName, user);
RepositoryFile projectFileInfo=buildProjectFile(projectNode, null ,classify,null);
return projectFileInfo;
}
示例4: findOrCreateNode
import javax.jcr.Node; //導入方法依賴的package包/類
private Node findOrCreateNode(Node parent, String path, String nodeType) throws RepositoryException {
Node result = parent;
for (String component : path.split("/")) {
component = Text.escapeIllegalJcrChars(component);
if (component.length() > 0) {
if (result.hasNode(component)) {
result = result.getNode(component);
} else {
if (ObjectHelper.isNotEmpty(nodeType)) {
result = result.addNode(component, nodeType);
} else {
result = result.addNode(component);
}
}
}
}
return result;
}
示例5: getGlobalPropertiesPath
import javax.jcr.Node; //導入方法依賴的package包/類
/**
* Takes resource and resource resolver return the global property path from the resource
*
* @param resource The resource to get the global property path from
* @return globalPropertiesPath
*/
public static String getGlobalPropertiesPath(Resource resource, ResourceResolver resourceResolver)
throws RepositoryException, PersistenceException {
String globalPropertiesPath = "";
Designer designer = resourceResolver.adaptTo(Designer.class);
Style style = designer.getStyle(resource);
Design design;
if (null != style) {
design = style.getDesign();
if (null != design) {
if (null != design.getContentResource()) {
if (null != design.getContentResource().getPath()) {
//add global node in design when it does not exist
Resource designResource = resourceResolver.getResource(design.getContentResource().getPath());
Node designNode = designResource.adaptTo(Node.class);
if (!designNode.hasNode(GLOBAL_PROPERTIES_KEY)) {
designNode.addNode(GLOBAL_PROPERTIES_KEY);
resourceResolver.commit();
}
// set global path
globalPropertiesPath = design.getContentResource().getPath() + GLOBAL_PATH;
}
}
}
}
return globalPropertiesPath;
}
示例6: createFileNode
import javax.jcr.Node; //導入方法依賴的package包/類
private void createFileNode(String path, String content,User user,boolean isFile) throws Exception{
String createUser=user.getUsername();
repositoryInteceptor.createFile(path,content);
Node rootNode=getRootNode();
path = processPath(path);
try {
if (rootNode.hasNode(path)) {
throw new RuleException("File [" + path + "] already exist.");
}
Node fileNode = rootNode.addNode(path);
fileNode.addMixin("mix:versionable");
fileNode.addMixin("mix:lockable");
Binary fileBinary = new BinaryImpl(content.getBytes());
fileNode.setProperty(DATA, fileBinary);
if(isFile){
fileNode.setProperty(FILE, true);
}
fileNode.setProperty(CRATE_USER, createUser);
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
DateValue dateValue = new DateValue(calendar);
fileNode.setProperty(CRATE_DATE, dateValue);
session.save();
} catch (Exception ex) {
throw new RuleException(ex);
}
}
示例7: getJcrFromFixture
import javax.jcr.Node; //導入方法依賴的package包/類
public Session getJcrFromFixture(InputStream fixture) {
Repository repository = null;
Session session = null;
try {
repository = MockJcr.newRepository();
session = repository.login();
Node rootNode = session.getRootNode();
Yaml parser = new Yaml();
List<Map<String, Object>> nodes = (ArrayList<Map<String, Object>>) parser.load(fixture);
for (Map object: nodes) {
NodeYaml node = new NodeYaml(
(String) object.get("path"),
(String) object.get("primaryType"),
(Map<String, Object>) object.getOrDefault("properties", emptyMap())
);
Node n = rootNode.addNode(node.path, node.primaryType);
for (Map.Entry<String, Object> entry : node.properties.entrySet()) {
if (entry.getValue() instanceof Boolean) {
n.setProperty(entry.getKey(), (Boolean) entry.getValue());
} else {
n.setProperty(entry.getKey(), entry.getValue().toString());
}
}
}
session.save();
} catch (RepositoryException e) {
throw new RuntimeException("Failed to set property on JCR node", e);
}
return session;
}
示例8: addNodeStringWithMultiRelativePathSegmentsCreatesChildNode
import javax.jcr.Node; //導入方法依賴的package包/類
@Test
public void addNodeStringWithMultiRelativePathSegmentsCreatesChildNode() throws Exception {
Node testObj = aNode("/content");
testObj.addNode("ko/foobar");
// BUG: DOES NOT EXIST
assertNull(client.getResourceResolver().getResource("/content/ko"));
// EXISTS
assertNotNull(client.getResourceResolver().getResource("/content/ko/foobar"));
}
示例9: removeWithExistingNodeRemovesNode
import javax.jcr.Node; //導入方法依賴的package包/類
@Test
public void removeWithExistingNodeRemovesNode() throws Exception {
Node target = aNode("/content");
Node testObj = target.addNode("foobar123");
assertThat(testObj, nodeExistsAt("/content/foobar123"));
testObj.remove();
try {
testObj.getNode("foobar123");
fail();
} catch (PathNotFoundException ex) {
// passed
}
}
示例10: addNodeStringWithSingleRelativePathSegmentCreatesChildNode
import javax.jcr.Node; //導入方法依賴的package包/類
@Test
public void addNodeStringWithSingleRelativePathSegmentCreatesChildNode() throws Exception {
Node testObj = aNode("/content");
testObj.addNode("test-pages");
assertNotNull(client.getResourceResolver().getResource("/content/test-pages"));
}
示例11: addNodeStringStringWithRelativePathAndPrimaryTypeCreatesNodeAndDoesNOTAssignDifferentType
import javax.jcr.Node; //導入方法依賴的package包/類
@Test
public void addNodeStringStringWithRelativePathAndPrimaryTypeCreatesNodeAndDoesNOTAssignDifferentType() throws Exception {
Node testObj = aNode("/content");
testObj.addNode("zipzap", "cq:Page");
Node actual = client.getResourceResolver().getResource("/content/zipzap").adaptTo(Node.class);
assertTrue(actual.isNodeType("cq:Page"));
}
示例12: createNode
import javax.jcr.Node; //導入方法依賴的package包/類
/**
* Creates new node.
*
* @param parentNodePath Absolute path to parent node.
* @param nodeName The name of the node to create.
* @param nodeType Node type, like nt:unstructured.
* @param properties Map of properties, where key is property name,
* value is {@link org.apache.commons.lang3.tuple.Pair}
* of
* <br>
* <property value, property type ({@link javax.jcr.PropertyType})>.
* @throws RepositoryException if problem with jcr repository occurred
*/
public void createNode(String parentNodePath, String nodeName, String nodeType,
Map<String, Pair<String, Integer>> properties) throws RepositoryException {
LOG.debug("Creating node '{}' of type '{}' under '{}'", nodeName, nodeType, parentNodePath);
session.refresh(true);
Node parentNode = session.getNode(parentNodePath);
Node createdNode = parentNode.addNode(nodeName, nodeType);
if (properties != null) {
for (Map.Entry<String, Pair<String, Integer>> mapEntry : properties.entrySet()) {
createdNode.setProperty(mapEntry.getKey(), mapEntry.getValue().getKey(), mapEntry.getValue()
.getValue());
}
}
session.save();
}
示例13: createBlueprint
import javax.jcr.Node; //導入方法依賴的package包/類
/**
* Static method to create a new blueprint.
*
* @param name The name for the new blueprint.
* @param title The title/jcr:title.
* @param sitePath Path of the current site's location
*/
protected void createBlueprint(String name, String title, String sitePath) throws RepositoryException, WCMException {
logger.info("Creating blueprint '{}' ({}) for {}", title, name, sitePath);
Page blueprintPage = pageManager.create("/etc/blueprints", name, "", title);
Node jcrContentNode = blueprintPage.getContentResource().adaptTo(Node.class);
jcrContentNode.setProperty("cq:template", "/libs/wcm/msm/templates/blueprint");
jcrContentNode.setProperty("sitePath", sitePath);
jcrContentNode.setProperty("sling:resourceType", "wcm/msm/components/blueprint");
jcrContentNode.setProperty("thumbnailRotate", "0");
Node dialogNode = jcrContentNode.addNode("dialog", "cq:Dialog");
dialogNode.setProperty("title", title + " Blueprint");
Node items1Node = dialogNode.addNode("items","cq:WidgetCollection");
Node tabsNode = items1Node.addNode("tabs", "cq:TabPanel");
Node items2Node = tabsNode.addNode("items", "cq:WidgetCollection");
Node tabLanNode = items2Node.addNode("tab_lan", "cq:Widget");
tabLanNode.setProperty("path", "/libs/wcm/msm/templates/blueprint/defaults/language_tab.infinity.json");
tabLanNode.setProperty("xtype", "cqinclude");
Node tabChapNode = items2Node.addNode("tab_chap", "cq:Widget");
tabChapNode.setProperty("path", "/libs/wcm/msm/templates/blueprint/defaults/chapters_tab.infinity.json");
tabChapNode.setProperty("xtype", "cqinclude");
Node tabLcNode = items2Node.addNode("tab_lc", "cq:Widget");
tabLcNode.setProperty("path", "/libs/wcm/msm/templates/blueprint/defaults/livecopy_tab.infinity.json");
tabLcNode.setProperty("xtype", "cqinclude");
}
示例14: saveScript
import javax.jcr.Node; //導入方法依賴的package包/類
private Script saveScript(ResourceResolver resolver, final String fileName, final InputStream input,
final boolean overwrite) {
Script result = null;
final Session session = resolver.adaptTo(Session.class);
final ValueFactory valueFactory;
try {
valueFactory = session.getValueFactory();
final Binary binary = valueFactory.createBinary(input);
final Node saveNode = session.getNode(getSavePath());
final Node fileNode, contentNode;
if (overwrite && saveNode.hasNode(fileName)) {
fileNode = saveNode.getNode(fileName);
contentNode = fileNode.getNode(JcrConstants.JCR_CONTENT);
} else {
fileNode = saveNode.addNode(generateFileName(fileName, saveNode), JcrConstants.NT_FILE);
contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
}
contentNode.setProperty(JcrConstants.JCR_DATA, binary);
contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name());
JcrUtils.setLastModified(contentNode, Calendar.getInstance());
session.save();
result = scriptFinder.find(fileNode.getPath(), resolver);
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
return result;
}
示例15: createDir
import javax.jcr.Node; //導入方法依賴的package包/類
public void createDir(String path,User user) throws Exception{
if(!permissionService.isAdmin()){
throw new NoPermissionException();
}
repositoryInteceptor.createDir(path);
Node rootNode=getRootNode();
path = processPath(path);
if (rootNode.hasNode(path)) {
throw new RuleException("Dir [" + path + "] already exist.");
}
boolean add = false;
String[] subpaths = path.split("/");
Node parentNode = rootNode;
for (String subpath : subpaths) {
if (StringUtils.isEmpty(subpath)) {
continue;
}
String subDirs[] = subpath.split("\\.");
for (String dir : subDirs) {
if (StringUtils.isEmpty(dir)) {
continue;
}
if (parentNode.hasNode(dir)) {
parentNode = parentNode.getNode(dir);
} else {
parentNode = parentNode.addNode(dir);
parentNode.addMixin("mix:versionable");
parentNode.addMixin("mix:lockable");
parentNode.setProperty(DIR_TAG, true);
parentNode.setProperty(FILE, true);
parentNode.setProperty(CRATE_USER,user.getUsername());
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
DateValue dateValue = new DateValue(calendar);
parentNode.setProperty(CRATE_DATE, dateValue);
add = true;
}
}
}
if (add) {
session.save();
}
}