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

The following examples show how to use org.alfresco.service.namespace.NamespacePrefixResolver#getPrefixes() . 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: 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 2
Source File: NodeSearcher.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see NodeServiceXPath
 */
public List<Serializable> selectProperties(NodeRef contextNodeRef, String xpath,
        QueryParameterDefinition[] paramDefs, NamespacePrefixResolver namespacePrefixResolver,
        boolean followAllParentLinks, String language)
{
    try
    {
        DocumentNavigator documentNavigator = new DocumentNavigator(dictionaryService, nodeService, searchService,
                namespacePrefixResolver, followAllParentLinks);
        NodeServiceXPath nsXPath = new NodeServiceXPath(xpath, documentNavigator, paramDefs);
        for (String prefix : namespacePrefixResolver.getPrefixes())
        {
            nsXPath.addNamespace(prefix, namespacePrefixResolver.getNamespaceURI(prefix));
        }
        @SuppressWarnings("rawtypes")
        List list = nsXPath.selectNodes(nodeService.getPrimaryParent(contextNodeRef));
        List<Serializable> answer = new ArrayList<Serializable>(list.size());
        for (Object o : list)
        {
            if (!(o instanceof DocumentNavigator.Property))
            {
                throw new XPathException("Xpath expression must only select nodes");
            }
            answer.add(((DocumentNavigator.Property) o).value);
        }
        return answer;
    }
    catch (JaxenException e)
    {
        throw new XPathException("Error executing xpath", e);
    }
}
 
Example 3
Source File: DBQuery.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String matchURI(String prefix, NamespacePrefixResolver namespacePrefixResolver)
{
    HashSet<String> prefixes = new HashSet<String>(namespacePrefixResolver.getPrefixes());
    if (prefixes.contains(prefix))
    {
        return namespacePrefixResolver.getNamespaceURI(prefix);
    }
    String match = null;
    for (String candidate : prefixes)
    {
        if (candidate.equalsIgnoreCase(prefix))
        {
            if (match == null)
            {
                match = candidate;
            }
            else
            {

                throw new QueryModelException("Ambiguous namespace prefix " + prefix);

            }
        }
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return namespacePrefixResolver.getNamespaceURI(match);
    }
}
 
Example 4
Source File: QueryParserUtils.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String matchURI(NamespacePrefixResolver namespacePrefixResolver, String prefix)
{
    HashSet<String> prefixes = new HashSet<String>(namespacePrefixResolver.getPrefixes());
    if (prefixes.contains(prefix))
    {
        return namespacePrefixResolver.getNamespaceURI(prefix);
    }
    String match = null;
    for (String candidate : prefixes)
    {
        if (candidate.equalsIgnoreCase(prefix))
        {
            if (match == null)
            {
                match = candidate;
            }
            else
            {

                throw new NamespaceException("Ambiguous namespace prefix " + prefix);

            }
        }
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return namespacePrefixResolver.getNamespaceURI(match);
    }
}
 
Example 5
Source File: NodeSearcher.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see NodeServiceXPath
 */
public List<NodeRef> selectNodes(NodeRef contextNodeRef, String xpathIn,
        QueryParameterDefinition[] paramDefs, NamespacePrefixResolver namespacePrefixResolver,
        boolean followAllParentLinks, String language)
{
    try
    {
        String xpath = xpathIn;

        List<AttributeOrder> order = null;

        DocumentNavigator documentNavigator = new DocumentNavigator(dictionaryService, nodeService, searchService,
                namespacePrefixResolver, followAllParentLinks);
        NodeServiceXPath nsXPath = new NodeServiceXPath(xpath, documentNavigator, paramDefs);
        for (String prefix : namespacePrefixResolver.getPrefixes())
        {
            nsXPath.addNamespace(prefix, namespacePrefixResolver.getNamespaceURI(prefix));
        }
        @SuppressWarnings("rawtypes")
        List list = nsXPath.selectNodes(nodeService.getPrimaryParent(contextNodeRef));
        HashSet<NodeRef> unique = new HashSet<NodeRef>(list.size());
        for (Object o : list)
        {
            if (o instanceof ChildAssociationRef)
            {
                unique.add(((ChildAssociationRef) o).getChildRef());
            }
            else if (o instanceof DocumentNavigator.Property)
            {
                unique.add(((DocumentNavigator.Property) o).parent);
            }
            else
            {
                throw new XPathException("Xpath expression must only select nodes");
            }
        }

        List<NodeRef> answer = new ArrayList<NodeRef>(unique.size());
        answer.addAll(unique);
        if (order != null)
        {
            orderNodes(answer, order);
            for(NodeRef node : answer)
            {
                StringBuffer buffer = new StringBuffer();
                for (AttributeOrder attOrd : order)
                {
                    buffer.append(" ").append(nodeService.getProperty(node, attOrd.attribute));
                }
            }
        }
        return answer;
    }
    catch (JaxenException e)
    {
        throw new XPathException("Error executing xpath: \n" + "   xpath: " + xpathIn, e);
    }
}