Java Code Examples for org.alfresco.service.namespace.QName#splitPrefixedQName()

The following examples show how to use org.alfresco.service.namespace.QName#splitPrefixedQName() . 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: QNameFieldProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String makeDataKeyForName(String propName, String prefix)
{
    String[] nameParts = QName.splitPrefixedQName(propName);
    String firstPart = nameParts[0];
    StringBuilder builder = new StringBuilder(prefix);
    if (firstPart.length() > 0)
    {
        builder.append(firstPart);
        builder.append(DATA_KEY_SEPARATOR);
    }
    builder.append(nameParts[1]);
    return builder.toString();
}
 
Example 2
Source File: ImporterComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a valid qname-based xpath
 * 
 * Note: 
 * - the localname will be truncated to 100 chars
 * - the localname should already be encoded for ISO 9075 (in case of MT bootstrap, the @ sign will be auto-encoded, see below)
 * 
 * Some examples:
 *      /
 *      sys:people/cm:admin
 *      /app:company_home/app:dictionary
 *      ../../cm:people_x0020_folder
 *      sys:people/cm:admin_x0040_test
 *      
 * @param path String
 * @return String
 */
private String createValidPath(String path)
{
    StringBuffer validPath = new StringBuffer(path.length());
    String[] segments = StringUtils.delimitedListToStringArray(path, "/");
    for (int i = 0; i < segments.length; i++)
    {
        if (segments[i] != null && segments[i].length() > 0)
        {
            int colonIndex = segments[i].indexOf(QName.NAMESPACE_PREFIX);
            if (colonIndex == -1)
            {
                // eg. ".."
                validPath.append(segments[i]);
            }
            else
            {
                String[] qnameComponents = QName.splitPrefixedQName(segments[i]);
                
                String localName = QName.createValidLocalName(qnameComponents[1]);
                
                // MT: bootstrap of "alfrescoUserStore.xml" requires 'sys:people/cm:admin@tenant' to be encoded as 'sys:people/cm:admin_x0040_tenant' (for XPath)
                localName = localName.replace("@", "_x0040_");
                
                QName segmentQName = QName.createQName(qnameComponents[0], localName, namespaceService);
                validPath.append(segmentQName.toPrefixString());
            }
        }
        if (i < (segments.length -1))
        {
            validPath.append("/");
        }
    }
    return validPath.toString();
}
 
Example 3
Source File: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the qualified name of the following format
 * <code>prefix:localName</code>, as a pair of (prefix, localName)
 * 
 * @param prefixedQName the prefixed name. E.g. <code>prefix:localName</code>
 * @return {@link Pair} of (prefix, localName)
 */
private Pair<String, String> splitPrefixedQName(String prefixedQName)
{
    // index 0 => prefix and index 1 => local name
    String[] prefixLocalName = QName.splitPrefixedQName(prefixedQName);

    if (NamespaceService.DEFAULT_PREFIX.equals(prefixLocalName[0]))
    {
        throw new InvalidArgumentException("cmm.rest_api.prefixed_qname_invalid_format", new Object[] { prefixedQName });
    }

    return new Pair<String, String>(prefixLocalName[0], prefixLocalName[1]);
}
 
