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

The following examples show how to use org.alfresco.service.namespace.QName#getNamespaceURI() . 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: AssocTargetRoleIntegrityEvent.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Checks that the association name matches the constraints imposed by the model.
 */
protected void checkAssocQNameRegex(
        List<IntegrityRecord> eventResults,
        ChildAssociationDefinition assocDef,
        QName assocQName,
        NodeRef sourceNodeRef)
{
    // check the association name
    QName assocRoleQName = assocDef.getTargetRoleName();
    if (assocRoleQName != null)
    {
        // the assoc defines a role name - check it
        RegexQNamePattern rolePattern = new RegexQNamePattern(assocRoleQName.getNamespaceURI(), assocRoleQName.getLocalName());
        if (!rolePattern.isMatch(assocQName))
        {
            IntegrityRecord result = new IntegrityRecord(
                    "The association name does not match the allowed role names: \n" +
                    "   Source Node: " + sourceNodeRef + "\n" +
                    "   Association: " + assocDef + "\n" +
                    "   Allowed roles: " + rolePattern + "\n" +
                    "   Name assigned: " + assocRoleQName);
            eventResults.add(result);
        }
    }
}
 
Example 2
Source File: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Pair<Long, QName> findByValue(QName qname)
{
    String uri = qname.getNamespaceURI();
    String localName = qname.getLocalName();
    Pair<Long, String> namespaceEntity = getNamespace(uri);
    if (namespaceEntity == null)
    {
        // There is no match on NS, so there is no QName like this
        return null;
    }
    Long nsId = namespaceEntity.getFirst();
    QNameEntity entity = findQNameEntityByNamespaceAndLocalName(nsId, localName);
    if (entity == null)
    {
        return null;
    }
    else
    {
        return new Pair<Long, QName>(entity.getId(), qname);
    }
}
 
Example 3
Source File: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int updateValue(Long id, QName qname)
{ 
    String uri = qname.getNamespaceURI();
    String localName = qname.getLocalName();

    QNameEntity entity = findQNameEntityById(id);
    if (entity == null)
    {
        // No chance of updating
        return 0;
    }

    // Create namespace
    Pair<Long, String> namespaceEntity = getOrCreateNamespace(uri);
    Long nsId = namespaceEntity.getFirst();
    // Create QName
    return updateQNameEntity(entity, nsId, localName);
}
 
Example 4
Source File: ISO9075.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String getXPathName(QName qName, NamespacePrefixResolver nspr)
{

    Collection<String> prefixes = nspr.getPrefixes(qName.getNamespaceURI());
    if (prefixes.size() == 0)
    {
        throw new NamespaceException("A namespace prefix is not registered for uri " + qName.getNamespaceURI());
    }
    String prefix = prefixes.iterator().next();
    if (prefix.equals(NamespaceService.DEFAULT_PREFIX))
    {
        return ISO9075.encode(qName.getLocalName());
    }
    else
    {
        return prefix + ":" + ISO9075.encode(qName.getLocalName());
    }

}
 
Example 5
Source File: DocumentNavigator.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getElementNamespaceUri(Object o)
{
    QName qName = ((ChildAssociationRef) o).getQName();
    if(qName == null)
    {
        return "";
    }
    return (qName.getNamespaceURI());
}
 
Example 6
Source File: MultiTServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private QName getName(QName name, String tenantDomain)
{
    if (name == null)
    {
        return null;
    }

    String namespace = name.getNamespaceURI();
    int idx1 = namespace.indexOf(SEPARATOR);
    if (idx1 == -1)
    {
        // no domain, so add it as a prefix (between two domain separators)
        namespace = SEPARATOR + tenantDomain + SEPARATOR + namespace;
        name = QName.createQName(namespace, name.getLocalName());
    }
    else
    {
        int idx2 = namespace.indexOf(SEPARATOR, 1);
        String nameDomain = namespace.substring(1, idx2);
        if (!tenantDomain.equalsIgnoreCase(nameDomain))
        {
            throw new AlfrescoRuntimeException("domain mismatch: expected = " + tenantDomain + ", actual = " + nameDomain);
        }
    }

    return name;
}
 
Example 7
Source File: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Pair<Long, QName> createValue(QName qname)
{
    String uri = qname.getNamespaceURI();
    String localName = qname.getLocalName();
    // Create namespace
    Pair<Long, String> namespaceEntity = getOrCreateNamespace(uri);
    Long nsId = namespaceEntity.getFirst();
    // Create QName
    QNameEntity entity = createQNameEntity(nsId, localName);
    return new Pair<Long, QName>(entity.getId(), qname);
}
 
