Java Code Examples for org.alfresco.util.ISO9075#decode()

The following examples show how to use org.alfresco.util.ISO9075#decode() . 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: NodeInfoFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String getName(QName qName)
{
    String name = null;
    
    try
    {
        name = qName.toPrefixString(namespaceService);
    }
    catch (NamespaceException e)
    {
        name = qName.toPrefixString();
    }
    name = ISO9075.decode(name);
    
    return name;
}
 
Example 3
Source File: DocumentNavigator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Iterator getChildAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException
{
    // decode the localname
    localName = ISO9075.decode(localName);
    
    // MNT-10730
    if (localName != null && (localName.equalsIgnoreCase("true") || localName.equalsIgnoreCase("false")))
    {
        return Collections.singletonList(new Boolean(Boolean.parseBoolean(localName))).iterator();
    }
    
    ChildAssociationRef assocRef = (ChildAssociationRef) contextNode;
    NodeRef childRef = assocRef.getChildRef();
    QName qName = QName.createQName(namespaceURI, localName);
    List<? extends ChildAssociationRef> list = null;
    list = nodeService.getChildAssocs(childRef, RegexQNamePattern.MATCH_ALL, qName);
    // done
    return list.iterator();
}
 
Example 4
Source File: SiteTitleDisplayHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public FacetLabel getDisplayLabel(String value)
{
    // Solr returns the site short name encoded
    value = ISO9075.decode(value);
    String title = null;

    if (nonSiteLocationsLabels.containsKey(value))
    {
        title = nonSiteLocationsLabels.get(value);
    }
    else
    {
        SiteService siteService = serviceRegistry.getSiteService();
        SiteInfo siteInfo = siteService.getSite(value);
        title = siteInfo != null ? siteInfo.getTitle() : value;
    }

    return new FacetLabel(value, title, -1);
}
 
Example 5
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the short name of the site this node is located within. If the 
 * node is not located within a site null is returned.
 * 
 * @return The short name of the site this node is located within, null
 *         if the node is not located within a site.
 */
public String getSiteShortName()
{
    if (!this.siteNameResolved)
    {
        this.siteNameResolved = true;
        
        Path path = this.services.getNodeService().getPath(getNodeRef());
        
        if (logger.isDebugEnabled())
            logger.debug("Determing if node is within a site using path: " + path);
        
        for (int i = 0; i < path.size(); i++)
        {
            if ("st:sites".equals(path.get(i).getPrefixedString(this.services.getNamespaceService())))
            {
                // we now know the node is in a site, find the next element in the array (if there is one)
                if ((i+1) < path.size())
                {
                    // get the site name
                    Path.Element siteName = path.get(i+1);
                 
                    // remove the "cm:" prefix and add to result object
                    this.siteName = ISO9075.decode(siteName.getPrefixedString(
                                this.services.getNamespaceService()).substring(3));
                }
              
                break;
            }
        }
    }
    
    if (logger.isDebugEnabled())
    {
        logger.debug(this.siteName != null ? 
                    "Node is in the site named \"" + this.siteName + "\"" : "Node is not in a site");
    }
    
    return this.siteName;
}
 
Example 6
Source File: BaseContentNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the short name of the site this node is located within. If the 
 * node is not located within a site null is returned.
 * 
 * @return The short name of the site this node is located within, null
 *         if the node is not located within a site.
 */
public String getSiteShortName()
{
    if (!this.siteNameResolved)
    {
        this.siteNameResolved = true;
        
        Path path = this.services.getNodeService().getPath(getNodeRef());
        
        for (int i = 0; i < path.size(); i++)
        {
            if ("st:sites".equals(path.get(i).getPrefixedString(this.services.getNamespaceService())))
            {
                // we now know the node is in a site, find the next element in the array (if there is one)
                if ((i+1) < path.size())
                {
                    // get the site name
                    Path.Element siteName = path.get(i+1);
                 
                    // remove the "cm:" prefix and add to result object
                    this.siteName = ISO9075.decode(siteName.getPrefixedString(
                                this.services.getNamespaceService()).substring(3));
                }
              
                break;
            }
        }
    }
    
    return this.siteName;
}
 
