当前位置: 首页>>代码示例>>Java>>正文


Java JcrUtils.getOrCreateByPath方法代码示例

本文整理汇总了Java中org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath方法的典型用法代码示例。如果您正苦于以下问题:Java JcrUtils.getOrCreateByPath方法的具体用法?Java JcrUtils.getOrCreateByPath怎么用?Java JcrUtils.getOrCreateByPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jackrabbit.commons.JcrUtils的用法示例。


在下文中一共展示了JcrUtils.getOrCreateByPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createEmptyCache

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
private Node createEmptyCache(HtmlLibrary library, String root, Session session)  {
	Node node = null;
	// this.lock.writeLock().lock();
	try {
		Node swap = JcrUtils.getOrCreateByPath(root, 
				JcrResourceConstants.NT_SLING_FOLDER, 
				JcrResourceConstants.NT_SLING_FOLDER, 
				session, true);
		node = swap.addNode(getLibraryName(library), JcrConstants.NT_FILE);
		swap = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
		swap.setProperty(JcrConstants.JCR_LASTMODIFIED, 0L);
		swap.setProperty(JcrConstants.JCR_MIMETYPE, library.getType().contentType);
		swap.setProperty(JcrConstants.JCR_DATA, 
				session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
		session.save();
		// this.lock.writeLock().unlock();
	} catch(RepositoryException re) {
		log.debug(re.getMessage());
	}
	return node;
}
 
开发者ID:steeleforge,项目名称:aemin,代码行数:22,代码来源:HtmlLibraryManagerDelegateImpl.java

示例2: setUp

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    predicateParams = new HashMap<String, String>();

    session = MockJcr.newSession();

    node = JcrUtils.getOrCreateByPath("/content/asset.pdf", JcrConstants.NT_UNSTRUCTURED, session);

    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-1", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-2", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-3", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-4", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-5", JcrConstants.NT_UNSTRUCTURED, session);

    when(row.getNode()).thenReturn(node);
    when(predicate.getParameters()).thenReturn(predicateParams);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:18,代码来源:NodeExistsPredicateEvaluatorTest.java

示例3: create

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
@Override
public Page create(String parentPath, String pageName, String template, String title,
                   boolean autoSave) throws WCMException {
    if (parentPath == null) throw new IllegalArgumentException("Parent path can't be null.");
    if (pageName == null && title == null)
        throw new IllegalArgumentException("Page and title name can't be both null.");
    if (template != null && !template.isEmpty())
        throw new UnsupportedOperationException("Templates are not supported.");

    try {
        Node parent = JcrUtils.getOrCreateByPath(parentPath, JcrConstants.NT_UNSTRUCTURED, session);

        if (pageName == null || pageName.isEmpty())
            pageName = JcrUtil.createValidName(title, JcrUtil.HYPHEN_LABEL_CHAR_MAPPING);
        if (!JcrUtil.isValidName(pageName)) throw new IllegalArgumentException("Illegal page name: " + pageName);

        Node pageNode = parent.addNode(pageName, JcrConstants.CQ_PAGE);
        Node contentNode = pageNode.addNode("jcr:content", JcrConstants.CQ_PAGE_CONTENT);

        if (title != null && !title.isEmpty()) contentNode.setProperty("jcr:title", title);
        if (autoSave) {
            session.save();
        }

        return getPage(pageNode.getPath());
    }
    catch (RepositoryException e) {
        throw new WCMException("Unable to create page", e);
    }
}
 
开发者ID:TWCable,项目名称:jackalope,代码行数:31,代码来源:PageManagerImpl.java

示例4: FlagStore

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
public FlagStore(final Jcrom jcrom, final Session initialSession)
    throws RepositoryException {
  this.jcrom = jcrom;
  for (FlagType ft : FlagType.values()) {
    JcrUtils.getOrCreateByPath(ft.getRootPath(),
        NodeType.NT_UNSTRUCTURED, initialSession);
  }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:9,代码来源:FlagStore.java

示例5: addFailure

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
public void addFailure(String payloadPath, String trackPath, Calendar failedAt) throws RepositoryException {
    Node failure = JcrUtils.getOrCreateByPath(resource.getChild(Workspace.NN_FAILURES).adaptTo(Node.class),
            Workspace.NN_FAILURE, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false);

    JcrUtil.setProperty(failure, Failure.PN_PAYLOAD_PATH, payloadPath);

    if (StringUtils.isNotBlank(trackPath)) {
        JcrUtil.setProperty(failure, Failure.PN_PATH, Payload.dereference(trackPath));
    }

    if (failedAt != null) {
        JcrUtil.setProperty(failure, Failure.PN_FAILED_AT, failedAt);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:15,代码来源:Workspace.java

示例6: create

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public final Page create(final ResourceResolver resourceResolver, String bucketSegment,
                         final String name, final String... paths) throws WCMException,
        RepositoryException {

    final Session session = resourceResolver.adaptTo(Session.class);
    final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);

    String bucketPath = "/etc/workflow/packages";
    if (StringUtils.isNotBlank(bucketSegment)) {
        bucketPath += "/" + bucketSegment;
    }

    final Node shardNode = JcrUtils.getOrCreateByPath(bucketPath,
            NT_SLING_FOLDER, NT_SLING_FOLDER, session, false);
    final Page page = pageManager.create(shardNode.getPath(), JcrUtil.createValidName(name),
            WORKFLOW_PACKAGE_TEMPLATE, name, false);
    final Resource contentResource = page.getContentResource();

    Node node = JcrUtil.createPath(contentResource.getPath() + "/" + NN_VLT_DEFINITION, NT_VLT_DEFINITION, session);
    node = JcrUtil.createPath(node.getPath() + "/filter", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtil.setProperty(node, SLING_RESOURCE_TYPE, FILTER_RESOURCE_TYPE);

    int i = 0;
    Node resourceNode = null;
    for (final String path : paths) {
        if (path != null) {
            resourceNode = JcrUtil.createPath(node.getPath() + "/resource_" + i++,
                    JcrConstants.NT_UNSTRUCTURED, session);
            JcrUtil.setProperty(resourceNode, "root", path);
            JcrUtil.setProperty(resourceNode, "rules", this.getIncludeRules(path));
            JcrUtil.setProperty(resourceNode, SLING_RESOURCE_TYPE, FILTER_RESOURCE_RESOURCE_TYPE);
        }
    }

    session.save();

    return page;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:42,代码来源:WorkflowPackageManagerImpl.java

示例7: execute

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
@Override
public String execute(ResourceResolver resourceResolver) {

    JcrObservationThrottle jcrObservationThrottle = null;
    try {
        // Create the unique, temp node under which the event queue will be stored.
        // Your resourceResolver must have permissions to create / modify / delete this node.

        final String tmpPath = "/tmp/jcr-event-throttle/" + this.getClass().getName() + "/" + UUID.randomUUID().toString();
        final Node tmpNode = JcrUtils.getOrCreateByPath(tmpPath, JcrConstants.NT_UNSTRUCTURED, resourceResolver.adaptTo(Session.class));

        // Create a new JcrObservationThrottle for this operation and pass in the tmpNode that will record/queue the events
        jcrObservationThrottle = new JcrObservationThrottle(tmpNode);

        // Start listening against this JCR Session
        jcrObservationThrottle.open();

        for (int i = 0; i < 10000; i++) {
            // Do a bunch of writes to the JCR
            if (i % 10 == 0) {
                // You can perform multiple saves and "trap" the events in this throttle
                resourceResolver.commit();
            }
        }

        if (resourceResolver.hasChanges()) {
            // Commit and lagging commits from the work loop above
            resourceResolver.commit();
        }

        log.debug("Waiting for throttled observation events to be delivered.");
        // *** WARNING ***
        // The amount of time to wait is determined by the event activity of the system at this point in time, so be conscious of this.
        final long t = jcrObservationThrottle.waitForEvents();
        log.info("Waited [ {} ] ms for throttled observation events to be delivered", t);
    } catch (RepositoryException | PersistenceException e) {
        log.error("Something bad happened!", e);
    } finally {
        if (jcrObservationThrottle != null) {
            // Always close the JcrObervationThrottle in a finally black to ensure it gets closed.
            jcrObservationThrottle.close();
        }
    }

    return null;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:47,代码来源:SampleJcrObservationThrottle.java

示例8: initialize

import org.apache.jackrabbit.commons.JcrUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void initialize(QueryHelper queryHelper, Config config) throws
        PersistenceException, RepositoryException {

    // Query for all candidate resources
    final ResourceResolver resourceResolver = config.getResourceResolver();
    final List<Resource> resources = queryHelper.findResources(resourceResolver,
            config.getQueryType(),
            config.getQueryStatement(),
            config.getRelativePath());

    int total = 0;

    // Create Workspace Node
    Node workspace = JcrUtils.getOrAddNode(config.getResource().adaptTo(Node.class), Workspace.NN_WORKSPACE, Workspace.NT_UNORDERED);
    // Create the PayloadGroups Launchpad node; this simply points to the first to process
    Node currentPayloadGroup = JcrUtils.getOrCreateByPath(workspace, Workspace.NN_PAYLOADS_LAUNCHPAD, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false);
    // Set the first Payload Group to be the launchpad node
    JcrUtil.setProperty(workspace, Workspace.PN_ACTIVE_PAYLOAD_GROUPS, new String[]{PayloadGroup.dereference(currentPayloadGroup.getPath())});


    // No begin populating the actual PayloadGroup nodes
    ListIterator<Resource> itr = resources.listIterator();

    while (itr.hasNext()) {
        // Increment to a new PayloadGroup as needed
        if (total % config.getBatchSize() == 0 && itr.hasNext()) {
            // payload group is complete; save...
            Node nextPayloadGroup = JcrUtils.getOrCreateByPath(workspace, Workspace.NN_PAYLOADS, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false);
            JcrUtil.setProperty(currentPayloadGroup, PayloadGroup.PN_NEXT, PayloadGroup.dereference(nextPayloadGroup.getPath()));
            currentPayloadGroup = nextPayloadGroup;
        }

        // Process the payload
        Resource payload = itr.next();
        Node payloadNode = JcrUtils.getOrCreateByPath(currentPayloadGroup, Payload.NN_PAYLOAD, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false);
        JcrUtil.setProperty(payloadNode, "path", Payload.dereference(payload.getPath()));
        log.debug("Created payload with search result [ {} ]", payload.getPath());

        if (++total % SAVE_THRESHOLD == 0 || !itr.hasNext()) {
            resourceResolver.commit();
        }
    } // while

    if (total > 0) {
        config.getWorkspace().getRunner().initialize(config.getWorkspace(), total);
        config.commit();

        log.info("Completed initialization of Bulk Workflow Manager");
    } else {
        throw new IllegalArgumentException("Query returned zero results.");
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:57,代码来源:AbstractWorkflowRunner.java


注:本文中的org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。