Example 8
Source File: AbstractLockDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Split a lock's qualified name into the component parts using the '.' (period) as a
 * separator on the localname.  The namespace is preserved.  The provided qualified
 * name will always be the last component in the returned list. 
 * 
 * @param lockQName                 the lock name to split into it's higher-level paths
 * @return                          Returns the namespace ID along with the ordered localnames
 */
protected List<QName> splitLockQName(QName lockQName)
{
    String ns = lockQName.getNamespaceURI();
    String name = lockQName.getLocalName();
    
    StringTokenizer tokenizer = new StringTokenizer(name, ".");
    List<QName> ret = new ArrayList<QName>(tokenizer.countTokens());
    StringBuilder sb = new StringBuilder();
    // Fill it
    boolean first = true;
    while (tokenizer.hasMoreTokens())
    {
        if (first)
        {
            first = false;
        }
        else
        {
            sb.append(".");
        }
        sb.append(tokenizer.nextToken());
        QName parentLockQName = QName.createQName(ns, sb.toString());
        ret.add(parentLockQName);
    }
    // Done
    return ret;
}
 
Example 9
Source File: ChildAssocEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set all required fields associated with the patch <code>QName</code>.
 * 
 * @param forUpdate                 <tt>true</tt> if the entity is going to be used for a
 *                                  data update i.e. the <code>QName</code> <b>must</b> exist.
 * @return                          Returns <tt>true</tt> if the <code>QName</code> namespace
 *                                  exists.
 */
public boolean setQNameAll(QNameDAO qnameDAO, QName qname, boolean forUpdate)
{
    String assocQNameNamespace = qname.getNamespaceURI();
    String assocQNameLocalName = qname.getLocalName();
    Long assocQNameNamespaceId = null;
    if (forUpdate)
    {
        assocQNameNamespaceId = qnameDAO.getOrCreateNamespace(assocQNameNamespace).getFirst();
    }
    else
    {
        Pair<Long, String> nsPair = qnameDAO.getNamespace(assocQNameNamespace);
        if (nsPair == null)
        {
            // We can't set anything
            return false;
        }
        else
        {
            assocQNameNamespaceId = nsPair.getFirst();
        }
    }
    Long assocQNameCrc = getQNameCrc(qname);

    this.qnameNamespaceId = assocQNameNamespaceId;
    this.qnameLocalName = assocQNameLocalName;
    this.qnameCrc = assocQNameCrc;
    
    // All set correctly
    return true;
}
 
Example 10
Source File: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the namespace URI and prefix from the parent's name, provided that the
 * given name is of a valid format. The valid format consist of a
 * <i>namespace prefix</i>, a <i>colon</i> and a <i>name</i>. <b>E.g. sys:localized</b>
 * 
 * @param parentName the parent name
 * @return a pair of namespace URI and prefix object
 */
protected Pair<String, String> resolveToUriAndPrefix(String parentName)
{
    QName qName = prefixedStringToQname(parentName);
    Collection<String> prefixes = namespaceService.getPrefixes(qName.getNamespaceURI());
    if (prefixes.size() == 0)
    {
        throw new InvalidArgumentException("cmm.rest_api.prefix_not_registered", new Object[] { qName.getNamespaceURI() });
    }
    String prefix = prefixes.iterator().next();
    return new Pair<String, String>(qName.getNamespaceURI(), prefix);
}
 
Example 11
Source File: MetadataExtracter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Map<QName, Serializable> applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
{
    /*
     * Negative and positive checks are mixed in the loop.
     */
    Map<QName, Serializable> modifiedProperties = new HashMap<QName, Serializable>(7);
    for (Map.Entry<QName, Serializable> entry : extractedProperties.entrySet())
    {
        QName propertyQName = entry.getKey();
        Serializable extractedValue = entry.getValue();
        
        // Ignore null extracted value
        if (extractedValue == null)
        {
            modifiedProperties.put(propertyQName, extractedValue);
            continue;
        }
        
        // If the property is media related, always extract
        String propertyNS = propertyQName.getNamespaceURI();
        if(propertyNS.equals(NamespaceService.EXIF_MODEL_1_0_URI) ||
           propertyNS.equals(NamespaceService.AUDIO_MODEL_1_0_URI))
        {
           targetProperties.put(propertyQName, extractedValue);
           modifiedProperties.put(propertyQName, extractedValue);
           continue;
        }
        
        // Handle the shortcut cases where the target value is missing or null
        if (!targetProperties.containsKey(propertyQName))
        {
            // There is nothing currently
            targetProperties.put(propertyQName, extractedValue);
            modifiedProperties.put(propertyQName, extractedValue);
            continue;
        }
        
        // Look at the old value, and decide based on that
        Serializable originalValue = targetProperties.get(propertyQName);
        if (originalValue == null)
        {
            // The previous value is null, extract
            targetProperties.put(propertyQName, extractedValue);
            modifiedProperties.put(propertyQName, extractedValue);
            continue;
        }
        // Check the string representation
        if (originalValue instanceof String)
        {
            String originalValueStr = (String) originalValue;
            if (originalValueStr != null && originalValueStr.length() > 0)
            {
                // The original value is non-trivial
                continue;
            }
            else
            {
                // The original string is trivial
                targetProperties.put(propertyQName, extractedValue);
                modifiedProperties.put(propertyQName, extractedValue);
                continue;
            }
        }
        
        // We have some other object as the original value, so keep it
    }
    return modifiedProperties;
}
 