Example 7
Source File: TemplateFilingRule.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private NodeRef parentNodeRefFor(Reference parentReference, boolean failIfNotFound)
{
    NodeRef fParentRef;
    if (path == null || path.length() == 0)
    {
        fParentRef = parentReference.execute(new GetActualNodeRefMethod(env));
    }
    else
    {
        String[] pathElements = NodeRefPathExpression.splitAndNormalizePath(path);
        for (int i = 0; i < pathElements.length; i++)
        {
            pathElements[i] = ISO9075.decode(pathElements[i]);
        }
        fParentRef = env.findQNamePath(pathElements);
    }

    boolean noReadPermissions = false;
    if (fParentRef != null && !env.hasPermission(fParentRef,
                                                 PermissionService.READ_PERMISSIONS))
    {
        fParentRef = null;
        noReadPermissions = true;
    }
    if (logger.isDebugEnabled())
    {
        if (fParentRef == null)
        {
            if (noReadPermissions)
            {
                logger.debug("Current user does not have READ_PERMISSIONS for filing path" + path + ".");
            }
            else
            {
                logger.debug("The filing path " + path + " doesn't exist.");
            }
        }
    }
    if (failIfNotFound && fParentRef == null)
    {
        throw new VirtualizationException("The filing path " + path + " could not be resolved.");
    }

    return fParentRef;
}
 
Example 8
Source File: SearcherComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tests the <b>like</b> and <b>contains</b> functions (FTS functions) within a currently executing transaction
 */
public void xtestLikeAndContains() throws Exception
{
    Map<QName, ChildAssociationRef> assocRefs = BaseNodeServiceTest.buildNodeGraph(nodeService, rootNodeRef);

    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    properties.put(QName.createQName(BaseNodeServiceTest.NAMESPACE, COMPLEX_LOCAL_NAME), "monkey");
    QName qnamerequiringescaping = QName.createQName(BaseNodeServiceTest.NAMESPACE, COMPLEX_LOCAL_NAME);
    nodeService.createNode(rootNodeRef, BaseNodeServiceTest.ASSOC_TYPE_QNAME_TEST_CHILDREN, qnamerequiringescaping,
            ContentModel.TYPE_CONTAINER, properties);

    // commit the node graph
    txn.commit();

    txn = transactionService.getUserTransaction();
    txn.begin();

    DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(null);
    namespacePrefixResolver.registerNamespace(BaseNodeServiceTest.TEST_PREFIX, BaseNodeServiceTest.NAMESPACE);

    List<NodeRef> answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:animal, 'm__k%', false)]", null,
            namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    System.out.println("Encoded = "+ISO9075.encode(COMPLEX_LOCAL_NAME));
    String roundTrip = ISO9075.decode(ISO9075.encode(COMPLEX_LOCAL_NAME));
    for(int i = 0; i < COMPLEX_LOCAL_NAME.length() && 1 < roundTrip.length(); i++)
    {
        System.out.println("Char at "+i+" = "+Integer.toHexString(COMPLEX_LOCAL_NAME.charAt(i))+ "   ...    "+Integer.toHexString(roundTrip.charAt(i)));
    }

    assertEquals( COMPLEX_LOCAL_NAME, roundTrip);

    answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:"
            + ISO9075.encode(COMPLEX_LOCAL_NAME) + ", 'm__k%', false)]", null, namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:animal, 'M__K%', false)]", null,
            namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:"
            + ISO9075.encode(COMPLEX_LOCAL_NAME) + ", 'M__K%', false)]", null, namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:UPPERANIMAL, 'm__k%', false)]", null,
            namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:UPPERANIMAL, 'M__K%', false)]", null,
            namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:UPPERANIMAL, 'M__K%', true)]", null,
            namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[contains('monkey')]", null, namespacePrefixResolver, false);
    assertEquals(2, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[contains('MONKEY')]", null, namespacePrefixResolver, false);
    assertEquals(2, answer.size());

    answer = searcher.selectNodes(rootNodeRef, "//*[contains(lower-case('MONKEY'))]", null,
            namespacePrefixResolver, false);
    assertEquals(2, answer.size());

    // select the monkey node in the second level
    QueryParameterDefinition[] paramDefs = new QueryParameterDefinition[2];
    paramDefs[0] = new QueryParameterDefImpl(QName.createQName("test:animal", namespacePrefixResolver),
            dictionaryService.getDataType(DataTypeDefinition.TEXT), true, "monkey%");
    paramDefs[1] = new QueryParameterDefImpl(QName.createQName("test:type", namespacePrefixResolver),
            dictionaryService.getDataType(DataTypeDefinition.TEXT), true,
            BaseNodeServiceTest.TYPE_QNAME_TEST_CONTENT.toString());
    answer = searcher.selectNodes(rootNodeRef,
            "./*/*[like(@test:animal, $test:animal, false) or subtypeOf($test:type)]", paramDefs,
            namespacePrefixResolver, false);
    assertEquals(1, answer.size());

    // select the monkey node again, but use the first level as the starting poing
    NodeRef n1Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "root_p_n1")).getChildRef();
    NodeRef n3Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n1_p_n3")).getChildRef();
    // first time go too deep
    answer = searcher.selectNodes(n1Ref, "./*/*[like(@test:animal, $test:animal, false) or subtypeOf($test:type)]",
            paramDefs, namespacePrefixResolver, false);
    assertEquals(0, answer.size());
    // second time get it right
    answer = searcher.selectNodes(n1Ref, "./*[like(@test:animal, $test:animal, false) or subtypeOf($test:type)]",
            paramDefs, namespacePrefixResolver, false);
    assertEquals(1, answer.size());
    assertFalse("Incorrect result: search root node pulled back", answer.contains(n1Ref));
    assertTrue("Incorrect result: incorrect node retrieved", answer.contains(n3Ref));
}
 
