What is the property corresponding to vanity URL?

  Written by The Jahia Team
 
Developers
   Estimated reading time:
7.1.1.0

What is the property corresponding to vanity URL?

Answer

This is the property j:url of a jnt:vanityUrl content type.

The content could be retrieved with the JCR SQL-2 select as below:

SELECT * FROM [jnt:vanityUrl] WHERE ISDESCENDANTNODE('/sites/mySite')

Here is a Groovy script showing the access to this property:

import org.jahia.api.Constants
import org.jahia.tools.patches.LoggerWrapper
import org.jahia.services.content.JCRCallback
import org.jahia.services.content.JCRNodeWrapper
import org.jahia.services.content.JCRSessionWrapper
import org.jahia.services.content.JCRTemplate
import org.jahia.services.content.JCRPublicationService

import javax.jcr.NodeIterator
import javax.jcr.RepositoryException
import javax.jcr.query.Query

final LoggerWrapper logger = log

final String nodeTypeName = "jnt:vanityUrl"
final String jUrl = "j:url"


JCRTemplate.getInstance().doExecuteWithSystemSession(null, Constants.EDIT_WORKSPACE, new JCRCallback() {
    @Override
    Object doInJCR(JCRSessionWrapper session) throws RepositoryException {

        final String stmt = "SELECT * FROM [" + nodeTypeName + "] WHERE ISDESCENDANTNODE(&#quot;/sites/mySiteunine&#quot;)"
        final NodeIterator iteratorSites = session.getWorkspace().getQueryManager().createQuery(stmt, Query.JCR_SQL2).execute().getNodes()
        while (iteratorSites.hasNext()) {
            JCRNodeWrapper node = iteratorSites.nextNode() as JCRNodeWrapper
            urlFound = node.getPropertyAsString(jUrl)
            log.info("SEO URL: "+urlFound)
        }
        return null
    }
})