Java Code Examples for org.alfresco.service.cmr.repository.Path#append()

The following examples show how to use org.alfresco.service.cmr.repository.Path#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a String representation of a path to a Path
 * 
 * e.g "/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/application/1.0}dictionary/{http://www.alfresco.org/model/application/1.0}transfers/{http://www.alfresco.org/model/content/1.0}default/{http://www.alfresco.org/model/transfer/1.0}snapshotMe";
 * @param value the string representation of the path.
 * @return Path 
 */
public static Path stringToPath(String value)
{
    Path path = new Path();
    
    // pattern for QName e.g. /{stuff}stuff
    
    Pattern pattern = Pattern.compile("/\\{[a-zA-Z:./0-9]*\\}[^/]*");
    Matcher matcher = pattern.matcher(value);
    
    // This is the root node
    path.append(new SimplePathElement("/"));
           
    while ( matcher.find() )
    {
        String group = matcher.group();
        final String val = ISO9075.decode(group.substring(1));
        path.append(new SimplePathElement(val));
    }
    
    return path;
}
 
Example 2
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * move transfer node to new parent.
 * @param childNode
 * @param newParent
 */
private void moveNode(TransferManifestNormalNode childNode, TransferManifestNormalNode newParent)
{
    List<ChildAssociationRef> currentParents = childNode.getParentAssocs();
    List<ChildAssociationRef> newParents = new ArrayList<ChildAssociationRef>();

    for (ChildAssociationRef parent : currentParents)
    {
        if (!parent.isPrimary())
        {
            newParents.add(parent);
        }
        else
        {
            ChildAssociationRef newPrimaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, newParent
                    .getNodeRef(), parent.getQName(), parent.getChildRef(), true, -1);
            newParents.add(newPrimaryAssoc);
            childNode.setPrimaryParentAssoc(newPrimaryAssoc);
            Path newParentPath = new Path();
            newParentPath.append(newParent.getParentPath());
            newParentPath.append(new Path.ChildAssocElement(newParent.getPrimaryParentAssoc()));
            childNode.setParentPath(newParentPath);
        }
    }
    childNode.setParentAssocs(newParents);
}
 
Example 3
Source File: NodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @throws UnsupportedOperationException always
 */
public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException
{
    ChildAssociationRef childAssocRef = getPrimaryParent(nodeRef);
    Path path = new Path();
    path.append(new Path.ChildAssocElement(childAssocRef));
    return path;
}
 
Example 4
Source File: GetPathMethod.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Path execute(NodeProtocol protocol, Reference reference) throws ProtocolMethodException
{
    Reference parent = protocol.getVirtualParentReference(reference);
    NodeRef nodeRef = protocol.getNodeRef(reference);
    Path nodeRefPath = environment.getPath(nodeRef);
    Path parentPath = parent.execute(this);
    parentPath.append(nodeRefPath.last());
    return parentPath;
}
 
Example 5
Source File: UnitTestTransferManifestNodeFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get mapped path
 */
public Path getMappedPath(Path from)
{
    Path to = new Path();

    /**
     * 
     */
    Path source = new Path();
    for (int i = 0; i < from.size(); i++)
    {
        // Source steps through each element of from.
        source.append(from.get(i));
        boolean replacePath = false;
        for (Pair<Path, Path> xx : getPathMap())
        {
            // Can't use direct equals because of mismatched node refs (which we don't care about)
            if (xx.getFirst().toString().equals(source.toString()))
            {
                to = xx.getSecond().subPath(xx.getSecond().size() - 1);
                replacePath = true;
                break;
            }
        }
        if (!replacePath)
        {
            to.append(from.get(i));
        }
    }

    return to;
}
 
Example 6
Source File: NodeChangeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("serial")
private Path newPath(Path parent, final String name)
{
    Path path = new Path();
    if (parent != null)
    {
        for(Path.Element element: parent)
        {
            path.append(element);
        }
    }
    path.append(new Path.Element()
    {
        @Override
        public String getElementString()
        {
            return name;
        }

        @Override
        public Element getBaseNameElement(TenantService tenantService)
        {
           return this;
        }
    });
    return path;
}