Example 9
Source File: FTSQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
static private String getText(Tree node, boolean returnTextFromUnknownNodes)
{
    String text = node.getText();
    int index;
    switch (node.getType())
    {
    case FTSParser.FTSWORD:
    case FTSParser.FTSPRE:
    case FTSParser.FTSWILD:
        index = text.indexOf('\\');
        if (index == -1)
        {
            return text;
        }
        else
        {
            return unescape(text);
        }
    case FTSParser.FTSPHRASE:
        String phrase = text.substring(1, text.length() - 1);
        index = phrase.indexOf('\\');
        if (index == -1)
        {
            return phrase;
        }
        else
        {
            return unescape(phrase);
        }
    case FTSParser.ID:
        index = text.indexOf('\\');
        if (index == -1)
        {
            return ISO9075.decode(text);
        }
        else
        {
            return ISO9075.decode(unescape(text));
        }
    case FTSParser.URI:
    case FTSParser.OR:
    case FTSParser.AND:
    case FTSParser.NOT:
    case FTSParser.TILDA:
    case FTSParser.PLUS:
    case FTSParser.MINUS:
    case FTSParser.COLON:
    case FTSParser.STAR:
    case FTSParser.DOTDOT:
    case FTSParser.DOT:
    case FTSParser.AMP:
    case FTSParser.EXCLAMATION:
    case FTSParser.BAR:
    case FTSParser.EQUALS:
    case FTSParser.QUESTION_MARK:
    case FTSParser.TO:
    case FTSParser.COMMA:
    case FTSParser.CARAT:
    case FTSParser.DOLLAR:
    case FTSParser.AT:
    case FTSParser.PERCENT:
    case FTSParser.DECIMAL_INTEGER_LITERAL:
    case FTSParser.FLOATING_POINT_LITERAL:
    case FTSParser.DATETIME:
        return text;
    default:
        if(returnTextFromUnknownNodes)
        {
            return text;
        }
        else
        {
            return "";
        }
    }
}
 
Example 10
Source File: NodeBrowserPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the current node primary path
 * 
 * @return primary path
 */
public String getPrimaryPath(NodeRef nodeRef)
{
    Path primaryPath = getNodeService().getPath(nodeRef);
    return ISO9075.decode(primaryPath.toString());
}
 
Example 11
Source File: NodeBrowserPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the current node primary path
 * 
 * @return primary path
 */
public String getPrimaryPrefixedPath(NodeRef nodeRef)
{
    Path primaryPath = getNodeService().getPath(nodeRef);
    return ISO9075.decode(primaryPath.toPrefixString(getNamespaceService()));
}
 
Example 12
Source File: Search.java    From alfresco-repository with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Decode a string from ISO9075
 * 
 * @param s     Value to decode
 * 
 * @return decoded value
 */
public String ISO9075Decode(String s)
{
    return ISO9075.decode(s);
}