Java Code Examples for org.alfresco.service.namespace.NamespaceService.getPrefixes()

The following are Jave code examples for showing how to use getPrefixes() of the org.alfresco.service.namespace.NamespaceService class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-repository   File: ScriptNode.java   View Source Code Vote up 6 votes
/**
 * @return The array of aspects applied to this node as short prefix qname strings
 */
public Scriptable getAspectsShort()
{
    final NamespaceService ns = this.services.getNamespaceService();
    final Map<String, String> cache = new HashMap<String, String>();
    final Set<QName> aspects = getAspectsSet();
    final Object[] result = new Object[aspects.size()];
    int count = 0;
    for (final QName qname : aspects)
    {
        String prefix = cache.get(qname.getNamespaceURI());
        if (prefix == null)
        {
            // first request for this namespace prefix, get and cache result
            Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
            prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
            cache.put(qname.getNamespaceURI(), prefix);
        }
        result[count++] = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName();
    }
    return Context.getCurrentContext().newArray(this.scope, result);
}
 
Example 2
Project: alfresco-repository   File: AlfrescoScriptVirtualContext.java   View Source Code Vote up 5 votes
/**
 * @return an array containing the plain qname path at index 0 and the
 *         ISO9075 element-encoded qname path at index 1
 */
private String[] createQNamePaths()
{
    final NamespaceService ns = serviceRegistry.getNamespaceService();
    final Map<String, String> cache = new HashMap<String, String>();
    final StringBuilder bufPlain = new StringBuilder(128);
    final StringBuilder bufISO9075 = new StringBuilder(128);

    final Path path = serviceRegistry.getNodeService().getPath(context.getActualNodeRef());
    for (final Path.Element e : path)
    {
        if (e instanceof Path.ChildAssocElement)
        {
            final QName qname = ((Path.ChildAssocElement) e).getRef().getQName();
            if (qname != null)
            {
                String prefix = cache.get(qname.getNamespaceURI());
                if (prefix == null)
                {
                    // first request for this namespace prefix, get and
                    // cache result
                    Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
                    prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
                    cache.put(qname.getNamespaceURI(),
                              prefix);
                }
                bufISO9075.append('/').append(prefix).append(':').append(ISO9075.encode(qname.getLocalName()));
                bufPlain.append('/').append(prefix).append(':').append(qname.getLocalName());
            }
        }
        else
        {
            bufISO9075.append('/').append(e.toString());
            bufPlain.append('/').append(e.toString());
        }
    }
    String[] qnamePaths = new String[] { bufPlain.toString(), bufISO9075.toString() };

    return qnamePaths;
}
 
Example 3
Project: alfresco-repository   File: ScriptNode.java   View Source Code Vote up 4 votes
/**
 * @return QName path to this node. This can be used for Lucene PATH: style queries
 */
public String getQnamePath()
{
    if (this.qnamePath == null)
    {
        final NamespaceService ns = this.services.getNamespaceService();
        final Map<String, String> cache = new HashMap<String, String>();
        final StringBuilder buf = new StringBuilder(128);
        final Path path = this.services.getNodeService().getPath(getNodeRef());
        for (final Path.Element e : path)
        {
            if (e instanceof Path.ChildAssocElement)
            {
                final QName qname = ((Path.ChildAssocElement)e).getRef().getQName();
                if (qname != null)
                {
                    String prefix = cache.get(qname.getNamespaceURI());
                    if (prefix == null)
                    {
                        // first request for this namespace prefix, get and cache result
                        Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
                        prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
                        cache.put(qname.getNamespaceURI(), prefix);
                    }
                    buf.append('/');
                    if(prefix.length() > 0)
                    {
                    	  buf.append(prefix).append(':');
                    }
                    buf.append(ISO9075.encode(qname.getLocalName()));
                }
            }
            else
            {
                buf.append('/').append(e.toString());
            }
        }
        this.qnamePath = buf.toString();
    }
    
    return this.qnamePath;
}