Example 12
Source File: AbstractLockDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Put new values against the given exclusive lock.  This works against the related locks as well.
 * @param optimistic                    <tt>true</tt> if a mismatch in the number of locked rows should
 *                                      be ignored.
 * @return                              <tt>true</tt> if the lock was successfully and fully updated
 *                                      using the lock token provided
 * @throws LockAcquisitionException     if the method is pessimistic and the number of rows does not
 *                                      correspond to the number expected
 */
private boolean updateLocks(
        QName lockQName,
        String lockToken,
        String newLockToken,
        long timeToLive,
        boolean optimistic)
{
    String qnameNamespaceUri = lockQName.getNamespaceURI();
    String qnameLocalName = lockQName.getLocalName();
    // Force lower case for case insensitivity
    if (!qnameLocalName.toLowerCase().equals(qnameLocalName))
    {
        lockQName = QName.createQName(qnameNamespaceUri, qnameLocalName.toLowerCase());
        qnameLocalName = lockQName.getLocalName();
    }
    // Force the lock token to lowercase
    lockToken = lockToken.toLowerCase();
    
    // Resolve the namespace
    Long qnameNamespaceId = qnameDAO.getOrCreateNamespace(qnameNamespaceUri).getFirst();
    
    // Get the lock resource for the exclusive lock.
    // All the locks that are created will need the exclusive case.
    LockResourceEntity exclusiveLockResource = getLockResource(qnameNamespaceId, qnameLocalName);
    if (exclusiveLockResource == null)
    {
        // If the exclusive lock doesn't exist, the locks don't exist
        throw new LockAcquisitionException(
                LockAcquisitionException.ERR_LOCK_RESOURCE_MISSING,
                lockQName, lockToken);
    }
    Long exclusiveLockResourceId = exclusiveLockResource.getId();
    // Split the lock name
    List<QName> lockQNames = splitLockQName(lockQName);
    // We just need to know how many resources needed updating.
    // They will all share the same exclusive lock resource
    int requiredUpdateCount = lockQNames.size();
    // Update
    int updateCount = updateLocks(exclusiveLockResourceId, lockToken, newLockToken, timeToLive);
    // Check
    if (updateCount != requiredUpdateCount)
    {
        if (optimistic)
        {
            // We don't mind.  Assume success but report that the lock was not removed by us.
            return false;
        }
        // Fall through to error states (pessimistic)
        if (LOCK_TOKEN_RELEASED.equals(newLockToken))
        {
            throw new LockAcquisitionException(
                    LockAcquisitionException.ERR_FAILED_TO_RELEASE_LOCK,
                    lockQName, lockToken);
        }
        else
        {
            throw new LockAcquisitionException(
                    LockAcquisitionException.ERR_LOCK_UPDATE_COUNT,
                    lockQName, lockToken, new Integer(updateCount), new Integer(requiredUpdateCount));
        }
    }
    else
    {
        // All updated successfully
        return true;
    }
    // Done
}
 
Example 13
Source File: DictionaryWebServiceBase.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param qname QName
 * @return the namespaceuri from a qname 
 */
public String getNamespaceURIfromQname(QName qname)
{
	return qname.getNamespaceURI();
}
 
Example 14
Source File: ISO9075.java    From alfresco-data-model with GNU Lesser General Public License v3.0 2 votes vote down vote up
public static String getXPathName(QName qName)
{

    return "{" + qName.getNamespaceURI() + "}" + ISO9075.encode(qName.getLocalName());

}