Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.Path

This class simplifies working with paths and using a Path is often more efficient that processing and manipulating the equivalent String. This class can easily {@link #iterator() iterate} over the segments, returnthe {@link #size() number of segments}, {@link #compareTo(Path) compare} with other paths, {@link #resolve(Path) resolve}relative paths, return the {@link #getParent() ancestor (or parent)}, determine whether one path is an {@link #isAncestorOf(Path) ancestor} or {@link #isDescendantOf(Path) decendent} of another path, and{@link #getCommonAncestor(Path) finding a common ancestor}.


            // Now process the changes ...
            for (Change change : changeSet) {
                // Look at property added and removed events.
                if (change instanceof PropertyAdded) {
                    PropertyAdded added = (PropertyAdded)change;
                    Path nodePath = added.getPathToNode();
                    String strPath = stringFactory.create(nodePath);
                    Name propName = added.getProperty().getName();
                    // Check if the property is sequencable ...
                    for (SequencingConfiguration config : configs) {
                        Matcher matcher = config.matches(strPath, propName);
                        if (!matcher.matches()) {
                            if (TRACE) {
                                LOGGER.trace("Added property '{1}:{0}' in repository '{2}' did not match sequencer '{3}' and path expression '{4}'",
                                             added.getPath(), workspaceName, repository.name(), config.getSequencer().getName(),
                                             config.getPathExpression());
                            }
                            continue;
                        }
                        if (TRACE) {
                            LOGGER.trace("Submitting added property '{1}:{0}' in repository '{2}' for sequencing using '{3}' and path expression '{4}'",
                                         added.getPath(), workspaceName, repository.name(), config.getSequencer().getName(),
                                         config.getPathExpression());
                        }
                        // The property should be sequenced ...
                        submitWork(config, matcher, workspaceName, stringFactory.create(propName), changeSet.getUserId());
                    }
                } else if (change instanceof PropertyChanged) {
                    PropertyChanged changed = (PropertyChanged)change;
                    Path nodePath = changed.getPathToNode();
                    String strPath = stringFactory.create(nodePath);
                    Name propName = changed.getNewProperty().getName();
                    // Check if the property is sequencable ...
                    for (SequencingConfiguration config : configs) {
                        Matcher matcher = config.matches(strPath, propName);
View Full Code Here


    @Test
    public void shouldConsiderPathDecendantOfOtherPathIfParentIsAtOrBelowOtherPath() {
        parent = mock(Path.class);
        path = new ChildPath(parent, segment("d"));
        Path other = mock(Path.class);
        when(parent.isAtOrBelow(other)).thenReturn(true);
        assertThat(path.isDescendantOf(other), is(true));
        verify(parent).isAtOrBelow(other);

        when(parent.isAtOrBelow(other)).thenReturn(false);
View Full Code Here

    protected void createInitialNodes() {
        super.createInitialNodes();

        for (Map.Entry<String, Document> entry : new HashMap<String, Document>(documentsByLocation).entrySet()) { // copy
            String pathStr = entry.getKey();
            Path path = pathFrom(pathStr);
            if (path.size() == 1 && isAutoCreatedNode(path)) {
                String parentId = readDocument(entry.getValue()).getDocumentId();

                String id1 = newId();
                Document doc1 = newDocument(id1).setPrimaryType("nt:unstructured").setParent(parentId).document();
                documentsById.put(id1, doc1);
View Full Code Here

    @Override
    protected void storedDocument( String documentId,
                                   Document document ) {
        String docPath = pathFromDocumentId(documentId);
        assert docPath != null;
        Path path = pathFrom(docPath);
        if (path.size() == 3 && path.getSegment(1).getName().getLocalName().equals("generate")) {
            List<DocInfo> newDocs = new ArrayList<DocInfo>();
            ConnectorChangeSet changes = newConnectorChangedSet();
            Name topName = path.getSegment(0).getName();
            Name name = path.getSegment(2).getName();

            // Find the parent ...
            String generatedOutPath = "/" + topName.getLocalName() + "/generated-out";
            String generatedOutId = getDocumentId(generatedOutPath);
            Document generatedOutDoc = getDocumentById(generatedOutId);
View Full Code Here

        root = path;
    }

    @Test
    public void shouldReturnRootForLowestCommonAncestorWithAnyNodePath() {
        Path other = mock(Path.class);
        when(other.isRoot()).thenReturn(true);
        assertThat(root.getCommonAncestor(other).isRoot(), is(true));

        when(other.isRoot()).thenReturn(false);
        assertThat(root.getCommonAncestor(other).isRoot(), is(true));
    }
View Full Code Here

    @Override
    protected void preRemoveDocument( String documentId,
                                      Document document ) {
        String docPath = pathFromDocumentId(documentId);
        Path path = pathFrom(docPath);
        if (path.size() == 3 && path.getSegment(1).getName().getLocalName().equals("generate")) {
            ConnectorChangeSet changes = newConnectorChangedSet();

            // Determine the id of the node we'll remove ...
            Name topName = path.getSegment(0).getName();
            Name name = path.getSegment(2).getName();
            String generatedOutPath = "/" + topName.getLocalName() + "/generated-out";
            Document generatedOutDoc = documentsByLocation.get(generatedOutPath);
            String generatedOutId = readDocument(generatedOutDoc).getDocumentId();

            String oldPath = generatedOutPath + "/" + name.getLocalName();
View Full Code Here

        assertThat(root.getCommonAncestor(other).isRoot(), is(true));
    }

    @Test
    public void shouldConsiderRootToBeAncestorOfEveryNodeExceptRoot() {
        Path other = mock(Path.class);
        when(other.size()).thenReturn(1);
        assertThat(root.isAncestorOf(other), is(true));
        assertThat(root.isAncestorOf(root), is(false));
    }
View Full Code Here

        assertThat(root.isAncestorOf(root), is(false));
    }

    @Test
    public void shouldNotConsiderRootNodeToBeDecendantOfAnyNode() {
        Path other = mock(Path.class);
        assertThat(root.isDescendantOf(other), is(false));
        assertThat(root.isDescendantOf(root), is(false));
    }
View Full Code Here

    @Test
    public void shouldReturnRelativePathConsistingOfSameNumberOfParentReferencesAsSizeOfSuppliedPath() {
        List<Path.Segment> segments = new ArrayList<Path.Segment>();
        segments.add(new BasicPathSegment(new BasicName("http://example.com", "a")));
        Path other = new BasicPath(segments, true);

        assertThat(root.relativeTo(other).toString(), is(".."));

        segments.add(new BasicPathSegment(new BasicName("http://example.com", "b")));
        other = new BasicPath(segments, true);
View Full Code Here

    @Test
    public void shouldResolveAllRelativePathsToTheirAbsolutePath() {
        List<Path.Segment> segments = new ArrayList<Path.Segment>();
        segments.add(new BasicPathSegment(new BasicName("http://example.com", "a")));
        Path other = mock(Path.class);
        when(other.isAbsolute()).thenReturn(false);
        when(other.getSegmentsList()).thenReturn(segments);
        when(other.getNormalizedPath()).thenReturn(other);
        Path resolved = root.resolve(other);
        assertThat(resolved.getSegmentsList(), is(segments));
        assertThat(resolved.isAbsolute(), is(true));
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.Path

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.