Example 4
Source File: DictionaryRepositoryBootstrap.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected NodeRef resolveQNamePath(NodeRef rootNodeRef, String[] pathPrefixQNameStrings)
{
    if (pathPrefixQNameStrings.length == 0)
    {
        throw new IllegalArgumentException("Path array is empty");
    }
    // walk the path
    NodeRef parentNodeRef = rootNodeRef;
    for (int i = 0; i < pathPrefixQNameStrings.length; i++)
    {
        String pathPrefixQNameString = pathPrefixQNameStrings[i];
        
        QName pathQName = null;
        if (tenantAdminService.isEnabled())
        {
            String[] parts = QName.splitPrefixedQName(pathPrefixQNameString);
            if ((parts.length == 2) && (parts[0].equals(NamespaceService.APP_MODEL_PREFIX)))
            {
                String pathUriQNameString = new StringBuilder(64).
                    append(QName.NAMESPACE_BEGIN).
                    append(NamespaceService.APP_MODEL_1_0_URI).
                    append(QName.NAMESPACE_END).
                    append(parts[1]).toString();
                
                pathQName = QName.createQName(pathUriQNameString);
            }
            else
            {
                pathQName = QName.createQName(pathPrefixQNameString, namespaceService);
            }
        }
        else
        {
            pathQName = QName.createQName(pathPrefixQNameString, namespaceService);
        }
        
        List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(parentNodeRef, RegexQNamePattern.MATCH_ALL, pathQName);
        if (childAssocRefs.size() != 1)
        {
            return null;
        }
        parentNodeRef = childAssocRefs.get(0).getChildRef();
    }
    return parentNodeRef;
}
 
Example 5
Source File: ImporterComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the child name to import node under
 * 
 * @param context  the node
 * @return  the child name
 */
private QName getChildName(ImportNode context)
{
    QName assocType = getAssocType(context);
    QName childQName = null;
    
    // Determine child name
    String childName = context.getChildName();
    if (childName != null)
    {
        childName = bindPlaceHolder(childName, binding);
        // <Fix for ETHREEOH-2299>
        if (ContentModel.TYPE_PERSON.equals(context.getTypeDefinition().getName())
                && assocType.equals(ContentModel.ASSOC_CHILDREN))
        {
            childName = childName.toLowerCase();
        }
        // </Fix for ETHREEOH-2299>
        String[] qnameComponents = QName.splitPrefixedQName(childName);
        childQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService); 
    }
    else
    {
        Map<QName, Serializable> typeProperties = context.getProperties();
        
        Serializable nameValue = typeProperties.get(ContentModel.PROP_NAME);

        if(nameValue != null && !String.class.isAssignableFrom(nameValue.getClass()))
        {
            throw new  ImporterException("Unable to use childName property: "+ ContentModel.PROP_NAME + " is not a string");  
        }
        
        String name = (String)nameValue;
        
        if (name != null && name.length() > 0)
        {
            name = bindPlaceHolder(name, binding);
            String localName = QName.createValidLocalName(name);
            childQName = QName.createQName(assocType.getNamespaceURI(), localName);
        }
    }
    
    return childQName;
}
 
Example 6
Source File: MessageServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected NodeRef resolveQNamePath(NodeRef rootNodeRef, String[] pathPrefixQNameStrings)
{
    if (pathPrefixQNameStrings.length == 0)
    {
        throw new IllegalArgumentException("Path array is empty");
    }
    // walk the path
    NodeRef parentNodeRef = rootNodeRef;
    for (int i = 0; i < pathPrefixQNameStrings.length; i++)
    {
        String pathPrefixQNameString = pathPrefixQNameStrings[i];
        
        QName pathQName = null;
        if (AuthenticationUtil.isMtEnabled())
        {
            String[] parts = QName.splitPrefixedQName(pathPrefixQNameString);
            if ((parts.length == 2) && (parts[0].equals(NamespaceService.APP_MODEL_PREFIX)))
            {
                String pathUriQNameString = new StringBuilder(64).
                    append(QName.NAMESPACE_BEGIN).
                    append(NamespaceService.APP_MODEL_1_0_URI).
                    append(QName.NAMESPACE_END).
                    append(parts[1]).toString();
                
                pathQName = QName.createQName(pathUriQNameString);
            }
            else
            {
                pathQName = QName.createQName(pathPrefixQNameString, namespaceService);
            }
        }
        else
        {
            pathQName = QName.createQName(pathPrefixQNameString, namespaceService);
        }
        
        List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(parentNodeRef, RegexQNamePattern.MATCH_ALL, pathQName);
        if (childAssocRefs.size() != 1)
        {
            return null;
        }
        parentNodeRef = childAssocRefs.get(0).getChildRef();
    }
    return parentNodeRef;
}